This commit is contained in:
Anuken
2019-08-13 18:15:40 -04:00
parent 335b6ae0cc
commit 84786c12d8
3 changed files with 95 additions and 85 deletions

View File

@ -170,8 +170,10 @@ public class EntityGroup<T extends Entity>{
}
public void clear(){
for(T entity : entityArray)
for(T entity : entityArray){
entity.removed();
entity.setGroup(null);
}
for(T entity : entitiesToAdd)
entity.setGroup(null);

View File

@ -2,6 +2,7 @@ package io.anuke.mindustry.io;
import io.anuke.arc.collection.*;
import io.anuke.arc.util.serialization.*;
import io.anuke.arc.util.serialization.Json.*;
import io.anuke.mindustry.*;
import io.anuke.mindustry.content.*;
import io.anuke.mindustry.game.*;
@ -11,10 +12,13 @@ import io.anuke.mindustry.world.*;
@SuppressWarnings("unchecked")
public class JsonIO{
private static CustomJson json = new CustomJson();
private static CustomJson jsonBase = new CustomJson();
private static Json json = new Json(){{
apply(this);
}};
public static String write(Object object){
return json.toJson(object);
return json.toJson(object, object.getClass());
}
public static <T> T copy(T object){
@ -26,22 +30,19 @@ public class JsonIO{
}
public static <T> T read(Class<T> type, T base, String string){
return json.fromBaseJson(type, base, string);
return jsonBase.fromBaseJson(type, base, string);
}
public static String print(String in){
return json.prettyPrint(in);
}
static class CustomJson extends Json{
private Object baseObject;
private static void apply(Json json){
json.setIgnoreUnknownFields(true);
json.setElementType(Rules.class, "spawns", SpawnGroup.class);
json.setElementType(Rules.class, "loadout", ItemStack.class);
{
setIgnoreUnknownFields(true);
setElementType(Rules.class, "spawns", SpawnGroup.class);
setElementType(Rules.class, "loadout", ItemStack.class);
setSerializer(Zone.class, new Serializer<Zone>(){
json.setSerializer(Zone.class, new Serializer<Zone>(){
@Override
public void write(Json json, Zone object, Class knownType){
json.writeValue(object.name);
@ -53,7 +54,7 @@ public class JsonIO{
}
});
setSerializer(Item.class, new Serializer<Item>(){
json.setSerializer(Item.class, new Serializer<Item>(){
@Override
public void write(Json json, Item object, Class knownType){
json.writeValue(object.name);
@ -72,7 +73,7 @@ public class JsonIO{
Class type = block.getClass();
if(type.isAnonymousClass()) type = type.getSuperclass();
setSerializer(type, new Serializer<Block>(){
json.setSerializer(type, new Serializer<Block>(){
@Override
public void write(Json json, Block object, Class knownType){
json.writeValue(object.name);
@ -85,7 +86,7 @@ public class JsonIO{
});
}
setSerializer(Block.class, new Serializer<Block>(){
json.setSerializer(Block.class, new Serializer<Block>(){
@Override
public void write(Json json, Block object, Class knownType){
json.writeValue(object.name);
@ -97,7 +98,7 @@ public class JsonIO{
}
});
setSerializer(TeamData.class, new Serializer<TeamData>(){
json.setSerializer(TeamData.class, new Serializer<TeamData>(){
@Override
public void write(Json json, TeamData object, Class knownType){
json.writeObjectStart();
@ -116,7 +117,7 @@ public class JsonIO{
}
});
setSerializer(ItemStack.class, new Serializer<ItemStack>(){
json.setSerializer(ItemStack.class, new Serializer<ItemStack>(){
@Override
public void write(Json json, ItemStack object, Class knownType){
json.writeObjectStart();
@ -132,6 +133,13 @@ public class JsonIO{
});
}
static class CustomJson extends Json{
private Object baseObject;
{
apply(this);
}
@Override
public <T> T fromJson(Class<T> type, String json){
return fromBaseJson(type, null, json);

View File

@ -14,7 +14,7 @@ import io.anuke.mindustry.entities.type.Player;
import io.anuke.mindustry.game.*;
import io.anuke.mindustry.game.EventType.GameOverEvent;
import io.anuke.mindustry.gen.Call;
import io.anuke.mindustry.io.SaveIO;
import io.anuke.mindustry.io.*;
import io.anuke.mindustry.maps.Map;
import io.anuke.mindustry.maps.MapException;
import io.anuke.mindustry.net.Administration.PlayerInfo;