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

Manages Porytiles-owned tilesets via TilesetManifest JSON files. More...

#include <project_porytiles_tileset_manager.hpp>

Inheritance diagram for porytiles::ProjectPorytilesTilesetManager:
[legend]
Collaboration diagram for porytiles::ProjectPorytilesTilesetManager:
[legend]

Public Member Functions

 ProjectPorytilesTilesetManager (std::filesystem::path project_root, const ProjectTilesetMetadataProvider *metadata_provider, const ProjectTilesetMetadataWriter *metadata_writer, const InfraConfig *infra_config, gsl::not_null< const UserDiagnostics * > diag, const IncbinDeclarationAppender *incbin_appender, const ProjectTilesetAnimsModifier *tileset_anims_modifier)
 Constructs a ProjectPorytilesTilesetManager with required dependencies.
 
ChainableResult< TilesetManifestread (const std::string &tileset_name) const
 Reads an TilesetManifest object from the porytiles utility directory.
 
void write (const std::string &tileset_name, const TilesetManifest &artifacts) const
 Writes an TilesetManifest object to the porytiles utility directory.
 
bool is_porytiles_managed (const std::string &tileset_name) const override
 Checks whether a tileset has an tileset-manifest.json file.
 
ChainableResult< void > persist_managed_existing (const std::string &tileset_name) const override
 Persists managed state for an existing tileset.
 
ChainableResult< void > persist_managed_new (const std::string &tileset_name, bool is_secondary=false) const override
 Persists managed state for a new tileset.
 
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.
 
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.
 
- Public Member Functions inherited from porytiles::PorytilesTilesetManager
virtual ~PorytilesTilesetManager ()=default
 

Detailed Description

Manages Porytiles-owned tilesets via TilesetManifest JSON files.

This class serializes and deserializes tileset-manifest.json files in the porytiles/tilesets/{tileset_name}/ directory. The presence of this file indicates that a tileset is Porytiles-managed.

The JSON format varies based on whether the tileset was imported from vanilla pokeemerald:

  • Imported tilesets: All original field values are stored for restoration support
  • Created tilesets: Only version and imported flag are stored
See also
TilesetManifest for the model class
PorytilesTilesetManager for the abstract interface

Definition at line 31 of file project_porytiles_tileset_manager.hpp.

Constructor & Destructor Documentation

◆ ProjectPorytilesTilesetManager()

porytiles::ProjectPorytilesTilesetManager::ProjectPorytilesTilesetManager ( std::filesystem::path  project_root,
const ProjectTilesetMetadataProvider metadata_provider,
const ProjectTilesetMetadataWriter metadata_writer,
const InfraConfig infra_config,
gsl::not_null< const UserDiagnostics * >  diag,
const IncbinDeclarationAppender incbin_appender,
const ProjectTilesetAnimsModifier tileset_anims_modifier 
)
inline

Constructs a ProjectPorytilesTilesetManager with required dependencies.

Parameters
project_rootPath to the pokeemerald project root directory
metadata_providerProvider for reading headers.h fields
metadata_writerWriter for updating headers.h fields
infra_configConfiguration provider for tileset paths and animation settings
diagDiagnostics interface for warnings/notes
incbin_appenderService for appending INCBIN declarations to header files
tileset_anims_modifierService for modifying tileset_anims.c includes

Definition at line 44 of file project_porytiles_tileset_manager.hpp.

Member Function Documentation

◆ is_porytiles_managed()

bool porytiles::ProjectPorytilesTilesetManager::is_porytiles_managed ( const std::string &  tileset_name) const
overridevirtual

Checks whether a tileset has an tileset-manifest.json file.

This is the canonical way to check if a tileset is Porytiles-managed.

Parameters
tileset_nameThe name of the tileset (e.g., "gTileset_General")
Returns
true if the tileset has an tileset-manifest.json file

Implements porytiles::PorytilesTilesetManager.

Definition at line 109 of file project_porytiles_tileset_manager.cpp.

◆ persist_managed_existing()

ChainableResult< void > porytiles::ProjectPorytilesTilesetManager::persist_managed_existing ( const std::string &  tileset_name) const
overridevirtual

Persists managed state for an existing tileset.

Used when an existing tileset in headers.h is being converted to Porytiles-managed. The implementation reads original field values from headers.h and stores them in the tileset manifest for potential restoration later.

