#include "game/entities/concrete/torch.hpp" #include #include #include "game/entities/entity_factory.hpp" namespace { // Ajut: extreu l'animació `idle` del bloc `animations` del YAML si existeix, // amb valors per defecte que sempre produïxen una animació vàlida (1 frame). auto buildIdleAnimation(const fkyaml::node& yaml) -> AnimationComponent { std::vector frames = {0}; float fps = 1.0F; bool loop = true; if (yaml.contains("animations") && yaml["animations"].contains("idle")) { const auto& anim = yaml["animations"]["idle"]; if (anim.contains("frames")) { frames.clear(); for (const auto& f : anim["frames"]) { // cppcheck-suppress useStlAlgorithm frames.push_back(f.get_value()); } if (frames.empty()) { frames.push_back(0); } } if (anim.contains("fps")) { fps = anim["fps"].get_value(); } if (anim.contains("loop")) { loop = anim["loop"].get_value(); } } return {frames, fps, loop}; } } // namespace Torch::Torch(const fkyaml::node& yaml) { name_ = yaml.contains("name") ? yaml["name"].get_value() : std::string("torch"); collides_ = false; interactable_ = false; anim_ = buildIdleAnimation(yaml); } REGISTER_ENTITY("torch", Torch)