[cavedroid.git] / core / src / ru / deadsoftware / cavedroid / game / input / handler / keyboard / ToggleControlsModeKeyboardInputHandler.kt
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.KeyboardInputHandler
7 import ru.deadsoftware.cavedroid.game.input.action.KeyboardInputAction
8 import ru.deadsoftware.cavedroid.game.input.action.keys.KeyboardInputActionKey
9 import ru.deadsoftware.cavedroid.game.mobs.MobsController
10 import ru.deadsoftware.cavedroid.game.mobs.player.Player
11 import javax.inject.Inject
13 @GameScope
14 @KeyboardInputHandler
15 class ToggleControlsModeKeyboardInputHandler @Inject constructor(
16 private val mainConfig: MainConfig,
17 private val mobsController: MobsController,
18 ) : IKeyboardInputHandler {
20 override fun checkConditions(action: KeyboardInputAction): Boolean {
21 return action.actionKey is KeyboardInputActionKey.SwitchControlsMode && !action.isKeyDown
22 && mainConfig.isTouch
23 }
25 override fun handle(action: KeyboardInputAction) {
26 if (mobsController.player.controlMode == Player.ControlMode.WALK) {
27 mobsController.player.controlMode = Player.ControlMode.CURSOR
28 } else {
29 mobsController.player.controlMode = Player.ControlMode.WALK
30 }
31 }
33 }