From 81a282d5443521508eec48d6359adeaaa744b449 Mon Sep 17 00:00:00 2001 From: "Zed A. Shaw" Date: Tue, 24 Feb 2026 11:36:57 -0500 Subject: [PATCH] Finally renamed animate2 to animation thus completing the refactor. There's still things to do to make the new animation actually work though. --- animate2.cpp => animation.cpp | 38 ++-- animate2.hpp => animation.hpp | 8 +- assets/{animate2.json => animation.json} | 0 assets/animations.json | 256 ----------------------- camera.cpp | 10 +- camera.hpp | 4 +- ease2.cpp | 4 +- ease2.hpp | 26 +-- gui/main_ui.cpp | 4 +- gui/main_ui.hpp | 6 +- gui/ritual_ui.cpp | 2 +- gui/ritual_ui.hpp | 4 +- meson.build | 4 +- raycaster.cpp | 4 +- scene.cpp | 4 +- scene.hpp | 4 +- systems.cpp | 12 +- tests/{animate2.cpp => animation.cpp} | 12 +- tools/animator.cpp | 12 +- tools/animator.hpp | 4 +- worldbuilder.cpp | 4 +- 21 files changed, 83 insertions(+), 339 deletions(-) rename animate2.cpp => animation.cpp (89%) rename animate2.hpp => animation.hpp (95%) rename assets/{animate2.json => animation.json} (100%) delete mode 100644 assets/animations.json rename tests/{animate2.cpp => animation.cpp} (94%) diff --git a/animate2.cpp b/animation.cpp similarity index 89% rename from animate2.cpp rename to animation.cpp index 77e3017..56f20f6 100644 --- a/animate2.cpp +++ b/animation.cpp @@ -1,4 +1,4 @@ -#include "animate2.hpp" +#include "animation.hpp" #include #include #include "dbc.hpp" @@ -10,10 +10,10 @@ constexpr float SUB_FRAME_SENSITIVITY = 0.999f; -namespace animate2 { +namespace animation { using namespace std::chrono_literals; - std::vector Animate2::calc_frames() { + std::vector Animation::calc_frames() { dbc::check(sequence.frames.size() == sequence.durations.size(), "sequence.frames.size() != sequence.durations.size()"); std::vector frames; @@ -29,7 +29,7 @@ namespace animate2 { return frames; } - void Animate2::play() { + void Animation::play() { dbc::check(!playing, "can't call play while playing?"); sequence.current = 0; sequence.subframe = 0.0f; @@ -39,21 +39,21 @@ namespace animate2 { sequence.INVARIANT(); } - void Animate2::stop() { + void Animation::stop() { playing = false; sequence.timer.reset(); } // need one for each kind of thing to animate // NOTE: possibly find a way to only run apply on frame change? - void Animate2::apply(sf::Sprite& sprite) { + void Animation::apply(sf::Sprite& sprite) { dbc::check(sequence.current < $frame_rects.size(), "current frame past $frame_rects"); // NOTE: pos is not updated yet auto& rect = $frame_rects.at(sequence.current); sprite.setTextureRect(rect); } - void Animate2::motion(sf::View& view_out, sf::Vector2f pos, sf::Vector2f size) { + void Animation::motion(sf::View& view_out, sf::Vector2f pos, sf::Vector2f size) { dbc::check(size.x > 1.0f && size.y > 1.0f, "motion size must be above 1.0 since it's not a ratio"); dbc::check(transform.flipped == false, "transform must be false, has no effect on View"); @@ -70,14 +70,14 @@ namespace animate2 { } } - void Animate2::apply_effect(std::shared_ptr effect) { + void Animation::apply_effect(std::shared_ptr effect) { dbc::check(effect != nullptr, "can't apply null effect"); effect->setUniform("u_time", sequence.timer.getElapsedTime().asSeconds()); sf::Vector2f u_resolution{float(sheet.frame_width), float(sheet.frame_height)}; effect->setUniform("u_resolution", u_resolution); } - void Animate2::play_sound() { + void Animation::play_sound() { // BUG: this can be optimized way better if(sounds.contains(form_name)) { for(auto& [at_frame, sound_name] : sounds.at(form_name)) { @@ -96,7 +96,7 @@ namespace animate2 { * calling getElapsedTime() when I already did that in commit(), so should I just ignore that and assume * elapsed is DELTA, or use elapsed here? */ - void Animate2::update() { + void Animation::update() { dbc::check(playing, "attempt to update animation that's not playing"); sequence.INVARIANT(); @@ -127,7 +127,7 @@ namespace animate2 { if(frame_change && onFrame != nullptr) onFrame(); } - void Animate2::motion(sf::Transformable& sprite, sf::Vector2f pos, sf::Vector2f scale) { + void Animation::motion(sf::Transformable& sprite, sf::Vector2f pos, sf::Vector2f scale) { sequence.INVARIANT(); transform.apply(sequence, pos, scale); @@ -196,11 +196,11 @@ namespace animate2 { motion_func(*this, pos_out, scale_out, tick, relative); } - bool Animate2::has_form(const std::string& as_form) { + bool Animation::has_form(const std::string& as_form) { return forms.contains(as_form); } - void Animate2::set_form(const std::string& as_form) { + void Animation::set_form(const std::string& as_form) { dbc::check(forms.contains(as_form), fmt::format("form {} does not exist in animation", as_form)); stop(); @@ -235,7 +235,7 @@ namespace animate2 { sequence.INVARIANT(); } - Animate2 load(const std::string &file, const std::string &anim_name) { + Animation load(const std::string &file, const std::string &anim_name) { using nlohmann::json; std::ifstream infile(file); auto data = json::parse(infile); @@ -243,8 +243,8 @@ namespace animate2 { 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); + Animation anim; + animation::from_json(data[anim_name], anim); dbc::check(anim.forms.contains("idle"), fmt::format("animation {} must have 'idle' form", anim_name)); @@ -276,7 +276,7 @@ namespace animate2 { // BUG: BAAADD REMOVE bool has(const std::string& name) { using nlohmann::json; - std::ifstream infile("assets/animate2.json"); + std::ifstream infile("assets/animation.json"); auto data = json::parse(infile); return data.contains(name); } @@ -285,12 +285,12 @@ namespace animate2 { auto sprite = world.get_if(entity); if(sprite != nullptr && has(sprite->name)) { - world.set(entity, animate2::load("assets/animate2.json", sprite->name)); + world.set(entity, animation::load("assets/animation.json", sprite->name)); } } void animate_entity(DinkyECS::World &world, DinkyECS::Entity entity) { - auto anim = world.get_if(entity); + auto anim = world.get_if(entity); if(anim != nullptr && !anim->playing) { anim->play(); diff --git a/animate2.hpp b/animation.hpp similarity index 95% rename from animate2.hpp rename to animation.hpp index bb81447..dfba6ae 100644 --- a/animate2.hpp +++ b/animation.hpp @@ -14,7 +14,7 @@ #include #include "dinkyecs.hpp" -namespace animate2 { +namespace animation { template struct NameOf; @@ -97,7 +97,7 @@ namespace animate2 { using Form = std::pair; using Sound = std::pair; - class Animate2 { + class Animation { public: Sheet sheet; std::unordered_map sequences; @@ -131,7 +131,7 @@ namespace animate2 { void motion(sf::View& view_out, sf::Vector2f pos, sf::Vector2f scale); }; - Animate2 load(const std::string &file, const std::string &anim_name); + Animation load(const std::string &file, const std::string &anim_name); // BUG: brought over from animation to finish the refactor, but these may not be needed or maybe they go in system.cpp? bool has(const std::string& name); @@ -144,5 +144,5 @@ namespace animate2 { ENROLL_COMPONENT(Sequence, frames, durations); ENROLL_COMPONENT(Transform, min_x, min_y, max_x, max_y, flipped, scaled, relative, toggled, looped, easing, motion); - ENROLL_COMPONENT(Animate2, sheet, sequences, transforms, forms, sounds); + ENROLL_COMPONENT(Animation, sheet, sequences, transforms, forms, sounds); } diff --git a/assets/animate2.json b/assets/animation.json similarity index 100% rename from assets/animate2.json rename to assets/animation.json diff --git a/assets/animations.json b/assets/animations.json deleted file mode 100644 index 8139ad4..0000000 --- a/assets/animations.json +++ /dev/null @@ -1,256 +0,0 @@ -{ - "burning_animation": { - "_type": "Animation", - "easing": 0, - "motion": 0, - "ease_rate": 0.5, - "min_x": 1.0, - "min_y": 1.0, - "max_x": 1.0, - "max_y": 1.0, - "simple": false, - "frames": 5, - "speed": 0.1, - "stationary": false, - "flipped": false, - "toggled": false, - "flipped": false, - "scaled": true, - "looped": false - }, - "male_hand": { - "_type": "Animation", - "easing": 0, - "motion": 0, - "ease_rate": 0.5, - "min_x": 1.0, - "min_y": 1.0, - "max_x": 1.0, - "max_y": 1.0, - "simple": false, - "frames": 3, - "speed": 0.08, - "scaled": true, - "stationary": false, - "flipped": false, - "toggled": false, - "flipped": false, - "looped": false - }, - "female_hand": { - "_type": "Animation", - "easing": 0, - "motion": 0, - "ease_rate": 0.5, - "min_x": 1.0, - "min_y": 1.0, - "max_x": 1.0, - "max_y": 1.0, - "simple": false, - "frames": 3, - "speed": 0.08, - "scaled": true, - "stationary": false, - "toggled": false, - "flipped": false, - "looped": false - }, - "lightning_animation": { - "_type": "Animation", - "easing": 0, - "motion": 0, - "ease_rate": 0.5, - "min_x": 1.0, - "min_y": 1.0, - "max_x": 1.0, - "max_y": 1.0, - "simple": false, - "frames": 5, - "speed": 0.5, - "scaled": true, - "stationary": false, - "toggled": false, - "flipped": false, - "looped": false - }, - "ritual_crafting_area": { - "_type": "Animation", - "easing": 0, - "motion": 0, - "ease_rate": 0.5, - "min_x": 1.0, - "min_y": 1.0, - "max_x": 1.0, - "max_y": 1.0, - "scaled": true, - "simple": false, - "frames": 3, - "speed": 0.2, - "stationary": true, - "toggled": true, - "flipped": false, - "looped": false - }, - "peasant_girl_rear_view": { - "_type": "Animation", - "easing": 6, - "motion": 1, - "ease_rate": 0.05, - "min_x": -20.0, - "min_y": -20.0, - "max_x": 20.0, - "max_y": 20.0, - "simple": true, - "frames": 1, - "speed": 0.01, - "scaled": false, - "stationary": true, - "toggled": false, - "flipped": false, - "looped": false - }, - "gold_savior": { - "_type": "Animation", - "easing": 1, - "motion": 0, - "ease_rate": 0.2, - "min_x": 1.1, - "min_y": 1.1, - "max_x": 1.2, - "max_y": 1.2, - "simple": true, - "frames": 10, - "speed": 0.3, - "scaled": true, - "stationary": false, - "toggled": false, - "flipped": false, - "looped": false - }, - "armored_knight" : { - "_type": "Animation", - "easing": 1, - "motion": 0, - "ease_rate": 0.2, - "min_x": 1.1, - "min_y": 1.1, - "max_x": 1.2, - "max_y": 1.2, - "simple": true, - "frames": 10, - "speed": 0.3, - "scaled": true, - "stationary": false, - "toggled": false, - "flipped": false, - "looped": false - }, - "axe_ranger": { - "_type": "Animation", - "easing": 3, - "motion": 0, - "ease_rate": 0.5, - "min_x": 1.1, - "min_y": 1.1, - "max_x": 1.2, - "max_y": 1.2, - "simple": true, - "frames": 1, - "speed": 0.2, - "scaled": true, - "stationary": false, - "toggled": false, - "flipped": false, - "looped": false - }, - "rat_with_sword": { - "_type": "Animation", - "easing": 6, - "motion": 2, - "ease_rate": 0.5, - "min_x": -150.0, - "min_y": -150.0, - "max_x": 150.0, - "max_y": 150.0, - "simple": true, - "frames": 1, - "speed": 0.5, - "scaled": false, - "stationary": true, - "toggled": false, - "flipped": false, - "looped": false - }, - "hairy_spider": { - "_type": "Animation", - "easing": 2, - "motion": 0, - "ease_rate": 0.5, - "min_x": 0.9, - "min_y": 0.9, - "max_x": 1.1, - "max_y": 1.1, - "simple": true, - "frames": 10, - "speed": 0.2, - "scaled": true, - "stationary": false, - "toggled": false, - "flipped": false, - "looped": false - }, - "test_boss": { - "_type": "Animation", - "easing": 1, - "motion": 0, - "ease_rate": 0.5, - "min_x": 0.4, - "min_y": 0.4, - "max_x": 0.4, - "max_y": 0.4, - "simple": true, - "frames": 1, - "speed": 0.02, - "scaled": true, - "stationary": true, - "toggled": false, - "flipped": false, - "looped": false - }, - "rat_king_boss": { - "_type": "Animation", - "easing": 4, - "motion": 0, - "ease_rate": 0.5, - "min_x": 0.6, - "min_y": 0.6, - "max_x": 0.8, - "max_y": 0.8, - "simple": false, - "frames": 2, - "speed": 0.02, - "scaled": true, - "stationary": true, - "toggled": false, - "flipped": false, - "looped": false - }, - "torch_fixture": { - "_type": "Animation", - "easing": 0, - "motion": 1000, - "ease_rate": 0.1, - "min_x": 0.6, - "min_y": 0.6, - "max_x": 0.6, - "max_y": 0.6, - "simple": false, - "frames": 3, - "speed": 0.2, - "scaled": true, - "stationary": true, - "toggled": false, - "flipped": false, - "looped": true - } -} diff --git a/camera.cpp b/camera.cpp index cc1e5c1..9dda552 100644 --- a/camera.cpp +++ b/camera.cpp @@ -7,10 +7,10 @@ #include namespace cinematic { - using animate2::Animate2, std::string, std::min, std::clamp; + using animation::Animation, std::string, std::min, std::clamp; struct CameraManager { - std::unordered_map animations; + std::unordered_map animations; }; static CameraManager MGR; @@ -22,7 +22,7 @@ namespace cinematic { auto data = settings::get("cameras"); for(auto [key, value] : data.json().items()) { - auto anim = components::convert(value); + auto anim = components::convert(value); MGR.animations.try_emplace(key, anim); } @@ -122,10 +122,10 @@ namespace cinematic { anim.forms.clear(); for(auto& [timecode, cell, transform, duration] : story.beats) { - animate2::Sequence seq{.frames={0}, .durations={std::stoi(duration)}}; + animation::Sequence seq{.frames={0}, .durations={std::stoi(duration)}}; anim.sequences.try_emplace(timecode, seq); - animate2::Form form{timecode, transform}; + animation::Form form{timecode, transform}; anim.forms.try_emplace(timecode, form); } } diff --git a/camera.hpp b/camera.hpp index 3303bfa..b6543ec 100644 --- a/camera.hpp +++ b/camera.hpp @@ -1,5 +1,5 @@ #pragma once -#include "animate2.hpp" +#include "animation.hpp" #include "constants.hpp" #include @@ -9,7 +9,7 @@ namespace components { namespace cinematic { struct Camera { - animate2::Animate2 anim; + animation::Animation anim; sf::Vector2f size{SCREEN_WIDTH, SCREEN_HEIGHT}; sf::Vector2f base_size{SCREEN_WIDTH, SCREEN_HEIGHT}; sf::Vector2f aimed_at{0,0}; diff --git a/ease2.cpp b/ease2.cpp index 9ddbff4..5741bfd 100644 --- a/ease2.cpp +++ b/ease2.cpp @@ -1,12 +1,12 @@ #include "easings.hpp" #include "rand.hpp" -#include "animate2.hpp" +#include "animation.hpp" #include #include #include "dbc.hpp" namespace ease2 { - using namespace animate2; + using namespace animation; double none(float tick) { return 0.0; diff --git a/ease2.hpp b/ease2.hpp index c76a51b..c0348a8 100644 --- a/ease2.hpp +++ b/ease2.hpp @@ -1,13 +1,13 @@ #include -#include "animate2.hpp" +#include "animation.hpp" -namespace animate2 { +namespace animation { struct Transform; } namespace ease2 { using EaseFunc = std::function; - using MotionFunc = std::function; + using MotionFunc = std::function; EaseFunc get_easing(const std::string& name); MotionFunc get_motion(const std::string& name); @@ -19,14 +19,14 @@ namespace ease2 { double random(double tick); double normal_dist(double tick); - void move_bounce(animate2::Transform &tr, sf::Vector2f& pos_out, sf::Vector2f& scale_out, float tick, bool relative); - void move_rush(animate2::Transform &tr, sf::Vector2f& pos_out, sf::Vector2f& scale_out, float tick, bool relative); - void scale_squeeze(animate2::Transform &tr, sf::Vector2f& pos_out, sf::Vector2f& scale_out, float tick, bool relative); - void scale_squash(animate2::Transform &tr, sf::Vector2f& pos_out, sf::Vector2f& scale_out, float tick, bool relative); - void scale_stretch(animate2::Transform &tr, sf::Vector2f& pos_out, sf::Vector2f& scale_out, float tick, bool relative); - void scale_grow(animate2::Transform &tr, sf::Vector2f& pos_out, sf::Vector2f& scale_out, float tick, bool relative); - void move_slide(animate2::Transform &tr, sf::Vector2f& pos_out, sf::Vector2f& scale_out, float tick, bool relative); - void move_none(animate2::Transform &tr, sf::Vector2f& pos_out, sf::Vector2f& scale_out, float tick, bool relative); - void scale_only(animate2::Transform &tr, sf::Vector2f& pos_out, sf::Vector2f& scale_out, float tick, bool relative); - void move_shake(animate2::Transform &tr, sf::Vector2f& pos_out, sf::Vector2f& scale_out, float tick, bool relative); + void move_bounce(animation::Transform &tr, sf::Vector2f& pos_out, sf::Vector2f& scale_out, float tick, bool relative); + void move_rush(animation::Transform &tr, sf::Vector2f& pos_out, sf::Vector2f& scale_out, float tick, bool relative); + void scale_squeeze(animation::Transform &tr, sf::Vector2f& pos_out, sf::Vector2f& scale_out, float tick, bool relative); + void scale_squash(animation::Transform &tr, sf::Vector2f& pos_out, sf::Vector2f& scale_out, float tick, bool relative); + void scale_stretch(animation::Transform &tr, sf::Vector2f& pos_out, sf::Vector2f& scale_out, float tick, bool relative); + void scale_grow(animation::Transform &tr, sf::Vector2f& pos_out, sf::Vector2f& scale_out, float tick, bool relative); + void move_slide(animation::Transform &tr, sf::Vector2f& pos_out, sf::Vector2f& scale_out, float tick, bool relative); + void move_none(animation::Transform &tr, sf::Vector2f& pos_out, sf::Vector2f& scale_out, float tick, bool relative); + void scale_only(animation::Transform &tr, sf::Vector2f& pos_out, sf::Vector2f& scale_out, float tick, bool relative); + void move_shake(animation::Transform &tr, sf::Vector2f& pos_out, sf::Vector2f& scale_out, float tick, bool relative); } diff --git a/gui/main_ui.cpp b/gui/main_ui.cpp index 0bbe2b2..09e26f0 100644 --- a/gui/main_ui.cpp +++ b/gui/main_ui.cpp @@ -2,7 +2,7 @@ #include "components.hpp" #include "easings.hpp" #include -#include "animate2.hpp" +#include "animation.hpp" #include "constants.hpp" #include "game_level.hpp" #include "ai.hpp" @@ -20,7 +20,7 @@ namespace gui { auto config = settings::get("config"); $hand = textures::get_sprite(config["player"]["hands"]); - $hand_anim = animate2::load("assets/animate2.json", config["player"]["hands"]); + $hand_anim = animation::load("assets/animation.json", config["player"]["hands"]); } void MainUI::dirty() { diff --git a/gui/main_ui.hpp b/gui/main_ui.hpp index 0b32ffb..49fe7dd 100644 --- a/gui/main_ui.hpp +++ b/gui/main_ui.hpp @@ -8,8 +8,8 @@ #include "raycaster.hpp" #include -namespace animate2 { - class Animate2; +namespace animation { + class Animation; } namespace gui { @@ -23,7 +23,7 @@ namespace gui { OverlayUI $overlay_ui; std::shared_ptr $rayview; textures::SpriteTexture $hand; - animate2::Animate2 $hand_anim; + animation::Animation $hand_anim; MainUI(sf::RenderWindow& window); diff --git a/gui/ritual_ui.cpp b/gui/ritual_ui.cpp index 9670c58..d80c92f 100644 --- a/gui/ritual_ui.cpp +++ b/gui/ritual_ui.cpp @@ -42,7 +42,7 @@ namespace gui { $ritual_ui = textures::get_sprite("ritual_crafting_area"); $ritual_ui.sprite->setPosition($gui.get_position()); $ritual_ui.sprite->setTextureRect($ritual_closed_rect); - $ritual_anim = animate2::load("assets/animate2.json", "ritual_crafting_area"); + $ritual_anim = animation::load("assets/animation.json", "ritual_crafting_area"); auto open_close_toggle = $gui.entity("ritual_ui"); $gui.set(open_close_toggle, { diff --git a/gui/ritual_ui.hpp b/gui/ritual_ui.hpp index ebcaba8..075c8fa 100644 --- a/gui/ritual_ui.hpp +++ b/gui/ritual_ui.hpp @@ -5,7 +5,7 @@ #include #include "rituals.hpp" #include "simplefsm.hpp" -#include "animate2.hpp" +#include "animation.hpp" namespace gui { namespace ritual { @@ -35,7 +35,7 @@ namespace gui { public: sf::IntRect $ritual_closed_rect{{0,0},{380,720}}; sf::IntRect $ritual_open_rect{{380 * 2,0},{380,720}}; - animate2::Animate2 $ritual_anim; + animation::Animation $ritual_anim; guecs::UI $gui; textures::SpriteTexture $ritual_ui; ::ritual::Engine $ritual_engine; diff --git a/meson.build b/meson.build index 8186667..5ca416e 100644 --- a/meson.build +++ b/meson.build @@ -87,7 +87,7 @@ dependencies += [ sources = [ 'ai.cpp', 'ai_debug.cpp', - 'animate2.cpp', + 'animation.cpp', 'autowalker.cpp', 'backend.cpp', 'battle.cpp', @@ -138,7 +138,7 @@ sources = [ executable('runtests', sources + [ 'tests/ai.cpp', - 'tests/animate2.cpp', + 'tests/animation.cpp', 'tests/base.cpp', 'tests/battle.cpp', 'tests/camera.cpp', diff --git a/raycaster.cpp b/raycaster.cpp index b62804b..30a5df8 100644 --- a/raycaster.cpp +++ b/raycaster.cpp @@ -11,7 +11,7 @@ #include "textures.hpp" #include "systems.hpp" #include "shaders.hpp" -#include "animate2.hpp" +#include "animation.hpp" using namespace fmt; using std::make_unique, std::shared_ptr; @@ -102,7 +102,7 @@ void Raycaster::apply_sprite_effect(shared_ptr effect, float width, } inline void step_animation(DinkyECS::World& world, DinkyECS::Entity entity, sf::Sprite& sprite, sf::Vector2f& position, sf::Vector2f& scale) { - auto anim = world.get_if(entity); + auto anim = world.get_if(entity); if(anim != nullptr && anim->playing) { anim->update(); diff --git a/scene.cpp b/scene.cpp index 582a7e9..6b5d61d 100644 --- a/scene.cpp +++ b/scene.cpp @@ -1,5 +1,5 @@ #include "scene.hpp" -#include "animate2.hpp" +#include "animation.hpp" #include "shaders.hpp" #include #include "dbc.hpp" @@ -18,7 +18,7 @@ namespace scene { bool flipped = config["flipped"]; // BUG: put the .json file to load as a default/optional arg - auto anim = animate2::load("./assets/animate2.json", sprite_name); + auto anim = animation::load("./assets/animation.json", sprite_name); anim.play(); anim.transform.flipped = flipped; diff --git a/scene.hpp b/scene.hpp index 4a7b895..023d911 100644 --- a/scene.hpp +++ b/scene.hpp @@ -7,7 +7,7 @@ #include #include "camera.hpp" #include -#include "animate2.hpp" +#include "animation.hpp" #include "components.hpp" namespace scene { @@ -17,7 +17,7 @@ namespace scene { struct Element { std::string name; textures::SpriteTexture st; - animate2::Animate2 anim; + animation::Animation anim; std::string cell; sf::Vector2f scale{1.0f, 1.0f}; sf::Vector2f pos{0.0f, 0.0f}; diff --git a/systems.cpp b/systems.cpp index d5a4143..f4b665f 100644 --- a/systems.cpp +++ b/systems.cpp @@ -18,7 +18,7 @@ #include "inventory.hpp" #include "game_level.hpp" #include "events.hpp" -#include "animate2.hpp" +#include "animation.hpp" using std::string; using namespace fmt; @@ -279,7 +279,7 @@ void System::combat(int attack_id) { if(enemy_action == "kill_enemy") { result.enemy_did = enemy.combat->attack(player_combat); - animate2::animate_entity(world, enemy.entity); + animation::animate_entity(world, enemy.entity); } world.send(game::Event::COMBAT, enemy.entity, result); @@ -654,13 +654,13 @@ void System::clear_attack() { auto world = GameDB::current_world(); std::vector dead_anim; - world->query([&](auto ent, auto& anim, auto&) { + world->query([&](auto ent, auto& anim, auto&) { if(!anim.playing) dead_anim.push_back(ent); }); for(auto ent : dead_anim) { world->remove(ent); - world->remove(ent); + world->remove(ent); world->remove(ent); remove_from_world(ent); } @@ -686,9 +686,9 @@ void System::spawn_attack(World& world, int attack_id, DinkyECS::Entity enemy) { // also add the same effect to the enemy world.set(enemy, {50, shader}); - auto anim = animate2::load("assets/animate2.json", effect); + auto anim = animation::load("assets/animation.json", effect); anim.play(); - world.set(effect_id, anim); + world.set(effect_id, anim); drop_item(effect_id); } diff --git a/tests/animate2.cpp b/tests/animation.cpp similarity index 94% rename from tests/animate2.cpp rename to tests/animation.cpp index 965a63b..6c7fed2 100644 --- a/tests/animate2.cpp +++ b/tests/animation.cpp @@ -7,17 +7,17 @@ #include #include #include "rand.hpp" -#include "animate2.hpp" +#include "animation.hpp" #include "sound.hpp" #include "components.hpp" using namespace components; using namespace textures; using namespace std::chrono_literals; -using namespace animate2; +using namespace animation; -Animate2 load_animation(const string& name) { - auto anim = animate2::load("assets/animate2.json", "rat_king_boss"); +Animation load_animation(const string& name) { + auto anim = animation::load("assets/animation.json", "rat_king_boss"); anim.set_form("attack"); anim.transform.looped = false; @@ -33,7 +33,7 @@ void FAKE_RENDER() { std::this_thread::sleep_for(Random::milliseconds(5, 32)); } -void PLAY_TEST(Animate2 &anim) { +void PLAY_TEST(Animation &anim) { REQUIRE(anim.transform.looped == false); anim.play(); @@ -158,7 +158,7 @@ TEST_CASE("confirm transition changes work", "[animation-new]") { } TEST_CASE("playing with delta time", "[animation-new]") { - animate2::Timer timer; + animation::Timer timer; timer.start(); for(int i = 0; i < 20; i++) { diff --git a/tools/animator.cpp b/tools/animator.cpp index 2d61df9..781a74c 100644 --- a/tools/animator.cpp +++ b/tools/animator.cpp @@ -5,7 +5,7 @@ #include "shaders.hpp" #include "backend.hpp" #include "constants.hpp" -#include "animate2.hpp" +#include "animation.hpp" #include "tools/animator.hpp" #include #include @@ -124,7 +124,7 @@ namespace animator { void FSM::check_update() { if($timer.getElapsedTime().toDuration() > 500ms) { try { - auto mod_time = std::filesystem::last_write_time("assets/animate2.json"); + auto mod_time = std::filesystem::last_write_time("assets/animation.json"); if($last_mod_time < mod_time) { event(Event::RELOAD); @@ -139,10 +139,10 @@ namespace animator { } void FSM::reload() { - animate2::Animate2 new_anim; + animation::Animation new_anim; try { - new_anim = animate2::load("assets/animate2.json", $anim_name); + new_anim = animation::load("assets/animation.json", $anim_name); } catch(...) { $ui.show_error("Failed to load JSON"); return; @@ -157,7 +157,7 @@ namespace animator { new_anim.set_form($cur_form); try { - $last_mod_time = std::filesystem::last_write_time("assets/animate2.json"); + $last_mod_time = std::filesystem::last_write_time("assets/animation.json"); } catch(...) { $ui.show_error("Filesystem error"); } @@ -262,7 +262,7 @@ namespace animator { return $ui.mouse(x, y, mods); } - void UI::update_status(animate2::Animate2& anim) { + void UI::update_status(animation::Animation& anim) { $overlay.show_text("form", guecs::to_wstring(anim.form_name)); $overlay.show_text("sequence", guecs::to_wstring(anim.sequence_name)); $overlay.show_text("transform", guecs::to_wstring(anim.transform_name)); diff --git a/tools/animator.hpp b/tools/animator.hpp index b1e0c7e..2186f2c 100644 --- a/tools/animator.hpp +++ b/tools/animator.hpp @@ -35,7 +35,7 @@ namespace animator { void init(const std::string& sprite_name, const std::string& background, int width, int height); void render(sf::RenderWindow& window, bool debug=false); bool mouse(float x, float y, guecs::Modifiers mods); - void update_status(animate2::Animate2& anim); + void update_status(animation::Animation& anim); std::shared_ptr get_sprite(); void show_error(const std::string& message); void clear_error(); @@ -47,7 +47,7 @@ namespace animator { sf::RenderWindow $window; sf::Vector2f $pos{0,0}; sf::Vector2f $scale{0,0}; - animate2::Animate2 $anim; + animation::Animation $anim; std::string $sprite_name=""; std::string $anim_name=""; std::string $background=""; diff --git a/worldbuilder.cpp b/worldbuilder.cpp index 931f9e2..1bf9bb5 100644 --- a/worldbuilder.cpp +++ b/worldbuilder.cpp @@ -8,7 +8,7 @@ #include "textures.hpp" #include "inventory.hpp" #include "systems.hpp" -#include "animate2.hpp" +#include "animation.hpp" using namespace fmt; using namespace components; @@ -101,7 +101,7 @@ DinkyECS::Entity WorldBuilder::configure_entity_in_map(DinkyECS::World &world, j } System::set_position(world, $collision, item, {pos.x, pos.y}); - animate2::configure(world, item); + animation::configure(world, item); return item; }