84c5b900cc5d12fdc2d217a5eee0326e716340e7
1 package ru.deadsoftware.cavedroid.game.input.handler.keyboard
3 import ru.deadsoftware.cavedroid.MainConfig
4 import ru.deadsoftware.cavedroid.game.GameScope
5 import ru.deadsoftware.cavedroid.game.input.IKeyboardInputHandler
6 import ru.deadsoftware.cavedroid.game.input.action.KeyboardInputAction
7 import ru.deadsoftware.cavedroid.game.input.action.keys.KeyboardInputActionKey
8 import ru.deadsoftware.cavedroid.game.mobs.MobsController
9 import ru.deadsoftware.cavedroid.game.mobs.player.Player
10 import ru.deadsoftware.cavedroid.game.world.GameWorld
11 import ru.deadsoftware.cavedroid.misc.annotations.multibinding.BindKeyboardInputHandler
12 import javax.inject.Inject
14 @GameScope
15 @BindKeyboardInputHandler
16 class MoveCursorControlsModeKeyboardInputHandler @Inject constructor(
17 private val mainConfig: MainConfig,
18 private val mobsController: MobsController,
19 private val gameWorld: GameWorld,
20 ) : IKeyboardInputHandler {
22 override fun checkConditions(action: KeyboardInputAction): Boolean {
23 return mainConfig.isTouch &&
24 mobsController.player.controlMode == Player.ControlMode.CURSOR && action.isKeyDown &&
25 (action.actionKey is KeyboardInputActionKey.Left ||
26 action.actionKey is KeyboardInputActionKey.Right ||
27 action.actionKey is KeyboardInputActionKey.Up ||
28 action.actionKey is KeyboardInputActionKey.Down)
29 }
31 override fun handle(action: KeyboardInputAction) {
32 val player = mobsController.player
34 when (action.actionKey) {
35 KeyboardInputActionKey.Left -> player.cursorX--
36 KeyboardInputActionKey.Right -> player.cursorX++
37 KeyboardInputActionKey.Up -> player.cursorY--
38 KeyboardInputActionKey.Down -> player.cursorY++
39 else -> return
40 }
42 player.checkCursorBounds(gameWorld);
43 }
45 companion object {
46 private const val SURVIVAL_CURSOR_RANGE = 4
47 }
48 }