diff --git a/animation.cpp b/animation.cpp index aea103d..ed6af21 100644 --- a/animation.cpp +++ b/animation.cpp @@ -36,8 +36,8 @@ namespace components { } void Animation::step(sf::Vector2f& scale_out, sf::Vector2f& pos_out, sf::IntRect& rect_out) { - dbc::check(rect_out.size.x > 0, "invalid frame width in animation"); - dbc::check(rect_out.size.y > 0, "invalid frame height in animation"); + dbc::check(rect_out.size.x > 0, "step given rect_out with size.x <= 0, must be >"); + dbc::check(rect_out.size.y > 0, "step given rect_out with size.y <= 0, must be >"); if(playing && current < frames) { float tick = twitching(); @@ -64,8 +64,6 @@ namespace components { } break; case ease::STRETCH: { scale_out.x = std::lerp(min_x, max_x, tick); - fmt::println("scale_x: {} max_scale: {} tick: {} scale_out.x: {}", - min_x, max_x, tick, scale_out.x); } break; case ease::GROW: { scale_out.y = std::lerp(min_y, max_y, tick); @@ -151,17 +149,18 @@ namespace animation { try { auto anim = components::convert(data); - dbc::check(sprites.contains(name), - fmt::format("animation '{}' doesn't have sprite, spelled wrong in config.json?", name)); + if(!sprites.contains(name)) { + fmt::println("animation '{}' doesn't have sprite, spelled wrong in config.json?", name); + } else { + auto& sprite_config = sprites[name]; - auto& sprite_config = sprites[name]; + anim.frame_width = sprite_config["frame_width"]; + anim.frame_height = sprite_config["frame_height"]; - anim.frame_width = sprite_config["frame_width"]; - anim.frame_height = sprite_config["frame_height"]; - - dbc::check(anim.frame_width > 0 && anim.frame_height > 0, - fmt::format("invalid frame width/height for animation: {}", - name)); + dbc::check(anim.frame_width > 0 && anim.frame_height > 0, + fmt::format("invalid frame width/height for animation: {}", + name)); + } MGR.animations.insert_or_assign(name, anim); } catch(...) { diff --git a/assets/animations.json b/assets/animations.json index 7b02df7..be39692 100644 --- a/assets/animations.json +++ b/assets/animations.json @@ -288,5 +288,23 @@ "toggled": false, "flipped": false, "looped": false + }, + "test_zoom": { + "_type": "Animation", + "easing": 6, + "motion": 5, + "ease_rate": 0.5, + "min_x": 1.0, + "min_y": 1.0, + "max_x": 1.2, + "max_y": 1.2, + "simple": true, + "frames": 1, + "speed": 0.01, + "scaled": true, + "stationary": true, + "toggled": false, + "flipped": false, + "looped": false } } diff --git a/boss/fight.cpp b/boss/fight.cpp index c92c334..f027859 100644 --- a/boss/fight.cpp +++ b/boss/fight.cpp @@ -86,7 +86,7 @@ namespace boss { $ui.status(L"PLAYER TURN"); const std::string& player_pos = run % 10 < 5 ? "player1" : "player2"; $ui.move_actor("player", player_pos); - $ui.zoom(player_pos); + $ui.$zoom_anim.play(); int attack_id = std::any_cast(data); boss::System::combat(attack_id); state(State::PLAYER_TURN); diff --git a/boss/ui.cpp b/boss/ui.cpp index cc97599..6d37d49 100644 --- a/boss/ui.cpp +++ b/boss/ui.cpp @@ -1,6 +1,8 @@ #include "boss/ui.hpp" #include "scene.hpp" #include "constants.hpp" +#include "components.hpp" +#include "animation.hpp" namespace boss { using namespace guecs; @@ -10,7 +12,8 @@ namespace boss { $combat_ui(true), $arena(scene), $view_texture({BOSS_VIEW_WIDTH, BOSS_VIEW_HEIGHT}), - $view_sprite($view_texture.getTexture()) + $view_sprite($view_texture.getTexture()), + $zoom_anim(animation::load("test_zoom")) { $view_sprite.setPosition({BOSS_VIEW_X, BOSS_VIEW_Y}); } @@ -40,6 +43,11 @@ namespace boss { void UI::render(sf::RenderWindow& window) { $actions.render(window); $combat_ui.render(window); + + if($zoom_anim.playing) { + zoom("player2"); + } + $arena.render($view_texture); $view_texture.display(); window.draw($view_sprite); @@ -71,10 +79,25 @@ namespace boss { if(cell_name == "") { sf::View zoom{{BOSS_VIEW_WIDTH/2,BOSS_VIEW_HEIGHT/2}, {BOSS_VIEW_WIDTH, BOSS_VIEW_HEIGHT}}; $view_texture.setView(zoom); - } else { + } else if($zoom_anim.playing) { auto& cell = $arena.$ui.cell_for(cell_name); - sf::View zoom{{(float)cell.mid_x, (float)cell.mid_y}, - {(float)cell.w*3, (float)cell.h*3}}; + 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, + {float(cell.w * 2), float(cell.h * 2)}}; + + if($zoom_anim.scaled) { + zoom.zoom(scale.x); + } + $view_texture.setView(zoom); } diff --git a/boss/ui.hpp b/boss/ui.hpp index 1ff4994..6a63eb9 100644 --- a/boss/ui.hpp +++ b/boss/ui.hpp @@ -4,6 +4,10 @@ #include "gui/combat_ui.hpp" #include "scene.hpp" +namespace components { + struct Animation; +} + namespace boss { using std::shared_ptr; @@ -14,6 +18,7 @@ namespace boss { guecs::UI $actions; sf::RenderTexture $view_texture; sf::Sprite $view_sprite; + components::Animation $zoom_anim; UI(components::AnimatedScene &scene, DinkyECS::Entity boss_id);