Now loading the new animations out of assets/animate2.json

This commit is contained in:
Zed A. Shaw 2026-02-03 00:30:49 -05:00
parent df730047ac
commit dea0607901
7 changed files with 108 additions and 137 deletions

View file

@ -15,40 +15,6 @@ using namespace textures;
using namespace std::chrono_literals;
using namespace animate2;
Animate2 crafter() {
Sheet sheet{
.width{720*2},
.height{720},
.frame_width{720},
.frame_height{720},
};
Sequence sequence{
.frames{0,1},
.durations{Random::milliseconds(1, 33), Random::milliseconds(1, 33)}
};
REQUIRE(sequence.frame_count == sequence.frames.size());
REQUIRE(sequence.frame_count == sequence.durations.size());
Transform transform{
.min_x{0.6f},
.min_y{0.6f},
.max_x{0.8f},
.max_y{0.8f},
.simple{false},
.flipped{false},
.ease_rate{5.0f},
.scaled{true},
.toggled{false},
.looped{false},
.easing = ease2::in_out_back,
.motion = ease2::move_rush,
};
return {sheet, sequence, transform};
}
void FAKE_RENDER() {
std::this_thread::sleep_for(Random::milliseconds(5, 32));
}
@ -78,7 +44,7 @@ void PLAY_TEST(Animate2 &anim) {
TEST_CASE("new animation system", "[animation-new]") {
textures::init();
auto anim = crafter();
auto anim = animate2::load("assets/animate2.json", "rat_king_boss");
PLAY_TEST(anim);
bool onLoop_ran = false;
@ -103,7 +69,7 @@ TEST_CASE("new animation system", "[animation-new]") {
};
PLAY_TEST(anim);
REQUIRE(anim.$sequence.loop_count == 2);
REQUIRE(anim.sequence.loop_count == 2);
// stops at end
anim.onLoop = [](auto& seq, auto& tr) -> bool {
@ -121,10 +87,10 @@ TEST_CASE("confirm frame sequencing works", "[animation-new]") {
textures::init();
animation::init();
auto anim = crafter();
auto anim = animate2::load("assets/animate2.json", "rat_king_boss");
auto blanket = textures::get_sprite("ritual_crafting_area");
sf::IntRect init_rect{{0,0}, {anim.$sheet.frame_width, anim.$sheet.frame_height}};
auto boss = textures::get_sprite("rat_king_boss");
sf::IntRect init_rect{{0,0}, {anim.sheet.frame_width, anim.sheet.frame_height}};
anim.play();
bool loop_ran = false;
@ -134,12 +100,12 @@ TEST_CASE("confirm frame sequencing works", "[animation-new]") {
seq.current = 0;
loop_ran = true;
REQUIRE(blanket.sprite->getTextureRect() != init_rect);
REQUIRE(boss.sprite->getTextureRect() != init_rect);
return false;
};
anim.onFrame = [&](){
anim.apply(*blanket.sprite);
anim.apply(*boss.sprite);
};
while(anim.playing) {
@ -151,7 +117,7 @@ TEST_CASE("confirm frame sequencing works", "[animation-new]") {
REQUIRE(anim.playing == false);
// this confirms it went back to the first frame
REQUIRE(blanket.sprite->getTextureRect() == init_rect);
REQUIRE(boss.sprite->getTextureRect() == init_rect);
}
TEST_CASE("confirm transition changes work", "[animation-new]") {
@ -162,7 +128,7 @@ TEST_CASE("confirm transition changes work", "[animation-new]") {
sf::Vector2f pos{100,100};
sprite.setPosition(pos);
auto scale = sprite.getScale();
auto anim = crafter();
auto anim = animate2::load("assets/animate2.json", "rat_king_boss");
// also testing that onFrame being null means it's not run
REQUIRE(anim.onFrame == nullptr);
@ -170,23 +136,11 @@ TEST_CASE("confirm transition changes work", "[animation-new]") {
anim.play();
REQUIRE(anim.playing == true);
sf::Clock clock;
clock.start();
sf::Time start;
sf::Time delta;
while(anim.playing) {
start = clock.getElapsedTime();
anim.update();
anim.motion(sprite, pos, scale);
std::this_thread::sleep_for(10ms);
fmt::println("POSITION: {},{}; SCALE: {},{}; current: {}; subframe: {}",
pos.x, pos.y, scale.x, scale.y, anim.$sequence.current, anim.$sequence.subframe);
delta = clock.getElapsedTime() - start;
fmt::println("FRAME RATE {}", 1.0f / delta.asSeconds());
}
REQUIRE(anim.playing == false);