26 const std::string &anim_name,
27 const std::string &frame_name,
28 std::size_t internal_tile_index,
29 std::size_t subtile_row,
30 std::size_t subtile_col)
33 "{} '{}' | frame '{}' | subtile {} | pixel {},{}",
44 const std::string &anim_name,
45 const std::string &frame_name,
46 std::size_t internal_tile_index)
49 "{} '{}' | frame '{}' | subtile {}",
77template <SupportsTransparency PixelType>
86 [[nodiscard]]
const std::string &
name()
const
98 params_ = std::move(
params);
108 return key_frame_.has_value();
123 if (!key_frame_.has_value()) {
124 panic(
"key_frame() called on Animation with no key frame set");
134 [[nodiscard]]
const std::map<std::string, AnimFrame<PixelType>> &
frames()
const
139 [[nodiscard]] std::map<std::string, AnimFrame<PixelType>> &
frames()
146 return frames_ | std::views::values | std::ranges::to<std::vector>();
156 return !frames_.empty();
166 return frames_.size();
171 return frames_.contains(frame_name);
183 if (!frames_.contains(frame_name)) {
184 panic(
"anim '" + name_ +
"' has no such frame '" + frame_name +
"'");
186 return frames_.at(frame_name);
197 frames_.emplace(
name, std::move(frame));
221 requires requires(
const PixelType &p) { p.is_transparent(p); }
230 std::size_t tile_count = 0;
235 tile_count = frames_.begin()->second.tile_count();
238 panic(
"composite_frame() called on Animation with no key frame and no frames");
241 AnimFrame<PixelType> composite{
"composite"};
243 for (std::size_t tile_idx = 0; tile_idx < tile_count; ++tile_idx) {
244 std::set<PixelType> all_colors;
248 auto key_colors =
key_frame().tile_at(tile_idx).unique_nontransparent_colors(extrinsic_transparency);
249 all_colors.merge(key_colors);
253 for (
const auto &[
name, frame] : frames_) {
254 auto colors = frame.tile_at(tile_idx).unique_nontransparent_colors(extrinsic_transparency);
255 all_colors.merge(colors);
259 PixelTile<PixelType> composite_tile{extrinsic_transparency};
260 std::size_t pix_idx = 1;
261 for (
const auto &color : all_colors) {
263 panic(
"pix_idx exceeded tile size in pixels");
265 composite_tile.set(pix_idx++, color);
268 if (composite_tile.unique_nontransparent_colors(extrinsic_transparency).size() >=
pal::max_size) {
269 panic(
"composite tile had >= 16 colors");
272 composite.add_tile(std::move(composite_tile));
281 std::optional<AnimFrame<PixelType>> key_frame_;
282 std::map<std::string, AnimFrame<PixelType>> frames_;
Represents a single frame of an animation, containing tiles and a frame name.
Configuration parameters for a single tileset animation.
A complete tileset animation with name, configuration, and frame data.
const AnimParams & params() const
AnimFrame< PixelType > composite_frame(const PixelType &extrinsic_transparency) const
Returns the "composite" frame for this animation.
Animation(std::string name)
const AnimFrame< PixelType > & frame_for_name(const std::string &frame_name) const
Returns the frame with the specified name.
void params(AnimParams params)
bool has_frames() const
Checks if this animation has any frames.
const std::string & name() const
void key_frame(AnimFrame< PixelType > key_frame)
bool has_key_frame() const
Checks if this animation has a key frame set.
Animation(std::string name, AnimParams params)
const AnimFrame< PixelType > & key_frame() const
Returns the key frame of this animation.
void put_frame(const std::string &name, AnimFrame< PixelType > frame)
Adds a frame to this Animation frame map.
std::map< std::string, AnimFrame< PixelType > > & frames()
bool has_frame(const std::string &frame_name)
std::vector< AnimFrame< PixelType > > frames_values() const
const std::map< std::string, AnimFrame< PixelType > > & frames() const
std::size_t frame_count() const
Returns the number of frames in this animation.
Abstract base class for applying text styling with context-aware formatting.
virtual std::string format(const std::string &format_str, const std::vector< FormatParam > ¶ms) const
Formats a string with styled parameters using fmtlib syntax.
constexpr std::string porytiles_managed_prefix
constexpr std::string g_tileset_anims_prefix
constexpr std::string s_tileset_anims_prefix
std::string message_header(const TextFormatter &format, const std::string &anim_name, const std::string &frame_name, std::size_t internal_tile_index, std::size_t subtile_row, std::size_t subtile_col)
constexpr std::size_t max_size
constexpr std::size_t size_pix
void panic(const StringViewSourceLoc &s)
Unconditionally terminates the program with a panic message.