diff options
Diffstat (limited to 'composeApp/src/commonMain/kotlin/coffee/liz/ecs/input')
3 files changed, 20 insertions, 13 deletions
diff --git a/composeApp/src/commonMain/kotlin/coffee/liz/ecs/input/Controlled.kt b/composeApp/src/commonMain/kotlin/coffee/liz/ecs/input/Controlled.kt index 8c54bfe..ddda2d6 100644 --- a/composeApp/src/commonMain/kotlin/coffee/liz/ecs/input/Controlled.kt +++ b/composeApp/src/commonMain/kotlin/coffee/liz/ecs/input/Controlled.kt @@ -2,6 +2,9 @@ package coffee.liz.ecs.input import coffee.liz.ecs.Component -interface Controlled: Component { +/** + * Processes the [InputState]. + */ +fun interface Controlled : Component { fun handleInput(inputState: InputState) -}
\ No newline at end of file +} diff --git a/composeApp/src/commonMain/kotlin/coffee/liz/ecs/input/InputProvider.kt b/composeApp/src/commonMain/kotlin/coffee/liz/ecs/input/InputProvider.kt deleted file mode 100644 index 5735665..0000000 --- a/composeApp/src/commonMain/kotlin/coffee/liz/ecs/input/InputProvider.kt +++ /dev/null @@ -1,7 +0,0 @@ -package coffee.liz.ecs.input - -data class InputState(val activeInputs: Set<String>) - -interface InputProvider { - val inputState: InputState -}
\ No newline at end of file diff --git a/composeApp/src/commonMain/kotlin/coffee/liz/ecs/input/InputSystem.kt b/composeApp/src/commonMain/kotlin/coffee/liz/ecs/input/InputSystem.kt index 6dc8256..f80c1ad 100644 --- a/composeApp/src/commonMain/kotlin/coffee/liz/ecs/input/InputSystem.kt +++ b/composeApp/src/commonMain/kotlin/coffee/liz/ecs/input/InputSystem.kt @@ -1,16 +1,27 @@ package coffee.liz.ecs.input -import coffee.liz.ecs.System import coffee.liz.ecs.TickedSystem import coffee.liz.ecs.World import kotlin.time.Duration +data class InputState( + val activeInputs: Set<String>, +) + +interface InputProvider { + val inputState: InputState +} + class InputSystem<Outside : InputProvider>( - pollRate: Duration + pollRate: Duration, ) : TickedSystem<Outside>(pollRate) { private val activeInputs = mutableMapOf<String, Int>() - override fun update(world: World<Outside>, state: Outside, ticks: Int) { + override fun update( + world: World<Outside>, + state: Outside, + ticks: Int, + ) { state.inputState.activeInputs.forEach { activeInputs[it] = (activeInputs[it] ?: 0) + ticks } @@ -20,4 +31,4 @@ class InputSystem<Outside : InputProvider>( it.get(Controlled::class).handleInput(activeInputs.toMap()) } } -}
\ No newline at end of file +} |
