mirror of
https://github.com/rive-app/rive-cpp.git
synced 2026-01-18 21:21:17 +01:00
chore: advance scripting only if it is still active (#11394) 0488666fb0
* chore: advance scripting only if it is still active Co-authored-by: hernan <hernan@rive.app>
This commit is contained in:
BIN
tests/unit_tests/assets/script_affects_has_changed.riv
Normal file
BIN
tests/unit_tests/assets/script_affects_has_changed.riv
Normal file
Binary file not shown.
@@ -2,6 +2,7 @@
|
||||
#include "catch.hpp"
|
||||
#include "scripting_test_utilities.hpp"
|
||||
#include "rive/animation/state_machine_instance.hpp"
|
||||
#include "rive/viewmodel/viewmodel_instance_boolean.hpp"
|
||||
#include "rive/lua/rive_lua_libs.hpp"
|
||||
#include "rive_file_reader.hpp"
|
||||
|
||||
@@ -311,14 +312,12 @@ TEST_CASE("script instances Artboard input", "[silver]")
|
||||
|
||||
CHECK(silver.matches("script_artboards"));
|
||||
}
|
||||
|
||||
TEST_CASE("script instances Artboard input with proper origin", "[silver]")
|
||||
{
|
||||
rive::SerializingFactory silver;
|
||||
auto file = ReadRiveFile("assets/script_artboard_origin_test.riv", &silver);
|
||||
|
||||
auto artboard = file->artboardNamed("Artboard");
|
||||
|
||||
silver.frameSize(artboard->width(), artboard->height());
|
||||
|
||||
REQUIRE(artboard != nullptr);
|
||||
@@ -337,4 +336,49 @@ TEST_CASE("script instances Artboard input with proper origin", "[silver]")
|
||||
}
|
||||
|
||||
CHECK(silver.matches("script_artboards_origin"));
|
||||
}
|
||||
|
||||
TEST_CASE("when script node is advanced it affects the didChange bool via dirt",
|
||||
"[silver]")
|
||||
{
|
||||
rive::SerializingFactory silver;
|
||||
auto file = ReadRiveFile("assets/script_affects_has_changed.riv", &silver);
|
||||
|
||||
auto artboard = file->artboardNamed("Main");
|
||||
silver.frameSize(artboard->width(), artboard->height());
|
||||
|
||||
REQUIRE(artboard != nullptr);
|
||||
auto stateMachine = artboard->stateMachineAt(0);
|
||||
|
||||
auto vmi = file->createViewModelInstance(artboard.get());
|
||||
stateMachine->bindViewModelInstance(vmi);
|
||||
auto boolProp =
|
||||
vmi->propertyValue("toLeft")->as<ViewModelInstanceBoolean>();
|
||||
stateMachine->advanceAndApply(0.1f);
|
||||
auto renderer = silver.makeRenderer();
|
||||
REQUIRE(artboard->didChange() == true);
|
||||
|
||||
artboard->draw(renderer.get());
|
||||
|
||||
// After one second has elapsed, the script code will return false on
|
||||
// advance
|
||||
silver.addFrame();
|
||||
stateMachine->advanceAndApply(1.0f);
|
||||
REQUIRE(artboard->didChange() == false);
|
||||
artboard->draw(renderer.get());
|
||||
|
||||
// When a property is updated, advance will be called again only once
|
||||
boolProp->propertyValue(true);
|
||||
silver.addFrame();
|
||||
stateMachine->advanceAndApply(0.1f);
|
||||
REQUIRE(artboard->didChange() == true);
|
||||
artboard->draw(renderer.get());
|
||||
|
||||
// Advance goes back to inactive
|
||||
silver.addFrame();
|
||||
stateMachine->advanceAndApply(0.1f);
|
||||
REQUIRE(artboard->didChange() == false);
|
||||
artboard->draw(renderer.get());
|
||||
|
||||
CHECK(silver.matches("script_affects_has_changed"));
|
||||
}
|
||||
BIN
tests/unit_tests/silvers/script_affects_has_changed.sriv
Normal file
BIN
tests/unit_tests/silvers/script_affects_has_changed.sriv
Normal file
Binary file not shown.
Reference in New Issue
Block a user