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
33template <SupportsTransparency PixelType>
34class AnimFrame {
35 public:
36 AnimFrame() = default;
37
38 explicit AnimFrame(std::string frame_name) : frame_name_{std::move(frame_name)} {}
39
41 : frame_name_{std::move(frame_name)}, tiles_{std::move(tiles)}
42 {
43 }
44
45 [[nodiscard]] const std::string &frame_name() const
46 {
47 return frame_name_;
48 }
49
50 void frame_name(std::string name)
51 {
52 frame_name_ = std::move(name);
53 }
54
55 [[nodiscard]] const std::vector<PixelTile<PixelType>> &tiles() const
56 {
57 return tiles_;
58 }
59
60 void tiles(std::vector<PixelTile<PixelType>> t)
61 {
62 tiles_ = std::move(t);
63 }
64
66 {
67 tiles_.push_back(std::move(tile));
68 }
69
70 [[nodiscard]] std::size_t tile_count() const
71 {
72 return tiles_.size();
73 }
74
75 // @pre: index must be less than tile_count()
76 [[nodiscard]] const PixelTile<PixelType> &tile_at(std::size_t index) const
77 {
78 return tiles_.at(index);
79 }
80
81 [[nodiscard]] bool has_palette() const
82 {
83 return palette_.has_value();
84 }
85
86 [[nodiscard]] const Palette<Rgba32> &palette() const
87 {
88 return palette_.value();
89 }
90
92 {
93 palette_ = std::move(pal);
94 }
95
96 private:
97 /*
98 * Note: Frame dimensions (width/height in tiles) are stored in AnimParams since all frames in an animation
99 * must share the same dimensions.
100 */
101 std::string frame_name_;
102 std::vector<PixelTile<PixelType>> tiles_;
103 std::optional<Palette<Rgba32>> palette_;
104};
105
106} // 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 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
void palette(Palette< Rgba32 > pal)
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:47
An 8x8 tile backed by literal-array-based per-pixel storage of an arbitrary pixel type.