8bf9b1c25d666408b1c3c1a70ac1e9f14bd9dd23
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.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.objects.drop.DropController
10 import ru.deadsoftware.cavedroid.game.ui.windows.GameWindowsManager
11 import ru.deadsoftware.cavedroid.misc.annotations.multibinding.BindKeyboardInputHandler
12 import javax.inject.Inject
14 @GameScope
15 @BindKeyboardInputHandler
16 class CloseGameWindowKeyboardInputHandler @Inject constructor(
17 private val gameWindowsManager: GameWindowsManager,
18 private val mobsController: MobsController,
19 private val dropController: DropController,
20 ) : IKeyboardInputHandler {
22 override fun checkConditions(action: KeyboardInputAction): Boolean {
23 return action.actionKey is KeyboardInputActionKey.OpenInventory &&
24 !action.isKeyDown && gameWindowsManager.getCurrentWindow() != GameUiWindow.NONE
25 }
27 override fun handle(action: KeyboardInputAction) {
28 val selectedItem = gameWindowsManager.currentWindow?.selectedItem
29 if (selectedItem != null) {
30 for (i in 1 .. selectedItem.amount) {
31 dropController.addDrop(
32 /* x = */ mobsController.player.x + (32f * mobsController.player.direction.basis),
33 /* y = */ mobsController.player.y,
34 /* item = */ selectedItem.item
35 )
36 }
37 gameWindowsManager.currentWindow?.selectedItem = null
38 }
39 gameWindowsManager.closeWindow()
40 }
41 }