X-Git-Url: https://deadsoftware.ru/gitweb?p=cavedroid.git;a=blobdiff_plain;f=core%2Fsrc%2Fru%2Fdeadsoftware%2Fcavedroid%2Fgame%2FGameSaver.java;h=0d796b8b3a22583ed5e7e540bcb3b0ebe5bfe6a0;hp=edc29e3f01c2ff97b16c60fade7ab31b1fb5921f;hb=2948fcd9c40ebf588ef7d0e7cd8dd34ecaa1f9b2;hpb=d58d40ec24363550fad10bd6047cee2618912186 diff --git a/core/src/ru/deadsoftware/cavedroid/game/GameSaver.java b/core/src/ru/deadsoftware/cavedroid/game/GameSaver.java index edc29e3..0d796b8 100644 --- a/core/src/ru/deadsoftware/cavedroid/game/GameSaver.java +++ b/core/src/ru/deadsoftware/cavedroid/game/GameSaver.java @@ -2,6 +2,7 @@ package ru.deadsoftware.cavedroid.game; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.files.FileHandle; +import org.jetbrains.annotations.NotNull; import ru.deadsoftware.cavedroid.CaveGame; import java.io.*; @@ -11,11 +12,12 @@ public class GameSaver { private static final int VERSION = 0; + @NotNull private static byte[] intToBytes(int i) { return ByteBuffer.allocate(4).putInt(i).array(); } - private static void saveMap(FileHandle file, int[][] map) throws IOException { + private static void saveMap(@NotNull FileHandle file, @NotNull int[][] map) throws IOException { int rl, bl; int width = map.length; int height = map[0].length; @@ -26,12 +28,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,7 +44,8 @@ public class GameSaver { out.close(); } - private static int[][] loadMap(FileHandle file) throws Exception { + @NotNull + private static int[][] loadMap(@NotNull FileHandle file) throws Exception { int[][] map; int ver, width, height; int rl, bl; @@ -73,8 +76,7 @@ public class GameSaver { 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")) );