Porytiles
Loading...
Searching...
No Matches
porytiles::IncbinDeclarationAppender Class Reference

Appends INCBIN declarations for Porytiles-managed tileset assets. More...

#include <incbin_declaration_appender.hpp>

Public Member Functions

 IncbinDeclarationAppender (std::filesystem::path project_root, gsl::not_null< const TextFormatter * > format)
 Constructs an IncbinDeclarationAppender with required dependencies.
 
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< void > remove_declarations (const std::string &tileset_name) const
 Removes INCBIN declarations for a Porytiles-managed tileset (for restore workflow).
 

Detailed Description

Appends INCBIN declarations for Porytiles-managed tileset assets.

This service adds new INCBIN array declarations to pokeemerald's graphics.h and metatiles.h files for Porytiles-managed tilesets. The declarations follow the naming convention gTilesetTiles_PorytilesManaged_{Shorthand} and point to deterministic paths in the porytiles_bin/ directory.

The service uses a parse-modify-write pattern to surgically append declarations without disrupting existing file content.

Appends are idempotent: any existing managed declarations for the tileset are removed before fresh ones are written.

See also
ProjectTilesetMetadataWriter for the pattern used for surgical file edits

Definition at line 29 of file incbin_declaration_appender.hpp.

Constructor & Destructor Documentation

◆ IncbinDeclarationAppender()

porytiles::IncbinDeclarationAppender::IncbinDeclarationAppender ( std::filesystem::path  project_root,
gsl::not_null< const TextFormatter * >  format 
)

Constructs an IncbinDeclarationAppender with required dependencies.

Parameters
project_rootPath to the pokeemerald project root directory
formatFormatter for styled error messages (non-owning, must outlive this object)

Definition at line 235 of file incbin_declaration_appender.cpp.

Member Function Documentation

◆ append_graphics_declarations()

ChainableResult< void > porytiles::IncbinDeclarationAppender::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.

Adds declarations for tiles and palettes:

  • gTilesetTiles_PorytilesManaged_{Shorthand} pointing to porytiles_bin/tiles.4bpp.lz
  • gTilesetPalettes_PorytilesManaged_{Shorthand} pointing to porytiles_bin/palettes/x.gbapal

The paths are constructed using the provided bin_path_base and tileset shorthand.

This is an idempotent operation. Any existing managed declarations for the tileset are removed first, then fresh ones are written after the last non-blank line, which is always at preprocessor conditional depth 0. This self-heals declarations previously misplaced inside a trailing preprocessor conditional, such as the #if IS_FRLG block at the end of pokeemerald-expansion's graphics.h.

Parameters
tileset_nameThe tileset name (e.g., "gTileset_General")
bin_path_baseThe base path for binary assets (e.g., "data/tilesets/primary")
num_palettesNumber of palette files to include (typically 6 for primary, 13 for secondary)
Precondition
tileset_name must start with "gTileset_"
Postcondition
Exactly one tiles and one palettes declaration for the tileset exist in graphics.h.
Returns
Success or error result with details

Definition at line 241 of file incbin_declaration_appender.cpp.

◆ append_metatiles_declarations()

ChainableResult< void > porytiles::IncbinDeclarationAppender::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.

Adds declarations for metatiles and attributes:

  • gMetatiles_PorytilesManaged_{Shorthand} pointing to porytiles_bin/metatiles.bin
  • gMetatileAttributes_PorytilesManaged_{Shorthand} pointing to porytiles_bin/metatile_attributes.bin

The attribute declaration uses const u16 / INCBIN_U16 when attribute_bytes is 2, or const u32 / INCBIN_U32 when attribute_bytes is 4.

This is an idempotent upsert. Any existing managed declarations for the tileset are removed first, then fresh ones are written after the last non-blank line, which is always at preprocessor conditional depth 0. This self-heals declarations previously misplaced inside a trailing preprocessor conditional, such as the #if !IS_FRLG ... #else ... #endif block at the end of pokeemerald-expansion's metatiles.h.

Parameters
tileset_nameThe tileset name (e.g., "gTileset_General")
bin_path_baseThe base path for binary assets (e.g., "data/tilesets/primary")
attribute_bytesThe size in bytes of each metatile attribute entry (2 or 4)
Precondition
tileset_name must start with "gTileset_"
attribute_bytes must be 2 or 4
Postcondition
Exactly one metatiles and one attributes declaration for the tileset exist in metatiles.h.
Returns
Success or error result with details

Definition at line 280 of file incbin_declaration_appender.cpp.

◆ remove_declarations()

ChainableResult< void > porytiles::IncbinDeclarationAppender::remove_declarations ( const std::string &  tileset_name) const

Removes INCBIN declarations for a Porytiles-managed tileset (for restore workflow).

Removes all declarations matching *_PorytilesManaged_{Shorthand} pattern from both graphics.h and metatiles.h.

Parameters
tileset_nameThe tileset name (e.g., "gTileset_General")
Precondition
tileset_name must start with "gTileset_"
Returns
Success or error result with details

Definition at line 319 of file incbin_declaration_appender.cpp.


The documentation for this class was generated from the following files: