DEADSOFTWARE

Add bed
authorfredboy <fredboy@protonmail.com>
Fri, 10 May 2024 17:41:38 +0000 (00:41 +0700)
committerfredboy <fredboy@protonmail.com>
Fri, 10 May 2024 17:41:38 +0000 (00:41 +0700)
android/assets/json/crafting.json
android/assets/json/game_items.json
core/src/ru/deadsoftware/cavedroid/game/actions/UpdateBlockActionsModule.kt
core/src/ru/deadsoftware/cavedroid/game/actions/UseItemActionsModule.kt
core/src/ru/deadsoftware/cavedroid/game/actions/updateblock/UpdateBedLeftAction.kt [new file with mode: 0644]
core/src/ru/deadsoftware/cavedroid/game/actions/updateblock/UpdateBedRightAction.kt [new file with mode: 0644]
core/src/ru/deadsoftware/cavedroid/game/actions/useitem/UseBedAction.kt [new file with mode: 0644]
core/src/ru/deadsoftware/cavedroid/game/world/GameWorld.java

index 6404dd6d6b7bb79acd57c977f2d4c5cde1c537fd..9a67e014520eb6d4cf1ae88d8b1606d5473949fa 100644 (file)
   },
   "chest": {
     "input": ["planks_.*", "planks_.*", "planks_.*", "planks_.*", "none", "planks_.*", "planks_.*", "planks_.*", "planks_.*"]
+  },
+  "bed": {
+    "input": ["wool_.*", "wool_.*", "wool_.*", "planks_.*", "planks_.*", "planks_.*", "none", "none", "none"]
   }
 }
\ No newline at end of file
index 95d4c7a084900a815d3ca228b606c36fa74d7997..5c1157690a9141876f5d96311f711677e3a70d14 100644 (file)
       "collision": false,
       "background": true,
       "transparent": true,
-      "drop": "none",
+      "drop": "bed",
       "texture": "bed_l",
       "tool_level": 0,
       "tool_type": "axe"
       "collision": false,
       "background": true,
       "transparent": true,
-      "drop": "none",
+      "drop": "bed",
       "texture": "bed_r",
       "tool_level": 0,
       "tool_type": "axe"
index 5dcfe0e72a80c987a6ac3227190855570d89e804..6f0fc0fcae365668b884095a250377119b6a18d4 100644 (file)
@@ -49,4 +49,20 @@ class UpdateBlockActionsModule {
     fun bindUpdateSnowedGrassAction(action: UpdateSnowedGrassAction): IUpdateBlockAction {
         return action;
     }
+
+    @Binds
+    @IntoMap
+    @StringKey(UpdateBedLeftAction.BLOCK_KEY)
+    @GameScope
+    fun bindUpdateBedLeftAction(action: UpdateBedLeftAction): IUpdateBlockAction {
+        return action;
+    }
+
+    @Binds
+    @IntoMap
+    @StringKey(UpdateBedRightAction.BLOCK_KEY)
+    @GameScope
+    fun bindUpdateBedRightAction(action: UpdateBedRightAction): IUpdateBlockAction {
+        return action;
+    }
 }
\ No newline at end of file
index a6aed22cfdc04b1f696efa4cb0e449247ec81380..d5e4f4fa80c5cda9a10328c9834a9d4dc7ba089a 100644 (file)
@@ -42,4 +42,12 @@ class UseItemActionsModule {
         return action
     }
 
+    @Binds
+    @IntoMap
+    @StringKey(UseBedAction.ACTION_KEY)
+    @GameScope
+    fun bindUseBedAction(action: UseBedAction): IUseItemAction {
+        return action
+    }
+
 }
