diff options
| author | Elizabeth Hunt <me@liz.coffee> | 2025-10-26 17:25:13 -0700 |
|---|---|---|
| committer | Elizabeth Hunt <me@liz.coffee> | 2025-10-26 17:25:13 -0700 |
| commit | 395aa7d1c312e495517701be11c21425d9a5838e (patch) | |
| tree | 4ad184b082838c56149cc1d1efe191cfd3d0679b /composeApp/src/commonMain/kotlin/coffee/liz/ecs/input | |
| parent | 64f825465de9fa30c4dfe2707067efdb96110db8 (diff) | |
| download | abstraction-engine-kt-395aa7d1c312e495517701be11c21425d9a5838e.tar.gz abstraction-engine-kt-395aa7d1c312e495517701be11c21425d9a5838e.zip | |
Checkpoint
Diffstat (limited to 'composeApp/src/commonMain/kotlin/coffee/liz/ecs/input')
3 files changed, 37 insertions, 0 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 new file mode 100644 index 0000000..8c54bfe --- /dev/null +++ b/composeApp/src/commonMain/kotlin/coffee/liz/ecs/input/Controlled.kt @@ -0,0 +1,7 @@ +package coffee.liz.ecs.input + +import coffee.liz.ecs.Component + +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 new file mode 100644 index 0000000..5735665 --- /dev/null +++ b/composeApp/src/commonMain/kotlin/coffee/liz/ecs/input/InputProvider.kt @@ -0,0 +1,7 @@ +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 new file mode 100644 index 0000000..6dc8256 --- /dev/null +++ b/composeApp/src/commonMain/kotlin/coffee/liz/ecs/input/InputSystem.kt @@ -0,0 +1,23 @@ +package coffee.liz.ecs.input + +import coffee.liz.ecs.System +import coffee.liz.ecs.TickedSystem +import coffee.liz.ecs.World +import kotlin.time.Duration + +class InputSystem<Outside : InputProvider>( + pollRate: Duration +) : TickedSystem<Outside>(pollRate) { + private val activeInputs = mutableMapOf<String, Int>() + + override fun update(world: World<Outside>, state: Outside, ticks: Int) { + state.inputState.activeInputs.forEach { + activeInputs[it] = (activeInputs[it] ?: 0) + ticks + } + activeInputs.keys.retainAll(state.inputState.activeInputs) + + world.query(Controlled::class).forEach { + it.get(Controlled::class).handleInput(activeInputs.toMap()) + } + } +}
\ No newline at end of file |
