Porytiles
Loading...
Searching...
No Matches
metatile_attribute.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <cstddef>
4#include <cstdint>
5#include <functional>
6#include <map>
7#include <optional>
8#include <string>
9#include <string_view>
10
12
13namespace porytiles {
14
15namespace attribute {
16
17// Field-name constants for the stock decomp attribute layouts. These are the names the schema inference produces when
18// it scans a stock Emerald or FireRed-family project. They're defined here so code and tests that address those fields
19// by name avoid duplicating them everywhere.
20constexpr std::string_view field_behavior = "behavior";
21constexpr std::string_view field_terrain = "terrain";
22constexpr std::string_view field_attribute_2 = "attribute_2";
23constexpr std::string_view field_attribute_3 = "attribute_3";
24constexpr std::string_view field_encounter_type = "encounter_type";
25constexpr std::string_view field_attribute_5 = "attribute_5";
26constexpr std::string_view field_attribute_7 = "attribute_7";
27
28// The name that schema inference assigns to the field carrying FieldRole::layer_type. The name carries no special
29// meaning to the schema. A field named "layer_type" without the role is an ordinary value field, which is what clearing
30// the role with `role: null` produces.
31constexpr std::string_view field_layer_type = "layer_type";
32
33} // namespace attribute
34
48 public:
49 MetatileAttribute() = default;
50
51 [[nodiscard]] LayerType layer_type() const
52 {
53 return layer_type_;
54 }
55
65 {
66 layer_type_ = layer_type;
67 explicit_layer_type_ = std::nullopt;
68 }
69
79 [[nodiscard]] const std::optional<LayerType> &explicit_layer_type() const
80 {
81 return explicit_layer_type_;
82 }
83
92 {
93 explicit_layer_type_ = layer_type;
94 layer_type_ = layer_type;
95 }
96
101 [[nodiscard]] std::uint32_t field(std::string_view field_name) const
102 {
103 const auto it = fields_.find(field_name);
104 return it != fields_.end() ? it->second : 0;
105 }
106
111 void field(std::string_view field_name, std::uint32_t value)
112 {
113 fields_.insert_or_assign(std::string{field_name}, value);
114 }
115
116 [[nodiscard]] const std::map<std::string, std::uint32_t, std::less<>> &fields() const
117 {
118 return fields_;
119 }
120
121 private:
122 LayerType layer_type_{};
123 std::optional<LayerType> explicit_layer_type_{};
124 std::map<std::string, std::uint32_t, std::less<>> fields_{};
125};
126
127} // namespace porytiles
The attributes of a single metatile, modeled as a map of named field values.
const std::map< std::string, std::uint32_t, std::less<> > & fields() const
const std::optional< LayerType > & explicit_layer_type() const
Returns the explicit (user-pinned) layer type, if one was set.
void field(std::string_view field_name, std::uint32_t value)
Sets the value of a named field, inserting or overwriting as needed.
void layer_type(LayerType layer_type)
Sets the plain (inferred) layer type, clearing any explicit pin.
std::uint32_t field(std::string_view field_name) const
Returns the value of a named field, or 0 if the field is absent.
void explicit_layer_type(LayerType layer_type)
Pins the layer type to an explicit value.
constexpr std::string_view field_attribute_7
constexpr std::string_view field_layer_type
constexpr std::string_view field_terrain
constexpr std::string_view field_attribute_5
constexpr std::string_view field_attribute_2
constexpr std::string_view field_behavior
constexpr std::string_view field_attribute_3
constexpr std::string_view field_encounter_type
LayerType
Specifies which layers of a metatile are used for rendering.
Definition layer.hpp:86