DEADSOFTWARE

Fix codestyle
[cavedroid.git] / core / src / ru / deadsoftware / cavedroid / game / GameSaver.java
index edc29e3f01c2ff97b16c60fade7ab31b1fb5921f..0788561d8edf39e8a4151278b41abd7a5398c8e3 100644 (file)
@@ -11,6 +11,7 @@ public class GameSaver {
 
     private static final int VERSION = 0;
 
+
     private static byte[] intToBytes(int i) {
         return ByteBuffer.allocate(4).putInt(i).array();
     }
@@ -26,12 +27,12 @@ public class GameSaver {
         for (int y = 0; y < height; y++) {
             bl = map[0][y];
             rl = 0;
-            for (int x = 0; x < width; x++) {
-                if (map[x][y] != bl) {
+            for (int[] ints : map) {
+                if (ints[y] != bl) {
                     out.write(intToBytes(rl));
                     out.write(intToBytes(bl));
                     rl = 0;
-                    bl = map[x][y];
+                    bl = ints[y];
                 }
                 rl++;
             }
@@ -42,6 +43,7 @@ public class GameSaver {
         out.close();
     }
 
+
     private static int[][] loadMap(FileHandle file) throws Exception {
         int[][] map;
         int ver, width, height;
@@ -56,11 +58,15 @@ public class GameSaver {
                 for (int x = 0; x < width; x += rl) {
                     rl = in.readInt();
                     bl = in.readInt();
-                    for (int i = x; i < x + rl; i++) map[i][y] = bl;
+                    for (int i = x; i < x + rl; i++) {
+                        map[i][y] = bl;
+                    }
                 }
             }
             in.close();
-        } else throw new Exception("version mismatch");
+        } else {
+            throw new Exception("version mismatch");
+        }
         return map;
     }
 
@@ -70,16 +76,18 @@ public class GameSaver {
         try {
             ObjectInputStream in = new ObjectInputStream(file.read());
             int ver = in.readInt();
-            if (VERSION == ver) gameProc = (GameProc) in.readObject();
-            else throw new Exception("version mismatch");
+            if (VERSION == ver) {
+                gameProc = (GameProc) in.readObject();
+            } else {
+                throw new Exception("version mismatch");
+            }
             in.close();
-            gameProc.world = new GameWorld();
-            gameProc.world.setMaps(
+            gameProc.world = new GameWorld(
                     loadMap(Gdx.files.absolute(CaveGame.GAME_FOLDER + "/saves/foremap.sav")),
                     loadMap(Gdx.files.absolute(CaveGame.GAME_FOLDER + "/saves/backmap.sav"))
             );
             gameProc.physics = new GamePhysics();
-            gameProc.resetRenderer();
+            gameProc.input = new GameInput();
         } catch (Exception e) {
             Gdx.app.error("GameSaver", e.getMessage(), e);
             Gdx.app.exit();