Persistent unit IDs

This commit is contained in:
Anuken
2021-11-29 10:02:03 -05:00
parent 117fd3769e
commit e2576f1538
16 changed files with 74 additions and 34 deletions

View File

@@ -0,0 +1,37 @@
package mindustry.io.versions;
import arc.func.*;
import arc.util.io.*;
import mindustry.gen.*;
import mindustry.io.*;
import java.io.*;
/** This version did not read/write entity IDs to the save. */
public class LegacySaveVersion2 extends SaveVersion{
public LegacySaveVersion2(int version){
super(version);
}
@Override
public void readWorldEntities(DataInput stream) throws IOException{
//entityMapping is null in older save versions, so use the default
Prov[] mapping = this.entityMapping == null ? EntityMapping.idMap : this.entityMapping;
int amount = stream.readInt();
for(int j = 0; j < amount; j++){
readChunk(stream, true, in -> {
int typeid = in.readUnsignedByte();
if(mapping[typeid] == null){
in.skipBytes(lastRegionLength - 1);
return;
}
Entityc entity = (Entityc)mapping[typeid].get();
entity.read(Reads.get(in));
entity.add();
});
}
}
}