DEADSOFTWARE

Fix NPE after loading game
authorfred-boy <fred-boy@protonmail.com>
Wed, 25 Apr 2018 14:35:12 +0000 (21:35 +0700)
committerfred-boy <fred-boy@protonmail.com>
Wed, 25 Apr 2018 14:35:12 +0000 (21:35 +0700)
core/src/ru/deadsoftware/cavecraft/game/GameRenderer.java
core/src/ru/deadsoftware/cavecraft/game/GameSaver.java
core/src/ru/deadsoftware/cavecraft/game/GameWorld.java

index 648e785e8d07a96c9de6728124be0bcaac3013a8..38c79f1641b3e335ab2838ba80a873d58998fa03 100644 (file)
@@ -54,7 +54,7 @@ public class GameRenderer extends Renderer {
         if (maxY>gameProc.world.getHeight()) maxY = gameProc.world.getHeight();
         for (int y=minY; y<maxY; y++) {
             for (int x=minX; x<maxX; x++) {
-                if (gameProc.world.getForeMap(x,y)>0) {
+                if (gameProc.world.getForeMap(x,y)>0 && !Items.BLOCKS.getValueAt(gameProc.world.getForeMap(x,y)).background) {
                     spriteBatch.draw(
                             Assets.blockTextures[Items.BLOCKS.getValueAt(gameProc.world.getForeMap(x,y)).getTexture()],
                             x * 16 - camera.position.x,y * 16 - camera.position.y);
index aab81f54ecb26d101c315e0fbe8c98bd4dab1e8f..2b5b906d877a3dadcd77baca27e1e346d8eeeff1 100644 (file)
@@ -2,6 +2,7 @@ package ru.deadsoftware.cavecraft.game;
 
 import com.badlogic.gdx.Gdx;
 import com.badlogic.gdx.files.FileHandle;
+import com.badlogic.gdx.utils.ArrayMap;
 import ru.deadsoftware.cavecraft.CaveGame;
 
 import java.io.*;
@@ -78,6 +79,7 @@ public class GameSaver {
                     loadMap(Gdx.files.absolute(CaveGame.GAME_FOLDER + "/saves/foremap.sav")),
                     loadMap(Gdx.files.absolute(CaveGame.GAME_FOLDER + "/saves/backmap.sav"))
             );
+            gameProc.world.metaMap = new ArrayMap<String, Integer>();
             gameProc.physics = new GamePhysics(gameProc);
             gameProc.resetRenderer();
         } catch (Exception e) {
index fc0c24712a88999124dac75967302106f7a06401..5f5a407d44a68c03e23a7ddeb848c61dd3abb26d 100644 (file)
@@ -8,7 +8,7 @@ public class GameWorld {
 
     private int WIDTH, HEIGHT;
 
-    private ArrayMap<String, Integer> metaMap;
+    public ArrayMap<String, Integer> metaMap;
     private int[][] foreMap;
     private int[][] backMap;