42 lines
1.4 KiB
C++
42 lines
1.4 KiB
C++
#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);
|
|
}
|
|
|
|
REGISTER_ENTITY("torch", Torch)
|