DEADSOFTWARE

Add top slabs
[cavedroid.git] / core / src / ru / deadsoftware / cavedroid / game / actions / placeblock / PlaceSlabAction.kt
1 package ru.deadsoftware.cavedroid.game.actions.placeblock
3 import com.badlogic.gdx.Gdx
4 import ru.deadsoftware.cavedroid.game.GameItemsHolder
5 import ru.deadsoftware.cavedroid.game.GameScope
6 import ru.deadsoftware.cavedroid.game.mobs.MobsController
7 import ru.deadsoftware.cavedroid.game.model.item.Item
8 import ru.deadsoftware.cavedroid.game.world.GameWorld
9 import javax.inject.Inject
10 import kotlin.random.Random
12 @GameScope
13 class PlaceSlabAction @Inject constructor(
14 private val gameWorld: GameWorld,
15 private val mobsController: MobsController,
16 private val gameItemsHolder: GameItemsHolder,
17 ) : IPlaceBlockAction {
19 override fun place(placeable: Item.Placeable, x: Int, y: Int) {
20 if (placeable !is Item.Slab) {
21 Gdx.app.debug(TAG, "Place slab action called on ${placeable.params.key} which is not a slab")
22 return
23 }
25 val slabPart = if (Random.nextBoolean()) placeable.topPartBlock else placeable.bottomPartBlock
26 gameWorld.placeToForeground(x, y, slabPart)
27 }
29 companion object {
30 private const val TAG = "PlaceSlabAction"
31 const val ACTION_KEY = "place_slab"
32 }
33 }