Refactored the animation so I can normalize it to one api. Next is to create the concept of a temporary entity that represents a transitive effect.

This commit is contained in:
Zed A. Shaw 2025-09-11 14:18:52 -04:00
parent 0afaa20c1d
commit 8384b11993
10 changed files with 123 additions and 23 deletions

View file

@ -110,8 +110,33 @@ namespace animation {
}
}
Animation load(std::string name) {
bool has(const std::string& name) {
return MGR.animations.contains(name);
}
Animation load(const std::string& name) {
dbc::check(initialized, "You forgot to initialize animation.");
return MGR.animations.at(name);
}
void configure(DinkyECS::World& world, DinkyECS::Entity entity) {
auto sprite = world.get_if<Sprite>(entity);
if(sprite != nullptr && animation::has(sprite->name)) {
world.set<Animation>(entity, animation::load(sprite->name));
}
}
void step_animation(DinkyECS::World& world, DinkyECS::Entity entity, sf::Vector2f& scale_out, sf::Vector2f& pos_out, sf::IntRect& rect_out) {
if(auto animation = world.get_if<components::Animation>(entity)) {
if(animation->playing) animation->step(scale_out, pos_out, rect_out);
}
}
void animate_entity(DinkyECS::World &world, DinkyECS::Entity entity) {
if(world.has<Animation>(entity)) {
auto& animation = world.get<Animation>(entity);
animation.play();
}
}
}