Now the Animation system is no more. Next is cleaning up the quick hacks I needed to finally get rid of it, like animate2::has.
This commit is contained in:
parent
b504afef2a
commit
89ca204f3d
15 changed files with 356 additions and 423 deletions
35
animate2.cpp
35
animate2.cpp
|
|
@ -6,6 +6,7 @@
|
|||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include "sound.hpp"
|
||||
#include "components.hpp"
|
||||
|
||||
constexpr float SUB_FRAME_SENSITIVITY = 0.999f;
|
||||
|
||||
|
|
@ -239,6 +240,9 @@ namespace animate2 {
|
|||
std::ifstream infile(file);
|
||||
auto data = json::parse(infile);
|
||||
|
||||
dbc::check(data.contains(anim_name),
|
||||
fmt::format("{} animation config does not have animation {}", file, anim_name));
|
||||
|
||||
Animate2 anim;
|
||||
animate2::from_json(data[anim_name], anim);
|
||||
|
||||
|
|
@ -268,4 +272,35 @@ namespace animate2 {
|
|||
fmt::format("current={} went past end of fame durations.size={}",
|
||||
current, durations.size()), location);
|
||||
}
|
||||
|
||||
// BUG: BAAADD REMOVE
|
||||
bool has(const std::string& name) {
|
||||
using nlohmann::json;
|
||||
std::ifstream infile("assets/animate2.json");
|
||||
auto data = json::parse(infile);
|
||||
return data.contains(name);
|
||||
}
|
||||
|
||||
void configure(DinkyECS::World& world, DinkyECS::Entity entity) {
|
||||
auto sprite = world.get_if<components::Sprite>(entity);
|
||||
|
||||
if(sprite != nullptr && has(sprite->name)) {
|
||||
world.set<Animate2>(entity, animate2::load("assets/animate2.json", sprite->name));
|
||||
}
|
||||
}
|
||||
|
||||
void step_animation(DinkyECS::World& world, DinkyECS::Entity entity, sf::Sprite& sprite) {
|
||||
if(auto anim = world.get_if<Animate2>(entity)) {
|
||||
if(anim->playing) {
|
||||
anim->update();
|
||||
anim->apply(sprite);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void animate_entity(DinkyECS::World &world, DinkyECS::Entity entity) {
|
||||
if(auto anim = world.get_if<Animate2>(entity)) {
|
||||
anim->play();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue