Barely functional IO

This commit is contained in:
Anuken
2020-02-13 19:26:36 -05:00
parent ad248e2e20
commit e3621f44da
68 changed files with 323 additions and 497 deletions

View File

@@ -5,7 +5,6 @@ import arc.util.serialization.Json.*;
import mindustry.*;
import mindustry.content.*;
import mindustry.ctype.*;
import mindustry.ctype.ContentType;
import mindustry.game.*;
import mindustry.type.*;
import mindustry.world.*;
@@ -69,6 +68,19 @@ public class JsonIO{
json.setElementType(Rules.class, "spawns", SpawnGroup.class);
json.setElementType(Rules.class, "loadout", ItemStack.class);
json.setSerializer(Sector.class, new Serializer<Sector>(){
@Override
public void write(Json json, Sector object, Class knownType){
json.writeValue(object.planet.name + "-" + object.id);
}
@Override
public Sector read(Json json, JsonValue jsonData, Class type){
String[] split = jsonData.asString().split("-");
return Vars.content.<Planet>getByName(ContentType.planet, split[0]).sectors.get(Integer.parseInt(split[1]));
}
});
json.setSerializer(Zone.class, new Serializer<Zone>(){
@Override
public void write(Json json, Zone object, Class knownType){

View File

@@ -186,7 +186,10 @@ public abstract class SaveVersion extends SaveFileReader{
if(tile.entity != null){
try{
readChunk(stream, true, in -> tile.entity.read(in));
readChunk(stream, true, in -> {
byte revision = in.readByte();
tile.entity.read(in, revision);
});
}catch(Exception e){
throw new IOException("Failed to read tile entity of block: " + block, e);
}
@@ -222,7 +225,7 @@ public abstract class SaveVersion extends SaveFileReader{
}
}
stream.writeInt(Groups.sync.size());
stream.writeInt(Groups.sync.count(Entityc::serialize));
for(Syncc entity : Groups.sync){
if(!entity.serialize()) continue;
@@ -251,6 +254,7 @@ public abstract class SaveVersion extends SaveFileReader{
byte typeid = in.readByte();
Syncc sync = (Syncc)EntityMapping.map(typeid).get();
sync.read(in);
sync.add();
});
}
}