From: fredboy Date: Sat, 20 Apr 2024 05:49:49 +0000 (+0700) Subject: Add slab full block reference in json X-Git-Tag: alpha0.6.0~22 X-Git-Url: http://deadsoftware.ru/gitweb?a=commitdiff_plain;h=127dbffee03093baee8c11a4e7e152aee0bf5343;p=cavedroid.git Add slab full block reference in json --- diff --git a/android/assets/json/game_items.json b/android/assets/json/game_items.json index eb1cb2a..97e4106 100644 --- a/android/assets/json/game_items.json +++ b/android/assets/json/game_items.json @@ -212,7 +212,8 @@ "top": 8, "transparent": true, "meta": "slab", - "sprite_top": 8 + "sprite_top": 8, + "full_block": "planks_oak" }, "obsidian": { "hp": 1500, @@ -243,7 +244,8 @@ "top": 8, "transparent": true, "meta": "slab", - "sprite_top": 8 + "sprite_top": 8, + "full_block": "sandstone" }, "sapling_oak": { "block_required": true, @@ -266,7 +268,8 @@ "sprite_top": 8, "top": 8, "transparent": true, - "meta": "slab" + "meta": "slab", + "full_block": "double_stone_slab" }, "stonebrick": { "hp": 450, @@ -279,6 +282,7 @@ "top": 8, "transparent": true, "meta": "slab", + "full_block": "stonebrick", "sprite_top": 8 }, "tallgrass": { diff --git a/core/src/ru/deadsoftware/cavedroid/game/GameItems.java b/core/src/ru/deadsoftware/cavedroid/game/GameItems.java index 079f485..eeeeb11 100644 --- a/core/src/ru/deadsoftware/cavedroid/game/GameItems.java +++ b/core/src/ru/deadsoftware/cavedroid/game/GameItems.java @@ -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) { diff --git a/core/src/ru/deadsoftware/cavedroid/game/objects/Block.kt b/core/src/ru/deadsoftware/cavedroid/game/objects/Block.kt index 3343c9a..020caf5 100644 --- a/core/src/ru/deadsoftware/cavedroid/game/objects/Block.kt +++ b/core/src/ru/deadsoftware/cavedroid/game/objects/Block.kt @@ -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 diff --git a/core/src/ru/deadsoftware/cavedroid/game/world/GameWorld.java b/core/src/ru/deadsoftware/cavedroid/game/world/GameWorld.java index d3e56c1..797e670 100644 --- a/core/src/ru/deadsoftware/cavedroid/game/world/GameWorld.java +++ b/core/src/ru/deadsoftware/cavedroid/game/world/GameWorld.java @@ -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())); + } } }