fd370db74b862cd812ec225e531a77444f910718
[cavedroid.git] / core / src / ru / deadsoftware / cavedroid / game / actions / useblock / UseChestAction.kt
1 package ru.deadsoftware.cavedroid.game.actions.useblock
3 import ru.deadsoftware.cavedroid.game.GameScope
4 import ru.deadsoftware.cavedroid.game.model.block.Block
5 import ru.deadsoftware.cavedroid.game.objects.container.Chest
6 import ru.deadsoftware.cavedroid.game.ui.windows.GameWindowsManager
7 import ru.deadsoftware.cavedroid.game.world.GameWorld
8 import javax.inject.Inject
10 @GameScope
11 @UseBlockAction(stringKey = UseChestAction.KEY)
12 class UseChestAction @Inject constructor(
13 private val gameWorld: GameWorld,
14 private val gameWindowsManager: GameWindowsManager,
15 ) : IUseBlockAction {
17 override fun perform(block: Block, x: Int, y: Int) {
18 val chest = (gameWorld.getForegroundContainer(x, y) as? Chest)
19 ?: (gameWorld.getBackgroundContainer(x, y) as? Chest)
20 ?: return
21 gameWindowsManager.openChest(chest)
22 }
24 companion object {
25 const val KEY = "chest"
26 }
27 }