1
0
mirror of https://github.com/Anuken/Mindustry.git synced 2024-09-22 13:57:46 +03:00

Changed save system to only convert saves on load, possibly fixing issues with saves disappearing on new version updates

This commit is contained in:
Anuken 2018-01-20 22:45:08 -05:00
parent bf83ccd636
commit 232a490d7d
7 changed files with 11 additions and 42 deletions

View File

@ -90,7 +90,6 @@ public class Mindustry extends ModuleCore {
@Override
public void postInit(){
Vars.control.reset();
Vars.control.getSaves().convertSaves();
}
@Override

View File

@ -108,7 +108,9 @@ public class SaveIO{
public static boolean isSaveValid(DataInputStream stream){
try{
SaveMeta meta = getData(stream);
int version = stream.readInt();
SaveFileVersion ver = versions.get(version);
SaveMeta meta = ver.getData(stream);
return meta.map != null;
}catch (Exception e){
return false;
@ -122,7 +124,7 @@ public class SaveIO{
public static SaveMeta getData(DataInputStream stream){
try{
SaveMeta meta = getVersion().getData(stream);
SaveMeta meta = getVersion().getData(stream);
stream.close();
return meta;
}catch (IOException e){
@ -146,7 +148,7 @@ public class SaveIO{
stream = new DataOutputStream(os);
getVersion().write(stream);
stream.close();
}catch (IOException e){
}catch (Exception e){
throw new RuntimeException(e);
}
}
@ -161,9 +163,13 @@ public class SaveIO{
try{
stream = new DataInputStream(is);
getVersion().read(stream);
int version = stream.readInt();
SaveFileVersion ver = versions.get(version);
ver.read(stream);
stream.close();
}catch (IOException e){
}catch (Exception e){
throw new RuntimeException(e);
}
}

View File

@ -34,18 +34,6 @@ public class Saves {
}
}
public void convertSaves(){
Array<SaveSlot> invalid = new Array<>();
for(SaveSlot slot : saves){
if(!SaveIO.checkConvert(slot.index)){
invalid.add(slot);
}
}
saves.removeAll(invalid, true);
}
public SaveSlot getCurrent() {
return current;
}

View File

@ -31,14 +31,8 @@ public class Save12 extends SaveFileVersion {
@Override
public void read(DataInputStream stream) throws IOException {
int version = stream.readInt();
/*long loadTime = */stream.readLong();
if(version != this.version){
throw new RuntimeException("Save file version mismatch!");
}
//general state
byte mode = stream.readByte();
byte mapid = stream.readByte();

View File

@ -32,14 +32,8 @@ public class Save13 extends SaveFileVersion {
@Override
public void read(DataInputStream stream) throws IOException {
int version = stream.readInt();
/*long loadTime = */stream.readLong();
if(version != this.version){
throw new RuntimeException("Save file version mismatch!");
}
//general state
byte mode = stream.readByte();
byte mapid = stream.readByte();

View File

@ -35,15 +35,9 @@ public class Save14 extends SaveFileVersion{
@Override
public void read(DataInputStream stream) throws IOException {
int version = stream.readInt();
/*long loadTime = */
stream.readLong();
if(version != this.version){
throw new RuntimeException("Save file version mismatch!");
}
//general state
byte mode = stream.readByte();
byte mapid = stream.readByte();

View File

@ -36,15 +36,9 @@ public class Save15 extends SaveFileVersion {
@Override
public void read(DataInputStream stream) throws IOException {
int version = stream.readInt();
/*long loadTime = */
stream.readLong();
if(version != this.version){
throw new RuntimeException("Save file version mismatch!");
}
//general state
byte mode = stream.readByte();
byte mapid = stream.readByte();