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

Provides surgical update capability for tileset metadata in headers.h files. More...

#include <project_tileset_metadata_writer.hpp>

Public Member Functions

 ProjectTilesetMetadataWriter (std::filesystem::path project_root, gsl::not_null< const TextFormatter * > format)
 
ChainableResult< void > update_callback (const std::string &tileset_name, const std::string &new_callback_value) const
 Updates the .callback field for a specific tileset.
 
ChainableResult< void > update_fields (const std::string &tileset_name, const std::map< std::string, std::string > &field_updates) const
 Updates multiple fields for a specific tileset in headers.h.
 
ChainableResult< void > update_to_porytiles_managed (const std::string &tileset_name) const
 Updates asset fields to Porytiles-managed values.
 
ChainableResult< void > create_tileset_struct (const std::string &tileset_name, bool is_secondary) const
 Creates a new tileset struct and appends it to headers.h.
 

Detailed Description

Provides surgical update capability for tileset metadata in headers.h files.

This class enables targeted modifications to specific fields within tileset struct declarations in pokeemerald headers.h files. Unlike a full rewrite approach, it performs surgical line-level edits to preserve formatting, comments, and other content in the file.

Supports updating any field in the Tileset struct, including .tiles, .palettes, .metatiles, .metatileAttributes, and .callback.

Definition at line 25 of file project_tileset_metadata_writer.hpp.

Constructor & Destructor Documentation

◆ ProjectTilesetMetadataWriter()

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

Definition at line 29 of file project_tileset_metadata_writer.cpp.

Member Function Documentation

◆ create_tileset_struct()

ChainableResult< void > porytiles::ProjectTilesetMetadataWriter::create_tileset_struct ( const std::string &  tileset_name,
bool  is_secondary 
) const

Creates a new tileset struct and appends it to headers.h.

Generates a complete Tileset struct with Porytiles-managed field values and appends it to the end of headers.h. The struct uses the standard pokeemerald format:

const struct Tileset gTileset_MyTileset =
{
.isCompressed = TRUE,
.isSecondary = FALSE,
.tiles = gTilesetTiles_PorytilesManaged_MyTileset,
.palettes = gTilesetPalettes_PorytilesManaged_MyTileset,
.metatiles = gMetatiles_PorytilesManaged_MyTileset,
.metatileAttributes = gMetatileAttributes_PorytilesManaged_MyTileset,
.callback = NULL,
};
A complete tileset containing both Porytiles and Porymap components.
Definition tileset.hpp:14
Parameters
tileset_nameThe tileset name (e.g., "gTileset_MyTileset")
is_secondaryIf true, sets .isSecondary = TRUE; if false, sets .isSecondary = FALSE
Precondition
tileset_name must start with "gTileset_"
tileset_name must not already exist in headers.h
Returns
Success or error result with details
Postcondition
A new tileset struct exists at the end of headers.h

Definition at line 146 of file project_tileset_metadata_writer.cpp.

◆ update_callback()

ChainableResult< void > porytiles::ProjectTilesetMetadataWriter::update_callback ( const std::string &  tileset_name,
const std::string &  new_callback_value 
) const

Updates the .callback field for a specific tileset.

Locates the tileset struct by name in headers.h and surgically replaces the .callback field value. The new value is written exactly as provided - callers should pass either "NULL" or "InitTilesetAnim_<name>" format.

Parameters
tileset_nameThe tileset name (e.g., "gTileset_General") - must match exactly
new_callback_valueThe exact value to write (e.g., "InitTilesetAnim_General" or "NULL")
Precondition
tileset_name must correspond to an existing tileset in headers.h
new_callback_value must be a valid C identifier or "NULL"
Returns
Success or error result with details

Definition at line 35 of file project_tileset_metadata_writer.cpp.

◆ update_fields()

ChainableResult< void > porytiles::ProjectTilesetMetadataWriter::update_fields ( const std::string &  tileset_name,
const std::map< std::string, std::string > &  field_updates 
) const

Updates multiple fields for a specific tileset in headers.h.

Locates the tileset struct by name and surgically replaces specified field values. All updates are performed in a single parse-modify-write cycle for efficiency. Field names should be provided WITHOUT the leading dot (e.g., "tiles" not ".tiles").

Parameters
tileset_nameThe tileset name (e.g., "gTileset_General") - must match exactly
field_updatesMap of field names to new values
Precondition
tileset_name must correspond to an existing tileset in headers.h
All field names in field_updates must exist in the tileset struct
Returns
Success or error result with details

Definition at line 41 of file project_tileset_metadata_writer.cpp.

◆ update_to_porytiles_managed()

ChainableResult< void > porytiles::ProjectTilesetMetadataWriter::update_to_porytiles_managed ( const std::string &  tileset_name) const

Updates asset fields to Porytiles-managed values.

Generates new field values using the "PorytilesManaged" naming convention:

  • .tiles = gTilesetTiles_PorytilesManaged_{Shorthand}
  • .palettes = gTilesetPalettes_PorytilesManaged_{Shorthand}
  • .metatiles = gMetatiles_PorytilesManaged_{Shorthand}
  • .metatileAttributes = gMetatileAttributes_PorytilesManaged_{Shorthand}
Parameters
tileset_nameThe tileset name (e.g., "gTileset_General")
Precondition
tileset_name must start with "gTileset_"
tileset_name must correspond to an existing tileset in headers.h
Returns
Success or error result with details

Definition at line 124 of file project_tileset_metadata_writer.cpp.


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