diff --git a/core/src/io/anuke/mindustry/io/SaveIO.java b/core/src/io/anuke/mindustry/io/SaveIO.java index 916c4ad414..cb79c0222d 100644 --- a/core/src/io/anuke/mindustry/io/SaveIO.java +++ b/core/src/io/anuke/mindustry/io/SaveIO.java @@ -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 versions = new IntMap<>(); - public static final Array versionArray = Array.with(new Save1()); + public static final Array versionArray = Array.with(new Save1(), new Save2()); static{ for(SaveVersion version : versionArray){ diff --git a/core/src/io/anuke/mindustry/io/SaveVersion.java b/core/src/io/anuke/mindustry/io/SaveVersion.java index d48fe46820..87c096b5b3 100644 --- a/core/src/io/anuke/mindustry/io/SaveVersion.java +++ b/core/src/io/anuke/mindustry/io/SaveVersion.java @@ -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++){ diff --git a/core/src/io/anuke/mindustry/io/versions/LegacyTypeTable.java b/core/src/io/anuke/mindustry/io/versions/LegacyTypeTable.java index 52fc77f0c7..6205313247 100644 --- a/core/src/io/anuke/mindustry/io/versions/LegacyTypeTable.java +++ b/core/src/io/anuke/mindustry/io/versions/LegacyTypeTable.java @@ -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; + } + } } diff --git a/core/src/io/anuke/mindustry/io/versions/Save1.java b/core/src/io/anuke/mindustry/io/versions/Save1.java index f9ea40b8ce..545ae99eb2 100644 --- a/core/src/io/anuke/mindustry/io/versions/Save1.java +++ b/core/src/io/anuke/mindustry/io/versions/Save1.java @@ -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); + }); + } + } + } } diff --git a/core/src/io/anuke/mindustry/io/versions/Save2.java b/core/src/io/anuke/mindustry/io/versions/Save2.java new file mode 100644 index 0000000000..66d61964c5 --- /dev/null +++ b/core/src/io/anuke/mindustry/io/versions/Save2.java @@ -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); + } +}