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
@@ -2,7 +2,6 @@
|
||||
|
||||
#include <random>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "core/audio/audio.hpp"
|
||||
#include "core/resources/resource_cache.hpp"
|
||||
@@ -21,26 +20,6 @@ namespace {
|
||||
return k_rng_;
|
||||
}
|
||||
|
||||
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};
|
||||
}
|
||||
|
||||
// Llig `tile_size: [w, h]` del YAML. Fallback [1,1] si no existeix.
|
||||
void readTileSize(const fkyaml::node& yaml, int& w, int& h) {
|
||||
w = 1;
|
||||
@@ -61,9 +40,9 @@ Sarcophagus::Sarcophagus(const fkyaml::node& yaml, int anchor_col, int anchor_ro
|
||||
}
|
||||
|
||||
Sarcophagus::Sarcophagus(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("sarcophagus");
|
||||
collides_ = true;
|
||||
interactable_ = true;
|
||||
|
||||
Reference in new issue
Block a user