diff --git a/animation.cpp b/animation.cpp index e4d3eab..ed6af21 100644 --- a/animation.cpp +++ b/animation.cpp @@ -102,39 +102,6 @@ namespace components { scale_out.x *= -1; } } - - bool Animation::apply(sf::Sprite& sprite, sf::Vector2f pos) { - sf::IntRect rect{{0,0}, {frame_width, frame_height}}; - sf::Vector2f scale{min_x, min_y}; - - step(scale, pos, rect); - - sprite.setTextureRect(rect); - sprite.setPosition(pos); - - // BUG: make this an option: apply_scale, apply_position and ranges for x y - if(scaled) { - sprite.setScale(scale); - } - - return playing; - } - - bool Animation::apply(sf::View& view_out, sf::Vector2f pos, sf::Vector2f size) { - sf::Vector2f scale{min_x, min_y}; - sf::IntRect ignored{{0,0}, {int(size.x), int(size.y)}}; - - step(scale, pos, ignored); - view_out.setCenter(pos); - - if(scaled) { - view_out.setSize({size.x * scale.x, size.y * scale.y}); - } else { - view_out.setSize(size); - } - - return playing; - } } namespace animation { @@ -144,6 +111,23 @@ namespace animation { static AnimationManager MGR; static bool initialized = false; + bool apply(Animation& anim, sf::Sprite& sprite, sf::Vector2f pos) { + sf::IntRect rect{{0,0}, {anim.frame_width, anim.frame_height}}; + sf::Vector2f scale{anim.min_x, anim.min_y}; + + anim.step(scale, pos, rect); + + sprite.setTextureRect(rect); + sprite.setPosition(pos); + + // BUG: make this an option: apply_scale, apply_position and ranges for x y + if(anim.scaled) { + sprite.setScale(scale); + } + + return anim.playing; + } + void rotate(sf::Sprite& target, float degrees) { target.rotate(sf::degrees(degrees)); } diff --git a/animation.hpp b/animation.hpp index cbe0d62..f89496a 100644 --- a/animation.hpp +++ b/animation.hpp @@ -11,6 +11,7 @@ namespace animation { std::unordered_map animations; }; + bool apply(components::Animation& anim, sf::Sprite& target, sf::Vector2f pos); void rotate(sf::Sprite& target, float degrees); void center(sf::Sprite& target, sf::Vector2f pos); diff --git a/assets/animations.json b/assets/animations.json index 03b980b..be39692 100644 --- a/assets/animations.json +++ b/assets/animations.json @@ -292,12 +292,12 @@ "test_zoom": { "_type": "Animation", "easing": 6, - "motion": 6, + "motion": 5, "ease_rate": 0.5, - "min_x": 0.8, - "min_y": 0.9, - "max_x": 1.1, - "max_y": 1.1, + "min_x": 1.0, + "min_y": 1.0, + "max_x": 1.2, + "max_y": 1.2, "simple": true, "frames": 1, "speed": 0.01, diff --git a/boss/ui.cpp b/boss/ui.cpp index 1e68080..6d37d49 100644 --- a/boss/ui.cpp +++ b/boss/ui.cpp @@ -81,9 +81,23 @@ namespace boss { $view_texture.setView(zoom); } else if($zoom_anim.playing) { auto& cell = $arena.$ui.cell_for(cell_name); + sf::Vector2f scale{$zoom_anim.min_x, $zoom_anim.min_y}; sf::Vector2f pos{float(cell.x), float(cell.y)}; - sf::View zoom; - $zoom_anim.apply(zoom, pos, {BOSS_VIEW_WIDTH/2, BOSS_VIEW_HEIGHT/2}); + sf::IntRect rect{{0,0}, {cell.w, cell.h}}; + + $zoom_anim.step(scale, pos, rect); + fmt::println("SCALE: {},{}; pos: {},{}; rect: {},{};{},{}", + scale.x, scale.y, pos.x, pos.y, + rect.position.x, rect.position.y, + rect.size.x, rect.size.y); + + sf::View zoom{pos, + {float(cell.w * 2), float(cell.h * 2)}}; + + if($zoom_anim.scaled) { + zoom.zoom(scale.x); + } + $view_texture.setView(zoom); } diff --git a/components.hpp b/components.hpp index 8e407a4..fe3500a 100644 --- a/components.hpp +++ b/components.hpp @@ -5,8 +5,6 @@ #include "point.hpp" #include #include -#include -#include #include #include #include @@ -140,9 +138,6 @@ namespace components { int frame_width = -1; int frame_height = -1; - bool apply(sf::Sprite& target, sf::Vector2f pos); - bool apply(sf::View& view_out, sf::Vector2f pos, sf::Vector2f size); - void play(); float twitching(); void step(sf::Vector2f& scale_out, sf::Vector2f& pos_out, sf::IntRect& rect_out); diff --git a/gui/main_ui.cpp b/gui/main_ui.cpp index 3a5892b..56844aa 100644 --- a/gui/main_ui.cpp +++ b/gui/main_ui.cpp @@ -145,7 +145,7 @@ namespace gui { } void MainUI::render_hands() { - if($hand_anim.apply(*$hand.sprite, {0,0})) { + if(animation::apply($hand_anim, *$hand.sprite, {0,0})) { $hand.sprite->setPosition({RAY_VIEW_X, RAY_VIEW_Y}); $window.draw(*$hand.sprite); } diff --git a/gui/ritual_ui.cpp b/gui/ritual_ui.cpp index 94e0e61..a446305 100644 --- a/gui/ritual_ui.cpp +++ b/gui/ritual_ui.cpp @@ -94,7 +94,7 @@ namespace gui { void UI::OPENING(Event ev) { if(ev == Event::TICK) { - if(!$ritual_anim.apply(*$ritual_ui.sprite, {0,0})) { + if(!animation::apply($ritual_anim, *$ritual_ui.sprite, {0,0})) { state(State::OPENED); } } diff --git a/scene.cpp b/scene.cpp index 2028773..6700d57 100644 --- a/scene.cpp +++ b/scene.cpp @@ -100,13 +100,13 @@ namespace scene { void Engine::play_animations() { for(auto& fixture : $fixtures) { if(fixture.anim.playing) { - fixture.anim.apply(*fixture.st.sprite, fixture.pos); + animation::apply(fixture.anim, *fixture.st.sprite, fixture.pos); } } for(auto& actor : $actors) { if(actor.anim.playing) { - actor.anim.apply(*actor.st.sprite, actor.pos); + animation::apply(actor.anim, *actor.st.sprite, actor.pos); } } } diff --git a/tests/animation.cpp b/tests/animation.cpp index 42a4df2..ad6f6a4 100644 --- a/tests/animation.cpp +++ b/tests/animation.cpp @@ -42,7 +42,7 @@ TEST_CASE("animation utility API", "[animation]") { anim.play(); - while(anim.apply(*blanket.sprite, {0,0})) { + while(animation::apply(anim, *blanket.sprite, {0,0})) { fmt::println("animation: {}", anim.subframe); } } diff --git a/tests/animation2.cpp b/tests/animation2.cpp index 3d96f42..d654c20 100644 --- a/tests/animation2.cpp +++ b/tests/animation2.cpp @@ -32,7 +32,7 @@ struct AnimationState { } void apply(textures::SpriteTexture& st) { - anim.apply(*st.sprite, pos); + animation::apply(anim, *st.sprite, pos); } };