Porytiles
Loading...
Searching...
No Matches
porytiles::HeaderTerrainTypeMapProvider Class Referencefinal

Loads terrain type mappings from a C/C++ header file containing terrain definitions. More...

#include <header_terrain_type_map_provider.hpp>

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

Public Member Functions

 HeaderTerrainTypeMapProvider (std::filesystem::path header_path, gsl::not_null< const TextFormatter * > format, gsl::not_null< const UserDiagnostics * > diag)
 Constructs a provider that will load from the specified header file.
 
ChainableResult< std::uint8_t > lookup (const std::string &terrain_name) const override
 Looks up the numeric value for a terrain type constant name.
 
ChainableResult< std::string > lookup (std::uint8_t terrain_value) const override
 Looks up the terrain type constant name for a numeric value.
 
- Public Member Functions inherited from porytiles::TerrainTypeMapProvider
virtual ~TerrainTypeMapProvider ()=default
 

Detailed Description

Loads terrain type mappings from a C/C++ header file containing terrain definitions.

Parses header files in the formats used by Pokemon decomp projects. Supports two formats:

Define format:

#define TILE_TERRAIN_NORMAL 0x00
#define TILE_TERRAIN_GRASS 0x01

Enum format:

TILE_TERRAIN_NORMAL,
TILE_TERRAIN_GRASS,

In the enum format, values are assigned sequentially starting from 0. Both formats support decimal and hexadecimal values (for define format). The provider loads lazily on first lookup and caches the mappings. Terrain type values occupy 5 bits (0-31) in the FireRed metatile attribute format.

Definition at line 42 of file header_terrain_type_map_provider.hpp.

Constructor & Destructor Documentation

◆ HeaderTerrainTypeMapProvider()

porytiles::HeaderTerrainTypeMapProvider::HeaderTerrainTypeMapProvider ( std::filesystem::path  header_path,
gsl::not_null< const TextFormatter * >  format,
gsl::not_null< const UserDiagnostics * >  diag 
)
inline

Constructs a provider that will load from the specified header file.

This constructor sets up the provider to read terrain type mappings from the specified header file. The file may use either the define format or the enum format. The header file is loaded lazily when first accessed via lookup() and cached for subsequent lookups.

Parameters
header_pathThe path to the project metatile_behaviors.h file
formatThe text formatter for styled output
diagThe user diagnostics for error reporting

Definition at line 56 of file header_terrain_type_map_provider.hpp.

Member Function Documentation

◆ lookup() [1/2]

ChainableResult< std::uint8_t > porytiles::HeaderTerrainTypeMapProvider::lookup ( const std::string &  terrain_name) const
overridevirtual

Looks up the numeric value for a terrain type constant name.

This function searches for the given terrain type constant name in the provider's mapping and returns its corresponding numeric value if found.

Parameters
terrain_nameThe terrain type constant name (e.g., "TILE_TERRAIN_GRASS")
Returns
The numeric value if found, or an error describing why the lookup failed

Implements porytiles::TerrainTypeMapProvider.

Definition at line 126 of file header_terrain_type_map_provider.cpp.

◆ lookup() [2/2]

ChainableResult< std::string > porytiles::HeaderTerrainTypeMapProvider::lookup ( std::uint8_t  terrain_value) const
overridevirtual

Looks up the terrain type constant name for a numeric value.

This function performs a reverse lookup, searching for the terrain type constant name that corresponds to the given numeric value.

Parameters
terrain_valueThe numeric terrain type value
Returns
The terrain type constant name if found, or an error describing why the lookup failed

Implements porytiles::TerrainTypeMapProvider.

Definition at line 150 of file header_terrain_type_map_provider.cpp.


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