diff --git a/core/src/ru/deadsoftware/cavedroid/game/actions/updateblock/UpdateBedLeftAction.kt b/core/src/ru/deadsoftware/cavedroid/game/actions/updateblock/UpdateBedLeftAction.kt
new file mode 100644 (file)
index 0000000..15621a2
--- /dev/null
@@ -0,0 +1,26 @@
+package ru.deadsoftware.cavedroid.game.actions.updateblock
+
+import ru.deadsoftware.cavedroid.game.GameItemsHolder
+import ru.deadsoftware.cavedroid.game.GameScope
+import ru.deadsoftware.cavedroid.game.mobs.FallingGravel
+import ru.deadsoftware.cavedroid.game.mobs.MobsController
+import ru.deadsoftware.cavedroid.game.world.GameWorld
+import javax.inject.Inject
+
+@GameScope
+class UpdateBedLeftAction @Inject constructor(
+    private val gameWorld: GameWorld,
+    private val gameItemsHolder: GameItemsHolder,
+) : IUpdateBlockAction {
+
+    override fun update(x: Int, y: Int) {
+        val bedRight = gameItemsHolder.getBlock("bed_r")
+        if (gameWorld.getForeMap(x + 1, y) != bedRight) {
+            gameWorld.resetForeMap(x, y)
+        }
+    }
+
+    companion object {
+        const val BLOCK_KEY = "bed_l"
+    }
+}
\ No newline at end of file
diff --git a/core/src/ru/deadsoftware/cavedroid/game/actions/updateblock/UpdateBedRightAction.kt b/core/src/ru/deadsoftware/cavedroid/game/actions/updateblock/UpdateBedRightAction.kt
new file mode 100644 (file)
index 0000000..4d47b35
--- /dev/null
@@ -0,0 +1,26 @@
+package ru.deadsoftware.cavedroid.game.actions.updateblock
+
+import ru.deadsoftware.cavedroid.game.GameItemsHolder
+import ru.deadsoftware.cavedroid.game.GameScope
+import ru.deadsoftware.cavedroid.game.mobs.FallingGravel
+import ru.deadsoftware.cavedroid.game.mobs.MobsController
+import ru.deadsoftware.cavedroid.game.world.GameWorld
+import javax.inject.Inject
+
+@GameScope
+class UpdateBedRightAction @Inject constructor(
+    private val gameWorld: GameWorld,
+    private val gameItemsHolder: GameItemsHolder,
+) : IUpdateBlockAction {
+
+    override fun update(x: Int, y: Int) {
+        val bedLeft = gameItemsHolder.getBlock("bed_l")
+        if (gameWorld.getForeMap(x - 1, y) != bedLeft) {
+            gameWorld.resetForeMap(x, y)
+        }
+    }
+
+    companion object {
+        const val BLOCK_KEY = "bed_r"
+    }
+}
\ No newline at end of file
diff --git a/core/src/ru/deadsoftware/cavedroid/game/actions/useitem/UseBedAction.kt b/core/src/ru/deadsoftware/cavedroid/game/actions/useitem/UseBedAction.kt
new file mode 100644 (file)
index 0000000..e0f9964
--- /dev/null
@@ -0,0 +1,31 @@
+package ru.deadsoftware.cavedroid.game.actions.useitem
+
+import ru.deadsoftware.cavedroid.game.GameItemsHolder
+import ru.deadsoftware.cavedroid.game.GameScope
+import ru.deadsoftware.cavedroid.game.mobs.MobsController
+import ru.deadsoftware.cavedroid.game.model.item.Item
+import ru.deadsoftware.cavedroid.game.world.GameWorld
+import javax.inject.Inject
+
+@GameScope
+class UseBedAction @Inject constructor(
+    private val gameWorld: GameWorld,
+    private val mobsController: MobsController,
+    private val gameItemsHolder: GameItemsHolder,
+) : IUseItemAction {
+
+    override fun perform(item: Item.Usable, x: Int, y: Int) {
+        val bedLeft = gameItemsHolder.getBlock("bed_l")
+        val bedRight = gameItemsHolder.getBlock("bed_r")
+
+        if (gameWorld.canPlaceToForeground(x, y, bedLeft) && gameWorld.canPlaceToForeground(x + 1, y, bedRight)) {
+            gameWorld.placeToForeground(x, y, bedLeft)
+            gameWorld.placeToForeground(x + 1, y, bedRight)
+            mobsController.player.inventory.decreaseCurrentItemAmount()
+        }
+    }
+
+    companion object {
+        const val ACTION_KEY = "use_bed_action"
+    }
+}
index c038f1541d21822f90c122a75e30961dfee1fa40..d52b50f672039328773896ee12f11072949db368 100644 (file)
@@ -183,8 +183,12 @@ public class GameWorld {
         setMap(x, y, BACKGROUND_Z, block);
     }
 
+    public boolean canPlaceToForeground(int x, int y, Block value) {
+        return !hasForeAt(x, y) || value == mGameItemsHolder.getFallbackBlock() || !getForeMap(x, y).hasCollision();
+    }
+
     public boolean placeToForeground(int x, int y, Block value) {
-        if (!hasForeAt(x, y) || value == mGameItemsHolder.getFallbackBlock() || !getForeMap(x, y).hasCollision()) {
+        if (canPlaceToForeground(x, y, value)) {
             setForeMap(x, y, value);
             return true;
         } else if (value instanceof Block.Slab && isSameSlab(value, getForeMap(x, y))) {