refactor(anim): migra AnimatedSprite al format sprite:/frame_ms, animacions en mapa

This commit is contained in:
JailDesigner committed 2026-04-24 21:01:21 +02:00
1 parent ea0f6d98a9
commit 50aae790b1
4 files changed
+158 -138

No files matched your search

@@ -11,11 +11,19 @@
class AnimatedSprite : public MovingSprite {
public:
// Dades d'una animació concreta dins d'un spritesheet. Les claus del
// mapa (`animations_`) són els noms; aquí només es guarden els fotogrames
// i l'estat de reproducció.
struct AnimationData {
std::string name;
std::vector<SDL_FRect> frames;
// Durada de cada frame en segons (convertit des de `frame_ms` al YAML).
// Si té un sol valor, val per a tots els frames; altrament ha de tenir
// la mateixa mida que `frames`.
std::vector<float> speeds;
int loop_from{-1};
// -1 = no loop (es queda al darrer frame i marca `completed`).
// 0 = loop complet des del primer frame.
// N>0 = rebota al frame N en passar del final.
int loop_from{0};
bool completed{false};
int current_frame{0};
float accumulated_time{0.0F};
@@ -28,16 +36,12 @@ class AnimatedSprite : public MovingSprite {
auto animationIsCompleted() -> bool;
void setCurrentAnimation(const std::string& name = "default");
void setCurrentAnimation(int index = 0);
void setCurrentAnimation(const std::string& name);
void resetAnimation();
void setCurrentAnimationFrame(int num);
void animate(float delta_time);
private:
void buildNameIndex();
std::vector<AnimationData> animations_;
std::unordered_map<std::string, int> animation_index_;
int current_animation_{0};
std::unordered_map<std::string, AnimationData> animations_;
// Nom de l'animació activa. Buit fins que algú crida `setCurrentAnimation`.
std::string current_animation_;
};