DEADSOFTWARE

Delete old GameItems
authorfredboy <fredboy@protonmail.com>
Sat, 20 Apr 2024 17:33:40 +0000 (00:33 +0700)
committerfredboy <fredboy@protonmail.com>
Sat, 20 Apr 2024 17:33:40 +0000 (00:33 +0700)
25 files changed:
android/assets/json/game_items.json
core/src/ru/deadsoftware/cavedroid/CaveGame.java
core/src/ru/deadsoftware/cavedroid/game/GameInput.java
core/src/ru/deadsoftware/cavedroid/game/GameItems.java [deleted file]
core/src/ru/deadsoftware/cavedroid/game/GameItemsHolder.kt
core/src/ru/deadsoftware/cavedroid/game/GameModule.java
core/src/ru/deadsoftware/cavedroid/game/GameProc.java
core/src/ru/deadsoftware/cavedroid/game/GameRenderer.java
core/src/ru/deadsoftware/cavedroid/game/GameSaver.java
core/src/ru/deadsoftware/cavedroid/game/actions/useitem/UseLavaBucketAction.kt
core/src/ru/deadsoftware/cavedroid/game/actions/useitem/UseWaterBucketAction.kt
core/src/ru/deadsoftware/cavedroid/game/mobs/FallingGravel.java
core/src/ru/deadsoftware/cavedroid/game/mobs/FallingSand.java
core/src/ru/deadsoftware/cavedroid/game/mobs/MobsController.kt
core/src/ru/deadsoftware/cavedroid/game/mobs/Player.java
core/src/ru/deadsoftware/cavedroid/game/model/block/Block.kt
core/src/ru/deadsoftware/cavedroid/game/model/dto/GameItemsDto.kt
core/src/ru/deadsoftware/cavedroid/game/model/item/Item.kt
core/src/ru/deadsoftware/cavedroid/game/model/mapper/BlockMapper.kt
core/src/ru/deadsoftware/cavedroid/game/model/mapper/ItemMapper.kt
core/src/ru/deadsoftware/cavedroid/game/objects/Drop.kt
core/src/ru/deadsoftware/cavedroid/game/objects/DropController.java
core/src/ru/deadsoftware/cavedroid/game/world/GameWorld.java
core/src/ru/deadsoftware/cavedroid/misc/Assets.java
core/src/ru/deadsoftware/cavedroid/misc/utils/ItemUtils.kt [new file with mode: 0644]

