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,66 +30,50 @@ 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);
|
@Override
|
||||||
setElementType(Rules.class, "spawns", SpawnGroup.class);
|
public void write(Json json, Zone object, Class knownType){
|
||||||
setElementType(Rules.class, "loadout", ItemStack.class);
|
json.writeValue(object.name);
|
||||||
|
|
||||||
setSerializer(Zone.class, new Serializer<Zone>(){
|
|
||||||
@Override
|
|
||||||
public void write(Json json, Zone object, Class knownType){
|
|
||||||
json.writeValue(object.name);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Zone read(Json json, JsonValue jsonData, Class type){
|
|
||||||
return Vars.content.getByName(ContentType.zone, jsonData.asString());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
setSerializer(Item.class, new Serializer<Item>(){
|
|
||||||
@Override
|
|
||||||
public void write(Json json, Item object, Class knownType){
|
|
||||||
json.writeValue(object.name);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Item read(Json json, JsonValue jsonData, Class type){
|
|
||||||
if(jsonData.asString() == null) return Items.copper;
|
|
||||||
Item i = Vars.content.getByName(ContentType.item, jsonData.asString());
|
|
||||||
return i == null ? Items.copper : i;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
//TODO extremely hacky and disgusting
|
|
||||||
for(Block block : Vars.content.blocks()){
|
|
||||||
Class type = block.getClass();
|
|
||||||
if(type.isAnonymousClass()) type = type.getSuperclass();
|
|
||||||
|
|
||||||
setSerializer(type, new Serializer<Block>(){
|
|
||||||
@Override
|
|
||||||
public void write(Json json, Block object, Class knownType){
|
|
||||||
json.writeValue(object.name);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Block read(Json json, JsonValue jsonData, Class type){
|
|
||||||
return Vars.content.getByName(ContentType.block, jsonData.asString());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
setSerializer(Block.class, new Serializer<Block>(){
|
@Override
|
||||||
|
public Zone read(Json json, JsonValue jsonData, Class type){
|
||||||
|
return Vars.content.getByName(ContentType.zone, jsonData.asString());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
json.setSerializer(Item.class, new Serializer<Item>(){
|
||||||
|
@Override
|
||||||
|
public void write(Json json, Item object, Class knownType){
|
||||||
|
json.writeValue(object.name);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Item read(Json json, JsonValue jsonData, Class type){
|
||||||
|
if(jsonData.asString() == null) return Items.copper;
|
||||||
|
Item i = Vars.content.getByName(ContentType.item, jsonData.asString());
|
||||||
|
return i == null ? Items.copper : i;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
//TODO extremely hacky and disgusting
|
||||||
|
for(Block block : Vars.content.blocks()){
|
||||||
|
Class type = block.getClass();
|
||||||
|
if(type.isAnonymousClass()) type = type.getSuperclass();
|
||||||
|
|
||||||
|
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);
|
||||||
@@ -96,40 +84,60 @@ public class JsonIO{
|
|||||||
return Vars.content.getByName(ContentType.block, jsonData.asString());
|
return Vars.content.getByName(ContentType.block, jsonData.asString());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
setSerializer(TeamData.class, new Serializer<TeamData>(){
|
json.setSerializer(Block.class, new Serializer<Block>(){
|
||||||
@Override
|
@Override
|
||||||
public void write(Json json, TeamData object, Class knownType){
|
public void write(Json json, Block object, Class knownType){
|
||||||
json.writeObjectStart();
|
json.writeValue(object.name);
|
||||||
json.writeValue("brokenBlocks", object.brokenBlocks.toArray());
|
}
|
||||||
json.writeValue("team", object.team.ordinal());
|
|
||||||
json.writeObjectEnd();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TeamData read(Json json, JsonValue jsonData, Class type){
|
public Block read(Json json, JsonValue jsonData, Class type){
|
||||||
long[] blocks = jsonData.get("brokenBlocks").asLongArray();
|
return Vars.content.getByName(ContentType.block, jsonData.asString());
|
||||||
Team team = Team.all[jsonData.getInt("team", 0)];
|
}
|
||||||
TeamData out = new TeamData(team, EnumSet.of(new Team[]{}));
|
});
|
||||||
out.brokenBlocks = new LongQueue(blocks);
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
setSerializer(ItemStack.class, new Serializer<ItemStack>(){
|
json.setSerializer(TeamData.class, new Serializer<TeamData>(){
|
||||||
@Override
|
@Override
|
||||||
public void write(Json json, ItemStack object, Class knownType){
|
public void write(Json json, TeamData object, Class knownType){
|
||||||
json.writeObjectStart();
|
json.writeObjectStart();
|
||||||
json.writeValue("item", object.item);
|
json.writeValue("brokenBlocks", object.brokenBlocks.toArray());
|
||||||
json.writeValue("amount", object.amount);
|
json.writeValue("team", object.team.ordinal());
|
||||||
json.writeObjectEnd();
|
json.writeObjectEnd();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ItemStack read(Json json, JsonValue jsonData, Class type){
|
public TeamData read(Json json, JsonValue jsonData, Class type){
|
||||||
return new ItemStack(json.getSerializer(Item.class).read(json, jsonData.get("item"), Item.class), jsonData.getInt("amount"));
|
long[] blocks = jsonData.get("brokenBlocks").asLongArray();
|
||||||
}
|
Team team = Team.all[jsonData.getInt("team", 0)];
|
||||||
});
|
TeamData out = new TeamData(team, EnumSet.of(new Team[]{}));
|
||||||
|
out.brokenBlocks = new LongQueue(blocks);
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
json.setSerializer(ItemStack.class, new Serializer<ItemStack>(){
|
||||||
|
@Override
|
||||||
|
public void write(Json json, ItemStack object, Class knownType){
|
||||||
|
json.writeObjectStart();
|
||||||
|
json.writeValue("item", object.item);
|
||||||
|
json.writeValue("amount", object.amount);
|
||||||
|
json.writeObjectEnd();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ItemStack read(Json json, JsonValue jsonData, Class type){
|
||||||
|
return new ItemStack(json.getSerializer(Item.class).read(json, jsonData.get("item"), Item.class), jsonData.getInt("amount"));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
static class CustomJson extends Json{
|
||||||
|
private Object baseObject;
|
||||||
|
|
||||||
|
{
|
||||||
|
apply(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -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