Loading input changes
diff --git a/include/rive/animation/state_machine_event.hpp b/include/rive/animation/state_machine_event.hpp index 8eca197..b3d7606 100644 --- a/include/rive/animation/state_machine_event.hpp +++ b/include/rive/animation/state_machine_event.hpp
@@ -14,6 +14,7 @@ public: size_t inputChangeCount() const { return m_InputChanges.size(); } + const EventInputChange* inputChange(size_t index) const; StatusCode import(ImportStack& importStack) override; }; } // namespace rive
diff --git a/src/animation/state_machine.cpp b/src/animation/state_machine.cpp index a767143..523b4c6 100644 --- a/src/animation/state_machine.cpp +++ b/src/animation/state_machine.cpp
@@ -106,7 +106,7 @@ } const StateMachineEvent* StateMachine::event(size_t index) const { - if (index >= 0 && index < m_Events.size()) { + if (index < m_Events.size()) { return m_Events[index]; } return nullptr;
diff --git a/src/animation/state_machine_event.cpp b/src/animation/state_machine_event.cpp index 5eadc0f..d6791b3 100644 --- a/src/animation/state_machine_event.cpp +++ b/src/animation/state_machine_event.cpp
@@ -17,3 +17,10 @@ stateMachineImporter->addEvent(this); return Super::import(importStack); } + +const EventInputChange* StateMachineEvent::inputChange(size_t index) const { + if (index < m_InputChanges.size()) { + return m_InputChanges[index]; + } + return nullptr; +} \ No newline at end of file
diff --git a/test/state_machine_event_test.cpp b/test/state_machine_event_test.cpp index e74e818..b65b32a 100644 --- a/test/state_machine_event_test.cpp +++ b/test/state_machine_event_test.cpp
@@ -12,6 +12,8 @@ #include <rive/animation/blend_animation_1d.hpp> #include <rive/animation/blend_state_direct.hpp> #include <rive/animation/blend_state_transition.hpp> +#include <rive/animation/event_input_change.hpp> +#include <rive/node.hpp> #include "catch.hpp" #include "rive_file_reader.hpp" #include <cstdio> @@ -30,8 +32,30 @@ REQUIRE(stateMachine->inputCount() == 4); // Expect each of the three events to have one input change each. - for (int i = 0; i < 3; i++) { - auto event = stateMachine->event(i); - REQUIRE(event->inputChangeCount() == 1); - } + auto event1 = stateMachine->event(0); + auto target1 = artboard->resolve(event1->targetId()); + REQUIRE(target1->is<rive::Node>()); + REQUIRE(target1->as<rive::Node>()->name() == "HandWickHit"); + REQUIRE(event1->inputChangeCount() == 1); + auto inputChange1 = event1->inputChange(0); + REQUIRE(inputChange1 != nullptr); + REQUIRE(inputChange1->inputId() == 0); + + auto event2 = stateMachine->event(1); + auto target2 = artboard->resolve(event2->targetId()); + REQUIRE(target2->is<rive::Node>()); + REQUIRE(target2->as<rive::Node>()->name() == "HandCannonHit"); + REQUIRE(event2->inputChangeCount() == 1); + auto inputChange2 = event2->inputChange(0); + REQUIRE(inputChange2 != nullptr); + REQUIRE(inputChange2->inputId() == 1); + + auto event3 = stateMachine->event(2); + auto target3 = artboard->resolve(event3->targetId()); + REQUIRE(target3->is<rive::Node>()); + REQUIRE(target3->as<rive::Node>()->name() == "HandHelmetHit"); + REQUIRE(event3->inputChangeCount() == 1); + auto inputChange3 = event3->inputChange(0); + REQUIRE(inputChange3 != nullptr); + REQUIRE(inputChange3->inputId() == 2); }