DEADSOFTWARE

Add use item actions module
[cavedroid.git] / core / src / ru / deadsoftware / cavedroid / game / actions / CommonBlockActionUtils.kt
1 package ru.deadsoftware.cavedroid.game.actions
3 import com.badlogic.gdx.Gdx
4 import ru.deadsoftware.cavedroid.game.actions.updateblock.IUpdateBlockAction
5 import ru.deadsoftware.cavedroid.game.actions.updateblock.UpdateRequiresBlockAction
6 import ru.deadsoftware.cavedroid.game.actions.useitem.IUseItemAction
7 import ru.deadsoftware.cavedroid.game.actions.useitem.PlaceBlockItemToBackgroundAction
8 import ru.deadsoftware.cavedroid.game.actions.useitem.PlaceBlockItemToForegroundAction
9 import ru.deadsoftware.cavedroid.game.objects.Item
11 private const val TAG = "PlaceBlockActionUtils"
13 fun Map<String, IUseItemAction>.placeToForegroundAction(item: Item, x: Int, y: Int) {
14 get(PlaceBlockItemToForegroundAction.ACTION_KEY)?.perform(item, x, y)
15 ?: Gdx.app.error(TAG, "action place_foreground_block not found")
16 }
18 fun Map<String, IUseItemAction>.placeToBackgroundAction(item: Item, x: Int, y: Int) {
19 get(PlaceBlockItemToBackgroundAction.ACTION_KEY)?.perform(item, x, y)
20 ?: Gdx.app.error(TAG, "action place_background_block not found")
21 }
23 fun Map<String, IUpdateBlockAction>.getRequiresBlockAction(): IUpdateBlockAction {
24 return requireNotNull(get(UpdateRequiresBlockAction.ACTION_KEY)) { "action requires_block not found" }
25 }