refactor(entities): unifica loader d'animacio via AnimationComponent::fromYaml i elimina fps:

This commit is contained in:
JailDesigner committed 2026-05-13 10:06:56 +02:00
1 parent a779533d61
commit b76a3eb1f3
21 files changed
+306 -231

No files matched your search

+1 -28
View File
@@ -1,41 +1,14 @@
#include "game/entities/concrete/torch.hpp"
#include <string>
#include <vector>
#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<int> 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<int>());
}
if (frames.empty()) { frames.push_back(0); }
}
if (anim.contains("fps")) { fps = anim["fps"].get_value<float>(); }
if (anim.contains("loop")) { loop = anim["loop"].get_value<bool>(); }
}
return {frames, fps, loop};
}
} // namespace
Torch::Torch(const fkyaml::node& yaml) {
name_ = yaml.contains("name") ? yaml["name"].get_value<std::string>() : std::string("torch");
collides_ = false;
interactable_ = false;
anim_ = buildIdleAnimation(yaml);
anim_ = AnimationComponent::fromYaml(yaml, "idle");
}
REGISTER_ENTITY("torch", Torch)