diff --git a/animation.cpp b/animation.cpp index 01d7879..e4d3eab 100644 --- a/animation.cpp +++ b/animation.cpp @@ -119,6 +119,22 @@ namespace components { 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 { diff --git a/assets/animations.json b/assets/animations.json index 7fe21d0..03b980b 100644 --- a/assets/animations.json +++ b/assets/animations.json @@ -292,16 +292,16 @@ "test_zoom": { "_type": "Animation", "easing": 6, - "motion": 1, + "motion": 6, "ease_rate": 0.5, - "min_x": -10.0, - "min_y": -10.0, - "max_x": 10.0, - "max_y": 10.0, + "min_x": 0.8, + "min_y": 0.9, + "max_x": 1.1, + "max_y": 1.1, "simple": true, "frames": 1, "speed": 0.01, - "scaled": false, + "scaled": true, "stationary": true, "toggled": false, "flipped": false, diff --git a/boss/ui.cpp b/boss/ui.cpp index 99ba366..1e68080 100644 --- a/boss/ui.cpp +++ b/boss/ui.cpp @@ -81,23 +81,9 @@ 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::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, - {BOSS_VIEW_WIDTH/2, BOSS_VIEW_HEIGHT/2}}; - - if($zoom_anim.scaled) { - zoom.zoom(scale.x); - } - + sf::View zoom; + $zoom_anim.apply(zoom, pos, {BOSS_VIEW_WIDTH/2, BOSS_VIEW_HEIGHT/2}); $view_texture.setView(zoom); } diff --git a/components.hpp b/components.hpp index 497ce9c..8e407a4 100644 --- a/components.hpp +++ b/components.hpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -140,6 +141,8 @@ namespace components { 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);