Scripting namespaces (#11429) f810efd11a

Co-authored-by: Philip Chung <philterdesign@gmail.com>
This commit is contained in:
philter
2026-01-12 17:55:36 +00:00
parent a45d0a411d
commit c5fdfdb3d7
8 changed files with 102 additions and 2 deletions

Binary file not shown.

View File

@@ -182,4 +182,54 @@ TEST_CASE(
CHECK(silver.matches(
"script_converter_with_dependency_with_library_with_update"));
}
// This test file uses 4 scripts in the following hierarchy:
// - rive
// - stringutil
// - StringReverse
// - StringPrefix
// - StringUpperCase
// - converter
// - StringConverter
// These scripts must have their full qualified namespace included in the
// require For example: require('rive/stringutil/StringReverse')
TEST_CASE("scripted data converter string with namespaced requires", "[silver]")
{
rive::SerializingFactory silver;
auto file = ReadRiveFile("assets/script_namespace_test.riv", &silver);
auto artboard = file->artboardNamed("Artboard");
silver.frameSize(artboard->width(), artboard->height());
REQUIRE(artboard != nullptr);
auto stateMachine = artboard->stateMachineAt(0);
int viewModelId = artboard.get()->viewModelId();
auto vmi = viewModelId == -1
? file->createViewModelInstance(artboard.get())
: file->createViewModelInstance(viewModelId, 0);
stateMachine->bindViewModelInstance(vmi);
stateMachine->advanceAndApply(0.1f);
auto renderer = silver.makeRenderer();
artboard->draw(renderer.get());
rive::ViewModelInstanceString* str =
vmi->propertyValue("InputString")->as<rive::ViewModelInstanceString>();
REQUIRE(str != nullptr);
std::vector<std::string> values = {"Hello world!",
"1,2,3",
"rive scripting",
"testing testing testing",
"Script Data Converter"};
for (int i = 0; i < values.size(); i++)
{
str->propertyValue(values[i]);
silver.addFrame();
stateMachine->advanceAndApply(0.016f);
artboard->draw(renderer.get());
}
CHECK(silver.matches("script_namespace_test"));
}

Binary file not shown.