Fixed a test that failed because loop was set on the tranform being used.

This commit is contained in:
Zed A. Shaw 2026-02-03 22:34:19 -05:00
parent c092b82dfc
commit ce3d142208
3 changed files with 15 additions and 9 deletions

View file

@ -6,8 +6,8 @@
"frame_height": 720
},
"sequence": {
"frames": [0, 1, 0, 1],
"durations": [800, 200, 33, 33]
"frames": [0, 1],
"durations": [240, 240]
},
"transform": {
"min_x": 0.6,

View file

@ -15,11 +15,19 @@ using namespace textures;
using namespace std::chrono_literals;
using namespace animate2;
Animate2 load_animation(const string& name) {
auto anim = animate2::load("assets/animate2.json", "rat_king_boss");
anim.transform.looped = false;
anim.sequence.durations = {Random::milliseconds(5, 33), Random::milliseconds(5, 33)};
return anim;
}
void FAKE_RENDER() {
std::this_thread::sleep_for(Random::milliseconds(5, 32));
}
void PLAY_TEST(Animate2 &anim) {
REQUIRE(anim.transform.looped == false);
anim.play();
while(anim.playing) {
@ -44,8 +52,7 @@ void PLAY_TEST(Animate2 &anim) {
TEST_CASE("new animation system", "[animation-new]") {
textures::init();
auto anim = animate2::load("assets/animate2.json", "rat_king_boss");
anim.sequence.durations = {Random::milliseconds(5, 33), Random::milliseconds(5, 33)};
auto anim = load_animation("rat_king_boss");
PLAY_TEST(anim);
bool onLoop_ran = false;
@ -88,7 +95,7 @@ TEST_CASE("confirm frame sequencing works", "[animation-new]") {
textures::init();
animation::init();
auto anim = animate2::load("assets/animate2.json", "rat_king_boss");
auto anim = load_animation("rat_king_boss");
auto boss = textures::get_sprite("rat_king_boss");
sf::IntRect init_rect{{0,0}, {anim.sheet.frame_width, anim.sheet.frame_height}};
@ -129,7 +136,7 @@ TEST_CASE("confirm transition changes work", "[animation-new]") {
sf::Vector2f pos{100,100};
sprite.setPosition(pos);
auto scale = sprite.getScale();
auto anim = animate2::load("assets/animate2.json", "rat_king_boss");
auto anim = load_animation("rat_king_boss");
// also testing that onFrame being null means it's not run
REQUIRE(anim.onFrame == nullptr);

View file

@ -80,7 +80,7 @@ namespace animator {
void FSM::run_animation() {
if($anim.playing) {
$anim.update();
$anim.apply(*$sprite);
if(!$anim.transform.simple) $anim.apply(*$sprite);
$anim.motion(*$sprite, $pos, $scale);
}
}
@ -91,8 +91,6 @@ namespace animator {
for(int i = 0; i < ticks; i++) {
event(animator::Event::TICK, {});
}
check_update();
}
void FSM::check_update() {
@ -189,6 +187,7 @@ int main(int argc, char* argv[]) {
while(main.active()) {
main.tick();
main.check_update();
main.render();
main.handle_keyboard_mouse();
}