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

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

#include <header_encounter_type_map_provider.hpp>

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

Public Member Functions

 HeaderEncounterTypeMapProvider (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 &encounter_name) const override
 Looks up the numeric value for an encounter type constant name.
 
ChainableResult< std::string > lookup (std::uint8_t encounter_value) const override
 Looks up the encounter type constant name for a numeric value.
 
- Public Member Functions inherited from porytiles::EncounterTypeMapProvider
virtual ~EncounterTypeMapProvider ()=default
 

Detailed Description

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

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

Define format:

#define TILE_ENCOUNTER_NONE 0x00
#define TILE_ENCOUNTER_LAND 0x01

Enum format:

TILE_ENCOUNTER_NONE,
TILE_ENCOUNTER_LAND,

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. Encounter type values occupy 3 bits (0-7) in the FireRed metatile attribute format.

Definition at line 42 of file header_encounter_type_map_provider.hpp.

Constructor & Destructor Documentation

◆ HeaderEncounterTypeMapProvider()

porytiles::HeaderEncounterTypeMapProvider::HeaderEncounterTypeMapProvider ( 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 encounter 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_encounter_type_map_provider.hpp.

Member Function Documentation

◆ lookup() [1/2]

ChainableResult< std::uint8_t > porytiles::HeaderEncounterTypeMapProvider::lookup ( const std::string &  encounter_name) const
overridevirtual

Looks up the numeric value for an encounter type constant name.

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

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

Implements porytiles::EncounterTypeMapProvider.

Definition at line 126 of file header_encounter_type_map_provider.cpp.

◆ lookup() [2/2]

ChainableResult< std::string > porytiles::HeaderEncounterTypeMapProvider::lookup ( std::uint8_t  encounter_value) const
overridevirtual

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

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

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

Implements porytiles::EncounterTypeMapProvider.

Definition at line 150 of file header_encounter_type_map_provider.cpp.


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