index 279e13fb5fd262d440178fbd0c23fce60b1abfd5..01d66ff111ed5981f43a24193ceccf84cdbaadeb 100644 (file)
 {
   "blocks": {
-    "bed_l": {
-      "background": true,
-      "collision": false,
-      "drop": "none",
-      "hp": 21,
-      "id": 23,
-      "transparent": true
-    },
-    "bed_r": {
-      "background": true,
+    "none": {
+      "id": 0,
       "collision": false,
-      "drop": "none",
-      "hp": 21,
-      "id": 24,
-      "transparent": true
-    },
-    "bedrock": {
-      "hp": -1,
-      "id": 7
-    },
-    "brick_slab": {
-      "hp": 600,
-      "id": 56,
-      "texture": "bricks",
-      "top": 8,
-      "sprite_top": 8,
-      "meta": "slab",
       "transparent": true,
-      "full_block": "bricks"
+      "drop": "none",
+      "texture": "none"
     },
-    "bricks": {
-      "hp": 600,
-      "id": 28
+    "stone": {
+      "id": 1,
+      "hp": 450,
+      "drop": "cobblestone",
+      "texture": "stone"
     },
-    "cactus": {
-      "block_required": true,
-      "hp": 39,
-      "id": 59,
-      "left": 1,
-      "right": 1,
-      "transparent": true
+    "grass": {
+      "id": 2,
+      "hp": 54,
+      "drop": "dirt",
+      "texture": "grass"
     },
-    "coal_ore": {
-      "drop": "coal",
-      "hp": 900,
-      "id": 14
+    "dirt": {
+      "id": 3,
+      "hp": 45,
+      "drop": "dirt",
+      "texture": "dirt"
     },
     "cobblestone": {
+      "id": 4,
       "hp": 600,
-      "id": 4
+      "drop": "cobblestone",
+      "texture": "cobblestone"
     },
-    "cobblestone_slab": {
-      "hp": 600,
-      "id": 55,
-      "texture": "cobblestone",
-      "top": 8,
-      "transparent": true
+    "planks_oak": {
+      "id": 5,
+      "hp": 180,
+      "drop": "planks_oak",
+      "texture": "planks_oak"
     },
-    "dandelion": {
+    "sapling_oak": {
+      "id": 6,
+      "collision": false,
+      "transparent": true,
       "block_required": true,
+      "drop": "sapling_oak",
+      "texture": "sapling_oak"
+    },
+    "bedrock": {
+      "id": 7,
+      "drop": "bedrock",
+      "texture": "bedrock"
+    },
+    "water": {
+      "id": 8,
       "collision": false,
-      "id": 29,
-      "transparent": true
+      "transparent": true,
+      "drop": "water",
+      "meta": "water",
+      "texture": "water_still",
+      "animated": true,
+      "frames": 16,
+      "state": 0
     },
-    "deadbush": {
-      "block_required": true,
+    "lava": {
+      "id": 9,
       "collision": false,
-      "id": 27,
-      "transparent": true
+      "drop": "lava",
+      "meta": "lava",
+      "texture": "lava_still",
+      "animated": true,
+      "frames": 16,
+      "state": 0
     },
-    "dirt": {
+    "sand": {
+      "id": 10,
       "hp": 45,
-      "id": 3
+      "drop": "sand",
+      "texture": "sand"
     },
-    "double_stone_slab": {
-      "drop": "stone_slab",
-      "hp": 600,
-      "id": 52,
-      "texture": "stone_slab"
+    "gravel": {
+      "id": 11,
+      "hp": 54,
+      "drop": "gravel",
+      "texture": "gravel"
     },
-    "glass": {
-      "drop": "none",
-      "hp": 27,
-      "id": 18,
-      "transparent": true
+    "gold_ore": {
+      "id": 12,
+      "hp": 900,
+      "drop": "gold_ore",
+      "texture": "gold_ore"
     },
-    "gold_block": {
+    "iron_ore": {
+      "id": 13,
       "hp": 900,
-      "id": 49
+      "drop": "iron_ore",
+      "texture": "iron_ore"
     },
-    "gold_ore": {
+    "coal_ore": {
+      "id": 14,
       "hp": 900,
-      "id": 12
+      "drop": "coal",
+      "texture": "coal_ore"
     },
-    "grass": {
-      "drop": "dirt",
-      "hp": 54,
-      "id": 2
+    "log_oak": {
+      "id": 15,
+      "hp": 180,
+      "drop": "log_oak",
+      "texture": "log_oak"
     },
-    "gravel": {
+    "leaves_oak": {
+      "id": 16,
+      "hp": 21,
+      "transparent": true,
+      "drop": "leaves_oak",
+      "texture": "leaves_oak"
+    },
+    "sponge": {
+      "id": 17,
       "hp": 54,
-      "id": 11
+      "drop": "sponge",
+      "texture": "sponge"
     },
-    "iron_block": {
-      "hp": 1500,
-      "id": 50
+    "glass": {
+      "id": 18,
+      "hp": 27,
+      "transparent": true,
+      "drop": "none",
+      "texture": "glass"
     },
-    "iron_ore": {
+    "lapis_ore": {
+      "id": 19,
       "hp": 900,
-      "id": 13
+      "drop": "lapis",
+      "texture": "lapis_ore"
     },
     "lapis_block": {
+      "id": 20,
       "hp": 900,
-      "id": 20
+      "drop": "lapis_block",
+      "texture": "lapis_block"
     },
-    "lapis_ore": {
-      "drop": "lapis",
-      "hp": 900,
-      "id": 19
+    "sandstone": {
+      "id": 21,
+      "hp": 240,
+      "drop": "sandstone",
+      "texture": "sandstone"
     },
-    "lava": {
-      "animated": true,
-      "collision": false,
-      "state": 0,
-      "frames": 16,
-      "hp": -1,
-      "id": 9,
-      "meta": "lava",
-      "texture": "lava_still"
+    "noteblock": {
+      "id": 22,
+      "hp": 75,
+      "drop": "noteblock",
+      "texture": "noteblock"
     },
-    "lava_12": {
-      "animated": true,
+    "bed_l": {
+      "id": 23,
+      "hp": 21,
       "collision": false,
-      "state": 2,
-      "frames": 16,
-      "hp": -1,
-      "id": 65,
-      "meta": "lava",
-      "sprite_top": 4,
-      "texture": "lava_flow",
-      "top": 4
+      "background": true,
+      "transparent": true,
+      "drop": "none",
+      "texture": "bed_l"
     },
-    "lava_16": {
-      "animated": true,
+    "bed_r": {
+      "id": 24,
+      "hp": 21,
       "collision": false,
-      "state": 1,
-      "frames": 16,
-      "hp": -1,
-      "id": 64,
-      "meta": "lava",
-      "texture": "lava_flow"
+      "background": true,
+      "transparent": true,
+      "drop": "none",
+      "texture": "bed_r"
     },
-    "lava_4": {
-      "animated": true,
+    "web": {
+      "id": 25,
+      "hp": 1200,
       "collision": false,
-      "state": 4,
-      "frames": 16,
-      "hp": -1,
-      "id": 67,
-      "meta": "lava",
-      "sprite_top": 12,
-      "texture": "lava_flow",
-      "top": 12
+      "transparent": true,
+      "drop": "web",
+      "texture": "web"
     },
-    "lava_8": {
-      "animated": true,
+    "tallgrass": {
+      "id": 26,
       "collision": false,
-      "state": 3,
-      "frames": 16,
-      "hp": -1,
-      "id": 66,
-      "meta": "lava",
-      "sprite_top": 8,
-      "texture": "lava_flow",
-      "top": 8
+      "transparent": true,
+      "block_required": true,
+      "drop": "tallgrass",
+      "texture": "tallgrass"
     },
-    "leaves_oak": {
-      "hp": 21,
-      "id": 16,
-      "transparent": true
+    "deadbush": {
+      "id": 27,
+      "collision": false,
+      "transparent": true,
+      "block_required": true,
+      "drop": "deadbush",
+      "texture": "deadbush"
     },
-    "log_oak": {
-      "hp": 180,
-      "id": 15
+    "bricks": {
+      "id": 28,
+      "hp": 600,
+      "drop": "bricks",
+      "texture": "bricks"
     },
-    "mushroom_brown": {
+    "dandelion": {
+      "id": 29,
+      "collision": false,
+      "transparent": true,
       "block_required": true,
+      "drop": "dandelion",
+      "texture": "dandelion"
+    },
+    "rose": {
+      "id": 30,
       "collision": false,
+      "transparent": true,
+      "block_required": true,
+      "drop": "rose",
+      "texture": "rose"
+    },
+    "mushroom_brown": {
       "id": 31,
-      "transparent": true
+      "collision": false,
+      "transparent": true,
+      "block_required": true,
+      "drop": "mushroom_brown",
+      "texture": "mushroom_brown"
     },
     "mushroom_red": {
-      "block_required": true,
-      "collision": false,
       "id": 32,
-      "transparent": true
-    },
-    "none": {
       "collision": false,
-      "id": 0,
-      "transparent": true
+      "transparent": true,
+      "block_required": true,
+      "drop": "mushroom_red",
+      "texture": "mushroom_red"
     },
-    "noteblock": {
+    "wool_colored_white": {
+      "id": 33,
       "hp": 75,
-      "id": 22
+      "drop": "wool_colored_white",
+      "texture": "wool_colored_white"
     },
-    "oak_slab": {
-      "hp": 180,
-      "id": 54,
-      "texture": "planks_oak",
-      "top": 8,
-      "transparent": true,
-      "meta": "slab",
-      "sprite_top": 8,
-      "full_block": "planks_oak"
+    "wool_colored_orange": {
+      "id": 34,
+      "hp": 75,
+      "drop": "wool_colored_orange",
+      "texture": "wool_colored_orange"
     },
-    "obsidian": {
-      "hp": 1500,
-      "id": 68
+    "wool_colored_magenta": {
+      "id": 35,
+      "hp": 75,
+      "drop": "wool_colored_magenta",
+      "texture": "wool_colored_magenta"
     },
-    "planks_oak": {
-      "hp": 180,
-      "id": 5
+    "wool_colored_light_blue": {
+      "id": 36,
+      "hp": 75,
+      "drop": "wool_colored_light_blue",
+      "texture": "wool_colored_light_blue"
     },
-    "rose": {
-      "block_required": true,
-      "collision": false,
-      "id": 30,
-      "transparent": true
+    "wool_colored_yellow": {
+      "id": 37,
+      "hp": 75,
+      "drop": "wool_colored_yellow",
+      "texture": "wool_colored_yellow"
     },
-    "sand": {
-      "hp": 45,
-      "id": 10
+    "wool_colored_lime": {
+      "id": 38,
+      "hp": 75,
+      "drop": "wool_colored_lime",
+      "texture": "wool_colored_lime"
     },
-    "sandstone": {
-      "hp": 240,
-      "id": 21
+    "wool_colored_pink": {
+      "id": 39,
+      "hp": 75,
+      "drop": "wool_colored_pink",
+      "texture": "wool_colored_pink"
     },
-    "sandstone_slab": {
+    "wool_colored_gray": {
+      "id": 40,
+      "hp": 75,
+      "drop": "wool_colored_gray",
+      "texture": "wool_colored_gray"
+    },
+    "wool_colored_silver": {
+      "id": 41,
+      "hp": 75,
+      "drop": "wool_colored_silver",
+      "texture": "wool_colored_silver"
+    },
+    "wool_colored_cyan": {
+      "id": 42,
+      "hp": 75,
+      "drop": "wool_colored_cyan",
+      "texture": "wool_colored_cyan"
+    },
+    "wool_colored_purple": {
+      "id": 43,
+      "hp": 75,
+      "drop": "wool_colored_purple",
+      "texture": "wool_colored_purple"
+    },
+    "wool_colored_blue": {
+      "id": 44,
+      "hp": 75,
+      "drop": "wool_colored_blue",
+      "texture": "wool_colored_blue"
+    },
+    "wool_colored_brown": {
+      "id": 45,
+      "hp": 75,
+      "drop": "wool_colored_brown",
+      "texture": "wool_colored_brown"
+    },
+    "wool_colored_green": {
+      "id": 46,
+      "hp": 75,
+      "drop": "wool_colored_green",
+      "texture": "wool_colored_green"
+    },
+    "wool_colored_red": {
+      "id": 47,
+      "hp": 75,
+      "drop": "wool_colored_red",
+      "texture": "wool_colored_red"
+    },
+    "wool_colored_black": {
+      "id": 48,
+      "hp": 75,
+      "drop": "wool_colored_black",
+      "texture": "wool_colored_black"
+    },
+    "gold_block": {
+      "id": 49,
+      "hp": 900,
+      "drop": "gold_block",
+      "texture": "gold_block"
+    },
+    "iron_block": {
+      "id": 50,
+      "hp": 1500,
+      "drop": "iron_block",
+      "texture": "iron_block"
+    },
+    "stone_slab": {
+      "id": 51,
+      "top": 8,
+      "sprite_top": 8,
+      "hp": 600,
+      "transparent": true,
+      "drop": "stone_slab",
+      "meta": "slab",
+      "texture": "stone_slab",
+      "full_block": "double_stone_slab"
+    },
+    "double_stone_slab": {
+      "id": 52,
       "hp": 600,
+      "drop": "stone_slab",
+      "texture": "stone_slab"
+    },
+    "sandstone_slab": {
       "id": 53,
-      "texture": "sandstone",
       "top": 8,
+      "sprite_top": 8,
+      "hp": 600,
       "transparent": true,
+      "drop": "sandstone_slab",
       "meta": "slab",
-      "sprite_top": 8,
+      "texture": "sandstone",
       "full_block": "sandstone"
     },
-    "sapling_oak": {
-      "block_required": true,
-      "collision": false,
-      "id": 6,
-      "transparent": true
-    },
-    "sponge": {
-      "hp": 54,
-      "id": 17
-    },
-    "stone": {
-      "drop": "cobblestone",
-      "hp": 450,
-      "id": 1
+    "oak_slab": {
+      "id": 54,
+      "top": 8,
+      "sprite_top": 8,
+      "hp": 180,
+      "transparent": true,
+      "drop": "oak_slab",
+      "meta": "slab",
+      "texture": "planks_oak",
+      "full_block": "planks_oak"
     },
-    "stone_slab": {
+    "cobblestone_slab": {
+      "id": 55,
+      "top": 8,
       "hp": 600,
-      "id": 51,
-      "sprite_top": 8,
+      "transparent": true,
+      "drop": "cobblestone_slab",
+      "texture": "cobblestone"
+    },
+    "brick_slab": {
+      "id": 56,
       "top": 8,
+      "sprite_top": 8,
+      "hp": 600,
       "transparent": true,
+      "drop": "brick_slab",
       "meta": "slab",
-      "full_block": "double_stone_slab"
+      "texture": "bricks",
+      "full_block": "bricks"
     },
     "stonebrick": {
+      "id": 57,
       "hp": 450,
-      "id": 57
+      "drop": "stonebrick",
+      "texture": "stonebrick"
     },
     "stonebrick_slab": {
-      "hp": 450,
       "id": 58,
-      "texture": "stonebrick",
       "top": 8,
+      "sprite_top": 8,
+      "hp": 450,
       "transparent": true,
+      "drop": "stonebrick_slab",
       "meta": "slab",
-      "full_block": "stonebrick",
-      "sprite_top": 8
+      "texture": "stonebrick",
+      "full_block": "stonebrick"
     },
-    "tallgrass": {
+    "cactus": {
+      "id": 59,
+      "left": 1,
+      "right": 1,
+      "hp": 39,
+      "transparent": true,
       "block_required": true,
-      "collision": false,
-      "id": 26,
-      "transparent": true
+      "drop": "cactus",
+      "texture": "cactus"
     },
-    "water": {
-      "animated": true,
+    "water_16": {
+      "id": 60,
       "collision": false,
-      "state": 0,
-      "frames": 16,
-      "hp": -1,
-      "id": 8,
+      "transparent": true,
+      "drop": "water_16",
       "meta": "water",
-      "texture": "water_still",
-      "transparent": true
-    },
-    "water_12": {
+      "texture": "water_flow",
       "animated": true,
-      "collision": false,
-      "state": 2,
       "frames": 16,
-      "hp": -1,
+      "state": 1
+    },
+    "water_12": {
       "id": 61,
-      "meta": "water",
+      "top": 4,
       "sprite_top": 4,
+      "collision": false,
+      "transparent": true,
+      "drop": "water_12",
+      "meta": "water",
       "texture": "water_flow",
-      "top": 4,
-      "transparent": true
-    },
-    "water_16": {
       "animated": true,
-      "collision": false,
-      "state": 1,
       "frames": 16,
-      "hp": -1,
-      "id": 60,
+      "state": 2
+    },
+    "water_8": {
+      "id": 62,
+      "top": 8,
+      "sprite_top": 8,
+      "collision": false,
+      "transparent": true,
+      "drop": "water_8",
       "meta": "water",
       "texture": "water_flow",
-      "transparent": true
-    },
-    "water_4": {
       "animated": true,
-      "collision": false,
-      "state": 4,
       "frames": 16,
-      "hp": -1,
+      "state": 3
+    },
+    "water_4": {
       "id": 63,
-      "meta": "water",
+      "top": 12,
       "sprite_top": 12,
+      "collision": false,
+      "transparent": true,
+      "drop": "water_4",
+      "meta": "water",
       "texture": "water_flow",
-      "top": 12,
-      "transparent": true
+      "animated": true,
+      "frames": 16,
+      "state": 4
     },
-    "water_8": {
+    "lava_16": {
+      "id": 64,
+      "collision": false,
+      "drop": "lava_16",
+      "meta": "lava",
+      "texture": "lava_flow",
       "animated": true,
+      "frames": 16,
+      "state": 1
+    },
+    "lava_12": {
+      "id": 65,
+      "top": 4,
+      "sprite_top": 4,
       "collision": false,
-      "state": 3,
+      "drop": "lava_12",
+      "meta": "lava",
+      "texture": "lava_flow",
+      "animated": true,
       "frames": 16,
-      "hp": -1,
-      "id": 62,
-      "meta": "water",
-      "sprite_top": 8,
-      "texture": "water_flow",
+      "state": 2
+    },
+    "lava_8": {
+      "id": 66,
       "top": 8,
-      "transparent": true
+      "sprite_top": 8,
+      "collision": false,
+      "drop": "lava_8",
+      "meta": "lava",
+      "texture": "lava_flow",
+      "animated": true,
+      "frames": 16,
+      "state": 3
     },
-    "web": {
+    "lava_4": {
+      "id": 67,
+      "top": 12,
+      "sprite_top": 12,
       "collision": false,
-      "hp": 1200,
-      "id": 25,
-      "transparent": true
+      "drop": "lava_4",
+      "meta": "lava",
+      "texture": "lava_flow",
+      "animated": true,
+      "frames": 16,
+      "state": 4
     },
-    "wool_colored_black": {
-      "hp": 75,
-      "id": 48
+    "obsidian": {
+      "id": 68,
+      "hp": 1500,
+      "drop": "obsidian",
+      "texture": "obsidian"
+    }
+  },
+  "items": {
+    "none": {
+      "id": 0,
+      "name": "",
+      "type": "block",
+      "texture": "none"
     },
-    "wool_colored_blue": {
-      "hp": 75,
-      "id": 44
+    "stone": {
+      "id": 1,
+      "name": "Stone",
+      "type": "block",
+      "texture": "stone"
     },
-    "wool_colored_brown": {
-      "hp": 75,
-      "id": 45
+    "grass": {
+      "id": 2,
+      "name": "Grass",
+      "type": "block",
+      "texture": "grass"
     },
-    "wool_colored_cyan": {
-      "hp": 75,
-      "id": 42
+    "dirt": {
+      "id": 3,
+      "name": "Dirt",
+      "type": "block",
+      "texture": "dirt"
     },
-    "wool_colored_gray": {
-      "hp": 75,
-      "id": 40
+    "cobblestone": {
+      "id": 4,
+      "name": "Cobblestone",
+      "type": "block",
+      "texture": "cobblestone"
     },
-    "wool_colored_green": {
-      "hp": 75,
-      "id": 46
+    "planks_oak": {
+      "id": 5,
+      "name": "Oak Planks",
+      "type": "block",
+      "texture": "planks_oak"
     },
-    "wool_colored_light_blue": {
-      "hp": 75,
-      "id": 36
+    "sapling_oak": {
+      "id": 6,
+      "name": "Oak Sapling",
+      "type": "block",
+      "texture": "sapling_oak"
     },
-    "wool_colored_lime": {
-      "hp": 75,
-      "id": 38
-    },
-    "wool_colored_magenta": {
-      "hp": 75,
-      "id": 35
-    },
-    "wool_colored_orange": {
-      "hp": 75,
-      "id": 34
-    },
-    "wool_colored_pink": {
-      "hp": 75,
-      "id": 39
-    },
-    "wool_colored_purple": {
-      "hp": 75,
-      "id": 43
-    },
-    "wool_colored_red": {
-      "hp": 75,
-      "id": 47
-    },
-    "wool_colored_silver": {
-      "hp": 75,
-      "id": 41
-    },
-    "wool_colored_white": {
-      "hp": 75,
-      "id": 33
-    },
-    "wool_colored_yellow": {
-      "hp": 75,
-      "id": 37
-    }
-  },
-  "items": {
     "bedrock": {
       "id": 7,
       "name": "Bedrock",
-      "type": "block"
+      "type": "block",
+      "texture": "bedrock"
     },
-    "brick_slab": {
-      "id": 51,
-      "name": "Brick Slab",
-      "type": "block"
+    "water": {
+      "id": 8,
+      "name": "Water",
+      "type": "block",
+      "texture": "water"
     },
-    "bricks": {
-      "id": 24,
-      "name": "Bricks",
-      "type": "block"
+    "lava": {
+      "id": 9,
+      "name": "Lava",
+      "type": "block",
+      "texture": "lava"
     },
-    "bucket_empty": {
-      "id": 66,
-      "name": "Empty Bucket",
-      "origin_x": 0.25,
-      "type": "bucket",
-      "action_key": "use_empty_bucket"
+    "sand": {
+      "id": 10,
+      "name": "Sand",
+      "type": "block",
+      "texture": "sand"
     },
-    "bucket_lava": {
-      "id": 68,
-      "name": "Lava Bucket",
-      "origin_x": 0.25,
-      "type": "bucket",
-      "action_key": "use_lava_bucket"
+    "gravel": {
+      "id": 11,
+      "name": "Gravel",
+      "type": "block",
+      "texture": "gravel"
     },
-    "bucket_water": {
-      "id": 67,
-      "name": "Water Bucket",
-      "origin_x": 0.25,
-      "type": "bucket",
-      "action_key": "use_water_bucket"
+    "gold_ore": {
+      "id": 12,
+      "name": "Golden Ore",
+      "type": "block",
+      "texture": "gold_ore"
     },
-    "cactus": {
-      "id": 54,
-      "name": "Cactus",
-      "type": "block"
+    "iron_ore": {
+      "id": 13,
+      "name": "Iron Ore",
+      "type": "block",
+      "texture": "iron_ore"
     },
     "coal_ore": {
       "id": 14,
       "name": "Coal Ore",
-      "type": "block"
-    },
-    "cobblestone": {
-      "id": 4,
-      "name": "Cobblestone",
-      "type": "block"
+      "type": "block",
+      "texture": "coal_ore"
     },
-    "cobblestone_slab": {
-      "id": 50,
-      "name": "Cobblestone Slab",
-      "type": "block"
-    },
-    "dandelion": {
-      "id": 25,
-      "name": "Dandelion",
-      "origin_x": 0.5,
-      "type": "block"
-    },
-    "deadbush": {
-      "id": 23,
-      "name": "Dead Bush",
-      "origin_x": 0.5,
-      "type": "block"
-    },
-    "diamond_shovel": {
-      "id": 64,
-      "name": "Diamond Shovel",
-      "origin_x": 0.125,
-      "type": "shovel"
-    },
-    "diamond_sword": {
-      "id": 59,
-      "name": "Diamond Sword",
-      "origin_x": 0.125,
-      "type": "sword"
+    "log_oak": {
+      "id": 15,
+      "name": "Wood",
+      "type": "block",
+      "texture": "log_oak"
     },
-    "dirt": {
-      "id": 3,
-      "name": "Dirt",
-      "type": "block"
+    "leaves_oak": {
+      "id": 16,
+      "name": "Leaves",
+      "type": "block",
+      "texture": "leaves_oak"
     },
     "glass": {
       "id": 17,
       "name": "Glass",
-      "type": "block"
-    },
-    "gold_block": {
-      "id": 45,
-      "name": "Gold Block",
-      "type": "block"
-    },
-    "gold_ore": {
-      "id": 12,
-      "name": "Golden Ore",
-      "type": "block"
-    },
-    "gold_shovel": {
-      "id": 65,
-      "name": "Golden Shovel",
-      "origin_x": 0.125,
-      "type": "shovel"
-    },
-    "gold_sword": {
-      "id": 60,
-      "name": "Golden Sword",
-      "origin_x": 0.125,
-      "type": "sword"
-    },
-    "grass": {
-      "id": 2,
-      "name": "Grass",
-      "type": "block"
-    },
-    "gravel": {
-      "id": 11,
-      "name": "Gravel",
-      "type": "block"
+      "type": "block",
+      "texture": "glass"
     },
-    "iron_block": {
-      "id": 46,
-      "name": "Iron Block",
-      "type": "block"
-    },
-    "iron_ore": {
-      "id": 13,
-      "name": "Iron Ore",
-      "type": "block"
-    },
-    "iron_shovel": {
-      "id": 63,
-      "name": "Iron Shovel",
-      "origin_x": 0.125,
-      "type": "shovel"
-    },
-    "iron_sword": {
-      "id": 58,
-      "name": "Iron Sword",
-      "origin_x": 0.125,
-      "type": "sword"
+    "lapis_ore": {
+      "id": 18,
+      "name": "Lapis Ore",
+      "type": "block",
+      "texture": "lapis_ore"
     },
     "lapis_block": {
       "id": 19,
       "name": "Lapis Block",
-      "type": "block"
+      "type": "block",
+      "texture": "lapis_block"
     },
-    "lapis_ore": {
-      "id": 18,
-      "name": "Lapis Ore",
-      "type": "block"
+    "sandstone": {
+      "id": 20,
+      "name": "Sandstone",
+      "type": "block",
+      "texture": "sandstone"
     },
-    "lava": {
-      "id": 9,
-      "name": "Lava",
-      "type": "block"
+    "web": {
+      "id": 21,
+      "name": "Cobweb",
+      "type": "block",
+      "texture": "web"
     },
-    "leaves_oak": {
-      "id": 16,
-      "name": "Leaves",
-      "type": "block"
+    "tallgrass": {
+      "id": 22,
+      "name": "Tall Grass",
+      "type": "block",
+      "texture": "tallgrass",
+      "origin_x": 0.5
     },
-    "log_oak": {
-      "id": 15,
-      "name": "Wood",
-      "type": "block"
+    "deadbush": {
+      "id": 23,
+      "name": "Dead Bush",
+      "type": "block",
+      "texture": "deadbush",
+      "origin_x": 0.5
+    },
+    "bricks": {
+      "id": 24,
+      "name": "Bricks",
+      "type": "block",
+      "texture": "bricks"
+    },
+    "dandelion": {
+      "id": 25,
+      "name": "Dandelion",
+      "type": "block",
+      "texture": "dandelion",
+      "origin_x": 0.5
+    },
+    "rose": {
+      "id": 26,
+      "name": "Rose",
+      "type": "block",
+      "texture": "rose",
+      "origin_x": 0.5
     },
     "mushroom_brown": {
       "id": 27,
       "name": "Mushroom",
-      "origin_x": 0.5,
-      "type": "block"
+      "type": "block",
+      "texture": "mushroom_brown",
+      "origin_x": 0.5
     },
     "mushroom_red": {
       "id": 28,
       "name": "Mushroom",
-      "origin_x": 0.5,
-      "type": "block"
+      "type": "block",
+      "texture": "mushroom_red",
+      "origin_x": 0.5
     },
-    "none": {
-      "id": 0,
-      "name": "",
-      "type": "block"
+    "wool_colored_white": {
+      "id": 29,
+      "name": "Wool",
+      "type": "block",
+      "texture": "wool_colored_white"
     },
-    "oak_slab": {
-      "id": 49,
-      "name": "Oak Slab",
-      "type": "block"
+    "wool_colored_orange": {
+      "id": 30,
+      "name": "Wool",
+      "type": "block",
+      "texture": "wool_colored_orange"
     },
-    "obsidian": {
-      "id": 55,
-      "name": "Obsidian",
-      "type": "block"
+    "wool_colored_magenta": {
+      "id": 31,
+      "name": "Wool",
+      "type": "block",
+      "texture": "wool_colored_magenta"
     },
-    "planks_oak": {
-      "id": 5,
-      "name": "Oak Planks",
-      "type": "block"
+    "wool_colored_light_blue": {
+      "id": 32,
+      "name": "Wool",
+      "type": "block",
+      "texture": "wool_colored_light_blue"
     },
-    "rose": {
-      "id": 26,
-      "name": "Rose",
-      "origin_x": 0.5,
-      "type": "block"
+    "wool_colored_yellow": {
+      "id": 33,
+      "name": "Wool",
+      "type": "block",
+      "texture": "wool_colored_yellow"
     },
-    "sand": {
-      "id": 10,
-      "name": "Sand",
-      "type": "block"
+    "wool_colored_lime": {
+      "id": 34,
+      "name": "Wool",
+      "type": "block",
+      "texture": "wool_colored_lime"
     },
-    "sandstone": {
-      "id": 20,
-      "name": "Sandstone",
-      "type": "block"
+    "wool_colored_pink": {
+      "id": 35,
+      "name": "Wool",
+      "type": "block",
+      "texture": "wool_colored_pink"
     },
-    "sandstone_slab": {
-      "id": 48,
-      "name": "Sandstone Slab",
-      "type": "block"
+    "wool_colored_gray": {
+      "id": 36,
+      "name": "Wool",
+      "type": "block",
+      "texture": "wool_colored_gray"
     },
-    "sapling_oak": {
-      "id": 6,
-      "name": "Oak Sapling",
-      "type": "block"
+    "wool_colored_silver": {
+      "id": 37,
+      "name": "Wool",
+      "type": "block",
+      "texture": "wool_colored_silver"
     },
-    "stone": {
-      "id": 1,
-      "name": "Stone",
-      "type": "block"
+    "wool_colored_cyan": {
+      "id": 38,
+      "name": "Wool",
+      "type": "block",
+      "texture": "wool_colored_cyan"
     },
-    "stone_shovel": {
-      "id": 62,
-      "name": "Stone Shovel",
-      "origin_x": 0.125,
-      "type": "shovel"
+    "wool_colored_purple": {
+      "id": 39,
+      "name": "Wool",
+      "type": "block",
+      "texture": "wool_colored_purple"
+    },
+    "wool_colored_blue": {
+      "id": 40,
+      "name": "Wool",
+      "type": "block",
+      "texture": "wool_colored_blue"
+    },
+    "wool_colored_brown": {
+      "id": 41,
+      "name": "Wool",
+      "type": "block",
+      "texture": "wool_colored_brown"
+    },
+    "wool_colored_green": {
+      "id": 42,
+      "name": "Wool",
+      "type": "block",
+      "texture": "wool_colored_green"
+    },
+    "wool_colored_red": {
+      "id": 43,
+      "name": "Wool",
+      "type": "block",
+      "texture": "wool_colored_red"
+    },
+    "wool_colored_black": {
+      "id": 44,
+      "name": "Wool",
+      "type": "block",
+      "texture": "wool_colored_black"
+    },
+    "gold_block": {
+      "id": 45,
+      "name": "Gold Block",
+      "type": "block",
+      "texture": "gold_block"
+    },
+    "iron_block": {
+      "id": 46,
+      "name": "Iron Block",
+      "type": "block",
+      "texture": "iron_block"
     },
     "stone_slab": {
       "id": 47,
       "name": "Stone Slab",
-      "type": "block"
+      "type": "block",
+      "texture": "stone_slab"
     },
-    "stone_sword": {
-      "id": 57,
-      "name": "Stone Sword",
-      "origin_x": 0.125,
-      "type": "sword"
+    "sandstone_slab": {
+      "id": 48,
+      "name": "Sandstone Slab",
+      "type": "block",
+      "texture": "sandstone_slab"
+    },
+    "oak_slab": {
+      "id": 49,
+      "name": "Oak Slab",
+      "type": "block",
+      "texture": "oak_slab"
+    },
+    "cobblestone_slab": {
+      "id": 50,
+      "name": "Cobblestone Slab",
+      "type": "block",
+      "texture": "cobblestone_slab"
+    },
+    "brick_slab": {
+      "id": 51,
+      "name": "Brick Slab",
+      "type": "block",
+      "texture": "brick_slab"
     },
     "stonebrick": {
       "id": 52,
       "name": "Stone Brick",
-      "type": "block"
+      "type": "block",
+      "texture": "stonebrick"
     },
     "stonebrick_slab": {
       "id": 53,
       "name": "Stone Brick Slab",
-      "type": "block"
-    },
-    "tallgrass": {
-      "id": 22,
-      "name": "Tall Grass",
-      "origin_x": 0.5,
-      "type": "block"
-    },
-    "water": {
-      "id": 8,
-      "name": "Water",
-      "type": "block"
+      "type": "block",
+      "texture": "stonebrick_slab"
     },
-    "web": {
-      "id": 21,
-      "name": "Cobweb",
-      "type": "block"
+    "cactus": {
+      "id": 54,
+      "name": "Cactus",
+      "type": "block",
+      "texture": "cactus"
     },
-    "wood_shovel": {
-      "id": 61,
-      "name": "Wooden Shovel",
-      "origin_x": 0.125,
-      "type": "shovel"
+    "obsidian": {
+      "id": 55,
+      "name": "Obsidian",
+      "type": "block",
+      "texture": "obsidian"
     },
     "wood_sword": {
       "id": 56,
       "name": "Wooden Sword",
-      "origin_x": 0.125,
-      "type": "sword"
-    },
-    "wool_colored_black": {
-      "id": 44,
-      "name": "Wool",
-      "type": "block"
-    },
-    "wool_colored_blue": {
-      "id": 40,
-      "name": "Wool",
-      "type": "block"
+      "type": "sword",
+      "texture": "wood_sword",
+      "origin_x": 0.125
     },
-    "wool_colored_brown": {
-      "id": 41,
-      "name": "Wool",
-      "type": "block"
-    },
-    "wool_colored_cyan": {
-      "id": 38,
-      "name": "Wool",
-      "type": "block"
-    },
-    "wool_colored_gray": {
-      "id": 36,
-      "name": "Wool",
-      "type": "block"
+    "stone_sword": {
+      "id": 57,
+      "name": "Stone Sword",
+      "type": "sword",
+      "texture": "stone_sword",
+      "origin_x": 0.125
     },
-    "wool_colored_green": {
-      "id": 42,
-      "name": "Wool",
-      "type": "block"
+    "iron_sword": {
+      "id": 58,
+      "name": "Iron Sword",
+      "type": "sword",
+      "texture": "iron_sword",
+      "origin_x": 0.125
     },
-    "wool_colored_light_blue": {
-      "id": 32,
-      "name": "Wool",
-      "type": "block"
+    "diamond_sword": {
+      "id": 59,
+      "name": "Diamond Sword",
+      "type": "sword",
+      "texture": "diamond_sword",
+      "origin_x": 0.125
     },
-    "wool_colored_lime": {
-      "id": 34,
-      "name": "Wool",
-      "type": "block"
+    "gold_sword": {
+      "id": 60,
+      "name": "Golden Sword",
+      "type": "sword",
+      "texture": "gold_sword",
+      "origin_x": 0.125
     },
-    "wool_colored_magenta": {
-      "id": 31,
-      "name": "Wool",
-      "type": "block"
+    "wood_shovel": {
+      "id": 61,
+      "name": "Wooden Shovel",
+      "type": "shovel",
+      "texture": "wood_shovel",
+      "origin_x": 0.125
     },
-    "wool_colored_orange": {
-      "id": 30,
-      "name": "Wool",
-      "type": "block"
+    "stone_shovel": {
+      "id": 62,
+      "name": "Stone Shovel",
+      "type": "shovel",
+      "texture": "stone_shovel",
+      "origin_x": 0.125
     },
-    "wool_colored_pink": {
-      "id": 35,
-      "name": "Wool",
-      "type": "block"
+    "iron_shovel": {
+      "id": 63,
+      "name": "Iron Shovel",
+      "type": "shovel",
+      "texture": "iron_shovel",
+      "origin_x": 0.125
     },
-    "wool_colored_purple": {
-      "id": 39,
-      "name": "Wool",
-      "type": "block"
+    "diamond_shovel": {
+      "id": 64,
+      "name": "Diamond Shovel",
+      "type": "shovel",
+      "texture": "diamond_shovel",
+      "origin_x": 0.125
     },
-    "wool_colored_red": {
-      "id": 43,
-      "name": "Wool",
-      "type": "block"
+    "gold_shovel": {
+      "id": 65,
+      "name": "Golden Shovel",
+      "type": "shovel",
+      "texture": "gold_shovel",
+      "origin_x": 0.125
     },
-    "wool_colored_silver": {
-      "id": 37,
-      "name": "Wool",
-      "type": "block"
+    "bucket_empty": {
+      "id": 66,
+      "name": "Empty Bucket",
+      "type": "bucket",
+      "texture": "bucket_empty",
+      "origin_x": 0.25,
+      "action_key": "use_empty_bucket"
     },
-    "wool_colored_white": {
-      "id": 29,
-      "name": "Wool",
-      "type": "block"
+    "bucket_water": {
+      "id": 67,
+      "name": "Water Bucket",
+      "type": "bucket",
+      "texture": "bucket_water",
+      "origin_x": 0.25,
+      "action_key": "use_water_bucket"
     },
-    "wool_colored_yellow": {
-      "id": 33,
-      "name": "Wool",
-      "type": "block"
+    "bucket_lava": {
+      "id": 68,
+      "name": "Lava Bucket",
+      "type": "bucket",
+      "texture": "bucket_lava",
+      "origin_x": 0.25,
+      "action_key": "use_lava_bucket"
     }
   }
 }
index 42533236e2794d906b6392480ecbd593f4dc5c25..5bd5c99ebd3b8b706d7ade5ae56f5ba0950df238 100644 (file)
@@ -3,7 +3,6 @@ package ru.deadsoftware.cavedroid;
 import com.badlogic.gdx.Application;
 import com.badlogic.gdx.Game;
 import com.badlogic.gdx.Gdx;
-import ru.deadsoftware.cavedroid.game.GameItems;
 import ru.deadsoftware.cavedroid.game.GameScreen;
 import ru.deadsoftware.cavedroid.misc.Assets;
 import ru.deadsoftware.cavedroid.misc.utils.AssetLoader;
@@ -84,12 +83,8 @@ public class CaveGame extends Game {
     public void create() {
         Gdx.app.log(TAG, mGameFolder);
         Gdx.files.absolute(mGameFolder).mkdirs();
-
         initConfig();
-
         Assets.load(mAssetLoader);
-        GameItems.load(mAssetLoader);
-
         setScreen(mMainComponent.getMenuScreen());
     }
 
index 32826528c62ba6ed0ce38772a5b44a45ff965f13..f8c44b310324762c20db96284c995471f3d6144c 100644 (file)
@@ -21,12 +21,11 @@ import ru.deadsoftware.cavedroid.game.world.GameWorld;
 import ru.deadsoftware.cavedroid.misc.Assets;
 import ru.deadsoftware.cavedroid.misc.ControlMode;
 
+import javax.annotation.CheckForNull;
 import javax.inject.Inject;
 
 import java.util.Map;
 
-import static ru.deadsoftware.cavedroid.game.GameItems.*;
-
 @GameScope
 public class GameInput {
 
@@ -210,27 +209,27 @@ public class GameInput {
         checkCursorBounds();
     }
 
-    private void useItem(int x, int y, int id, boolean bg) {
+    private void useItem(int x, int y, @CheckForNull Item item, boolean bg) {
         mPlayer.startHitting();
 
-        if (id > 0) {
-            final Item item = getItem(id);
+        if (item == null) {
+            return;
+        }
 
-            if (item instanceof Item.Placeable) {
-                if (!bg) {
-                    CommonBlockActionUtilsKt.placeToForegroundAction(mPlaceBlockActionMap, (Item.Placeable) item, x, y);
-                } else {
-                    CommonBlockActionUtilsKt.placeToBackgroundAction(mPlaceBlockActionMap, (Item.Placeable) item, x, y);
-                }
-            } else if (item instanceof Item.Usable) {
-                final String actionKey = ((Item.Usable)item).getUseActionKey();
-                final IUseItemAction useItemAction = mUseItemActionMap.get(actionKey);
+        if (item instanceof Item.Placeable) {
+            if (!bg) {
+                CommonBlockActionUtilsKt.placeToForegroundAction(mPlaceBlockActionMap, (Item.Placeable) item, x, y);
+            } else {
+                CommonBlockActionUtilsKt.placeToBackgroundAction(mPlaceBlockActionMap, (Item.Placeable) item, x, y);
+            }
+        } else if (item instanceof Item.Usable) {
+            final String actionKey = ((Item.Usable) item).getUseActionKey();
+            final IUseItemAction useItemAction = mUseItemActionMap.get(actionKey);
 
-                if (useItemAction != null) {
-                    useItemAction.perform((Item.Usable) item, x, y);
-                } else {
-                    Gdx.app.error(TAG, "use item action " + actionKey + " not found");
-                }
+            if (useItemAction != null) {
+                useItemAction.perform((Item.Usable) item, x, y);
+            } else {
+                Gdx.app.error(TAG, "use item action " + actionKey + " not found");
             }
         }
     }
@@ -406,14 +405,13 @@ public class GameInput {
             if (mMainConfig.checkGameUiWindow(GameUiWindow.CREATIVE_INVENTORY) && insideCreativeInv(screenX, screenY)) {
                 int ix = (int) (screenX - (mMainConfig.getWidth() / 2 - creative.getRegionWidth() / 2 + 8)) / 18;
                 int iy = (int) (screenY - (mMainConfig.getHeight() / 2 - creative.getRegionHeight() / 2 + 18)) / 18;
-                int item = mCreativeScroll * 8 + (ix + iy * 8);
+                int itemPos = mCreativeScroll * 8 + (ix + iy * 8);
                 if (ix >= 8 || ix < 0 || iy < 0 || iy >= 5) {
-                    item = -1;
-                }
-                if (item >= 0 && item < GameItems.getItemsSize()) {
-                    System.arraycopy(mPlayer.inventory, 0, mPlayer.inventory, 1, 8);
-                    mPlayer.inventory[0] = item;
+                    itemPos = -1;
                 }
+
+                System.arraycopy(mPlayer.inventory, 0, mPlayer.inventory, 1, 8);
+                mPlayer.inventory[0] = mGameItemsHolder.getItemFromCreativeInventory(itemPos);
             } else if (mMainConfig.checkGameUiWindow(GameUiWindow.CREATIVE_INVENTORY)) {
                 mMainConfig.setGameUiWindow(GameUiWindow.NONE);
             } else if (screenY < hotbar.getRegionHeight() &&
@@ -444,8 +442,10 @@ public class GameInput {
                 if (mCreativeScroll < 0) {
                     mCreativeScroll = 0;
                 }
-                if (mCreativeScroll > GameProc.MAX_CREATIVE_SCROLL) {
-                    mCreativeScroll = GameProc.MAX_CREATIVE_SCROLL;
+
+                final int maxScroll = mGameItemsHolder.getCreativeScrollAmount();
+                if (mCreativeScroll > maxScroll) {
+                    mCreativeScroll = maxScroll;
                 }
             }
         }
@@ -467,8 +467,10 @@ public class GameInput {
                 if (mCreativeScroll < 0) {
                     mCreativeScroll = 0;
                 }
-                if (mCreativeScroll > GameProc.MAX_CREATIVE_SCROLL) {
-                    mCreativeScroll = GameProc.MAX_CREATIVE_SCROLL;
+
+                final int maxScroll = mGameItemsHolder.getCreativeScrollAmount();
+                if (mCreativeScroll > maxScroll) {
+                    mCreativeScroll = maxScroll;
                 }
                 break;
         }
diff --git a/core/src/ru/deadsoftware/cavedroid/game/GameItems.java b/core/src/ru/deadsoftware/cavedroid/game/GameItems.java
deleted file mode 100644 (file)
index 370f1b0..0000000
+++ /dev/null
@@ -1,242 +0,0 @@
-package ru.deadsoftware.cavedroid.game;
-
-import com.badlogic.gdx.Gdx;
-import com.badlogic.gdx.graphics.Texture;
-import com.badlogic.gdx.graphics.g2d.Sprite;
-import com.badlogic.gdx.math.MathUtils;
-import com.badlogic.gdx.utils.ArrayMap;
-import com.badlogic.gdx.utils.GdxRuntimeException;
-import com.badlogic.gdx.utils.JsonValue;
-import ru.deadsoftware.cavedroid.game.model.block.*;
-import ru.deadsoftware.cavedroid.game.model.item.CommonItemParams;
-import ru.deadsoftware.cavedroid.game.model.item.Item;
-import ru.deadsoftware.cavedroid.misc.Assets;
-import ru.deadsoftware.cavedroid.misc.utils.AssetLoader;
-import ru.deadsoftware.cavedroid.misc.utils.SpriteOrigin;
-
-import java.io.FileInputStream;
-import java.util.*;
-
-public class GameItems {
-
-    private static final String TAG = "GameItems";
-
-    private static final HashMap<String, Integer> blocksIds = new HashMap<>();
-    private static final HashMap<String, Integer> itemsIds = new HashMap<>();
-
-    private static final ArrayMap<String, Block> blocks = new ArrayMap<>();
-    private static final ArrayMap<String, Item> items = new ArrayMap<>();
-
-    public static boolean isFluid(int id) {
-        return getBlock(id).isFluid();
-    }
-
-    public static boolean isWater(int id) {
-        return isWater(getBlock(id));
-    }
-
-    @Deprecated
-    public static boolean isWater(Block block) {
-        return block instanceof Block.Water;
-    }
-
-    @Deprecated
-    public static boolean isLava(int id) {
-        return isLava(getBlock(id));
-    }
-
-    @Deprecated
-    public static boolean isLava(Block block) {
-        return block instanceof Block.Lava;
-    }
-
-    @Deprecated
-    public static boolean isSlab(int id) {
-        return getBlock(id) instanceof Block.Slab;
-    }
-
-    public static Block getBlock(int id) {
-        return blocks.getValueAt(id);
-    }
-
-    public static Item getItem(int id) {
-        return items.getValueAt(id);
-    }
-
-    public static Block getBlock(String key) {
-        return blocks.getValueAt(blocksIds.get(key));
-    }
-
-    public static Item getItem(String key) {
-        return items.getValueAt(itemsIds.get(key));
-    }
-
-    public static int getBlockId(String key) {
-        return blocksIds.get(key);
-    }
-
-    public static int getItemId(String key) {
-        return itemsIds.get(key);
-    }
-
-    public static String getBlockKey(int id) {
-        return blocks.getKeyAt(id);
-    }
-
-    public static String getItemKey(int id) {
-        return items.getKeyAt(id);
-    }
-
-    public static int getBlockIdByItemId(int id) {
-        return getBlockId(items.getKeyAt(id));
-    }
-
-    public static int getItemIdByBlockId(int id) {
-        return getItemId(blocks.getKeyAt(id));
-    }
-
-    public static int getBlocksSize() {
-        return blocks.size;
-    }
-
-    public static int getItemsSize() {
-        return items.size;
-    }
-
-    public static Sprite getBlockTex(int id) {
-        return getBlock(id).getTexture();
-    }
-
-    public static void load(AssetLoader assetLoader) {
-        JsonValue json = Assets.jsonReader.parse(assetLoader.getAssetHandle("json/game_items.json"));
-
-        TreeSet<Block> blocksSet = new TreeSet<>(Comparator.comparingInt(a -> a.getParams().getId()));
-        TreeSet<Item> itemsSet = new TreeSet<>(Comparator.comparingInt(a -> a.getParams().getId()));
-
-
-        int count = 0;
-        for (JsonValue block = json.get("blocks").child(); block != null; block = block.next()) {
-            try {
-                String key = block.name();
-                int left = Assets.getIntFromJson(block, "left", 0);
-                int right = Assets.getIntFromJson(block, "right", 0);
-                int top = Assets.getIntFromJson(block, "top", 0);
-                int bottom = Assets.getIntFromJson(block, "bottom", 0);
-                int clipX = Assets.getIntFromJson(block, "sprite_left", 0);
-                int clipY = Assets.getIntFromJson(block, "sprite_top", 0);
-                int clipWidth = Assets.getIntFromJson(block, "sprite_right", 0);
-                int clipHeight = Assets.getIntFromJson(block, "sprite_bottom", 0);
-                int hp = Assets.getIntFromJson(block, "hp", -1);
-                boolean collision = Assets.getBooleanFromJson(block, "collision", true);
-                boolean background = Assets.getBooleanFromJson(block, "background", false);
-                boolean transparent = Assets.getBooleanFromJson(block, "transparent", false);
-                boolean requiresBlock = Assets.getBooleanFromJson(block, "block_required", false);
-                boolean fluid = Assets.getBooleanFromJson(block, "fluid", false);
-                String drop = Assets.getStringFromJson(block, "drop", key);
-                String meta = Assets.getStringFromJson(block, "meta", "");
-                String tex = Assets.getStringFromJson(block, "texture", key);
-                Texture texture = tex.equals("none") ? null :
-                        new Texture(assetLoader.getAssetHandle("textures/blocks/" + tex + ".png"));
-                boolean animated = Assets.getBooleanFromJson(block, "animated", false);
-                int frames = Assets.getIntFromJson(block, "frames", 0);
-                int id = Assets.getIntFromJson(block, "id", count);
-                int dropCount = Assets.getIntFromJson(block, "drop_count", 1);
-                String fullBlock = Assets.getStringFromJson(block, "full_block", null);
-                int state = Assets.getIntFromJson(block, "state", 0);
-                blocksIds.put(key, id);
-
-                if (count >= id) {
-                    count++;
-                }
-
-                BlockMargins collMargins = new BlockMargins(left, top, right, bottom);
-                BlockMargins spriteMargins = new BlockMargins(clipX, clipY, clipWidth, clipHeight);
-                BlockDropInfo dropInfo = new BlockDropInfo(drop, dropCount);
-                BlockAnimationInfo animInfo = null;
-                if (animated) {
-                    animInfo = new BlockAnimationInfo(frames);
-                }
-
-                CommonBlockParams params = new CommonBlockParams(
-                        id,
-                        key,
-                        collMargins,
-                        hp,
-                        dropInfo,
-                        collision,
-                        background,
-                        transparent,
-                        requiresBlock,
-                        animInfo,
-                        texture,
-                        spriteMargins
-                );
-
-                Block newBlock = switch (meta) {
-                    case "water" -> new Block.Water(params, state);
-                    case "lava" -> new Block.Lava(params, state);
-                    case "slab" -> new Block.Slab(params, fullBlock);
-                    default -> new Block.Normal(params);
-                };
-
-                newBlock.initialize();
-                blocksSet.add(newBlock);
-            } catch (GdxRuntimeException e) {
-                Gdx.app.error(TAG, e.getMessage());
-            }
-        }
-
-        blocksSet.forEach((block -> blocks.put(block.getParams().getKey(), block)));
-
-        count = 0;
-        for (JsonValue item = json.get("items").child(); item != null; item = item.next()) {
-            try {
-                String key = item.name();
-                String name = Assets.getStringFromJson(item, "name", key);
-                String type = Assets.getStringFromJson(item, "type", "item");
-                String texture = Assets.getStringFromJson(item, "texture", key);
-                Sprite sprite = type.equals("block") ? null :
-                        new Sprite(new Texture(assetLoader.getAssetHandle("textures/items/" + texture + ".png")));
-
-                if (sprite != null) {
-                    sprite.flip(false, true);
-                }
-
-                float originX = Assets.getFloatFromJson(item, "origin_x", 0f);
-                float originY = Assets.getFloatFromJson(item, "origin_y", 1f);
-                originX = MathUtils.clamp(originX, 0f, 1f);
-                originY = MathUtils.clamp(originY, 0f, 1f);
-                SpriteOrigin origin = new SpriteOrigin(originX, originY);
-
-                int id = Assets.getIntFromJson(item, "id", count);
-
-                String actionKey = Assets.getStringFromJson(item, "action_key", null);
-
-                float mobDamage = Assets.getFloatFromJson(item, "mob_damage_multiplier", 1f);
-                float blockDamage = Assets.getFloatFromJson(item, "block_damage_multiplier", 1f);
-
-                if (count >= id) {
-                    count++;
-                }
-
-                CommonItemParams params = new CommonItemParams(id, key, name, origin);
-
-                Item newItem = switch (type) {
-                    case "bucket" -> new Item.Bucket(params, sprite, actionKey);
-                    case "shovel" -> new Item.Shovel(params, sprite, mobDamage, blockDamage);
-                    case "sword" -> new Item.Sword(params, sprite, mobDamage, blockDamage);
-                    case "block" -> new Item.Placeable(params, blocks.get(key));
-                    default -> throw new RuntimeException("Unknown item type: " + type);
-                };
-
-                itemsIds.put(key, id);
-                itemsSet.add(newItem);
-            } catch (GdxRuntimeException e) {
-                Gdx.app.error(TAG, e.getMessage());
-            }
-        }
-
-        itemsSet.forEach((item -> items.put(item.getParams().getKey(), item)));
-    }
-
-}
\ No newline at end of file
index 058e84d7f283a8ab47dc03df09d48a997cb3824e..23fe4fbe4104977b0f47e1b1523417e7fae2cfc2 100644 (file)
@@ -63,7 +63,7 @@ class GameItemsHolder @Inject constructor(
         }
 
         val jsonString = assetLoader.getAssetHandle("json/game_items.json").readString()
-        val gameItemsDto = JsonFormat.decodeFromString(GameItemsDto.GameItemsDtoJsonSerializer, jsonString)
+        val gameItemsDto = JsonFormat.decodeFromString<GameItemsDto>(jsonString)
 
         loadBlocks(gameItemsDto.blocks)
         loadItems(gameItemsDto.items)
@@ -95,6 +95,20 @@ class GameItemsHolder @Inject constructor(
         }
     }
 
+    fun getAllItems(): Collection<Item> {
+        return itemsMap.values
+    }
+
+    fun getItemFromCreativeInventory(position: Int): Item? {
+        return if (position in itemsMap.values.indices) {
+            itemsMap.values.elementAt(position)
+        } else {
+            null
+        }
+    }
+
+    fun getCreativeScrollAmount(): Int = itemsMap.size / 8
+
     fun <T : Block> getBlocksByType(type: Class<T>): List<T> {
         return blocksMap.values.filterIsInstance(type)
     }
index c47a0e19144a7a6f3d25e78a18d16df26fc2df56..0637f595f819b790b7ac8791ef4db5bcf07042ac 100644 (file)
@@ -35,8 +35,8 @@ public class GameModule {
 
     @Provides
     @GameScope
-    public static MobsController provideMobsController() {
-        MobsController controller = data != null ? data.retrieveMobsController() : new MobsController();
+    public static MobsController provideMobsController(GameItemsHolder gameItemsHolder) {
+        MobsController controller = data != null ? data.retrieveMobsController() : new MobsController(gameItemsHolder);
         makeDataNullIfEmpty();
         return controller;
     }
index 3a2244052b1c8b1353ea104751570aea671fe055..ef33b8ee9c66b5f27e81d7ae1c55eff3464df014 100644 (file)
@@ -12,8 +12,6 @@ import javax.inject.Inject;
 @GameScope
 public class GameProc implements Disposable {
 
-    public static final int MAX_CREATIVE_SCROLL = GameItems.getItemsSize() / 8;
-
     private final GamePhysics mGamePhysics;
     private final GameInput mGameInput;
     private final GameRenderer mGameRenderer;
index 49b9f0c9bc4d64fd61a9514ff6d1e6e7cb86067a..43973bcea0116f9713baff4de5182ec39aa09fe2 100644 (file)
@@ -9,6 +9,7 @@ import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
 import com.badlogic.gdx.math.Intersector;
 import com.badlogic.gdx.math.MathUtils;
 import com.badlogic.gdx.math.Rectangle;
+import kotlin.collections.CollectionsKt;
 import ru.deadsoftware.cavedroid.MainConfig;
 import ru.deadsoftware.cavedroid.game.mobs.Mob;
 import ru.deadsoftware.cavedroid.game.mobs.MobsController;
@@ -25,6 +26,8 @@ import javax.annotation.CheckForNull;
 import javax.annotation.Nullable;
 import javax.inject.Inject;
 
+import java.util.Collection;
+
 import static ru.deadsoftware.cavedroid.misc.Assets.*;
 
 @GameScope
@@ -37,13 +40,15 @@ public class GameRenderer extends Renderer {
     private final GameWorld mGameWorld;
     private final MobsController mMobsController;
     private final DropController mDropController;
+    private final GameItemsHolder mGameItemsHolder;
 
     @Inject
     GameRenderer(MainConfig mainConfig,
                  GameInput gameInput,
                  GameWorld gameWorld,
                  MobsController mobsController,
-                 DropController dropController) {
+                 DropController dropController,
+                 GameItemsHolder gameItemsHolder) {
         super(mainConfig.getWidth(), mainConfig.getHeight());
 
         mMainConfig = mainConfig;
@@ -51,6 +56,7 @@ public class GameRenderer extends Renderer {
         mGameWorld = gameWorld;
         mMobsController = mobsController;
         mDropController = dropController;
+        mGameItemsHolder = gameItemsHolder;
 
         Gdx.gl.glClearColor(0f, .6f, .6f, 1f);
     }
@@ -173,18 +179,13 @@ public class GameRenderer extends Renderer {
     }
 
     private void drawDrop(Drop drop) {
-        if (drop.getId() <= 0) {
-            return;
-        }
-
         @CheckForNull final Rectangle drawingRect = getDrawingRectIfInsideViewport(drop);
 
         if (drawingRect == null) {
             return;
         }
 
-        final Item item = GameItems.getItem(drop.getId());
-        final Sprite sprite = item.getSprite();
+        final Sprite sprite = drop.getItem().getSprite();
 
         sprite.setPosition(drawingRect.x, drawingRect.y);
         sprite.setSize(drawingRect.width, drawingRect.height);
@@ -198,17 +199,21 @@ public class GameRenderer extends Renderer {
         float y = getHeight() / 2 - (float) creative.getRegionHeight() / 2;
         spriter.draw(creative, x, y);
         spriter.draw(textureRegions.get("handle"), x + 156,
-                y + 18 + (mGameInput.getCreativeScroll() * (72f / GameProc.MAX_CREATIVE_SCROLL)));
+                y + 18 + (mGameInput.getCreativeScroll() * (72f / mGameItemsHolder.getCreativeScrollAmount())));
+        final Collection<Item> items = mGameItemsHolder.getAllItems();
         for (int i = mGameInput.getCreativeScroll() * 8; i < mGameInput.getCreativeScroll() * 8 + 40; i++) {
-            if (i > 0 && i < GameItems.getItemsSize()) {
-                spriter.draw(GameItems.getItem(i).getSprite(),
-                        x + 8 + ((i - mGameInput.getCreativeScroll() * 8) % 8) * 18,
-                        y + 18 + ((i - mGameInput.getCreativeScroll() * 8) / 8) * 18);
+            if (i > 0 && i < items.size()) {
+                Item item = CollectionsKt.elementAt(items, i);
+                if (item != mGameItemsHolder.getFallbackItem()) {
+                    spriter.draw(CollectionsKt.elementAt(items, i).getSprite(),
+                            x + 8 + ((i - mGameInput.getCreativeScroll() * 8) % 8) * 18,
+                            y + 18 + ((i - mGameInput.getCreativeScroll() * 8) / 8) * 18);
+                }
             }
         }
         for (int i = 0; i < 9; i++) {
-            if (mMobsController.getPlayer().inventory[i] > 0) {
-                spriter.draw(GameItems.getItem(mMobsController.getPlayer().inventory[i]).getSprite(),
+            if (mMobsController.getPlayer().inventory[i] != null && mMobsController.getPlayer().inventory[i] != mGameItemsHolder.getFallbackItem()) {
+                spriter.draw(mMobsController.getPlayer().inventory[i].getSprite(),
                         x + 8 + i * 18, y + creative.getRegionHeight() - 24);
             }
         }
@@ -252,8 +257,8 @@ public class GameRenderer extends Renderer {
         drawHealth(hotbarX, hotbar.getRegionHeight());
 
         for (int i = 0; i < 9; i++) {
-            if (mMobsController.getPlayer().inventory[i] > 0) {
-                spriter.draw(GameItems.getItem(mMobsController.getPlayer().inventory[i]).getSprite(),
+            if (mMobsController.getPlayer().inventory[i] != null && mMobsController.getPlayer().inventory[i] != mGameItemsHolder.getFallbackItem()) {
+                spriter.draw(mMobsController.getPlayer().inventory[i].getSprite(),
                         getWidth() / 2 - (float) hotbar.getRegionWidth() / 2 + 3 + i * 20,
                         3);
             }
@@ -303,9 +308,9 @@ public class GameRenderer extends Renderer {
         if (hasForeMap) {
             final Block block = mGameWorld.getForeMap(x, y);
 
-            if (GameItems.isWater(block)) {
+            if (block.isWater()) {
                 result = Color.BLUE;
-            } else if (GameItems.isLava(block)) {
+            } else if (block.isLava()) {
                 result = Color.RED;
             } else {
                 result = Color.BLACK;
@@ -386,7 +391,7 @@ public class GameRenderer extends Renderer {
             drawString("Mobs: " + mMobsController.getMobs().size(), 0, 70);
             drawString("Drops: " + mDropController.getSize(), 0, 80);
             drawString("Block: " + mGameWorld.getForeMap(mGameInput.getCurX(), mGameInput.getCurY()).getParams().getKey(), 0, 90);
-            drawString("Hand: " + GameItems.getItemKey(mMobsController.getPlayer().inventory[mMobsController.getPlayer().slot]), 0, 100);
+            drawString("Hand: " + mMobsController.getPlayer().inventory[mMobsController.getPlayer().slot].getParams().getKey(), 0, 100);
             drawString("Game mode: " + player.gameMode, 0, 110);
             spriter.end();
         }
index 0864a6878ae4fac02fbbf5e9c3cf4b252fe89ee3..51dbd5bfb935f100b93a9ddd0c4a4f33e80a1de9 100644 (file)
@@ -13,6 +13,8 @@ import java.nio.ByteBuffer;
 
 public class GameSaver {
 
+    private static final String TAG = "GameSaver";
+
     public static class Data {
         @CheckForNull
         private MobsController mMobsController;
@@ -168,7 +170,11 @@ public class GameSaver {
                             MobsController mobsController,
                             GameWorld gameWorld) {
 
-        String folder = mainConfig.getGameFolder();
+        Gdx.app.debug(TAG, "Saves are disabled for this build");
+        return;
+
+
+/*        String folder = mainConfig.getGameFolder();
         FileHandle file = Gdx.files.absolute(folder + "/saves/");
         file.mkdirs();
         file = Gdx.files.absolute(folder + "/saves/game.sav");
@@ -184,13 +190,14 @@ public class GameSaver {
 //            saveMap(Gdx.files.absolute(folder + "/saves/backmap.sav"), gameWorld.getFullBackMap());
         } catch (Exception e) {
             e.printStackTrace();
-        }
+        }*/
     }
 
     public static boolean exists(MainConfig mainConfig) {
-        String folder = mainConfig.getGameFolder();
-        return (Gdx.files.absolute(folder + "/saves/game.sav").exists() &&
-                Gdx.files.absolute(folder + "/saves/foremap.sav").exists() &&
-                Gdx.files.absolute(folder + "/saves/backmap.sav").exists());
+        return false;
+//        String folder = mainConfig.getGameFolder();
+//        return (Gdx.files.absolute(folder + "/saves/game.sav").exists() &&
+//                Gdx.files.absolute(folder + "/saves/foremap.sav").exists() &&
+//                Gdx.files.absolute(folder + "/saves/backmap.sav").exists());
     }
 }
index 7256ae9519c2c420bb333be106f3505389f71ed5..7f834ae1e8c411aa551902ecc03026809d9f377f 100644 (file)
@@ -1,6 +1,5 @@
 package ru.deadsoftware.cavedroid.game.actions.useitem
 
-import ru.deadsoftware.cavedroid.game.GameItems
 import ru.deadsoftware.cavedroid.game.GameItemsHolder
 import ru.deadsoftware.cavedroid.game.GameScope
 import ru.deadsoftware.cavedroid.game.mobs.MobsController
@@ -17,7 +16,7 @@ class UseLavaBucketAction @Inject constructor(
 
     override fun perform(item: Item.Usable, x: Int, y: Int) {
         gameWorld.placeToForeground(x, y, gameItemsHolder.getBlock("lava"))
-        mobsController.player.setCurrentInventorySlotItem(GameItems.getItemId("bucket_empty"))
+        mobsController.player.setCurrentInventorySlotItem(gameItemsHolder.getItem("bucket_empty"))
     }
 
     companion object {
index 32025ced4c98f86d9ca7093de11e17e019a7e6a7..596d5872950fcde8343f45e27e61c4a862a4537a 100644 (file)
@@ -1,6 +1,5 @@
 package ru.deadsoftware.cavedroid.game.actions.useitem
 
-import ru.deadsoftware.cavedroid.game.GameItems
 import ru.deadsoftware.cavedroid.game.GameItemsHolder
 import ru.deadsoftware.cavedroid.game.GameScope
 import ru.deadsoftware.cavedroid.game.mobs.MobsController
@@ -17,7 +16,7 @@ class UseWaterBucketAction @Inject constructor(
 
     override fun perform(item: Item.Usable, x: Int, y: Int) {
         gameWorld.placeToForeground(x, y, gameItemsHolder.getBlock("water"))
-        mobsController.player.setCurrentInventorySlotItem(GameItems.getItemId("bucket_empty"))
+        mobsController.player.setCurrentInventorySlotItem(gameItemsHolder.getItem("bucket_empty"))
     }
 
     companion object {
index e80f91b5e70987b2697fe9005a2d10d6e1841248..4743fcfc54289382a255855e97210dc113c1bc34 100644 (file)
@@ -1,10 +1,14 @@
 package ru.deadsoftware.cavedroid.game.mobs;
 
+import com.badlogic.gdx.Gdx;
+import com.badlogic.gdx.graphics.Texture;
 import com.badlogic.gdx.graphics.g2d.SpriteBatch;
 import com.badlogic.gdx.math.Vector2;
-import ru.deadsoftware.cavedroid.game.GameItems;
 import ru.deadsoftware.cavedroid.game.GameItemsHolder;
 import ru.deadsoftware.cavedroid.game.world.GameWorld;
+import ru.deadsoftware.cavedroid.misc.Assets;
+
+import javax.annotation.CheckForNull;
 
 /**
  * Falling gravel is actually a mob, that spawns in place of gravel when there is no block under it,
@@ -12,6 +16,8 @@ import ru.deadsoftware.cavedroid.game.world.GameWorld;
  */
 public class FallingGravel extends Mob {
 
+    private static final String TAG = "FallingGravel";
+
     /**
      * Creates a FallingGravel mob at coordinates
      *
@@ -47,7 +53,15 @@ public class FallingGravel extends Mob {
 
     @Override
     public void draw(SpriteBatch spriteBatch, float x, float y, float delta) {
-        spriteBatch.draw(GameItems.getBlockTex(11), x, y);
+        @CheckForNull final Texture texture = Assets.blockTextures.get("gravel");
+
+        if (texture == null) {
+            Gdx.app.error(TAG, "Couldn't draw: texture not found");
+            kill();
+            return;
+        }
+
+        spriteBatch.draw(texture, x, y);
     }
 
 }
index 14ec825d5735d37f7000ca84df0e4851b582c9e1..bce918e34fb811024815022970dd00ffa834e316 100644 (file)
@@ -1,10 +1,14 @@
 package ru.deadsoftware.cavedroid.game.mobs;
 
+import com.badlogic.gdx.Gdx;
+import com.badlogic.gdx.graphics.Texture;
 import com.badlogic.gdx.graphics.g2d.SpriteBatch;
 import com.badlogic.gdx.math.Vector2;
-import ru.deadsoftware.cavedroid.game.GameItems;
 import ru.deadsoftware.cavedroid.game.GameItemsHolder;
 import ru.deadsoftware.cavedroid.game.world.GameWorld;
+import ru.deadsoftware.cavedroid.misc.Assets;
+
+import javax.annotation.CheckForNull;
 
 
 /**
@@ -13,6 +17,8 @@ import ru.deadsoftware.cavedroid.game.world.GameWorld;
  */
 public class FallingSand extends Mob {
 
+    private static final String TAG = "FallingSand";
+
     /**
      * Creates a FallingSand mob at coordinates
      *
@@ -48,7 +54,15 @@ public class FallingSand extends Mob {
 
     @Override
     public void draw(SpriteBatch spriteBatch, float x, float y, float delta) {
-        spriteBatch.draw(GameItems.getBlockTex(10), x, y);
+        @CheckForNull final Texture texture = Assets.blockTextures.get("sand");
+
+        if (texture == null) {
+            Gdx.app.error(TAG, "Couldn't draw: texture not found");
+            kill();
+            return;
+        }
+
+        spriteBatch.draw(texture, x, y);
     }
 
 }
index e83908808b5b9f0fe349d1651bdab6c2754f714f..0ec111bbd66bd5b96ff38a9cdd7e323d53b7bf0c 100644 (file)
@@ -1,16 +1,19 @@
 package ru.deadsoftware.cavedroid.game.mobs
 
+import ru.deadsoftware.cavedroid.game.GameItemsHolder
 import ru.deadsoftware.cavedroid.game.GameScope
 import java.io.Serializable
 import java.util.*
 import javax.inject.Inject
 
 @GameScope
-class MobsController @Inject constructor() : Serializable {
+class MobsController @Inject constructor(
+    gameItemsHolder: GameItemsHolder
+) : Serializable {
 
     private val _mobs = LinkedList<Mob>()
 
-    val player: Player = Player()
+    val player: Player = Player(gameItemsHolder)
 
     val mobs: List<Mob>
         get() = _mobs
index d6d848c12621aad20fd0c6c471814aaaf60b26c6..3c33ee574efefe17a1010f8a96694a42b67e1744 100644 (file)
@@ -4,7 +4,6 @@ import com.badlogic.gdx.graphics.g2d.Sprite;
 import com.badlogic.gdx.graphics.g2d.SpriteBatch;
 import com.badlogic.gdx.math.MathUtils;
 import com.badlogic.gdx.math.Vector2;
-import ru.deadsoftware.cavedroid.game.GameItems;
 import ru.deadsoftware.cavedroid.game.GameItemsHolder;
 import ru.deadsoftware.cavedroid.game.model.item.Item;
 import ru.deadsoftware.cavedroid.game.objects.Drop;
@@ -13,8 +12,6 @@ import ru.deadsoftware.cavedroid.misc.Assets;
 import ru.deadsoftware.cavedroid.misc.utils.SpriteOrigin;
 import ru.deadsoftware.cavedroid.misc.utils.SpriteUtilsKt;
 
-import javax.annotation.CheckForNull;
-
 public class Player extends Mob {
 
     private static final float SPEED = 69.072f;
@@ -25,15 +22,18 @@ public class Player extends Mob {
     private float hitAnim = 0f;
     private float hitAnimDelta = ANIMATION_SPEED;
 
-    public final int[] inventory;
+    public final Item[] inventory;
     public int slot;
     public int gameMode;
     public boolean swim;
     public float headRotation = 0f;
 
-    public Player() {
+    public Player(GameItemsHolder gameItemsHolder) {
         super(0, 0, 4, 30, randomDir(), Type.MOB, MAX_HEALTH);
-        inventory = new int[9];
+        inventory = new Item[9];
+        for (int i = 0; i < 9; i++) {
+            inventory[i] = gameItemsHolder.getFallbackItem();
+        }
         swim = false;
     }
 
@@ -48,8 +48,8 @@ public class Player extends Mob {
 
     public void pickUpDrop(Drop drop) {
         for (int i = 0; i < inventory.length; i++) {
-            if (inventory[i] == 0 || inventory[i] == drop.getId()) {
-                inventory[i] = drop.getId();
+            if (inventory[i] == null || inventory[i].getParams().getKey().equals(GameItemsHolder.FALLBACK_ITEM_KEY) || inventory[i] == drop.getItem()) {
+                inventory[i] = drop.getItem();
                 drop.setPickedUp(true);
                 break;
             }
@@ -77,8 +77,8 @@ public class Player extends Mob {
         }
     }
 
-    public void setCurrentInventorySlotItem(int itemId) {
-        inventory[slot] = itemId;
+    public void setCurrentInventorySlotItem(Item item) {
+        inventory[slot] = item;
     }
 
     @Override
@@ -116,13 +116,12 @@ public class Player extends Mob {
     }
 
     private void drawItem(SpriteBatch spriteBatch, float x, float y, float anim) {
-        final int itemId = inventory[slot];
+        final Item item = inventory[slot];
 
-        if (itemId == 0) {
+        if (item == null || item.getParams().getKey().equals(GameItemsHolder.FALLBACK_ITEM_KEY)) {
             return;
         }
 
-        final Item item = GameItems.getItem(itemId);
         final Sprite sprite = item.getSprite();
 
         if (!item.isTool()) {
index 798e3d9b8bfe3e5506de866b4c6e06215cbfaaf5..2411a6352d963823bb921f1a8a741172150fddfb 100644 (file)
@@ -4,6 +4,7 @@ import com.badlogic.gdx.graphics.g2d.Sprite
 import com.badlogic.gdx.graphics.g2d.SpriteBatch
 import com.badlogic.gdx.math.Rectangle
 import com.badlogic.gdx.utils.TimeUtils
+import ru.deadsoftware.cavedroid.game.model.item.Item
 import kotlin.contracts.ExperimentalContracts
 import kotlin.contracts.contract
 
@@ -35,6 +36,14 @@ sealed class Block {
             } ?: 0
         }
 
+    override fun hashCode(): Int {
+        return params.key.hashCode()
+    }
+
+    override fun equals(other: Any?): Boolean {
+        return params.key == (other as Item).params.key
+    }
+
     fun initialize() {
         initAnimation()
         initSprite()
index 63229b390578e87b6bebfeb1c3b74b2df700933f..aef3a13a2cc0011ebadebbf24254ee3bc5555310 100644 (file)
@@ -8,43 +8,4 @@ import kotlinx.serialization.json.*
 data class GameItemsDto(
     @SerialName("blocks") val blocks: Map<String, BlockDto>,
     @SerialName("items") val items: Map<String, ItemDto>,
-) {
-    object GameItemsDtoJsonSerializer : JsonTransformingSerializer<GameItemsDto>(GameItemsDto.serializer()) {
-        private val defaultBlockValuesEqualKeyFieldNames = listOf("drop", "texture")
-        private val defaultItemValuesEqualKeyFieldNames = listOf("name", "texture")
-
-        override fun transformDeserialize(element: JsonElement): JsonElement {
-            val root = element.jsonObject
-            val blocks = root["blocks"]!!.jsonObject
-            val items = root["items"]!!.jsonObject
-
-            return buildJsonObject {
-                putJsonObject("blocks") {
-                    blocks.forEach { (key, blockObj) ->
-                        putJsonObject(key) {
-                            defaultBlockValuesEqualKeyFieldNames.forEach { fieldName ->
-                                put(fieldName, key)
-                            }
-                            blockObj.jsonObject.forEach { (prop, propValue) ->
-                                put(prop, propValue)
-                            }
-                        }
-                    }
-                }
-
-                putJsonObject("items") {
-                    items.forEach { (key, itemObj) ->
-                        putJsonObject(key) {
-                            defaultItemValuesEqualKeyFieldNames.forEach { fieldName ->
-                                put(fieldName, key)
-                            }
-                            itemObj.jsonObject.forEach { (prop, propValue) ->
-                                put(prop, propValue)
-                            }
-                        }
-                    }
-                }
-            }
-        }
-    }
-}
\ No newline at end of file
+)
\ No newline at end of file
index 42dae7ea68eee2c0b47098c3805ae68416d28dae..a479a4f7280c2ad8d5fd936dd78546a01f13bf74 100644 (file)
@@ -11,6 +11,14 @@ sealed class Item {
     abstract val params: CommonItemParams
     abstract val sprite: Sprite
 
+    override fun hashCode(): Int {
+        return params.key.hashCode()
+    }
+
+    override fun equals(other: Any?): Boolean {
+        return params.key == (other as Item).params.key
+    }
+
     fun isPlaceable(): Boolean {
         contract { returns(true) implies (this@Item is Placeable) }
         return this is Placeable
index 363801c013f02d96b3619b37b230dd37272ec223..eb3080fd876233630c269753582beacca3ce9df6 100644 (file)
@@ -6,13 +6,11 @@ import ru.deadsoftware.cavedroid.game.GameItemsHolder
 import ru.deadsoftware.cavedroid.game.model.block.*
 import ru.deadsoftware.cavedroid.game.model.block.Block.*
 import ru.deadsoftware.cavedroid.game.model.dto.BlockDto
-import ru.deadsoftware.cavedroid.misc.utils.AssetLoader
+import ru.deadsoftware.cavedroid.misc.Assets
 import javax.inject.Inject
 
 @Reusable
-class BlockMapper @Inject constructor(
-    private val assetLoader: AssetLoader,
-) {
+class BlockMapper @Inject constructor() {
 
     fun map(key: String, dto: BlockDto): Block {
         val commonBlockParams = mapCommonParams(key, dto)
@@ -81,7 +79,7 @@ class BlockMapper @Inject constructor(
             return null
         }
 
-        return Texture(assetLoader.getAssetHandle("textures/blocks/$textureName.png"))
+        return Assets.blockTextures[textureName]
     }
 
 }
\ No newline at end of file
index 796fc8b28fdb25a81f6c59477d7e42c56ffb2788..311c10c838b3fe33b6d92d3af93cb68b9b12d138 100644 (file)
@@ -1,6 +1,5 @@
 package ru.deadsoftware.cavedroid.game.model.mapper
 
-import com.badlogic.gdx.graphics.Texture
 import com.badlogic.gdx.graphics.g2d.Sprite
 import dagger.Reusable
 import ru.deadsoftware.cavedroid.game.GameItemsHolder
@@ -9,14 +8,12 @@ import ru.deadsoftware.cavedroid.game.model.dto.ItemDto
 import ru.deadsoftware.cavedroid.game.model.item.CommonItemParams
 import ru.deadsoftware.cavedroid.game.model.item.Item
 import ru.deadsoftware.cavedroid.game.model.item.Item.*
-import ru.deadsoftware.cavedroid.misc.utils.AssetLoader
+import ru.deadsoftware.cavedroid.misc.Assets
 import ru.deadsoftware.cavedroid.misc.utils.SpriteOrigin
 import javax.inject.Inject
 
 @Reusable
-class ItemMapper @Inject constructor(
-    private val assetLoader: AssetLoader,
-) {
+class ItemMapper @Inject constructor() {
 
     fun map(key: String, dto: ItemDto, block: Block?): Item {
         val params = mapCommonParams(key, dto)
@@ -47,7 +44,8 @@ class ItemMapper @Inject constructor(
             return null
         }
 
-        return Sprite(Texture(assetLoader.getAssetHandle("textures/items/${dto.texture}.png")))
+        return Sprite(Assets.itemTextures[dto.texture])
+            .apply { flip(false, true) }
     }
 
 }
\ No newline at end of file
index accd9722c943f63a2bfe27c55154a2682bcee55b..b9a141c33cdb0fce3734ed5a507811699f75acfa 100644 (file)
@@ -3,11 +3,12 @@ package ru.deadsoftware.cavedroid.game.objects
 import com.badlogic.gdx.math.Intersector
 import com.badlogic.gdx.math.Rectangle
 import com.badlogic.gdx.math.Vector2
+import ru.deadsoftware.cavedroid.game.model.item.Item
 
 class Drop(
     x: Float,
     y: Float,
-    val id: Int,
+    val item: Item,
 ) : Rectangle(x, y, DROP_SIZE, DROP_SIZE) {
 
     val velocity = getInitialVelocity()
index 0e4c6592abe3badac802872be953ab84c68b2324..084180d10b9cb4ae4a4c5b895b95c2a44fdb00f8 100644 (file)
@@ -1,6 +1,7 @@
 package ru.deadsoftware.cavedroid.game.objects;
 
 import ru.deadsoftware.cavedroid.game.GameScope;
+import ru.deadsoftware.cavedroid.game.model.item.Item;
 
 import javax.inject.Inject;
 import java.io.Serializable;
@@ -20,8 +21,8 @@ public class DropController implements Serializable {
     public DropController() {
     }
 
-    public void addDrop(float x, float y, int id) {
-        mDrops.add(new Drop(x, y, id));
+    public void addDrop(float x, float y, Item item) {
+        mDrops.add(new Drop(x, y, item));
     }
 
     public int getSize() {
index 39ae5d39e070c4ec8d24312c21300bd5361214a4..449c958da450fa3bb68901df527b0ebf473f7221 100644 (file)
@@ -1,7 +1,6 @@
 package ru.deadsoftware.cavedroid.game.world;
 
 import kotlin.Pair;
-import ru.deadsoftware.cavedroid.game.GameItems;
 import ru.deadsoftware.cavedroid.game.GameItemsHolder;
 import ru.deadsoftware.cavedroid.game.GameScope;
 import ru.deadsoftware.cavedroid.game.mobs.MobsController;
@@ -152,7 +151,7 @@ public class GameWorld {
     public void destroyForeMap(int x, int y) {
         Block block = getForeMap(x, y);
         if (block.hasDrop()) {
-            mDropController.addDrop(transformX(x) * 16 + 4, y * 16 + 4, GameItems.getItemId(block.getDrop()));
+            mDropController.addDrop(transformX(x) * 16 + 4, y * 16 + 4, mGameItemsHolder.getItem(block.getDrop()));
         }
         placeToForeground(x, y, mGameItemsHolder.getFallbackBlock());
     }
@@ -160,7 +159,7 @@ public class GameWorld {
     public void destroyBackMap(int x, int y) {
         Block block = getBackMap(x, y);
         if (block.hasDrop()) {
-            mDropController.addDrop(transformX(x) * 16 + 4, y * 16 + 4, GameItems.getItemId(block.getDrop()));
+            mDropController.addDrop(transformX(x) * 16 + 4, y * 16 + 4, mGameItemsHolder.getItem(block.getDrop()));
         }
         placeToBackground(x, y, mGameItemsHolder.getFallbackBlock());
     }
index 05bd47f0559b162702919b950bc20ca20d35e159..d4f7a46936df1d249caa5d7b20adef9af150765b 100644 (file)
@@ -1,5 +1,6 @@
 package ru.deadsoftware.cavedroid.misc;
 
+import com.badlogic.gdx.files.FileHandle;
 import com.badlogic.gdx.graphics.Texture;
 import com.badlogic.gdx.graphics.g2d.BitmapFont;
 import com.badlogic.gdx.graphics.g2d.GlyphLayout;
@@ -11,7 +12,10 @@ import com.badlogic.gdx.utils.JsonValue;
 import ru.deadsoftware.cavedroid.game.objects.TouchButton;
 import ru.deadsoftware.cavedroid.misc.utils.AssetLoader;
 
+import java.io.File;
+import java.io.FilenameFilter;
 import java.util.HashMap;
+import java.util.Map;
 
 public class Assets {
 
@@ -23,6 +27,9 @@ public class Assets {
     private static final GlyphLayout glyphLayout = new GlyphLayout();
     static BitmapFont minecraftFont;
 
+    public static Map<String, Texture> blockTextures = new HashMap<>();
+    public static Map<String, Texture> itemTextures = new HashMap<>();
+
     private static TextureRegion flippedRegion(Texture texture, int x, int y, int width, int height) {
         return new TextureRegion(texture, x, y + height, width, -height);
     }
@@ -78,10 +85,28 @@ public class Assets {
         }
     }
 
+    private static void loadAllPngsFromDirInto(FileHandle dir, Map<String, Texture> loadInto) {
+        for (FileHandle handle : dir.list((d, name) -> name.endsWith(".png"))) {
+            loadInto.put(handle.nameWithoutExtension(), new Texture(handle));
+        }
+    }
+
+    private static void loadItems(AssetLoader assetLoader) {
+        final FileHandle itemsDir = assetLoader.getAssetHandle("textures/items");
+        loadAllPngsFromDirInto(itemsDir, itemTextures);
+    }
+
+    private static void loadBlocks(AssetLoader assetLoader) {
+        final FileHandle blocksDir = assetLoader.getAssetHandle("textures/blocks");
+        loadAllPngsFromDirInto(blocksDir, blockTextures);
+    }
+
     public static void load(final AssetLoader assetLoader) {
         loadMob(assetLoader, playerSprite, "char");
         loadMob(assetLoader, pigSprite, "pig");
         loadJSON(assetLoader);
+        loadBlocks(assetLoader);
+        loadItems(assetLoader);
         setPlayerHeadOrigin();
         minecraftFont = new BitmapFont(assetLoader.getAssetHandle("font.fnt"), true);
         minecraftFont.getData().setScale(.375f);
diff --git a/core/src/ru/deadsoftware/cavedroid/misc/utils/ItemUtils.kt b/core/src/ru/deadsoftware/cavedroid/misc/utils/ItemUtils.kt
new file mode 100644 (file)
index 0000000..8e1f730
--- /dev/null
@@ -0,0 +1,8 @@
+package ru.deadsoftware.cavedroid.misc.utils
+
+import ru.deadsoftware.cavedroid.game.GameItemsHolder.Companion.FALLBACK_ITEM_KEY
+import ru.deadsoftware.cavedroid.game.model.item.Item
+
+fun Item.isFallback(): Boolean {
+    return this.params.key == FALLBACK_ITEM_KEY
+}