diff --git a/.rive_head b/.rive_head index 0a67fde2..d2358efc 100644 --- a/.rive_head +++ b/.rive_head @@ -1 +1 @@ -4566a1208a50671aede1fd1bf30a1806b757c343 +68f58eef4ef521e93a5ada5cb3bf4fbfc7c7687d diff --git a/kotlin/src/androidTest/java/app/rive/runtime/kotlin/core/RiveNestedInputsTest.kt b/kotlin/src/androidTest/java/app/rive/runtime/kotlin/core/RiveNestedInputsTest.kt new file mode 100644 index 00000000..e731c372 --- /dev/null +++ b/kotlin/src/androidTest/java/app/rive/runtime/kotlin/core/RiveNestedInputsTest.kt @@ -0,0 +1,75 @@ +package app.rive.runtime.kotlin.core + +import androidx.test.ext.junit.runners.AndroidJUnit4 +import androidx.test.internal.runner.junit4.statement.UiThreadStatement +import app.rive.runtime.kotlin.core.errors.StateMachineInputException +import app.rive.runtime.kotlin.test.R +import org.junit.Assert.assertThrows +import org.junit.Before +import org.junit.Test +import org.junit.runner.RunWith + +@RunWith(AndroidJUnit4::class) +class RiveNestedInputsTest { + private val testUtils = TestUtils() + private val appContext = testUtils.context + private lateinit var view: TestUtils.MockRiveAnimationView + + + @Before + fun init() { + view = TestUtils.MockRiveAnimationView(appContext) + } + + @Test + fun can_set_inputs_at_path_no_errors() { + UiThreadStatement.runOnUiThread { + view.setRiveResource(R.raw.nested_inputs_test, artboardName = "Artboard", stateMachineName = "State Machine 1") + view.play() + view.setBooleanStateAtPath("bool", true, "nested") + view.setNumberStateAtPath("number", 1f, "nested") + view.fireStateAtPath("trigger", "nested") + } + } + + @Test + fun set_incorrect_name_inputs_at_path_throws() { + UiThreadStatement.runOnUiThread { + view.setRiveResource(R.raw.nested_inputs_test, artboardName = "Artboard", stateMachineName = "State Machine 1") + view.play() + assertThrows(StateMachineInputException::class.java) { + view.setBooleanStateAtPath("wrongname", true, "nested") + view.artboardRenderer?.advance(0.16f) + } + assertThrows(StateMachineInputException::class.java) { + view.setNumberStateAtPath("wrongname", 1f, "nested") + view.artboardRenderer?.advance(0.16f) + } + assertThrows(StateMachineInputException::class.java) { + view.fireStateAtPath("wrongname", "nested") + view.artboardRenderer?.advance(0.16f) + } + } + } + + @Test + fun set_incorrect_path_inputs_at_path_throws() { + UiThreadStatement.runOnUiThread { + view.setRiveResource(R.raw.nested_inputs_test, artboardName = "Artboard", stateMachineName = "State Machine 1") + view.play() + assertThrows(StateMachineInputException::class.java) { + view.setBooleanStateAtPath("bool", true, "wrongPath") + view.artboardRenderer?.advance(0.16f) + } + assertThrows(StateMachineInputException::class.java) { + view.setNumberStateAtPath("number", 1f, "wrongPath") + view.artboardRenderer?.advance(0.16f) + } + assertThrows(StateMachineInputException::class.java) { + view.fireStateAtPath("trigger", "wrongPath") + view.artboardRenderer?.advance(0.16f) + } + } + } + +} \ No newline at end of file diff --git a/kotlin/src/androidTest/res/raw/nested_inputs_test.riv b/kotlin/src/androidTest/res/raw/nested_inputs_test.riv new file mode 100644 index 00000000..c9fa66bb Binary files /dev/null and b/kotlin/src/androidTest/res/raw/nested_inputs_test.riv differ diff --git a/kotlin/src/main/java/app/rive/runtime/kotlin/controllers/RiveFileController.kt b/kotlin/src/main/java/app/rive/runtime/kotlin/controllers/RiveFileController.kt index 2da774ad..abc5e3c0 100644 --- a/kotlin/src/main/java/app/rive/runtime/kotlin/controllers/RiveFileController.kt +++ b/kotlin/src/main/java/app/rive/runtime/kotlin/controllers/RiveFileController.kt @@ -550,27 +550,27 @@ class RiveFileController( } fun fireState(stateMachineName: String, inputName: String, path: String? = null) { - queueInput(stateMachineName, inputName, path) + queueInput(stateMachineName = stateMachineName, inputName = inputName, path = path) } fun setBooleanState(stateMachineName: String, inputName: String, value: Boolean, path: String? = null) { - queueInput(stateMachineName, inputName, value, path) + queueInput(stateMachineName = stateMachineName, inputName = inputName, value = value, path = path) } fun setNumberState(stateMachineName: String, inputName: String, value: Float, path: String? = null) { - queueInput(stateMachineName, inputName, value, path) + queueInput(stateMachineName = stateMachineName, inputName = inputName, value = value, path = path) } fun fireStateAtPath(inputName: String, path: String) { - queueInput("", inputName, path) + queueInput(stateMachineName = "", inputName = inputName, path = path) } fun setBooleanStateAtPath(inputName: String, value: Boolean, path: String) { - queueInput("", inputName, value, path) + queueInput(stateMachineName = "", inputName = inputName, value = value, path = path) } fun setNumberStateAtPath(inputName: String, value: Float, path: String) { - queueInput("", inputName, value, path) + queueInput(stateMachineName = "", inputName = inputName, value = value, path = path) } /** @@ -611,7 +611,7 @@ class RiveFileController( } } - private var userSetVolume: Float? = null; // Default value + private var userSetVolume: Float? = null // Default value /** * Get the active [Artboard]'s volume. @@ -622,8 +622,8 @@ class RiveFileController( * Set the active [Artboard]'s volume to [value]. */ fun setVolume(value: Float) { - userSetVolume = value; - activeArtboard?.volume = value; + userSetVolume = value + activeArtboard?.volume = value } private fun animations(animationName: String): List {