Bugfixes
This commit is contained in:
@@ -170,8 +170,10 @@ public class EntityGroup<T extends Entity>{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void clear(){
|
public void clear(){
|
||||||
for(T entity : entityArray)
|
for(T entity : entityArray){
|
||||||
|
entity.removed();
|
||||||
entity.setGroup(null);
|
entity.setGroup(null);
|
||||||
|
}
|
||||||
|
|
||||||
for(T entity : entitiesToAdd)
|
for(T entity : entitiesToAdd)
|
||||||
entity.setGroup(null);
|
entity.setGroup(null);
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package io.anuke.mindustry.io;
|
|||||||
|
|
||||||
import io.anuke.arc.collection.*;
|
import io.anuke.arc.collection.*;
|
||||||
import io.anuke.arc.util.serialization.*;
|
import io.anuke.arc.util.serialization.*;
|
||||||
|
import io.anuke.arc.util.serialization.Json.*;
|
||||||
import io.anuke.mindustry.*;
|
import io.anuke.mindustry.*;
|
||||||
import io.anuke.mindustry.content.*;
|
import io.anuke.mindustry.content.*;
|
||||||
import io.anuke.mindustry.game.*;
|
import io.anuke.mindustry.game.*;
|
||||||
@@ -11,10 +12,13 @@ import io.anuke.mindustry.world.*;
|
|||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public class JsonIO{
|
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){
|
public static String write(Object object){
|
||||||
return json.toJson(object);
|
return json.toJson(object, object.getClass());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T> T copy(T object){
|
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){
|
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){
|
public static String print(String in){
|
||||||
return json.prettyPrint(in);
|
return json.prettyPrint(in);
|
||||||
}
|
}
|
||||||
|
|
||||||
static class CustomJson extends Json{
|
private static void apply(Json json){
|
||||||
private Object baseObject;
|
json.setIgnoreUnknownFields(true);
|
||||||
|
json.setElementType(Rules.class, "spawns", SpawnGroup.class);
|
||||||
|
json.setElementType(Rules.class, "loadout", ItemStack.class);
|
||||||
|
|
||||||
{
|
json.setSerializer(Zone.class, new Serializer<Zone>(){
|
||||||
setIgnoreUnknownFields(true);
|
|
||||||
setElementType(Rules.class, "spawns", SpawnGroup.class);
|
|
||||||
setElementType(Rules.class, "loadout", ItemStack.class);
|
|
||||||
|
|
||||||
setSerializer(Zone.class, new Serializer<Zone>(){
|
|
||||||
@Override
|
@Override
|
||||||
public void write(Json json, Zone object, Class knownType){
|
public void write(Json json, Zone object, Class knownType){
|
||||||
json.writeValue(object.name);
|
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
|
@Override
|
||||||
public void write(Json json, Item object, Class knownType){
|
public void write(Json json, Item object, Class knownType){
|
||||||
json.writeValue(object.name);
|
json.writeValue(object.name);
|
||||||
@@ -72,7 +73,7 @@ public class JsonIO{
|
|||||||
Class type = block.getClass();
|
Class type = block.getClass();
|
||||||
if(type.isAnonymousClass()) type = type.getSuperclass();
|
if(type.isAnonymousClass()) type = type.getSuperclass();
|
||||||
|
|
||||||
setSerializer(type, new Serializer<Block>(){
|
json.setSerializer(type, new Serializer<Block>(){
|
||||||
@Override
|
@Override
|
||||||
public void write(Json json, Block object, Class knownType){
|
public void write(Json json, Block object, Class knownType){
|
||||||
json.writeValue(object.name);
|
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
|
@Override
|
||||||
public void write(Json json, Block object, Class knownType){
|
public void write(Json json, Block object, Class knownType){
|
||||||
json.writeValue(object.name);
|
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
|
@Override
|
||||||
public void write(Json json, TeamData object, Class knownType){
|
public void write(Json json, TeamData object, Class knownType){
|
||||||
json.writeObjectStart();
|
json.writeObjectStart();
|
||||||
@@ -116,7 +117,7 @@ public class JsonIO{
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
setSerializer(ItemStack.class, new Serializer<ItemStack>(){
|
json.setSerializer(ItemStack.class, new Serializer<ItemStack>(){
|
||||||
@Override
|
@Override
|
||||||
public void write(Json json, ItemStack object, Class knownType){
|
public void write(Json json, ItemStack object, Class knownType){
|
||||||
json.writeObjectStart();
|
json.writeObjectStart();
|
||||||
@@ -132,6 +133,13 @@ public class JsonIO{
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static class CustomJson extends Json{
|
||||||
|
private Object baseObject;
|
||||||
|
|
||||||
|
{
|
||||||
|
apply(this);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <T> T fromJson(Class<T> type, String json){
|
public <T> T fromJson(Class<T> type, String json){
|
||||||
return fromBaseJson(type, null, json);
|
return fromBaseJson(type, null, json);
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ import io.anuke.mindustry.entities.type.Player;
|
|||||||
import io.anuke.mindustry.game.*;
|
import io.anuke.mindustry.game.*;
|
||||||
import io.anuke.mindustry.game.EventType.GameOverEvent;
|
import io.anuke.mindustry.game.EventType.GameOverEvent;
|
||||||
import io.anuke.mindustry.gen.Call;
|
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.Map;
|
||||||
import io.anuke.mindustry.maps.MapException;
|
import io.anuke.mindustry.maps.MapException;
|
||||||
import io.anuke.mindustry.net.Administration.PlayerInfo;
|
import io.anuke.mindustry.net.Administration.PlayerInfo;
|
||||||
|
|||||||
Reference in New Issue
Block a user