2323import com .google .gson .JsonObject ;
2424import com .google .gson .JsonParser ;
2525import com .google .gson .stream .JsonReader ;
26+ import org .destinationsol .Const ;
2627import org .destinationsol .IniReader ;
2728import org .destinationsol .common .SolRandom ;
2829import org .destinationsol .files .HullConfigManager ;
4748import java .util .List ;
4849
4950public 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
0 commit comments