DEADSOFTWARE

705f9aa0e71a5ae60a64c8ac1e411c8cbf511a45
[cavedroid.git] /
1 package ru.deadsoftware.cavedroid.game.input.handler.keyboard
3 import ru.deadsoftware.cavedroid.game.GameScope
4 import ru.deadsoftware.cavedroid.game.GameUiWindow
5 import ru.deadsoftware.cavedroid.game.input.IGameInputHandler
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.objects.DropController
10 import ru.deadsoftware.cavedroid.game.windows.GameWindowsManager
11 import javax.inject.Inject
13 @GameScope
14 class CloseGameWindowKeyboardInputHandler @Inject constructor(
15 private val gameWindowsManager: GameWindowsManager,
16 private val mobsController: MobsController,
17 private val dropController: DropController,
18 ) : IGameInputHandler<KeyboardInputAction> {
20 override fun checkConditions(action: KeyboardInputAction): Boolean {
21 return action.actionKey is KeyboardInputActionKey.OpenInventory &&
22 action.isKeyDown && gameWindowsManager.getCurrentWindow() != GameUiWindow.NONE
23 }
25 override fun handle(action: KeyboardInputAction) {
26 val selectedItem = gameWindowsManager.currentWindow?.selectedItem
27 if (selectedItem != null) {
28 for (i in 1 .. selectedItem.amount) {
29 dropController.addDrop(
30 /* x = */ mobsController.player.x + (32f * mobsController.player.direction.basis),
31 /* y = */ mobsController.player.y,
32 /* item = */ selectedItem.item
33 )
34 }
35 gameWindowsManager.currentWindow?.selectedItem = null
36 }
37 gameWindowsManager.closeWindow()
38 }
39 }