Parameters
tileset_nameThe name of the tileset (e.g., "gTileset_General")
Precondition
tileset_name must correspond to an existing tileset in headers.h
Returns
a ChainableResult indicating success or containing error details

Implements porytiles::PorytilesTilesetManager.

Definition at line 114 of file project_porytiles_tileset_manager.cpp.

◆ persist_managed_new()

ChainableResult< void > porytiles::ProjectPorytilesTilesetManager::persist_managed_new ( const std::string &  tileset_name,
bool  is_secondary = false 
) const
overridevirtual

Persists managed state for a new tileset.

Used when a new tileset is being added from scratch. The implementation creates a new entry in headers.h rather than modifying an existing one.

Parameters
tileset_nameThe name of the tileset (e.g., "gTileset_MyNewTileset")
Precondition
tileset_name must not already exist in headers.h
Returns
a ChainableResult indicating success or containing error details

Implements porytiles::PorytilesTilesetManager.

Definition at line 170 of file project_porytiles_tileset_manager.cpp.

◆ read()

ChainableResult< TilesetManifest > porytiles::ProjectPorytilesTilesetManager::read ( const std::string &  tileset_name) const

Reads an TilesetManifest object from the porytiles utility directory.

Looks for tileset-manifest.json at {project_root}/porytiles/tilesets/{tileset_name}/. Returns an error if the file doesn't exist or contains invalid JSON.

Parameters
tileset_nameThe name of the tileset (e.g., "gTileset_General")
Returns
The deserialized TilesetManifest, or an error if the file doesn't exist or is invalid

Definition at line 59 of file project_porytiles_tileset_manager.cpp.

◆ remove_wired_anim_code()

ChainableResult< void > porytiles::ProjectPorytilesTilesetManager::remove_wired_anim_code ( const std::string &  tileset_name,
bool  is_secondary 
) const
overridevirtual

Removes wired animation code for a tileset from the project.

Performs the inverse of wire_anim_code(). This method:

  1. Removes the #include directive from tileset_anims.c
  2. Removes the function declaration from tileset_anims.h
  3. Updates the .callback field in headers.h to "NULL" (only if it's a Porytiles-managed callback)

The callback is only cleared if it starts with "InitTilesetAnim_PorytilesManaged_". User-managed callbacks are preserved, allowing users to set wire_anim_code=false while maintaining their own custom animation callbacks.

This method is idempotent - safe to call even if no wiring exists. Should be called after compilation when a tileset has no animations to ensure stale animation references are cleaned up.

Parameters
tileset_nameName of the tileset to remove wiring for
is_secondaryTrue if this is a secondary tileset
Returns
ChainableResult<void> Success or error

Implements porytiles::PorytilesTilesetManager.

Definition at line 254 of file project_porytiles_tileset_manager.cpp.

◆ wire_anim_code()

ChainableResult< void > porytiles::ProjectPorytilesTilesetManager::wire_anim_code ( const std::string &  tileset_name,
bool  is_secondary 
) const
overridevirtual

Wires animation code for a tileset that already has its manifest persisted.

Called after compilation when a tileset has animations. Performs:

  1. Adds #include for generated_anim_code.h in tileset_anims.c
  2. Adds function declaration in tileset_anims.h
  3. Updates .callback field in headers.h

Idempotent - safe to call multiple times.

Parameters
tileset_nameThe tileset name (e.g., "gTileset_MyTileset")
is_secondaryTrue for secondary tilesets, false for primary
Precondition
tileset_name must be an existing Porytiles-managed tileset
Returns
ChainableResult indicating success or error details

Implements porytiles::PorytilesTilesetManager.

Definition at line 213 of file project_porytiles_tileset_manager.cpp.

◆ write()

void porytiles::ProjectPorytilesTilesetManager::write ( const std::string &  tileset_name,
const TilesetManifest artifacts 
) const

Writes an TilesetManifest object to the porytiles utility directory.

Creates the directory structure porytiles/tilesets/{tileset_name}/ if it doesn't exist, then writes tileset-manifest.json with 2-space indented JSON formatting.

Parameters
tileset_nameThe name of the tileset (e.g., "gTileset_General")
artifactsThe TilesetManifest data to serialize
Postcondition
tileset-manifest.json exists at {project_root}/porytiles/tilesets/{tileset_name}/

Definition at line 87 of file project_porytiles_tileset_manager.cpp.


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