Fixed a test that failed because loop was set on the tranform being used.
This commit is contained in:
parent
c092b82dfc
commit
ce3d142208
3 changed files with 15 additions and 9 deletions
|
|
@ -6,8 +6,8 @@
|
||||||
"frame_height": 720
|
"frame_height": 720
|
||||||
},
|
},
|
||||||
"sequence": {
|
"sequence": {
|
||||||
"frames": [0, 1, 0, 1],
|
"frames": [0, 1],
|
||||||
"durations": [800, 200, 33, 33]
|
"durations": [240, 240]
|
||||||
},
|
},
|
||||||
"transform": {
|
"transform": {
|
||||||
"min_x": 0.6,
|
"min_x": 0.6,
|
||||||
|
|
|
||||||
|
|
@ -15,11 +15,19 @@ using namespace textures;
|
||||||
using namespace std::chrono_literals;
|
using namespace std::chrono_literals;
|
||||||
using namespace animate2;
|
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() {
|
void FAKE_RENDER() {
|
||||||
std::this_thread::sleep_for(Random::milliseconds(5, 32));
|
std::this_thread::sleep_for(Random::milliseconds(5, 32));
|
||||||
}
|
}
|
||||||
|
|
||||||
void PLAY_TEST(Animate2 &anim) {
|
void PLAY_TEST(Animate2 &anim) {
|
||||||
|
REQUIRE(anim.transform.looped == false);
|
||||||
anim.play();
|
anim.play();
|
||||||
|
|
||||||
while(anim.playing) {
|
while(anim.playing) {
|
||||||
|
|
@ -44,8 +52,7 @@ void PLAY_TEST(Animate2 &anim) {
|
||||||
TEST_CASE("new animation system", "[animation-new]") {
|
TEST_CASE("new animation system", "[animation-new]") {
|
||||||
textures::init();
|
textures::init();
|
||||||
|
|
||||||
auto anim = animate2::load("assets/animate2.json", "rat_king_boss");
|
auto anim = load_animation("rat_king_boss");
|
||||||
anim.sequence.durations = {Random::milliseconds(5, 33), Random::milliseconds(5, 33)};
|
|
||||||
PLAY_TEST(anim);
|
PLAY_TEST(anim);
|
||||||
|
|
||||||
bool onLoop_ran = false;
|
bool onLoop_ran = false;
|
||||||
|
|
@ -88,7 +95,7 @@ TEST_CASE("confirm frame sequencing works", "[animation-new]") {
|
||||||
textures::init();
|
textures::init();
|
||||||
animation::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");
|
auto boss = textures::get_sprite("rat_king_boss");
|
||||||
sf::IntRect init_rect{{0,0}, {anim.sheet.frame_width, anim.sheet.frame_height}};
|
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};
|
sf::Vector2f pos{100,100};
|
||||||
sprite.setPosition(pos);
|
sprite.setPosition(pos);
|
||||||
auto scale = sprite.getScale();
|
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
|
// also testing that onFrame being null means it's not run
|
||||||
REQUIRE(anim.onFrame == nullptr);
|
REQUIRE(anim.onFrame == nullptr);
|
||||||
|
|
|
||||||
|
|
@ -80,7 +80,7 @@ namespace animator {
|
||||||
void FSM::run_animation() {
|
void FSM::run_animation() {
|
||||||
if($anim.playing) {
|
if($anim.playing) {
|
||||||
$anim.update();
|
$anim.update();
|
||||||
$anim.apply(*$sprite);
|
if(!$anim.transform.simple) $anim.apply(*$sprite);
|
||||||
$anim.motion(*$sprite, $pos, $scale);
|
$anim.motion(*$sprite, $pos, $scale);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -91,8 +91,6 @@ namespace animator {
|
||||||
for(int i = 0; i < ticks; i++) {
|
for(int i = 0; i < ticks; i++) {
|
||||||
event(animator::Event::TICK, {});
|
event(animator::Event::TICK, {});
|
||||||
}
|
}
|
||||||
|
|
||||||
check_update();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void FSM::check_update() {
|
void FSM::check_update() {
|
||||||
|
|
@ -189,6 +187,7 @@ int main(int argc, char* argv[]) {
|
||||||
|
|
||||||
while(main.active()) {
|
while(main.active()) {
|
||||||
main.tick();
|
main.tick();
|
||||||
|
main.check_update();
|
||||||
main.render();
|
main.render();
|
||||||
main.handle_keyboard_mouse();
|
main.handle_keyboard_mouse();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue