Porytiles
Loading...
Searching...
No Matches
anim_frame.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <optional>
4#include <string>
5#include <vector>
6
11
12namespace porytiles {
13
31template <SupportsTransparency PixelType>
32class AnimFrame {
33 public:
34 AnimFrame() = default;
35
36 explicit AnimFrame(std::string frame_name) : frame_name_{std::move(frame_name)} {}
37
39 : frame_name_{std::move(frame_name)}, tiles_{std::move(tiles)}
40 {
41 }
42
43 [[nodiscard]] const std::string &frame_name() const
44 {
45 return frame_name_;
46 }
47
48 void frame_name(std::string name)
49 {
50 frame_name_ = std::move(name);
51 }
52
53 [[nodiscard]] const std::vector<PixelTile<PixelType>> &tiles() const
54 {
55 return tiles_;
56 }
57
58 void tiles(std::vector<PixelTile<PixelType>> t)
59 {
60 tiles_ = std::move(t);
61 }
62
64 {
65 tiles_.push_back(std::move(tile));
66 }
67
68 [[nodiscard]] std::size_t tile_count() const
69 {
70 return tiles_.size();
71 }
72
73 // @pre: index must be less than tile_count()
74 [[nodiscard]] const PixelTile<PixelType> &tile_at(std::size_t index) const
75 {
76 return tiles_.at(index);
77 }
78
79 [[nodiscard]] bool has_palette() const
80 {
81 return palette_.has_value();
82 }
83
84 [[nodiscard]] const Palette<Rgba32> &palette() const
85 {
86 return palette_.value();
87 }
88
90 {
91 palette_ = std::move(palette);
92 }
93
94 private:
95 // Note: Frame dimensions (width/height in tiles) are stored in AnimParams since all frames in an animation
96 // must share the same dimensions.
97 std::string frame_name_;
98 std::vector<PixelTile<PixelType>> tiles_;
99 std::optional<Palette<Rgba32>> palette_;
100};
101
102} // namespace porytiles
Represents a single frame of an animation, containing tiles and a frame name.
void add_tile(PixelTile< PixelType > tile)
const Palette< Rgba32 > & palette() const
AnimFrame(std::string frame_name, std::vector< PixelTile< PixelType > > tiles)
void palette(Palette< Rgba32 > palette)
void tiles(std::vector< PixelTile< PixelType > > t)
void frame_name(std::string name)
const PixelTile< PixelType > & tile_at(std::size_t index) const
const std::string & frame_name() const
std::size_t tile_count() const
bool has_palette() const
const std::vector< PixelTile< PixelType > > & tiles() const
AnimFrame(std::string frame_name)
A generic palette container for colors that support transparency checking.
Definition palette.hpp:45
An 8x8 tile backed by literal-array-based per-pixel storage of an arbitrary pixel type.
std::string name