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 InfraConfig * > config, gsl::not_null< const UserDiagnostics * > diag)
 Constructs an AttributesCsvLoader with required dependencies.
 
ChainableResult< AttributesCsvLoadResultload (const std::filesystem::path &path, const Schema &schema, const ProviderMap &providers, const std::string &tileset_name) const
 Loads metatile attributes from a CSV file.
 

Detailed Description

A service that loads metatile attributes from a CSV file.

AttributesCsvLoader parses the Porytiles attributes CSV format, whose columns come from the resolved metatile attribute schema: the header is id followed by every schema field name in schema order. A provider-backed field's cells hold value constant names resolved through the field's provider; a raw field's cells hold plain unsigned integers capped at the field's maximum value. For the stock emerald schema this is:

id,behavior
0,MB_NORMAL
1,MB_TALL_GRASS

The header row is cross-checked against the resolved schema, so a CSV written for a different schema fails with a diagnostic naming the offending column. Rich error messages with file context highlighting are produced via FileHighlightPrinter.

Definition at line 51 of file attributes_csv_loader.hpp.

Constructor & Destructor Documentation

◆ AttributesCsvLoader()

porytiles::AttributesCsvLoader::AttributesCsvLoader ( gsl::not_null< const TextFormatter * >  format,
gsl::not_null< const InfraConfig * >  config,
gsl::not_null< const UserDiagnostics * >  diag 
)
inline

Constructs an AttributesCsvLoader with required dependencies.

Parameters
formatThe text formatter for styled output
configA pointer to the InfraConfig for the loader
diagA pointer to the UserDiagnostics for the loader

Definition at line 58 of file attributes_csv_loader.hpp.

Member Function Documentation

◆ load()

ChainableResult< AttributesCsvLoadResult > porytiles::AttributesCsvLoader::load ( const std::filesystem::path &  path,
const Schema schema,
const ProviderMap providers,
const std::string &  tileset_name 
) const

Loads metatile attributes from a CSV file.

Parses the CSV file, validates the header row against the given schema, resolves each field cell (constant names through the field's provider, integers for raw fields), and returns a map of metatile ID to MetatileAttribute. All attributes are created with LayerType::normal.

The schema and providers must belong to the tileset that owns the CSV: when compiling a secondary, the paired primary's CSV parses against the primary's own resolved schema, which can differ from the secondary's. A provider-backed field missing from the ProviderMap is an internal invariant violation and panics.

Parameters
pathThe path to the attributes CSV file
schemaThe owning tileset's resolved attribute schema the CSV columns are validated and parsed against
providersThe provider map holding one provider per provider-backed schema field
tileset_nameThe tileset whose config scope resolves the role_pins. When compiling a secondary this is the primary's name for the primary's CSV, so the config resolves under the file's owning tileset.
Precondition
File must exist and be readable
Returns
Map of metatile IDs to their attributes, or an error with file context

Definition at line 470 of file attributes_csv_loader.cpp.


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