Fixed loading of older saves
This commit is contained in:
@@ -6,6 +6,7 @@ import io.anuke.arc.util.io.CounterInputStream;
|
||||
import io.anuke.arc.util.io.FastDeflaterOutputStream;
|
||||
import io.anuke.mindustry.Vars;
|
||||
import io.anuke.mindustry.io.versions.Save1;
|
||||
import io.anuke.mindustry.io.versions.Save2;
|
||||
import io.anuke.mindustry.world.WorldContext;
|
||||
|
||||
import java.io.*;
|
||||
@@ -18,7 +19,7 @@ public class SaveIO{
|
||||
/** Format header. This is the string 'MSAV' in ASCII. */
|
||||
public static final byte[] header = {77, 83, 65, 86};
|
||||
public static final IntMap<SaveVersion> versions = new IntMap<>();
|
||||
public static final Array<SaveVersion> versionArray = Array.with(new Save1());
|
||||
public static final Array<SaveVersion> versionArray = Array.with(new Save1(), new Save2());
|
||||
|
||||
static{
|
||||
for(SaveVersion version : versionArray){
|
||||
|
||||
@@ -21,7 +21,7 @@ public abstract class SaveVersion extends SaveFileReader{
|
||||
public final int version;
|
||||
|
||||
//HACK stores the last read build of the save file, valid after read meta call
|
||||
private int lastReadBuild;
|
||||
protected int lastReadBuild;
|
||||
|
||||
public SaveVersion(int version){
|
||||
this.version = version;
|
||||
@@ -236,62 +236,6 @@ public abstract class SaveVersion extends SaveFileReader{
|
||||
}
|
||||
|
||||
public void readEntities(DataInput stream) throws IOException{
|
||||
/*
|
||||
Latest data:
|
||||
|
||||
0 = Player
|
||||
1 = Fire
|
||||
2 = Puddle
|
||||
3 = Draug
|
||||
4 = Spirit
|
||||
5 = Phantom
|
||||
6 = Dagger
|
||||
7 = Crawler
|
||||
8 = Titan
|
||||
9 = Fortress
|
||||
10 = Eruptor
|
||||
11 = Wraith
|
||||
12 = Ghoul
|
||||
13 = Revenant
|
||||
|
||||
Before removal of lightining/bullet:
|
||||
|
||||
0 = Player
|
||||
1 = Fire
|
||||
2 = Puddle
|
||||
3 = Bullet
|
||||
4 = Lightning
|
||||
5 = Draug
|
||||
6 = Spirit
|
||||
7 = Phantom
|
||||
8 = Dagger
|
||||
9 = Crawler
|
||||
10 = Titan
|
||||
11 = Fortress
|
||||
12 = Eruptor
|
||||
13 = Wraith
|
||||
14 = Ghoul
|
||||
15 = Revenant
|
||||
|
||||
Before addition of new units:
|
||||
|
||||
0 = Player
|
||||
1 = Fire
|
||||
2 = Puddle
|
||||
3 = Bullet
|
||||
4 = Lightning
|
||||
5 = Spirit
|
||||
6 = Dagger
|
||||
7 = Crawler
|
||||
8 = Titan
|
||||
9 = Fortress
|
||||
10 = Eruptor
|
||||
11 = Wraith
|
||||
12 = Ghoul
|
||||
13 = Phantom
|
||||
14 = Revenant
|
||||
*/
|
||||
|
||||
byte groups = stream.readByte();
|
||||
|
||||
for(int i = 0; i < groups; i++){
|
||||
|
||||
@@ -83,7 +83,7 @@ public class LegacyTypeTable{
|
||||
Player::new,
|
||||
Fire::new,
|
||||
Puddle::new,
|
||||
Bullet::new, //TODO reading these will crash
|
||||
Bullet::new, //TODO reading these may crash
|
||||
Lightning::new,
|
||||
Draug::new,
|
||||
Spirit::new,
|
||||
@@ -102,7 +102,7 @@ public class LegacyTypeTable{
|
||||
Player::new,
|
||||
Fire::new,
|
||||
Puddle::new,
|
||||
Bullet::new, //TODO reading these will crash
|
||||
Bullet::new, //TODO reading these may crash
|
||||
Lightning::new,
|
||||
Spirit::new,
|
||||
Dagger::new,
|
||||
@@ -115,4 +115,15 @@ public class LegacyTypeTable{
|
||||
Phantom::new,
|
||||
Revenant::new
|
||||
};
|
||||
|
||||
public static Supplier[] getTable(int build){
|
||||
if(build == -1 || build == 81){
|
||||
//return most recent one since that's probably is; not guaranteed
|
||||
return build81Table;
|
||||
}else if(build == 80){
|
||||
return build80Table;
|
||||
}else{
|
||||
return build79Table;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,34 @@
|
||||
package io.anuke.mindustry.io.versions;
|
||||
|
||||
import io.anuke.arc.function.Supplier;
|
||||
import io.anuke.mindustry.entities.traits.SaveTrait;
|
||||
import io.anuke.mindustry.io.SaveVersion;
|
||||
|
||||
import java.io.DataInput;
|
||||
import java.io.IOException;
|
||||
|
||||
public class Save1 extends SaveVersion{
|
||||
|
||||
public Save1(){
|
||||
super(1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readEntities(DataInput stream) throws IOException{
|
||||
Supplier[] table = LegacyTypeTable.getTable(lastReadBuild);
|
||||
|
||||
byte groups = stream.readByte();
|
||||
|
||||
for(int i = 0; i < groups; i++){
|
||||
int amount = stream.readInt();
|
||||
for(int j = 0; j < amount; j++){
|
||||
readChunk(stream, true, in -> {
|
||||
byte typeid = in.readByte();
|
||||
byte version = in.readByte();
|
||||
SaveTrait trait = (SaveTrait)table[typeid].get();
|
||||
trait.readSave(in, version);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
9
core/src/io/anuke/mindustry/io/versions/Save2.java
Normal file
9
core/src/io/anuke/mindustry/io/versions/Save2.java
Normal file
@@ -0,0 +1,9 @@
|
||||
package io.anuke.mindustry.io.versions;
|
||||
|
||||
import io.anuke.mindustry.io.SaveVersion;
|
||||
|
||||
public class Save2 extends SaveVersion{
|
||||
public Save2(){
|
||||
super(2);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user