refactor(entities): unifica loader d'animacio via AnimationComponent::fromYaml i elimina fps:
This commit is contained in:
1 parent
a779533d61
commit
b76a3eb1f3
21 files changed
+306
-231
No files matched your search
@@ -1,45 +1,16 @@
|
||||
#include "game/entities/concrete/door.hpp"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "game/entities/entity_factory.hpp"
|
||||
#include "game/entities/event_bus.hpp"
|
||||
#include "game/entities/player.hpp"
|
||||
#include "game/map/map.hpp"
|
||||
|
||||
namespace {
|
||||
|
||||
// Carrega una animació d'un bloc concret (closed/opening/open) amb
|
||||
// fallbacks tolerants. Si la clau no existeix, retorna una animació
|
||||
// d'un sol frame loopant: no fa estat invàlid, simplement no hi ha res
|
||||
// per reproduir.
|
||||
auto buildAnimation(const fkyaml::node& yaml, const std::string& key) -> AnimationComponent {
|
||||
std::vector<int> frames = {0};
|
||||
float fps = 1.0F;
|
||||
bool loop = true;
|
||||
if (yaml.contains("animations") && yaml["animations"].contains(key)) {
|
||||
const auto& anim = yaml["animations"][key];
|
||||
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
|
||||
|
||||
Door::Door(const fkyaml::node& yaml)
|
||||
: anim_closed_(buildAnimation(yaml, "closed")),
|
||||
anim_opening_(buildAnimation(yaml, "opening")),
|
||||
anim_open_(buildAnimation(yaml, "open")) {
|
||||
: anim_closed_(AnimationComponent::fromYaml(yaml, "closed")),
|
||||
anim_opening_(AnimationComponent::fromYaml(yaml, "opening")),
|
||||
anim_open_(AnimationComponent::fromYaml(yaml, "open")) {
|
||||
name_ = yaml.contains("name") ? yaml["name"].get_value<std::string>() : std::string("door");
|
||||
collides_ = true;
|
||||
interactable_ = true;
|
||||
@@ -99,7 +70,7 @@ void Door::open() {
|
||||
// placeholders defineixen `loop: false` explícitament al YAML, així
|
||||
// que aquest fallback només actua si algú dissenya malament.
|
||||
if (anim_.has_value() && anim_->frameCount() <= 1 && anim_->loops()) {
|
||||
anim_ = AnimationComponent({0}, 6.0F, false);
|
||||
anim_ = AnimationComponent::uniform({0}, 167.0F, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user