(int currentSlot)
| 59 | } |
| 60 | |
| 61 | static public boolean load(int currentSlot) { |
| 62 | |
| 63 | String fileName = WorldSave.getSaveFile(currentSlot); |
| 64 | if (!new File(fileName).exists()) |
| 65 | return false; |
| 66 | new File(getSaveDir()).mkdirs(); |
| 67 | try { |
| 68 | try (FileInputStream fos = new FileInputStream(fileName); |
| 69 | InflaterInputStream inf = new InflaterInputStream(fos); |
| 70 | ObjectInputStream oos = new ObjectInputStream(inf)) { |
| 71 | currentSave.header = (WorldSaveHeader) oos.readObject(); |
| 72 | SaveFileData mainData = (SaveFileData) oos.readObject(); |
| 73 | currentSave.player.load(mainData.readSubData("player")); |
| 74 | GamePlayerUtil.getGuiPlayer().setName(currentSave.player.getName()); |
| 75 | try { |
| 76 | currentSave.world.load(mainData.readSubData("world")); |
| 77 | currentSave.pointOfInterestChanges.load(mainData.readSubData("pointOfInterestChanges")); |
| 78 | WorldStage.getInstance().load(mainData.readSubData("worldStage")); |
| 79 | |
| 80 | } catch (Exception e) { |
| 81 | System.err.println("Generating New World"); |
| 82 | if (!currentSave.world.generateNew(0)) |
| 83 | return false; |
| 84 | } |
| 85 | |
| 86 | currentSave.onLoadList.emit(); |
| 87 | |
| 88 | } |
| 89 | } catch (ClassNotFoundException | IOException e) { |
| 90 | e.printStackTrace(); |
| 91 | return false; |
| 92 | } |
| 93 | return true; |
| 94 | } |
| 95 | |
| 96 | public static boolean isSafeFile(String name) { |
| 97 | return filenameToSlot(name) != INVALID_SAVE_SLOT; |
no test coverage detected