Added backwards compatibility for legacy saves

This commit is contained in:
Anuken
2020-02-17 11:13:46 -05:00
parent 18d4efa315
commit e215772f30
34 changed files with 1009 additions and 855 deletions
@@ -1,139 +0,0 @@
package mindustry.io.versions;
/*
Latest data: [build 81]
0 = Player
1 = Fire
2 = Puddle
3 = MinerDrone
4 = RepairDrone
5 = BuilderDrone
6 = GroundUnit
7 = GroundUnit
8 = GroundUnit
9 = GroundUnit
10 = GroundUnit
11 = FlyingUnit
12 = FlyingUnit
13 = Revenant
Before removal of lightining/bullet: [build 80]
0 = Player
1 = Fire
2 = Puddle
3 = Bullet
4 = Lightning
5 = MinerDrone
6 = RepairDrone
7 = BuilderDrone
8 = GroundUnit
9 = GroundUnit
10 = GroundUnit
11 = GroundUnit
12 = GroundUnit
13 = FlyingUnit
14 = FlyingUnit
15 = Revenant
Before addition of new units: [build 79 and below]
0 = Player
1 = Fire
2 = Puddle
3 = Bullet
4 = Lightning
5 = RepairDrone
6 = GroundUnit
7 = GroundUnit
8 = GroundUnit
9 = GroundUnit
10 = GroundUnit
11 = FlyingUnit
12 = FlyingUnit
13 = BuilderDrone
14 = Revenant
*/
public class LegacyTypeTable{
/*
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
private static final Prov[] build81Table = {
Playerc::new,
Fire::new,
Puddle::new,
MinerDrone::new,
RepairDrone::new,
BuilderDrone::new,
GroundUnit::new,
GroundUnit::new,
GroundUnit::new,
GroundUnit::new,
GroundUnit::new,
FlyingUnit::new,
FlyingUnit::new,
HoverUnit::new
};
private static final Prov[] build80Table = {
Playerc::new,
Fire::new,
Puddle::new,
Bullet::new,
Lightning::new,
MinerDrone::new,
RepairDrone::new,
BuilderDrone::new,
GroundUnit::new,
GroundUnit::new,
GroundUnit::new,
GroundUnit::new,
GroundUnit::new,
FlyingUnit::new,
FlyingUnit::new,
HoverUnit::new
};
private static final Prov[] build79Table = {
Playerc::new,
Fire::new,
Puddle::new,
Bullet::new,
Lightning::new,
RepairDrone::new,
GroundUnit::new,
GroundUnit::new,
GroundUnit::new,
GroundUnit::new,
GroundUnit::new,
FlyingUnit::new,
FlyingUnit::new,
BuilderDrone::new,
HoverUnit::new
};
public static Prov[] getTable(int build){
if(build == -1 || build == 81){
//return most recent one since that's probably it; not guaranteed
return build81Table;
}else if(build == 80){
return build80Table;
}else{
return build79Table;
}
}*/
}
-30
View File
@@ -1,30 +0,0 @@
package mindustry.io.versions;
import java.io.*;
public class Save1 extends Save2{
public Save1(){
version = 1;
}
@Override
public void readEntities(DataInput stream) throws IOException{
//TODO implement
//Prov[] 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);
});
}
}
}
}
-31
View File
@@ -1,31 +0,0 @@
package mindustry.io.versions;
import mindustry.io.*;
import java.io.*;
public class Save2 extends SaveVersion{
public Save2(){
super(2);
}
@Override
public void readEntities(DataInput stream) throws IOException{
//TODO implement
byte groups = stream.readByte();
for(int i = 0; i < groups; i++){
int amount = stream.readInt();
for(int j = 0; j < amount; j++){
//TODO throw exception on read fail
readChunk(stream, true, in -> {
byte typeid = in.readByte();
byte version = in.readByte();
//SaveTrait trait = (SaveTrait)content.<TypeID>getByID(ContentType.typeid, typeid).constructor.get();
//trait.readSave(in, version);
});
}
}
}
}
@@ -1,9 +0,0 @@
package mindustry.io.versions;
import mindustry.io.*;
public class Save3 extends SaveVersion{
public Save3(){
super(3);
}
}
+10
View File
@@ -0,0 +1,10 @@
package mindustry.io.versions;
import mindustry.io.*;
public class Save4 extends SaveVersion{
public Save4(){
super(4);
}
}