DEADSOFTWARE

Add slab full block reference in json
authorfredboy <fredboy@protonmail.com>
Sat, 20 Apr 2024 05:49:49 +0000 (12:49 +0700)
committerfredboy <fredboy@protonmail.com>
Sat, 20 Apr 2024 08:22:46 +0000 (15:22 +0700)
android/assets/json/game_items.json
core/src/ru/deadsoftware/cavedroid/game/GameItems.java
core/src/ru/deadsoftware/cavedroid/game/objects/Block.kt
core/src/ru/deadsoftware/cavedroid/game/world/GameWorld.java

index eb1cb2a8eb11a07db189e0d5b5867f0e9a106fd6..97e4106ceb6fc15230ae1549ed739c5e24d69f99 100644 (file)
       "top": 8,
       "transparent": true,
       "meta": "slab",
-      "sprite_top": 8
+      "sprite_top": 8,
+      "full_block": "planks_oak"
     },
     "obsidian": {
       "hp": 1500,
       "top": 8,
       "transparent": true,
       "meta": "slab",
-      "sprite_top": 8
+      "sprite_top": 8,
+      "full_block": "sandstone"
     },
     "sapling_oak": {
       "block_required": true,
       "sprite_top": 8,
       "top": 8,
       "transparent": true,
-      "meta": "slab"
+      "meta": "slab",
+      "full_block": "double_stone_slab"
     },
     "stonebrick": {
       "hp": 450,
       "top": 8,
       "transparent": true,
       "meta": "slab",
+      "full_block": "stonebrick",
       "sprite_top": 8
     },
     "tallgrass": {
index 079f4855d88465aebea7b60091b06e773d3ac328..eeeeb115da03fad2112abe5b96682373251d083f 100644 (file)
@@ -144,6 +144,7 @@ public class GameItems {
                 boolean animated = Assets.getBooleanFromJson(block, "animated", false);
                 int frames = Assets.getIntFromJson(block, "frames", 0);
                 int id = Assets.getIntFromJson(block, "id", count);
+                String fullBlock = Assets.getStringFromJson(block, "full_block", null);
                 blocksIds.put(key, id);
 
                 if (count >= id) {
@@ -171,7 +172,8 @@ public class GameItems {
                         clipX,
                         clipY,
                         clipWidth,
-                        clipHeight
+                        clipHeight,
+                        fullBlock
                 );
                 blocksSet.add(newBlock);
             } catch (GdxRuntimeException e) {
index 3343c9ac294b6e18cb7e5812fc62d00ce99415a4..020caf5356c7b4d7dd142afbc7c045f3787e53e2 100644 (file)
@@ -32,6 +32,7 @@ private const val DEPRECATION_MESSAGE =
  * @param spriteTop     block's sprite y on texture
  * @param spriteRight   block's sprite right edge on texture
  * @param spriteBottom  block's sprite bottom on texture
+ * @param fullBlockKey for slabs. block for two slabs of one kind
  */
 data class Block(
         val id: Int,
@@ -54,7 +55,8 @@ data class Block(
         private val spriteLeft: Int,
         private val spriteTop: Int,
         private val spriteRight: Int,
-        private val spriteBottom: Int
+        private val spriteBottom: Int,
+        val fullBlockKey: String?,
 ) {
 
     val width = 16 - right - left
index d3e56c1a760ba6d9991870343bc2502efee48942..797e670033ebe4f2abadad58fa96b41cf88b8576 100644 (file)
@@ -134,34 +134,14 @@ public class GameWorld {
         setMap(x, y, 1, id);
     }
 
-    private void placeSlab(int x, int y, int value) {
-        switch (value) {
-            case 51:
-                setForeMap(x, y, 52);
-                break;
-            case 53:
-                setForeMap(x, y, 21);
-                break;
-            case 54:
-                setForeMap(x, y, 5);
-                break;
-            case 55:
-                setForeMap(x, y, 4);
-                break;
-            case 56:
-                setForeMap(x, y, 28);
-                break;
-            case 58:
-                setForeMap(x, y, 57);
-                break;
-        }
-    }
-
     public void placeToForeground(int x, int y, int value) {
         if (!hasForeAt(x, y) || value == 0 || !GameItems.getBlock(getForeMap(x, y)).hasCollision()) {
             setForeMap(x, y, value);
         } else if (GameItems.isSlab(value) && getForeMap(x, y) == value) {
-            placeSlab(x, y, value);
+            final Block block = GameItems.getBlock(value);
+            if (block.getFullBlockKey() != null) {
+                setForeMap(x, y, GameItems.getBlockId(block.getFullBlockKey()));
+            }
         }
     }