Skip to content

Commit 2567cb9

Browse files
disable continue from different major version
1 parent f552884 commit 2567cb9

File tree

3 files changed

+18
-10
lines changed

3 files changed

+18
-10
lines changed

engine/src/main/java/org/destinationsol/Const.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,8 @@ public class Const {
3737
public static final float CAM_VIEW_DIST_JOURNEY = 8.6f;
3838
public static final float DEFAULT_AI_SPD = 4f;
3939
public static final float BIG_AI_SPD = 2f;
40+
41+
public static final String SAVE_FILE_NAME = "prevShip.ini";
42+
public static final String MERC_SAVE_FILE = "mercenaries.json";
43+
public static final String WORLD_SAVE_FILE_NAME = "world.json";
4044
}

engine/src/main/java/org/destinationsol/game/SaveManager.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import com.google.gson.JsonObject;
2424
import com.google.gson.JsonParser;
2525
import com.google.gson.stream.JsonReader;
26+
import org.destinationsol.Const;
2627
import org.destinationsol.IniReader;
2728
import org.destinationsol.common.SolRandom;
2829
import org.destinationsol.files.HullConfigManager;
@@ -47,9 +48,6 @@
4748
import java.util.List;
4849

4950
public class SaveManager {
50-
protected static final String SAVE_FILE_NAME = "prevShip.ini";
51-
protected static final String MERC_SAVE_FILE = "mercenaries.json";
52-
protected static final String WORLD_SAVE_FILE_NAME = "world.json";
5351

5452
private static Logger logger = LoggerFactory.getLogger(SaveManager.class);
5553

@@ -66,7 +64,8 @@ public static void writeShips(HullConfig hull, float money, List<SolItem> itemsL
6664

6765
String waypoints = waypointsToString(hero.getWaypoints());
6866

69-
IniReader.write(SAVE_FILE_NAME, "hull", hullName, "money", (int) money, "items", items, "x", pos.x, "y", pos.y, "waypoints", waypoints);
67+
IniReader.write(Const.SAVE_FILE_NAME, "hull", hullName, "money", (int) money, "items", items,
68+
"x", pos.x, "y", pos.y, "waypoints", waypoints, "version", Const.VERSION);
7069
}
7170

7271
private static String waypointsToString(ArrayList<Waypoint> waypoints) {
@@ -156,7 +155,7 @@ private static void writeMercs(Hero hero, HullConfigManager hullConfigManager) {
156155
// Using PrintWriter because it truncates the file if it exists or creates a new one if it doesn't
157156
// And truncation is good because we don't want dead mercs respawning
158157
try {
159-
writer = new PrintWriter(getResourcePath(MERC_SAVE_FILE), "UTF-8");
158+
writer = new PrintWriter(getResourcePath(Const.MERC_SAVE_FILE), "UTF-8");
160159
writer.write(stringToWrite);
161160
writer.close();
162161
} catch (FileNotFoundException | UnsupportedEncodingException e) {
@@ -199,7 +198,7 @@ public static boolean hasPrevShip(String fileName) {
199198
* Load last saved ship from file
200199
*/
201200
public static ShipConfig readShip(HullConfigManager hullConfigs, ItemManager itemManager) {
202-
IniReader ir = new IniReader(SAVE_FILE_NAME, null);
201+
IniReader ir = new IniReader(Const.SAVE_FILE_NAME, null);
203202

204203
String hullName = ir.getString("hull", null);
205204
if (hullName == null) {
@@ -229,7 +228,7 @@ public static ShipConfig readShip(HullConfigManager hullConfigs, ItemManager ite
229228
*/
230229
public static void saveWorld(int numberOfSystems) {
231230
Long seed = SolRandom.getSeed();
232-
String fileName = SaveManager.getResourcePath(WORLD_SAVE_FILE_NAME);
231+
String fileName = SaveManager.getResourcePath(Const.WORLD_SAVE_FILE_NAME);
233232

234233
JsonObject world = new JsonObject();
235234
world.addProperty("seed", seed);
@@ -257,11 +256,11 @@ public static void saveWorld(int numberOfSystems) {
257256
* Load the last saved world from file, or returns null if there is no file
258257
*/
259258
public static WorldConfig loadWorld() {
260-
if (SaveManager.resourceExists(WORLD_SAVE_FILE_NAME)) {
259+
if (SaveManager.resourceExists(Const.WORLD_SAVE_FILE_NAME)) {
261260
WorldConfig config = new WorldConfig();
262261
JsonReader reader = null;
263262
try {
264-
reader = new com.google.gson.stream.JsonReader(new FileReader(SaveManager.getResourcePath(WORLD_SAVE_FILE_NAME)));
263+
reader = new com.google.gson.stream.JsonReader(new FileReader(SaveManager.getResourcePath(Const.WORLD_SAVE_FILE_NAME)));
265264
reader.setLenient(true); // without this it will fail with strange errors
266265
JsonObject world = new JsonParser().parse(reader).getAsJsonObject();
267266

engine/src/main/java/org/destinationsol/menu/NewGameScreen.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818

1919
import com.badlogic.gdx.graphics.Texture;
2020
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
21+
import org.destinationsol.Const;
2122
import org.destinationsol.GameOptions;
23+
import org.destinationsol.IniReader;
2224
import org.destinationsol.SolApplication;
2325
import org.destinationsol.assets.Assets;
2426
import org.destinationsol.common.SolColor;
@@ -58,7 +60,10 @@ public class NewGameScreen extends SolUiBaseScreen {
5860

5961
@Override
6062
public void onAdd(SolApplication solApplication) {
61-
continueControl.setEnabled(SaveManager.hasPrevShip("prevShip.ini"));
63+
IniReader reader = new IniReader(Const.SAVE_FILE_NAME, null);
64+
String saveMajorVersion = reader.getString("version", "").split("\\.")[0];
65+
String gameMajorVersion = Const.VERSION.split("\\.")[0];
66+
continueControl.setEnabled(SaveManager.hasPrevShip("prevShip.ini") && saveMajorVersion.equals(gameMajorVersion));
6267
}
6368

6469
@Override

0 commit comments

Comments
 (0)