From fd61bd01979cd6c337cd35f0e6ea37448d28dcf9 Mon Sep 17 00:00:00 2001 From: Anthony Berg Date: Tue, 7 May 2024 12:50:59 +0100 Subject: [PATCH] feat(connector): add init for VDMJTransaction --- .../connector/shared/vdmj/VDMJTransaction.kt | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 connector/shared/src/commonMain/kotlin/io/anthonyberg/connector/shared/vdmj/VDMJTransaction.kt diff --git a/connector/shared/src/commonMain/kotlin/io/anthonyberg/connector/shared/vdmj/VDMJTransaction.kt b/connector/shared/src/commonMain/kotlin/io/anthonyberg/connector/shared/vdmj/VDMJTransaction.kt new file mode 100644 index 0000000..0f92c5d --- /dev/null +++ b/connector/shared/src/commonMain/kotlin/io/anthonyberg/connector/shared/vdmj/VDMJTransaction.kt @@ -0,0 +1,56 @@ +package io.anthonyberg.connector.shared.vdmj + +import io.anthonyberg.connector.shared.entity.Action +import io.anthonyberg.connector.shared.vdmj.type.* +import io.anthonyberg.connector.shared.xpc.XPC +import io.ktor.utils.io.errors.* + +/** + * VDMJ transactions used to control the aircraft in the simulator + * and run steps + */ +class VDMJTransaction(val actions: List, xpc: XPC) { + private val vdmj = VDMJ() + + private var aircraft: Aircraft + + init { + // Check X-Plane is running + if (!xpc.connected()) { + throw IOException("Could not connect to X-Plane") + } + + // Create Aircraft + val items: MutableMap = mutableMapOf() + val procedure: MutableList = mutableListOf() + for (item: Action in actions) { + val dref = item.type + val type = ItemType.SWITCH + val initDref = xpc.getState(dref)[0].toInt() + val goal = item.goal.toInt() + val middlePosition: Boolean = goal > 1 + + items[dref] = ItemObject( + type = type, + item = Switch( + position = initDref, + middlePosition = middlePosition + ) + ) + procedure.addLast( + ProcedureItem( + dref = dref, + type = type, + goal = goal, + complete = false + ) + ) + } + + aircraft = Aircraft(items = items, procedure = procedure) + } + + fun nextStep() { + + } +}