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

Parses and writes animation configuration JSON files (anim.json). More...

#include <anim_json_parser.hpp>

Public Member Functions

 AnimJsonParser (gsl::not_null< const TextFormatter * > format)
 
ChainableResult< std::map< DynamicCasedName, AnimParams > > parse (const std::filesystem::path &json_path) const
 Parses an anim.json file into a map of animation parameters.
 
ChainableResult< std::map< DynamicCasedName, std::vector< AnimOverrideEntry > > > parse_primary_references (const std::filesystem::path &json_path) const
 Parses the primary_references section from an anim.json file.
 
ChainableResult< void > write (const std::filesystem::path &json_path, const std::map< DynamicCasedName, AnimParams > &params, const std::map< DynamicCasedName, std::vector< AnimOverrideEntry > > &primary_references={}) const
 Writes animation parameters to an anim.json file.
 

Detailed Description

Parses and writes animation configuration JSON files (anim.json).

AnimJsonParser handles reading and writing of anim.json files, which define animation parameters for a tileset's Porytiles component. The JSON structure maps animation names to their configuration parameters.

Example anim.json structure:

{
"flower": {
"frame_factor": 16,
"frame_offset": 1,
"frames": ["0", "1", "0", "2"]
},
"water": {
"frame_factor": 16,
"frame_offset": 2,
"frames": ["0", "1", "2", "3"]
}
}

Fields:

  • frame_factor: Modulus divisor for timer (default: 16)
  • frame_offset: Remainder for timer modulo check (default: 0)
  • frames: Array of frame names defining unique frames (default: ["0"])
  • frame_order: Array of frame names defining playback order (default: same as frames)
  • counter_max: Timer wrap-around value (default: 256, optional)

Note: tile_offset and tile_count are NOT stored in anim.json - they are computed during compilation and stored in generated_anim_code.h.

Definition at line 51 of file anim_json_parser.hpp.

Constructor & Destructor Documentation

◆ AnimJsonParser()

porytiles::AnimJsonParser::AnimJsonParser ( gsl::not_null< const TextFormatter * >  format)
explicit

Definition at line 281 of file anim_json_parser.cpp.

Member Function Documentation

◆ parse()

ChainableResult< std::map< DynamicCasedName, AnimParams > > porytiles::AnimJsonParser::parse ( const std::filesystem::path &  json_path) const

Parses an anim.json file into a map of animation parameters.

Reads the JSON file at the specified path and extracts animation parameters for each animation defined. Missing optional fields use default values from AnimParams.

Parameters
json_pathPath to the anim.json file
Returns
Map of animation name to AnimParams, or error if parsing fails

Definition at line 284 of file anim_json_parser.cpp.

◆ parse_primary_references()

ChainableResult< std::map< DynamicCasedName, std::vector< AnimOverrideEntry > > > porytiles::AnimJsonParser::parse_primary_references ( const std::filesystem::path &  json_path) const

Parses the primary_references section from an anim.json file.

Reads the JSON file and extracts only the "primary_references" key, which maps primary animation names to override entries. This is used by secondary tilesets to manually link metatile entries to primary animation tile ranges.

Parameters
json_pathPath to the anim.json file
Returns
Map of primary animation name to override entries, or error if parsing fails

Definition at line 419 of file anim_json_parser.cpp.

◆ write()

ChainableResult< void > porytiles::AnimJsonParser::write ( const std::filesystem::path &  json_path,
const std::map< DynamicCasedName, AnimParams > &  params,
const std::map< DynamicCasedName, std::vector< AnimOverrideEntry > > &  primary_references = {} 
) const

Writes animation parameters to an anim.json file.

Serializes the provided animation parameters map to JSON format and writes to the specified path. Overwrites any existing file at that location. Optionally includes a primary_references section for secondary tilesets.

Parameters
json_pathPath to write the anim.json file
paramsMap of animation name to AnimParams to serialize
primary_referencesMap of primary animation name to override entries (optional, omitted when empty)
Returns
Success or error if writing fails

Definition at line 520 of file anim_json_parser.cpp.


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