DEADSOFTWARE

Return tools
[cavedroid.git] / core / src / ru / deadsoftware / cavedroid / game / GameItems.java
index 1bbb03cf1997384679f975411c7b958515b834e4..61b3af736653e9097b30df8f49ca1d6c0cfd280d 100644 (file)
@@ -13,11 +13,11 @@ import java.util.HashMap;
 
 public class GameItems {
 
-    private static HashMap<String, Integer> blocksIds = new HashMap<String, Integer>();
-    private static HashMap<String, Integer> itemsIds = new HashMap<String, Integer>();
+    private static HashMap<String, Integer> blocksIds = new HashMap<>();
+    private static HashMap<String, Integer> itemsIds = new HashMap<>();
 
-    private static ArrayMap<String, Block> blocks = new ArrayMap<String, Block>();
-    private static ArrayMap<String, Item> items = new ArrayMap<String, Item>();
+    private static ArrayMap<String, Block> blocks = new ArrayMap<>();
+    private static ArrayMap<String, Item> items = new ArrayMap<>();
 
     public static boolean isFluid(int id) {
         return getBlock(id).isFluid();
@@ -35,6 +35,12 @@ public class GameItems {
         return getBlock(id).getMeta().equals("slab");
     }
 
+    public static boolean fluidCanFlowThere(int thisId, int thatId) {
+        return thatId == 0 || (!getBlock(thatId).hasCollision() && !isFluid(thatId)) ||
+                (isWater(thisId) && isWater(thatId) && thisId < thatId) ||
+                (isLava(thisId) && isLava(thatId) && thisId < thatId);
+    }
+
     public static Block getBlock(int id) {
         return blocks.getValueAt(id);
     }
@@ -107,11 +113,26 @@ public class GameItems {
             boolean fluid = (block.has("fluid") && block.getBoolean("fluid"));
             String meta = (block.has("meta") ? block.getString("meta") : "");
             String texture = (block.has("texture") ? block.getString("texture") : key);
+            Sprite sprite = key.equals("none") ? null :
+                    new Sprite(new Texture(Gdx.files.internal("textures/blocks/" + texture + ".png")));
+            Block newBlock = new Block(
+                    left,
+                    top,
+                    right,
+                    bottom,
+                    hp,
+                    drop,
+                    collision,
+                    background,
+                    transparent,
+                    blockRequired,
+                    fluid,
+                    meta,
+                    sprite
+            );
+
             blocksIds.put(key, blocks.size);
-            blocks.put(key, new Block(left, top, right, bottom, hp, drop, collision,
-                    background, transparent, blockRequired, fluid, meta,
-                    key.equals("none") ? null :
-                            new Sprite(new Texture(Gdx.files.internal("textures/" + texture + ".png")))));
+            blocks.put(key, newBlock);
             block = block.next();
         }
         while (item != null) {
@@ -119,9 +140,10 @@ public class GameItems {
             String name = (item.has("name") ? item.getString("name") : key);
             String type = (item.has("type") ? item.getString("type") : "item");
             String texture = (item.has("texture") ? item.getString("texture") : key);
+            Sprite sprite = type.equals("block") ? null :
+                    new Sprite(new Texture(Gdx.files.internal("textures/items/" + texture + ".png")));
             itemsIds.put(key, items.size);
-            items.put(key, new Item(name, type, type.equals("block") ? null :
-                    new Sprite(new Texture(Gdx.files.internal("textures/" + texture + ".png")))));
+            items.put(key, new Item(name, type, sprite));
             item = item.next();
         }
     }