Scene now renders correctly, but I need to pull out the json in config_scene_element and make a component that's loaded.
This commit is contained in:
parent
2cef58be69
commit
458bf7e25e
2 changed files with 18 additions and 25 deletions
41
scene.cpp
41
scene.cpp
|
|
@ -8,7 +8,7 @@
|
|||
const bool DEBUG=false;
|
||||
|
||||
namespace scene {
|
||||
Element Engine::config_scene_element(nlohmann::json& config, bool and_play, bool duped) {
|
||||
Element Engine::config_scene_element(nlohmann::json& config, bool duped) {
|
||||
std::string sprite_name = config["sprite"];
|
||||
auto st = textures::get_sprite(sprite_name, duped);
|
||||
|
||||
|
|
@ -20,7 +20,7 @@ namespace scene {
|
|||
|
||||
// BUG: put the .json file to load as a default/optional arg
|
||||
auto anim = animate2::load("./assets/animate2.json", sprite_name);
|
||||
if(and_play) anim.play();
|
||||
anim.play();
|
||||
|
||||
anim.transform.flipped = flipped;
|
||||
|
||||
|
|
@ -38,7 +38,7 @@ namespace scene {
|
|||
$scene(scene)
|
||||
{
|
||||
for(auto& config : $scene.actors) {
|
||||
auto element = config_scene_element(config, false, false);
|
||||
auto element = config_scene_element(config, false);
|
||||
dbc::check(!$actor_name_ids.contains(element.name),
|
||||
fmt::format("actors key {} already exists", element.name));
|
||||
$actors.push_back(element);
|
||||
|
|
@ -46,7 +46,7 @@ namespace scene {
|
|||
}
|
||||
|
||||
for(auto& fixture : $scene.fixtures) {
|
||||
auto element = config_scene_element(fixture, true, true);
|
||||
auto element = config_scene_element(fixture, true);
|
||||
$fixtures.push_back(element);
|
||||
}
|
||||
|
||||
|
|
@ -125,28 +125,20 @@ namespace scene {
|
|||
if(!config.anim.playing) config.anim.play();
|
||||
}
|
||||
|
||||
void Engine::play_animations() {
|
||||
for(auto& fixture : $fixtures) {
|
||||
if(fixture.anim.playing) {
|
||||
fixture.anim.update();
|
||||
fixture.anim.motion(*fixture.st.sprite, fixture.pos, fixture.scale);
|
||||
fixture.anim.apply(*fixture.st.sprite);
|
||||
} else {
|
||||
fixture.effect = nullptr;
|
||||
inline void this_is_stupid_refactor(std::vector<Element>& elements) {
|
||||
for(auto& element : elements) {
|
||||
if(element.anim.playing) {
|
||||
element.anim.update();
|
||||
element.anim.motion(*element.st.sprite, element.pos, element.scale);
|
||||
element.anim.apply(*element.st.sprite);
|
||||
if(element.effect != nullptr) element.anim.apply_effect(element.effect);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for(auto& actor : $actors) {
|
||||
if(actor.anim.playing) {
|
||||
actor.anim.update();
|
||||
actor.anim.motion(*actor.st.sprite, actor.pos, actor.scale);
|
||||
actor.anim.apply(*actor.st.sprite);
|
||||
// REFACTOR: actor.anim.apply(actor.text, actor.pos);
|
||||
// if(actor.effect != nullptr) actor.anim.apply_effect(actor.effect);
|
||||
} else {
|
||||
actor.effect = nullptr;
|
||||
}
|
||||
}
|
||||
void Engine::play_animations() {
|
||||
this_is_stupid_refactor($fixtures);
|
||||
this_is_stupid_refactor($actors);
|
||||
}
|
||||
|
||||
sf::Vector2f Engine::position_sprite(textures::SpriteTexture& st, const std::string& cell_name, sf::Vector2f scale, bool at_mid, float x_diff, float y_diff) {
|
||||
|
|
@ -179,9 +171,10 @@ namespace scene {
|
|||
|
||||
void Engine::set_end_cb(std::function<void()> cb) {
|
||||
for(auto& actor : $actors) {
|
||||
actor.anim.onLoop = [=](auto& seq, auto& tr) -> bool {
|
||||
actor.anim.onLoop = [&,cb](auto& seq, auto& tr) -> bool {
|
||||
seq.current = tr.toggled ? seq.frame_count - 1 : 0;
|
||||
cb();
|
||||
actor.effect = nullptr;
|
||||
return tr.looped;
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue