#pragma once #include #include // Para uint8_t #include // Para shared_ptr #include // Para string #include #include // Para vector #include "core/rendering/sprites/moving_sprite.hpp" // Para MovingSprite class Surface; // Recurso de animación: bytes crudos de un fichero YAML (para carga lazy) struct AnimationResource { std::string name; // Nombre del fichero std::vector yaml_data; // Bytes del archivo YAML sin parsear }; class AnimatedSprite : public MovingSprite { public: using Animations = std::vector; struct AnimationData { std::string name; std::vector frames; float speed{0.083F}; // Segundos por frame int loop{0}; // Frame al que vuelve al terminar (-1 = sin loop) bool completed{false}; int current_frame{0}; float accumulated_time{0.0F}; }; // Carga las animaciones desde un fichero YAML en el sistema de ficheros static auto loadAnimationsFromYAML(const std::string& file_path, std::shared_ptr& surface, float& frame_width, float& frame_height) -> std::vector; // Constructor con datos pre-cargados (bytes YAML en memoria) explicit AnimatedSprite(const AnimationResource& cached_data); ~AnimatedSprite() override = default; void update(float delta_time) override; auto animationIsCompleted() -> bool; auto getIndex(const std::string& name) -> int; auto getCurrentAnimationSize() -> int { return static_cast(animations_[current_animation_].frames.size()); } void setCurrentAnimation(const std::string& name = "default"); void setCurrentAnimation(int index = 0); void resetAnimation(); void setCurrentAnimationFrame(int num); protected: AnimatedSprite(std::shared_ptr surface, SDL_FRect pos); void animate(float delta_time); private: std::vector animations_; int current_animation_{0}; };