7#include "nlohmann/json.hpp"
17std::filesystem::path artifacts_file(
const std::filesystem::path &project_root,
const std::string &tileset_name)
19 return project_root /
"porytiles" /
"tilesets" / tileset_name /
"tileset-manifest.json";
22[[nodiscard]]
bool is_porytiles_managed_callback(
const std::optional<std::string> &callback)
24 if (!callback.has_value()) {
32 const std::string &tileset_name,
33 const std::string &bin_path_base,
34 std::size_t attribute_bytes)
40 "Failed to append graphics INCBIN declarations for '{}'.",
47 "Failed to append metatiles INCBIN declarations for '{}'.",
59 const auto input_path = artifacts_file(project_root_, tileset_name);
61 if (!std::filesystem::exists(input_path)) {
65 std::ifstream file{input_path};
66 nlohmann::json json_data;
69 const auto version = json_data[
"version"].get<std::uint32_t>();
70 const auto imported = json_data[
"imported"].get<
bool>();
75 json_data[
".tiles"].get<std::string>(),
76 json_data[
".palettes"].get<std::string>(),
77 json_data[
".metatiles"].get<std::string>(),
78 json_data[
".metatileAttributes"].get<std::string>(),
79 json_data[
".callback"].get<std::string>()};
87 const auto manifest_file = artifacts_file(project_root_, tileset_name);
88 std::filesystem::create_directories(manifest_file.parent_path());
89 std::ofstream file{manifest_file};
91 nlohmann::json json_data;
92 json_data[
"version"] = artifacts.
version();
93 json_data[
"imported"] = artifacts.
imported();
96 json_data[
".tiles"] = artifacts.
tiles();
97 json_data[
".palettes"] = artifacts.
palettes();
98 json_data[
".metatiles"] = artifacts.
metatiles();
100 json_data[
".callback"] = artifacts.
callback();
103 file << json_data.dump(2);
109 return std::filesystem::exists(artifacts_file(project_root_, tileset_name));
119 "Failed to read metadata for tileset '{}'.",
123 constexpr std::uint32_t version = 1;
124 const std::optional<std::string> original_callback_value = metadata.callback_func();
128 metadata.tiles_var(),
129 metadata.palettes_var(),
130 metadata.metatiles_var(),
131 metadata.metatile_attributes_var(),
132 original_callback_value.value_or(
"NULL")};
135 write(tileset_name, artifacts);
138 const bool is_secondary = metadata.is_secondary();
145 "Failed to get tileset bin path config for '{}'.",
150 append_incbin_declarations(incbin_appender_, tileset_name, bin_path_base, declaration_attribute_bytes_);
151 if (!incbin_result.has_value()) {
152 return incbin_result;
167 "Failed to create tileset struct in headers.h for '{}'.",
174 constexpr std::uint32_t version = 1;
183 "Failed to get tileset bin path config for '{}'.",
188 append_incbin_declarations(incbin_appender_, tileset_name, bin_path_base, declaration_attribute_bytes_);
189 if (!incbin_result.has_value()) {
190 return incbin_result;
204 "Failed to get wire_anim_code config for '{}'.",
208 std::vector<std::string> remark_text;
209 remark_text.emplace_back(
"Config 'tileset.animations.wire_anim_code' is false, removing any existing wiring.");
210 remark_text.emplace_back(
"");
211 remark_text.append_range(should_wire.prettify(diag_->
formatter()));
212 diag_->
remark(
"wire-tileset-animation", remark_text);
220 "Failed to wire tileset_anims include/declaration for '{}'.",
230 "Failed to update callback in headers.h for '{}'.",
243 "Failed to remove animation includes for '{}'.",
252 "Failed to read metadata for '{}'.",
255 const auto ¤t_callback = metadata.callback_func();
256 if (is_porytiles_managed_callback(current_callback)) {
260 "Failed to update callback to NULL for '{}'.",
#define PT_TRY_ASSIGN_CHAIN_ERR(var, expr, return_type,...)
Unwraps a ChainableResult, chaining a new error message on failure.
#define PT_TRY_CALL_CHAIN_ERR(expr, return_type,...)
Unwraps a void ChainableResult, chaining a new error message on failure.
A result type that maintains a chainable sequence of errors for debugging and error reporting.
Appends INCBIN declarations for Porytiles-managed tileset assets.
ChainableResult< void > append_graphics_declarations(const std::string &tileset_name, const std::string &bin_path_base, std::size_t num_palettes) const
Appends INCBIN declarations for a Porytiles-managed tileset to graphics.h.
ChainableResult< void > append_metatiles_declarations(const std::string &tileset_name, const std::string &bin_path_base, std::size_t attribute_bytes) const
Appends INCBIN declarations for a Porytiles-managed tileset to metatiles.h.
ChainableResult< ConfigValue< std::string > > tileset_paths_secondary_bin(ConfigScopeType type, const std::string &scope) const
ChainableResult< ConfigValue< std::string > > tileset_paths_primary_bin(ConfigScopeType type, const std::string &scope) const
ChainableResult< ConfigValue< bool > > tileset_animations_wire_anim_code(ConfigScopeType type, const std::string &scope) const
void write(const std::string &tileset_name, const TilesetManifest &artifacts) const
Writes an TilesetManifest object to the porytiles utility directory.
ChainableResult< void > persist_managed_new(const std::string &tileset_name, bool is_secondary=false) const override
Persists managed state for a new tileset.
ChainableResult< TilesetManifest > read(const std::string &tileset_name) const
Reads an TilesetManifest object from the porytiles utility directory.
ChainableResult< void > persist_managed_existing(const std::string &tileset_name) const override
Persists managed state for an existing tileset.
ChainableResult< void > remove_wired_anim_code(const std::string &tileset_name, bool is_secondary) const override
Removes wired animation code for a tileset from the project.
ChainableResult< void > wire_anim_code(const std::string &tileset_name, bool is_secondary) const override
Wires animation code for a tileset that already has its manifest persisted.
bool is_porytiles_managed(const std::string &tileset_name) const override
Checks whether a tileset has an tileset-manifest.json file.
ChainableResult< void > wire_include_for_tileset(const std::string &tileset_name, bool is_secondary) const
Adds an #include directive for the tileset's generated animation code.
ChainableResult< void > remove_include_for_tileset(const std::string &tileset_name, bool is_secondary) const
Removes the #include directive for the tileset's generated animation code.
static const Style bold
Bold text formatting.
Stores manifest metadata for Porytiles-managed tilesets.
static TilesetManifest for_created_tileset(std::uint32_t version)
Creates a TilesetManifest for a tileset created from scratch by Porytiles.
bool imported() const
Returns whether this tileset was imported from vanilla pokeemerald.
const std::string & callback() const
Returns the original .callback field value.
const std::string & tiles() const
Returns the original .tiles field value.
const std::string & metatile_attributes() const
Returns the original .metatileAttributes field value.
std::uint32_t version() const
Returns the schema version for format migration support.
const std::string & palettes() const
Returns the original .palettes field value.
const std::string & metatiles() const
Returns the original .metatiles field value.
virtual void remark(const std::string &tag, const std::vector< std::string > &lines) const =0
Display a tagged remark message.
const TextFormatter & formatter() const
std::string managed_callback_name(const std::string &tileset_name)
constexpr std::string_view porytiles_managed_callback_prefix
constexpr std::size_t num_palettes
@ tileset
Configuration scoped to a specific tileset.