Porytiles
Loading...
Searching...
No Matches
porymap_tileset_component.cpp
Go to the documentation of this file.
2
3#include <format>
4#include <utility>
5
15
16namespace porytiles {
17
19{
21}
22
24{
25 // std::move here even though TilemapEntry is trivially-copyable, in case it changes later
26 metatiles_bin_.push_back(std::move(entry));
27}
28
30{
31 metatile_attributes_.push_back(std::move(attribute));
32}
33
35{
36 if (pal_index >= pal::num_pals) {
37 panic(std::format("invalid pal index {}: out of range", pal_index));
38 }
39 pals_.at(pal_index) = std::move(pal);
40}
41
43{
44 if (pal_index >= pal::num_pals) {
45 panic(std::format("invalid pal index {}: out of range", pal_index));
46 }
47 return pals_.at(pal_index);
48}
49
51{
52 return metatiles_bin_.empty();
53}
54
56{
57 const auto &entries = metatiles_bin();
58 const auto &attributes = metatile_attributes_bin();
59 const std::size_t metatile_count = attributes.size();
60
61 if (entries.size() % metatile::entries_per_metatile_triple == 0 &&
62 entries.size() / metatile::entries_per_metatile_triple == metatile_count) {
63 return LayerMode::triple;
64 }
65 if (entries.size() % metatile::entries_per_metatile_dual == 0 &&
66 entries.size() / metatile::entries_per_metatile_dual == metatile_count) {
67 return LayerMode::dual;
68 }
69
70 return FormattableError{
71 std::vector<std::string>{
72 "unexpected tilemap entry count in metatiles.bin",
73 "found {} tilemap entries for {} metatile attributes",
74 "for dual layer metatiles, expected {} entries ({} per metatile)",
75 "for triple layer metatiles, expected {} entries ({} per metatile)"},
76 std::vector<std::vector<FormatParam>>{
77 {},
78 {FormatParam{entries.size(), Style::bold}, FormatParam{metatile_count, Style::bold}},
83}
84
86{
87 const std::string &name = anim.name();
88 if (anims_.contains(name)) {
89 panic("animation '" + name + "' already exists in PorymapTilesetComponent");
90 }
91 anims_.insert({name, std::move(anim)});
92}
93
94} // namespace porytiles
A complete tileset animation with name, configuration, and frame data.
Definition animation.hpp:78
const std::string & name() const
Definition animation.hpp:86
A result type that maintains a chainable sequence of errors for debugging and error reporting.
A text parameter with associated styling for formatted output.
General-purpose error implementation with formatted message support.
Definition error.hpp:63
Represents the attributes of a single metatile.
A generic palette container for colors that support transparency checking.
Definition palette.hpp:47
const std::vector< TilemapEntry > & metatiles_bin() const
ChainableResult< LayerMode > detect_layer_mode() const
const Palette< Rgba32, pal::max_size > & pal_at(std::size_t pal_index) const
void add_anim(Animation< IndexPixel > anim)
const std::vector< MetatileAttribute > & metatile_attributes_bin() const
void push_back_tilemap_entry(TilemapEntry entry)
Add a TilemapEntry to the end of the entry vector.
void set_pal(std::size_t pal_index, Palette< Rgba32, pal::max_size > pal)
void push_back_attribute(MetatileAttribute attribute)
Add a MetatileAttribute to the end of the attribute vector.
Represents a 32-bit RGBA color.
Definition rgba32.hpp:23
static const Style bold
Bold text formatting.
Represents a tilemap entry referencing a tile with palette and flip attributes.
constexpr std::size_t entries_per_metatile_dual
Definition metatile.hpp:20
constexpr std::size_t entries_per_metatile_triple
Definition metatile.hpp:21
constexpr std::size_t num_pals
Definition palette.hpp:21
void panic(const StringViewSourceLoc &s)
Unconditionally terminates the program with a panic message.
Definition panic.cpp:43