Created a nice utility library for doing animations, and used it in the ritual crafting UI.

This commit is contained in:
Zed A. Shaw 2025-03-20 01:10:01 -04:00
parent 0a40135f5d
commit 1aa6674e42
14 changed files with 213 additions and 150 deletions

53
tests/animation.cpp Normal file
View file

@ -0,0 +1,53 @@
#include <catch2/catch_test_macros.hpp>
#include "animation.hpp"
#include "dinkyecs.hpp"
#include "config.hpp"
#include <iostream>
using namespace components;
using namespace textures;
TEST_CASE("animation easing tests", "[animation]") {
Animation anim;
anim.easing = ease::NONE;
float res = anim.twitching();
REQUIRE(res == 0.0);
anim.easing = ease::SINE;
anim.subframe = 1.0f;
res = anim.twitching();
REQUIRE(!std::isnan(res));
anim.easing = ease::OUT_CIRC;
res = anim.twitching();
REQUIRE(!std::isnan(res));
anim.easing = ease::OUT_BOUNCE;
res = anim.twitching();
REQUIRE(!std::isnan(res));
anim.easing = ease::IN_OUT_BACK;
res = anim.twitching();
REQUIRE(!std::isnan(res));
anim.easing = ease::FUCKFACE;
bool throws = false;
try { anim.twitching(); } catch(...) { throws = true; }
REQUIRE(throws);
}
TEST_CASE("animation utility API", "[animation]") {
textures::init();
animation::init();
auto blanket = textures::get("ritual_crafting_area");
auto anim = animation::load("ritual_blanket");
anim.play();
while(animation::apply(anim, blanket)) {
fmt::println("animation: {}", anim.subframe);
}
}

View file

@ -60,34 +60,3 @@ TEST_CASE("make sure json_mods works", "[components]") {
auto boss2 = world.get<BossFight>(devils_fingers);
REQUIRE(boss2.stage != std::nullopt);
}
TEST_CASE("animation component special cases", "[components]") {
Animation anim;
anim.easing = ease::NONE;
float res = anim.twitching();
REQUIRE(res == 0.0);
anim.easing = ease::SINE;
anim.subframe = 1.0f;
res = anim.twitching();
REQUIRE(!std::isnan(res));
anim.easing = ease::OUT_CIRC;
res = anim.twitching();
REQUIRE(!std::isnan(res));
anim.easing = ease::OUT_BOUNCE;
res = anim.twitching();
REQUIRE(!std::isnan(res));
anim.easing = ease::IN_OUT_BACK;
res = anim.twitching();
REQUIRE(!std::isnan(res));
anim.easing = ease::FUCKFACE;
bool throws = false;
try { anim.twitching(); } catch(...) { throws = true; }
REQUIRE(throws);
}