mirror of
https://github.com/smyalygames/checklist-tester.git
synced 2025-05-18 06:24:12 +02:00
feat(connector): track initial state in test runs
This commit is contained in:
parent
452756e3d3
commit
5f456bb898
@ -25,7 +25,11 @@ class TestRun (
|
||||
private val actions: List<Action>
|
||||
) : Screen {
|
||||
|
||||
private val xpc = XPC()
|
||||
private val xpcConnected = xpc.connected()
|
||||
|
||||
private var tested = mutableStateListOf<Boolean>()
|
||||
private val initState = getInitState()
|
||||
|
||||
@Composable
|
||||
override fun Content() {
|
||||
@ -37,6 +41,11 @@ class TestRun (
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
) {
|
||||
if (!xpcConnected) {
|
||||
Text("Could not connect to the simulator!")
|
||||
return
|
||||
}
|
||||
|
||||
// Progress Indicator
|
||||
if (running) {
|
||||
LinearProgressIndicator(
|
||||
@ -50,7 +59,7 @@ class TestRun (
|
||||
) {
|
||||
LazyColumn {
|
||||
items(actions) { action ->
|
||||
ActionItem(action)
|
||||
ActionItem(action, initState[action.step])
|
||||
}
|
||||
}
|
||||
|
||||
@ -75,8 +84,9 @@ class TestRun (
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun ActionItem(action: Action) {
|
||||
private fun ActionItem(action: Action, initState: FloatArray) {
|
||||
ListItem(
|
||||
overlineContent = { Text("Initial State: ${initState[0]}") },
|
||||
headlineContent = { Text(action.type) },
|
||||
supportingContent = { Text("Goal: ${action.goal}") },
|
||||
leadingContent = {
|
||||
@ -103,16 +113,6 @@ class TestRun (
|
||||
}
|
||||
|
||||
private suspend fun runSteps() {
|
||||
val xpc = XPC()
|
||||
|
||||
// Checks if the simulator is running before running the other tests
|
||||
if (!xpc.connected()) {
|
||||
for (action in actions) {
|
||||
tested.add(false)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
for (action in actions) {
|
||||
delay(1000L)
|
||||
|
||||
@ -123,4 +123,19 @@ class TestRun (
|
||||
tested.add(result)
|
||||
}
|
||||
}
|
||||
|
||||
private fun getInitState(): Array<FloatArray> {
|
||||
if (!xpc.connected()) {
|
||||
return Array(actions.size) { FloatArray(0) }
|
||||
}
|
||||
|
||||
var initDrefs = arrayOf<String>()
|
||||
for (action in actions) {
|
||||
initDrefs += action.type
|
||||
}
|
||||
|
||||
val result = xpc.getStates(initDrefs)
|
||||
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
@ -27,6 +27,24 @@ class XPC {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the state of all Datarefs
|
||||
*
|
||||
* @param drefs Array of Datarefs (maximum list size = 255)
|
||||
*
|
||||
* @return List of all the values for each Dataref
|
||||
*/
|
||||
@Throws(IllegalArgumentException::class)
|
||||
fun getStates(drefs: Array<String>): Array<FloatArray> {
|
||||
if (drefs.size > 255) {
|
||||
throw IllegalArgumentException("The drefs cannot contain more than 255 elements")
|
||||
}
|
||||
|
||||
val result = xpc.getDREFs(drefs)
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a dataref in X-Plane to the set goal
|
||||
*
|
||||
|
Loading…
x
Reference in New Issue
Block a user