39 auto bottom_png_key = key_provider_->
key_for(tileset.
name(), bottom_png_artifact);
40 if (
auto result = writer_->
write(bottom_png_key, bottom_png_artifact, tileset); !result.has_value()) {
47 auto middle_png_key = key_provider_->
key_for(tileset.
name(), middle_png_artifact);
48 if (
auto result = writer_->
write(middle_png_key, middle_png_artifact, tileset); !result.has_value()) {
55 auto top_png_key = key_provider_->
key_for(tileset.
name(), top_png_artifact);
56 if (
auto result = writer_->
write(top_png_key, top_png_artifact, tileset); !result.has_value()) {
63 auto attr_csv_key = key_provider_->
key_for(tileset.
name(), attr_csv_artifact);
64 if (
auto result = writer_->
write(attr_csv_key, attr_csv_artifact, tileset); !result.has_value()) {
74 auto metatiles_key = key_provider_->
key_for(tileset.
name(), metatiles_artifact);
75 if (
auto result = writer_->
write(metatiles_key, metatiles_artifact, tileset); !result.has_value()) {
82 auto attr_key = key_provider_->
key_for(tileset.
name(), attr_artifact);
83 if (
auto result = writer_->
write(attr_key, attr_artifact, tileset); !result.has_value()) {
90 auto tiles_png_key = key_provider_->
key_for(tileset.
name(), tiles_png_artifact);
91 if (
auto result = writer_->
write(tiles_png_key, tiles_png_artifact, tileset); !result.has_value()) {
100 if (
auto result = writer_->
write(pal_key,
TilesetArtifact{pal_n, i}, tileset); !result.has_value()) {
108 if (
auto result = writer_->
commit(); !result.has_value()) {
126 if (!cache_result.has_value()) {
137 bool fail_at_exit =
false;
144 auto porytiles_component = std::make_unique<PorytilesTilesetComponent>();
145 auto porymap_component = std::make_unique<PorymapTilesetComponent>();
146 auto tileset = std::make_unique<Tileset>(name, std::move(porytiles_component), std::move(porymap_component));
151 const auto bottom_png_key = key_provider_->
key_for(tileset->name(), bottom_png_artifact);
153 const auto result = reader_->
read(*tileset, bottom_png_key, bottom_png_artifact);
154 if (!result.has_value()) {
160 const auto middle_png_key = key_provider_->
key_for(tileset->name(), middle_png_artifact);
162 const auto result = reader_->
read(*tileset, middle_png_key, middle_png_artifact);
163 if (!result.has_value()) {
169 const auto top_png_key = key_provider_->
key_for(tileset->name(), top_png_artifact);
171 const auto result = reader_->
read(*tileset, top_png_key, top_png_artifact);
172 if (!result.has_value()) {
178 const auto attr_csv_key = key_provider_->
key_for(tileset->name(), attr_csv_artifact);
180 const auto result = reader_->
read(*tileset, attr_csv_key, attr_csv_artifact);
181 if (!result.has_value()) {
192 const auto result = reader_->
read(*tileset, override_key,
TilesetArtifact{pal_override_n, i});
193 if (!result.has_value()) {
195 FormattableError{fmt::format(
"failed to read {}", override_key.key())}, result};
201 for (
const auto &anim : porytiles_anims) {
203 auto frame_00_key = key_provider_->
key_for(tileset->name(),
TilesetArtifact{porytiles_anim_frame, anim, 0});
209 const auto frame_00_result =
211 if (!frame_00_result.has_value()) {
213 FormattableError{fmt::format(
"failed to read {}", frame_00_key.key())}, frame_00_result};
218 int expected_frame = 1;
219 for (
const auto frame : frames) {
220 if (frame != expected_frame) {
226 const auto frame_n_result =
228 if (!frame_n_result.has_value()) {
230 FormattableError{fmt::format(
"failed to read {}", frame_n_key.key())}, frame_n_result};
239 const auto metatiles_key = key_provider_->
key_for(tileset->name(), metatiles_artifact);
243 const auto metatiles_result = reader_->
read(*tileset, metatiles_key, metatiles_artifact);
244 if (!metatiles_result.has_value()) {
250 const auto attr_key = key_provider_->
key_for(tileset->name(), attr_artifact);
252 return FormattableError{
"missing required porymap artifact metatile_attributes.bin"};
254 const auto attr_result = reader_->
read(*tileset, attr_key, attr_artifact);
255 if (!attr_result.has_value()) {
261 const auto tiles_png_key = key_provider_->
key_for(tileset->name(), tiles_png_artifact);
265 const auto tiles_png_result = reader_->
read(*tileset, tiles_png_key, tiles_png_artifact);
266 if (!tiles_png_result.has_value()) {
279 if (!pal_result.has_value()) {
281 FormattableError{fmt::format(
"failed to read {}", pal_key.key())}, pal_result};
286 const auto &anim : porymap_anims) {
288 auto frame_00_key = key_provider_->
key_for(tileset->name(),
TilesetArtifact{porymap_anim_frame, anim, 0});
294 const auto frame_00_result =
296 if (!frame_00_result.has_value()) {
298 FormattableError{fmt::format(
"failed to read {}", frame_00_key.key())}, frame_00_result};
303 int expected_frame = 1;
304 for (
const auto frame : frames) {
305 if (frame != expected_frame) {
311 const auto frame_n_result =
313 if (!frame_n_result.has_value()) {
315 FormattableError{fmt::format(
"failed to read {}", frame_n_key.key())}, frame_n_result};
virtual std::unordered_map< ArtifactKey, std::string > compute_tileset_artifact_checksums(const std::string &tileset_name) const =0
Computes checksums for the artifacts that belong to the given Tileset.
virtual Result< void > cache_tileset_checksums(const std::string &tileset_name, const std::unordered_map< ArtifactKey, std::string > &checksums) const =0
Caches checksums for the given Tileset to persistent storage.
A result type that maintains a chainable sequence of errors for debugging and error reporting.
virtual std::set< int > discover_porytiles_anim_frames(const std::string &tileset_name, const std::string &anim_name) const =0
Discovers the frame indices for a specific Porytiles animation.
virtual ArtifactKey key_for(const std::string &tileset_name, const TilesetArtifact &artifact) const =0
Constructs a key for a given tileset artifact.
virtual bool artifact_exists(const ArtifactKey &key) const =0
Checks whether an artifact exists in the backing store for the given key.
virtual std::set< int > discover_porymap_anim_frames(const std::string &tileset_name, const std::string &anim_name) const =0
Discovers the frame indices for a specific Porymap animation.
virtual bool tileset_exists(const std::string &tileset_name) const =0
Checks whether a tileset exists in the backing store for the given tileset name.
virtual std::set< std::string > discover_porymap_anims(const std::string &tileset_name) const =0
Discovers the names of all Porymap animations available for a tileset.
virtual std::set< std::string > discover_porytiles_anims(const std::string &tileset_name) const =0
Discovers the names of all Porytiles animations available for a tileset.
virtual ChainableResult< void > read(Tileset &dest, const ArtifactKey &src_key, const TilesetArtifact &artifact) const =0
Reads an artifact from the backing store and updates the target Tileset.
virtual Result< void > rollback()=0
Rolls back all buffered write operations in the current transaction.
virtual ChainableResult< void > write(const ArtifactKey &dest_key, const TilesetArtifact &artifact, const Tileset &src)=0
Writes an artifact from a Tileset to the backing store.
virtual ChainableResult< void > commit()=0
Commits all buffered write operations in the current transaction.
virtual Result< void > begin_transaction()=0
Begins a new transaction for atomic write operations.
Represents a Pokémon Generation III decomp tileset artifact with type and optional metadata.
Type
Enumeration of all supported tileset artifact types.
ChainableResult< void > save(const Tileset &tileset) const
Persists a given Tileset and caches new artifact checksums.
bool exists(const std::string &name) const
Checks if the given Tileset exists in the backing store.
ChainableResult< std::unique_ptr< Tileset > > load(const std::string &name) const
Loads an existing Tileset from storage.
A complete tileset containing both Porytiles and Porymap components.
const std::string & name() const
constexpr std::size_t num_pals
@ bold
Bold text formatting.