Skip to content

Commit 485ae2a

Browse files
committed
chore: simplify delegation of input processing
1 parent 8bf7683 commit 485ae2a

File tree

1 file changed

+4
-39
lines changed
  • cake/core/src/main/java/org/demoth/cake

1 file changed

+4
-39
lines changed

cake/core/src/main/java/org/demoth/cake/Cake.kt

Lines changed: 4 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ class Cake : KtxApplicationAdapter, KtxInputAdapter {
142142
}
143143

144144
Cmd.AddCommand("precache") {
145+
// todo: check the game state first, do not precache in the middle of the game
145146
Com.Printf("precache - loading resources\n")
146147
val precache_spawncount = it[1].toInt()
147148
// no udp downloads anymore!!
@@ -165,45 +166,9 @@ class Cake : KtxApplicationAdapter, KtxInputAdapter {
165166
handlers.add(menuStage)
166167
}
167168
// delegate the rest to the current 3d screen
168-
handlers.add(
169-
object : InputProcessor {
170-
override fun keyDown(keycode: Int): Boolean {
171-
return game3dScreen?.keyDown(keycode) ?: false
172-
}
173-
174-
override fun keyUp(keycode: Int): Boolean {
175-
return game3dScreen?.keyUp(keycode) ?: false
176-
}
177-
178-
override fun keyTyped(character: Char): Boolean {
179-
return game3dScreen?.keyTyped(character) ?: false
180-
}
181-
182-
override fun touchDown(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
183-
return game3dScreen?.touchDown(screenX, screenY, pointer, button) ?: false
184-
}
185-
186-
override fun touchUp(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
187-
return game3dScreen?.touchUp(screenX, screenY, pointer, button) ?: false
188-
}
189-
190-
override fun touchCancelled(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
191-
return game3dScreen?.touchCancelled(screenX, screenY, pointer, button) ?: false
192-
}
193-
194-
override fun touchDragged(screenX: Int, screenY: Int, pointer: Int): Boolean {
195-
return game3dScreen?.touchDragged(screenX, screenY, pointer) ?: false
196-
}
197-
198-
override fun mouseMoved(screenX: Int, screenY: Int): Boolean {
199-
return game3dScreen?.mouseMoved(screenX, screenY) ?: false
200-
}
201-
202-
override fun scrolled(amountX: Float, amountY: Float): Boolean {
203-
return game3dScreen?.scrolled(amountX, amountY) ?: false
204-
}
205-
}
206-
)
169+
game3dScreen?.let { screen ->
170+
handlers.add(object : InputProcessor by screen {})
171+
}
207172
Gdx.input.inputProcessor = InputMultiplexer(
208173
this, // global input processor to control console and menu
209174
*handlers.toTypedArray()

0 commit comments

Comments
 (0)