Json cleanup

This commit is contained in:
Anuken
2019-10-14 17:36:58 -04:00
parent 53e9d4a3e3
commit 3ffa768cfc
2 changed files with 19 additions and 42 deletions

View File

@@ -8,12 +8,27 @@ import io.anuke.mindustry.game.*;
import io.anuke.mindustry.type.*; import io.anuke.mindustry.type.*;
import io.anuke.mindustry.world.*; import io.anuke.mindustry.world.*;
import java.io.*;
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public class JsonIO{ public class JsonIO{
private static CustomJson jsonBase = new CustomJson(); private static CustomJson jsonBase = new CustomJson();
private static Json json = new Json(){{ private static Json json = new Json(){
apply(this); { apply(this); }
}};
@Override
public void writeValue(Object value, Class knownType, Class elementType){
if(value instanceof MappableContent){
try{
getWriter().value(((MappableContent)value).name);
}catch(IOException e){
throw new RuntimeException(e);
}
}else{
super.writeValue(value, knownType, elementType);
}
}
};
public static String write(Object object){ public static String write(Object object){
return json.toJson(object, object.getClass()); return json.toJson(object, object.getClass());
@@ -66,24 +81,6 @@ public class JsonIO{
} }
}); });
//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
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());
}
});
}
json.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){
@@ -96,26 +93,6 @@ public class JsonIO{
} }
}); });
/*
json.setSerializer(TeamData.class, new Serializer<TeamData>(){
@Override
public void write(Json json, TeamData object, Class knownType){
json.writeObjectStart();
json.writeValue("brokenBlocks", object.brokenBlocks.toArray());
json.writeValue("team", object.team.ordinal());
json.writeObjectEnd();
}
@Override
public TeamData read(Json json, JsonValue jsonData, Class type){
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>(){ 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){

View File

@@ -1,3 +1,3 @@
org.gradle.daemon=true org.gradle.daemon=true
org.gradle.jvmargs=-Xms256m -Xmx1024m org.gradle.jvmargs=-Xms256m -Xmx1024m
archash=9ed2c7bd64741309e2ece3fdc15f169862922ef3 archash=737a74af85af88ee003a6e5a5c4cbc6f0f375a44