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

A service that loads metatile attributes from a CSV file. More...

#include <attributes_csv_loader.hpp>

Public Member Functions

 AttributesCsvLoader (gsl::not_null< const TextFormatter * > format, gsl::not_null< const BehaviorMapProvider * > behavior_map, std::optional< BaseGame > base_game=std::nullopt, const TerrainTypeMapProvider *terrain_map=nullptr, const EncounterTypeMapProvider *encounter_map=nullptr)
 Constructs an AttributesCsvLoader with required dependencies.
 
ChainableResult< std::map< std::size_t, MetatileAttribute > > load (const std::filesystem::path &path) const
 Loads metatile attributes from a CSV file.
 

Detailed Description

A service that loads metatile attributes from a CSV file.

AttributesCsvLoader parses CSV files in two supported Porytiles attributes formats:

Emerald format (2 columns):

id,behavior
0,MB_NORMAL
1,MB_TALL_GRASS

FireRed format (4 columns):

id,behavior,terrainType,encounterType
0,MB_NORMAL,TILE_TERRAIN_NORMAL,TILE_ENCOUNTER_NONE
1,MB_TALL_GRASS,TILE_TERRAIN_GRASS,TILE_ENCOUNTER_LAND

The format is auto-detected from the CSV header row. If a BaseGame is provided, the loader validates that the detected format matches the expected base game. Rich error messages with file context highlighting are produced via FileHighlightPrinter.

Definition at line 45 of file attributes_csv_loader.hpp.

Constructor & Destructor Documentation

◆ AttributesCsvLoader()

porytiles::AttributesCsvLoader::AttributesCsvLoader ( gsl::not_null< const TextFormatter * >  format,
gsl::not_null< const BehaviorMapProvider * >  behavior_map,
std::optional< BaseGame base_game = std::nullopt,
const TerrainTypeMapProvider terrain_map = nullptr,
const EncounterTypeMapProvider encounter_map = nullptr 
)
inline

Constructs an AttributesCsvLoader with required dependencies.

This constructor provides backward compatibility with the original 2-column loader. The optional parameters enable FireRed 4-column CSV support when provided.

Parameters
formatThe text formatter for styled output
behavior_mapThe behavior map provider for resolving behavior names to values
base_gameOptional base game for format validation against the detected CSV format
terrain_mapOptional terrain type provider (required for FireRed CSV format)
encounter_mapOptional encounter type provider (required for FireRed CSV format)

Definition at line 60 of file attributes_csv_loader.hpp.

Member Function Documentation

◆ load()

ChainableResult< std::map< std::size_t, MetatileAttribute > > porytiles::AttributesCsvLoader::load ( const std::filesystem::path &  path) const

Loads metatile attributes from a CSV file.

Parses the CSV file, auto-detects format from the header row, validates format against the base game (if provided), resolves behaviors (and terrain/encounter types for FireRed), and returns a map of metatile ID to MetatileAttribute. All attributes are created with LayerType::normal.

Parameters
pathThe path to the attributes CSV file
Precondition
File must exist and be readable
Returns
Map of metatile IDs to their attributes, or an error with file context

Definition at line 349 of file attributes_csv_loader.cpp.


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