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

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

#include <header_behavior_map_provider.hpp>

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

Public Member Functions

 HeaderBehaviorMapProvider (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::uint16_t > lookup (const std::string &behavior_name) const override
 Looks up the numeric value for a behavior constant name.
 
ChainableResult< std::string > lookup (std::uint16_t behavior_value) const override
 Looks up the behavior constant name for a numeric value.
 
- Public Member Functions inherited from porytiles::BehaviorMapProvider
virtual ~BehaviorMapProvider ()=default
 

Detailed Description

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

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

Define format (older pokeemerald):

#define MB_NORMAL 0x00
#define MB_TALL_GRASS 0x02

Enum format (newer pokeemerald):

MB_NORMAL,
MB_TALL_GRASS, // optional comment

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. Entries named MB_INVALID are skipped in both formats.

Definition at line 42 of file header_behavior_map_provider.hpp.

Constructor & Destructor Documentation

◆ HeaderBehaviorMapProvider()

porytiles::HeaderBehaviorMapProvider::HeaderBehaviorMapProvider ( 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 behavior 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_behavior_map_provider.hpp.

Member Function Documentation

◆ lookup() [1/2]

ChainableResult< std::uint16_t > porytiles::HeaderBehaviorMapProvider::lookup ( const std::string &  behavior_name) const
overridevirtual

Looks up the numeric value for a behavior constant name.

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

Parameters
behavior_nameThe behavior constant name (e.g., "MB_NORMAL")
Returns
The numeric value if found, or an error describing why the lookup failed

Implements porytiles::BehaviorMapProvider.

Definition at line 132 of file header_behavior_map_provider.cpp.

◆ lookup() [2/2]

ChainableResult< std::string > porytiles::HeaderBehaviorMapProvider::lookup ( std::uint16_t  behavior_value) const
overridevirtual

Looks up the behavior constant name for a numeric value.

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

Parameters
behavior_valueThe numeric behavior value
Returns
The behavior constant name if found, or an error describing why the lookup failed

Implements porytiles::BehaviorMapProvider.

Definition at line 157 of file header_behavior_map_provider.cpp.


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