Finally renamed animate2 to animation thus completing the refactor. There's still things to do to make the new animation actually work though.

This commit is contained in:
Zed A. Shaw 2026-02-24 11:36:57 -05:00
parent 83f62e3f45
commit 81a282d544
21 changed files with 83 additions and 339 deletions

View file

@ -1,4 +1,4 @@
#include "animate2.hpp" #include "animation.hpp"
#include <memory> #include <memory>
#include <chrono> #include <chrono>
#include "dbc.hpp" #include "dbc.hpp"
@ -10,10 +10,10 @@
constexpr float SUB_FRAME_SENSITIVITY = 0.999f; constexpr float SUB_FRAME_SENSITIVITY = 0.999f;
namespace animate2 { namespace animation {
using namespace std::chrono_literals; using namespace std::chrono_literals;
std::vector<sf::IntRect> Animate2::calc_frames() { std::vector<sf::IntRect> Animation::calc_frames() {
dbc::check(sequence.frames.size() == sequence.durations.size(), "sequence.frames.size() != sequence.durations.size()"); dbc::check(sequence.frames.size() == sequence.durations.size(), "sequence.frames.size() != sequence.durations.size()");
std::vector<sf::IntRect> frames; std::vector<sf::IntRect> frames;
@ -29,7 +29,7 @@ namespace animate2 {
return frames; return frames;
} }
void Animate2::play() { void Animation::play() {
dbc::check(!playing, "can't call play while playing?"); dbc::check(!playing, "can't call play while playing?");
sequence.current = 0; sequence.current = 0;
sequence.subframe = 0.0f; sequence.subframe = 0.0f;
@ -39,21 +39,21 @@ namespace animate2 {
sequence.INVARIANT(); sequence.INVARIANT();
} }
void Animate2::stop() { void Animation::stop() {
playing = false; playing = false;
sequence.timer.reset(); sequence.timer.reset();
} }
// need one for each kind of thing to animate // need one for each kind of thing to animate
// NOTE: possibly find a way to only run apply on frame change? // 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"); dbc::check(sequence.current < $frame_rects.size(), "current frame past $frame_rects");
// NOTE: pos is not updated yet // NOTE: pos is not updated yet
auto& rect = $frame_rects.at(sequence.current); auto& rect = $frame_rects.at(sequence.current);
sprite.setTextureRect(rect); 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(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"); 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<sf::Shader> effect) { void Animation::apply_effect(std::shared_ptr<sf::Shader> effect) {
dbc::check(effect != nullptr, "can't apply null effect"); dbc::check(effect != nullptr, "can't apply null effect");
effect->setUniform("u_time", sequence.timer.getElapsedTime().asSeconds()); effect->setUniform("u_time", sequence.timer.getElapsedTime().asSeconds());
sf::Vector2f u_resolution{float(sheet.frame_width), float(sheet.frame_height)}; sf::Vector2f u_resolution{float(sheet.frame_width), float(sheet.frame_height)};
effect->setUniform("u_resolution", u_resolution); effect->setUniform("u_resolution", u_resolution);
} }
void Animate2::play_sound() { void Animation::play_sound() {
// BUG: this can be optimized way better // BUG: this can be optimized way better
if(sounds.contains(form_name)) { if(sounds.contains(form_name)) {
for(auto& [at_frame, sound_name] : sounds.at(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 * calling getElapsedTime() when I already did that in commit(), so should I just ignore that and assume
* elapsed is DELTA, or use elapsed here? * elapsed is DELTA, or use elapsed here?
*/ */
void Animate2::update() { void Animation::update() {
dbc::check(playing, "attempt to update animation that's not playing"); dbc::check(playing, "attempt to update animation that's not playing");
sequence.INVARIANT(); sequence.INVARIANT();
@ -127,7 +127,7 @@ namespace animate2 {
if(frame_change && onFrame != nullptr) onFrame(); 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(); sequence.INVARIANT();
transform.apply(sequence, pos, scale); transform.apply(sequence, pos, scale);
@ -196,11 +196,11 @@ namespace animate2 {
motion_func(*this, pos_out, scale_out, tick, relative); 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); 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), dbc::check(forms.contains(as_form),
fmt::format("form {} does not exist in animation", as_form)); fmt::format("form {} does not exist in animation", as_form));
stop(); stop();
@ -235,7 +235,7 @@ namespace animate2 {
sequence.INVARIANT(); 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; using nlohmann::json;
std::ifstream infile(file); std::ifstream infile(file);
auto data = json::parse(infile); auto data = json::parse(infile);
@ -243,8 +243,8 @@ namespace animate2 {
dbc::check(data.contains(anim_name), dbc::check(data.contains(anim_name),
fmt::format("{} animation config does not have animation {}", file, anim_name)); fmt::format("{} animation config does not have animation {}", file, anim_name));
Animate2 anim; Animation anim;
animate2::from_json(data[anim_name], anim); animation::from_json(data[anim_name], anim);
dbc::check(anim.forms.contains("idle"), dbc::check(anim.forms.contains("idle"),
fmt::format("animation {} must have 'idle' form", anim_name)); fmt::format("animation {} must have 'idle' form", anim_name));
@ -276,7 +276,7 @@ namespace animate2 {
// BUG: BAAADD REMOVE // BUG: BAAADD REMOVE
bool has(const std::string& name) { bool has(const std::string& name) {
using nlohmann::json; using nlohmann::json;
std::ifstream infile("assets/animate2.json"); std::ifstream infile("assets/animation.json");
auto data = json::parse(infile); auto data = json::parse(infile);
return data.contains(name); return data.contains(name);
} }
@ -285,12 +285,12 @@ namespace animate2 {
auto sprite = world.get_if<components::Sprite>(entity); auto sprite = world.get_if<components::Sprite>(entity);
if(sprite != nullptr && has(sprite->name)) { if(sprite != nullptr && has(sprite->name)) {
world.set<Animate2>(entity, animate2::load("assets/animate2.json", sprite->name)); world.set<Animation>(entity, animation::load("assets/animation.json", sprite->name));
} }
} }
void animate_entity(DinkyECS::World &world, DinkyECS::Entity entity) { void animate_entity(DinkyECS::World &world, DinkyECS::Entity entity) {
auto anim = world.get_if<Animate2>(entity); auto anim = world.get_if<Animation>(entity);
if(anim != nullptr && !anim->playing) { if(anim != nullptr && !anim->playing) {
anim->play(); anim->play();

View file

@ -14,7 +14,7 @@
#include <source_location> #include <source_location>
#include "dinkyecs.hpp" #include "dinkyecs.hpp"
namespace animate2 { namespace animation {
template <typename T> struct NameOf; template <typename T> struct NameOf;
@ -97,7 +97,7 @@ namespace animate2 {
using Form = std::pair<std::string, std::string>; using Form = std::pair<std::string, std::string>;
using Sound = std::pair<size_t, std::string>; using Sound = std::pair<size_t, std::string>;
class Animate2 { class Animation {
public: public:
Sheet sheet; Sheet sheet;
std::unordered_map<std::string, Sequence> sequences; std::unordered_map<std::string, Sequence> sequences;
@ -131,7 +131,7 @@ namespace animate2 {
void motion(sf::View& view_out, sf::Vector2f pos, sf::Vector2f scale); 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? // 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); bool has(const std::string& name);
@ -144,5 +144,5 @@ namespace animate2 {
ENROLL_COMPONENT(Sequence, frames, durations); ENROLL_COMPONENT(Sequence, frames, durations);
ENROLL_COMPONENT(Transform, min_x, min_y, max_x, max_y, ENROLL_COMPONENT(Transform, min_x, min_y, max_x, max_y,
flipped, scaled, relative, toggled, looped, easing, motion); flipped, scaled, relative, toggled, looped, easing, motion);
ENROLL_COMPONENT(Animate2, sheet, sequences, transforms, forms, sounds); ENROLL_COMPONENT(Animation, sheet, sequences, transforms, forms, sounds);
} }

View file

@ -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
}
}

View file

@ -7,10 +7,10 @@
#include <cstdlib> #include <cstdlib>
namespace cinematic { namespace cinematic {
using animate2::Animate2, std::string, std::min, std::clamp; using animation::Animation, std::string, std::min, std::clamp;
struct CameraManager { struct CameraManager {
std::unordered_map<string, Animate2> animations; std::unordered_map<string, Animation> animations;
}; };
static CameraManager MGR; static CameraManager MGR;
@ -22,7 +22,7 @@ namespace cinematic {
auto data = settings::get("cameras"); auto data = settings::get("cameras");
for(auto [key, value] : data.json().items()) { for(auto [key, value] : data.json().items()) {
auto anim = components::convert<Animate2>(value); auto anim = components::convert<Animation>(value);
MGR.animations.try_emplace(key, anim); MGR.animations.try_emplace(key, anim);
} }
@ -122,10 +122,10 @@ namespace cinematic {
anim.forms.clear(); anim.forms.clear();
for(auto& [timecode, cell, transform, duration] : story.beats) { 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); anim.sequences.try_emplace(timecode, seq);
animate2::Form form{timecode, transform}; animation::Form form{timecode, transform};
anim.forms.try_emplace(timecode, form); anim.forms.try_emplace(timecode, form);
} }
} }

View file

@ -1,5 +1,5 @@
#pragma once #pragma once
#include "animate2.hpp" #include "animation.hpp"
#include "constants.hpp" #include "constants.hpp"
#include <SFML/Graphics/RenderTexture.hpp> #include <SFML/Graphics/RenderTexture.hpp>
@ -9,7 +9,7 @@ namespace components {
namespace cinematic { namespace cinematic {
struct Camera { struct Camera {
animate2::Animate2 anim; animation::Animation anim;
sf::Vector2f size{SCREEN_WIDTH, SCREEN_HEIGHT}; sf::Vector2f size{SCREEN_WIDTH, SCREEN_HEIGHT};
sf::Vector2f base_size{SCREEN_WIDTH, SCREEN_HEIGHT}; sf::Vector2f base_size{SCREEN_WIDTH, SCREEN_HEIGHT};
sf::Vector2f aimed_at{0,0}; sf::Vector2f aimed_at{0,0};

View file

@ -1,12 +1,12 @@
#include "easings.hpp" #include "easings.hpp"
#include "rand.hpp" #include "rand.hpp"
#include "animate2.hpp" #include "animation.hpp"
#include <fmt/core.h> #include <fmt/core.h>
#include <unordered_map> #include <unordered_map>
#include "dbc.hpp" #include "dbc.hpp"
namespace ease2 { namespace ease2 {
using namespace animate2; using namespace animation;
double none(float tick) { double none(float tick) {
return 0.0; return 0.0;

View file

@ -1,13 +1,13 @@
#include <functional> #include <functional>
#include "animate2.hpp" #include "animation.hpp"
namespace animate2 { namespace animation {
struct Transform; struct Transform;
} }
namespace ease2 { namespace ease2 {
using EaseFunc = std::function<double(double)>; using EaseFunc = std::function<double(double)>;
using MotionFunc = std::function<void(animate2::Transform &tr, sf::Vector2f& pos_out, sf::Vector2f& scale_out, float tick, bool relative)>; using MotionFunc = std::function<void(animation::Transform &tr, sf::Vector2f& pos_out, sf::Vector2f& scale_out, float tick, bool relative)>;
EaseFunc get_easing(const std::string& name); EaseFunc get_easing(const std::string& name);
MotionFunc get_motion(const std::string& name); MotionFunc get_motion(const std::string& name);
@ -19,14 +19,14 @@ namespace ease2 {
double random(double tick); double random(double tick);
double normal_dist(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_bounce(animation::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 move_rush(animation::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_squeeze(animation::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_squash(animation::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_stretch(animation::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 scale_grow(animation::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_slide(animation::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 move_none(animation::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 scale_only(animation::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_shake(animation::Transform &tr, sf::Vector2f& pos_out, sf::Vector2f& scale_out, float tick, bool relative);
} }

View file

@ -2,7 +2,7 @@
#include "components.hpp" #include "components.hpp"
#include "easings.hpp" #include "easings.hpp"
#include <fmt/xchar.h> #include <fmt/xchar.h>
#include "animate2.hpp" #include "animation.hpp"
#include "constants.hpp" #include "constants.hpp"
#include "game_level.hpp" #include "game_level.hpp"
#include "ai.hpp" #include "ai.hpp"
@ -20,7 +20,7 @@ namespace gui {
auto config = settings::get("config"); auto config = settings::get("config");
$hand = textures::get_sprite(config["player"]["hands"]); $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() { void MainUI::dirty() {

View file

@ -8,8 +8,8 @@
#include "raycaster.hpp" #include "raycaster.hpp"
#include <optional> #include <optional>
namespace animate2 { namespace animation {
class Animate2; class Animation;
} }
namespace gui { namespace gui {
@ -23,7 +23,7 @@ namespace gui {
OverlayUI $overlay_ui; OverlayUI $overlay_ui;
std::shared_ptr<Raycaster> $rayview; std::shared_ptr<Raycaster> $rayview;
textures::SpriteTexture $hand; textures::SpriteTexture $hand;
animate2::Animate2 $hand_anim; animation::Animation $hand_anim;
MainUI(sf::RenderWindow& window); MainUI(sf::RenderWindow& window);

View file

@ -42,7 +42,7 @@ namespace gui {
$ritual_ui = textures::get_sprite("ritual_crafting_area"); $ritual_ui = textures::get_sprite("ritual_crafting_area");
$ritual_ui.sprite->setPosition($gui.get_position()); $ritual_ui.sprite->setPosition($gui.get_position());
$ritual_ui.sprite->setTextureRect($ritual_closed_rect); $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"); auto open_close_toggle = $gui.entity("ritual_ui");
$gui.set<Clickable>(open_close_toggle, { $gui.set<Clickable>(open_close_toggle, {

View file

@ -5,7 +5,7 @@
#include <guecs/ui.hpp> #include <guecs/ui.hpp>
#include "rituals.hpp" #include "rituals.hpp"
#include "simplefsm.hpp" #include "simplefsm.hpp"
#include "animate2.hpp" #include "animation.hpp"
namespace gui { namespace gui {
namespace ritual { namespace ritual {
@ -35,7 +35,7 @@ namespace gui {
public: public:
sf::IntRect $ritual_closed_rect{{0,0},{380,720}}; sf::IntRect $ritual_closed_rect{{0,0},{380,720}};
sf::IntRect $ritual_open_rect{{380 * 2,0},{380,720}}; sf::IntRect $ritual_open_rect{{380 * 2,0},{380,720}};
animate2::Animate2 $ritual_anim; animation::Animation $ritual_anim;
guecs::UI $gui; guecs::UI $gui;
textures::SpriteTexture $ritual_ui; textures::SpriteTexture $ritual_ui;
::ritual::Engine $ritual_engine; ::ritual::Engine $ritual_engine;

View file

@ -87,7 +87,7 @@ dependencies += [
sources = [ sources = [
'ai.cpp', 'ai.cpp',
'ai_debug.cpp', 'ai_debug.cpp',
'animate2.cpp', 'animation.cpp',
'autowalker.cpp', 'autowalker.cpp',
'backend.cpp', 'backend.cpp',
'battle.cpp', 'battle.cpp',
@ -138,7 +138,7 @@ sources = [
executable('runtests', sources + [ executable('runtests', sources + [
'tests/ai.cpp', 'tests/ai.cpp',
'tests/animate2.cpp', 'tests/animation.cpp',
'tests/base.cpp', 'tests/base.cpp',
'tests/battle.cpp', 'tests/battle.cpp',
'tests/camera.cpp', 'tests/camera.cpp',

View file

@ -11,7 +11,7 @@
#include "textures.hpp" #include "textures.hpp"
#include "systems.hpp" #include "systems.hpp"
#include "shaders.hpp" #include "shaders.hpp"
#include "animate2.hpp" #include "animation.hpp"
using namespace fmt; using namespace fmt;
using std::make_unique, std::shared_ptr; using std::make_unique, std::shared_ptr;
@ -102,7 +102,7 @@ void Raycaster::apply_sprite_effect(shared_ptr<sf::Shader> effect, float width,
} }
inline void step_animation(DinkyECS::World& world, DinkyECS::Entity entity, sf::Sprite& sprite, sf::Vector2f& position, sf::Vector2f& scale) { inline void step_animation(DinkyECS::World& world, DinkyECS::Entity entity, sf::Sprite& sprite, sf::Vector2f& position, sf::Vector2f& scale) {
auto anim = world.get_if<animate2::Animate2>(entity); auto anim = world.get_if<animation::Animation>(entity);
if(anim != nullptr && anim->playing) { if(anim != nullptr && anim->playing) {
anim->update(); anim->update();

View file

@ -1,5 +1,5 @@
#include "scene.hpp" #include "scene.hpp"
#include "animate2.hpp" #include "animation.hpp"
#include "shaders.hpp" #include "shaders.hpp"
#include <fmt/core.h> #include <fmt/core.h>
#include "dbc.hpp" #include "dbc.hpp"
@ -18,7 +18,7 @@ namespace scene {
bool flipped = config["flipped"]; bool flipped = config["flipped"];
// BUG: put the .json file to load as a default/optional arg // 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.play();
anim.transform.flipped = flipped; anim.transform.flipped = flipped;

View file

@ -7,7 +7,7 @@
#include <guecs/ui.hpp> #include <guecs/ui.hpp>
#include "camera.hpp" #include "camera.hpp"
#include <functional> #include <functional>
#include "animate2.hpp" #include "animation.hpp"
#include "components.hpp" #include "components.hpp"
namespace scene { namespace scene {
@ -17,7 +17,7 @@ namespace scene {
struct Element { struct Element {
std::string name; std::string name;
textures::SpriteTexture st; textures::SpriteTexture st;
animate2::Animate2 anim; animation::Animation anim;
std::string cell; std::string cell;
sf::Vector2f scale{1.0f, 1.0f}; sf::Vector2f scale{1.0f, 1.0f};
sf::Vector2f pos{0.0f, 0.0f}; sf::Vector2f pos{0.0f, 0.0f};

View file

@ -18,7 +18,7 @@
#include "inventory.hpp" #include "inventory.hpp"
#include "game_level.hpp" #include "game_level.hpp"
#include "events.hpp" #include "events.hpp"
#include "animate2.hpp" #include "animation.hpp"
using std::string; using std::string;
using namespace fmt; using namespace fmt;
@ -279,7 +279,7 @@ void System::combat(int attack_id) {
if(enemy_action == "kill_enemy") { if(enemy_action == "kill_enemy") {
result.enemy_did = enemy.combat->attack(player_combat); result.enemy_did = enemy.combat->attack(player_combat);
animate2::animate_entity(world, enemy.entity); animation::animate_entity(world, enemy.entity);
} }
world.send<game::Event>(game::Event::COMBAT, enemy.entity, result); world.send<game::Event>(game::Event::COMBAT, enemy.entity, result);
@ -654,13 +654,13 @@ void System::clear_attack() {
auto world = GameDB::current_world(); auto world = GameDB::current_world();
std::vector<Entity> dead_anim; std::vector<Entity> dead_anim;
world->query<animate2::Animate2, Temporary>([&](auto ent, auto& anim, auto&) { world->query<animation::Animation, Temporary>([&](auto ent, auto& anim, auto&) {
if(!anim.playing) dead_anim.push_back(ent); if(!anim.playing) dead_anim.push_back(ent);
}); });
for(auto ent : dead_anim) { for(auto ent : dead_anim) {
world->remove<Sprite>(ent); world->remove<Sprite>(ent);
world->remove<animate2::Animate2>(ent); world->remove<animation::Animation>(ent);
world->remove<SpriteEffect>(ent); world->remove<SpriteEffect>(ent);
remove_from_world(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 // also add the same effect to the enemy
world.set<SpriteEffect>(enemy, {50, shader}); world.set<SpriteEffect>(enemy, {50, shader});
auto anim = animate2::load("assets/animate2.json", effect); auto anim = animation::load("assets/animation.json", effect);
anim.play(); anim.play();
world.set<animate2::Animate2>(effect_id, anim); world.set<animation::Animation>(effect_id, anim);
drop_item(effect_id); drop_item(effect_id);
} }

View file

@ -7,17 +7,17 @@
#include <chrono> #include <chrono>
#include <thread> #include <thread>
#include "rand.hpp" #include "rand.hpp"
#include "animate2.hpp" #include "animation.hpp"
#include "sound.hpp" #include "sound.hpp"
#include "components.hpp" #include "components.hpp"
using namespace components; using namespace components;
using namespace textures; using namespace textures;
using namespace std::chrono_literals; using namespace std::chrono_literals;
using namespace animate2; using namespace animation;
Animate2 load_animation(const string& name) { Animation load_animation(const string& name) {
auto anim = animate2::load("assets/animate2.json", "rat_king_boss"); auto anim = animation::load("assets/animation.json", "rat_king_boss");
anim.set_form("attack"); anim.set_form("attack");
anim.transform.looped = false; anim.transform.looped = false;
@ -33,7 +33,7 @@ void FAKE_RENDER() {
std::this_thread::sleep_for(Random::milliseconds(5, 32)); std::this_thread::sleep_for(Random::milliseconds(5, 32));
} }
void PLAY_TEST(Animate2 &anim) { void PLAY_TEST(Animation &anim) {
REQUIRE(anim.transform.looped == false); REQUIRE(anim.transform.looped == false);
anim.play(); anim.play();
@ -158,7 +158,7 @@ TEST_CASE("confirm transition changes work", "[animation-new]") {
} }
TEST_CASE("playing with delta time", "[animation-new]") { TEST_CASE("playing with delta time", "[animation-new]") {
animate2::Timer timer; animation::Timer timer;
timer.start(); timer.start();
for(int i = 0; i < 20; i++) { for(int i = 0; i < 20; i++) {

View file

@ -5,7 +5,7 @@
#include "shaders.hpp" #include "shaders.hpp"
#include "backend.hpp" #include "backend.hpp"
#include "constants.hpp" #include "constants.hpp"
#include "animate2.hpp" #include "animation.hpp"
#include "tools/animator.hpp" #include "tools/animator.hpp"
#include <unistd.h> #include <unistd.h>
#include <ranges> #include <ranges>
@ -124,7 +124,7 @@ namespace animator {
void FSM::check_update() { void FSM::check_update() {
if($timer.getElapsedTime().toDuration() > 500ms) { if($timer.getElapsedTime().toDuration() > 500ms) {
try { 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) { if($last_mod_time < mod_time) {
event(Event::RELOAD); event(Event::RELOAD);
@ -139,10 +139,10 @@ namespace animator {
} }
void FSM::reload() { void FSM::reload() {
animate2::Animate2 new_anim; animation::Animation new_anim;
try { try {
new_anim = animate2::load("assets/animate2.json", $anim_name); new_anim = animation::load("assets/animation.json", $anim_name);
} catch(...) { } catch(...) {
$ui.show_error("Failed to load JSON"); $ui.show_error("Failed to load JSON");
return; return;
@ -157,7 +157,7 @@ namespace animator {
new_anim.set_form($cur_form); new_anim.set_form($cur_form);
try { try {
$last_mod_time = std::filesystem::last_write_time("assets/animate2.json"); $last_mod_time = std::filesystem::last_write_time("assets/animation.json");
} catch(...) { } catch(...) {
$ui.show_error("Filesystem error"); $ui.show_error("Filesystem error");
} }
@ -262,7 +262,7 @@ namespace animator {
return $ui.mouse(x, y, mods); 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("form", guecs::to_wstring(anim.form_name));
$overlay.show_text("sequence", guecs::to_wstring(anim.sequence_name)); $overlay.show_text("sequence", guecs::to_wstring(anim.sequence_name));
$overlay.show_text("transform", guecs::to_wstring(anim.transform_name)); $overlay.show_text("transform", guecs::to_wstring(anim.transform_name));

View file

@ -35,7 +35,7 @@ namespace animator {
void init(const std::string& sprite_name, const std::string& background, int width, int height); void init(const std::string& sprite_name, const std::string& background, int width, int height);
void render(sf::RenderWindow& window, bool debug=false); void render(sf::RenderWindow& window, bool debug=false);
bool mouse(float x, float y, guecs::Modifiers mods); bool mouse(float x, float y, guecs::Modifiers mods);
void update_status(animate2::Animate2& anim); void update_status(animation::Animation& anim);
std::shared_ptr<sf::Sprite> get_sprite(); std::shared_ptr<sf::Sprite> get_sprite();
void show_error(const std::string& message); void show_error(const std::string& message);
void clear_error(); void clear_error();
@ -47,7 +47,7 @@ namespace animator {
sf::RenderWindow $window; sf::RenderWindow $window;
sf::Vector2f $pos{0,0}; sf::Vector2f $pos{0,0};
sf::Vector2f $scale{0,0}; sf::Vector2f $scale{0,0};
animate2::Animate2 $anim; animation::Animation $anim;
std::string $sprite_name=""; std::string $sprite_name="";
std::string $anim_name=""; std::string $anim_name="";
std::string $background=""; std::string $background="";

View file

@ -8,7 +8,7 @@
#include "textures.hpp" #include "textures.hpp"
#include "inventory.hpp" #include "inventory.hpp"
#include "systems.hpp" #include "systems.hpp"
#include "animate2.hpp" #include "animation.hpp"
using namespace fmt; using namespace fmt;
using namespace components; 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}); System::set_position(world, $collision, item, {pos.x, pos.y});
animate2::configure(world, item); animation::configure(world, item);
return item; return item;
} }