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

+13 -36
View File
@@ -33,42 +33,18 @@ namespace {
return sprite;
}
// Construeix l'`AnimationComponent` del swing a partir del bloc
// `animations.swing`. Convenció igual que la resta d'entitats:
// - `frames` : llista d'índexs dins l'spritesheet (obligatori).
// - `frame_ms` : durada uniforme per frame (ms). Alternativament `fps`.
// - `loop` : per defecte true; al látigo el volem false (mor en
// completar).
auto buildSwingAnim(const fkyaml::node& yaml, std::vector<int>& active_out)
-> AnimationComponent {
std::vector<int> frames = {0};
float fps = 8.0F;
bool loop = false;
if (yaml.contains("animations") && yaml["animations"].contains("swing")) {
const auto& sw = yaml["animations"]["swing"];
if (sw.contains("frames")) {
frames.clear();
for (const auto& f : sw["frames"]) {
// cppcheck-suppress useStlAlgorithm
frames.push_back(f.get_value<int>());
}
if (frames.empty()) { frames.push_back(0); }
}
if (sw.contains("frame_ms")) {
const auto MS = static_cast<float>(sw["frame_ms"].get_value<int>());
if (MS > 0.0F) { fps = 1000.0F / MS; }
} else if (sw.contains("fps")) {
fps = sw["fps"].get_value<float>();
}
if (sw.contains("loop")) { loop = sw["loop"].get_value<bool>(); }
if (sw.contains("active_frames")) {
for (const auto& f : sw["active_frames"]) {
// cppcheck-suppress useStlAlgorithm
active_out.push_back(f.get_value<int>());
}
}
// Llig el camp `active_frames` del bloc `animations.swing` — específic
// del látigo: els índexs llistats són els frames on la hitbox aplica
// dany (wind-up i recovery no danyen). La resta de l'animació la
// construeix `AnimationComponent::fromYaml`.
void readActiveFrames(const fkyaml::node& yaml, std::vector<int>& active_out) {
if (!yaml.contains("animations") || !yaml["animations"].contains("swing")) { return; }
const auto& sw = yaml["animations"]["swing"];
if (!sw.contains("active_frames")) { return; }
for (const auto& f : sw["active_frames"]) {
// cppcheck-suppress useStlAlgorithm
active_out.push_back(f.get_value<int>());
}
return {frames, fps, loop};
}
} // namespace
@@ -86,7 +62,8 @@ WhipAttack::WhipAttack(const fkyaml::node& yaml) {
if (s.contains("west")) { sprite_west_ = readDirSprite(s["west"]); }
}
anim_swing_ = buildSwingAnim(yaml, active_frames_);
anim_swing_ = AnimationComponent::fromYaml(yaml, "swing");
readActiveFrames(yaml, active_frames_);
anim_ = anim_swing_;
}