DEADSOFTWARE

Add top slabs
[cavedroid.git] / core / src / ru / deadsoftware / cavedroid / game / world / GameWorld.java
index 449c958da450fa3bb68901df527b0ebf473f7221..32fef769bed2b89c4e1d71e55d68c2eb37cd04eb 100644 (file)
@@ -7,6 +7,7 @@ import ru.deadsoftware.cavedroid.game.mobs.MobsController;
 import ru.deadsoftware.cavedroid.game.model.block.Block;
 import ru.deadsoftware.cavedroid.game.model.world.generator.WorldGeneratorConfig;
 import ru.deadsoftware.cavedroid.game.objects.DropController;
+import ru.deadsoftware.cavedroid.misc.utils.MeasureUnitsUtilsKt;
 
 import javax.annotation.CheckForNull;
 import javax.inject.Inject;
@@ -59,12 +60,20 @@ public class GameWorld {
         return mHeight;
     }
 
+    /**
+     * @deprecated for kotlin use {@link MeasureUnitsUtilsKt#getPx } extension val
+     */
+    @Deprecated
     public float getWidthPx() {
-        return mWidth * 16f;
+        return MeasureUnitsUtilsKt.getPx(mWidth);
     }
 
+    /**
+     * @deprecated for kotlin use {@link MeasureUnitsUtilsKt#getPx } extension val
+     */
+    @Deprecated
     public float getHeightPx() {
-        return mHeight * 16f;
+        return MeasureUnitsUtilsKt.getPx(mHeight);
     }
 
     public Block[][] getFullForeMap() {
@@ -105,6 +114,15 @@ public class GameWorld {
         }
     }
 
+    private boolean isSameSlab(Block slab1, Block slab2) {
+        if (!(slab1 instanceof Block.Slab) || !(slab2 instanceof Block.Slab)) {
+            return false;
+        }
+
+        return slab1.getParams().getKey().equals(((Block.Slab) slab2).getOtherPartBlockKey())
+                || slab1.getParams().getKey().equals(slab2.getParams().getKey());
+    }
+
     public boolean hasForeAt(int x, int y) {
         return getMap(x, y, 0) != mGameItemsHolder.getFallbackBlock();
     }
@@ -136,7 +154,7 @@ public class GameWorld {
     public void placeToForeground(int x, int y, Block value) {
         if (!hasForeAt(x, y) || value == mGameItemsHolder.getFallbackBlock() || !getForeMap(x, y).hasCollision()) {
             setForeMap(x, y, value);
-        } else if (value instanceof Block.Slab && getForeMap(x, y) == value) {
+        } else if (value instanceof Block.Slab && isSameSlab(value, getForeMap(x, y))) {
             setForeMap(x, y, mGameItemsHolder.getBlock(((Block.Slab) value).getFullBlockKey()));
         }
     }