mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-03-13 11:29:48 +07:00
Json cleanup
This commit is contained in:
parent
53e9d4a3e3
commit
3ffa768cfc
@ -8,12 +8,27 @@ import io.anuke.mindustry.game.*;
|
||||
import io.anuke.mindustry.type.*;
|
||||
import io.anuke.mindustry.world.*;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public class JsonIO{
|
||||
private static CustomJson jsonBase = new CustomJson();
|
||||
private static Json json = new Json(){{
|
||||
apply(this);
|
||||
}};
|
||||
private static Json json = new Json(){
|
||||
{ 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){
|
||||
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>(){
|
||||
@Override
|
||||
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>(){
|
||||
@Override
|
||||
public void write(Json json, ItemStack object, Class knownType){
|
||||
|
@ -1,3 +1,3 @@
|
||||
org.gradle.daemon=true
|
||||
org.gradle.jvmargs=-Xms256m -Xmx1024m
|
||||
archash=9ed2c7bd64741309e2ece3fdc15f169862922ef3
|
||||
archash=737a74af85af88ee003a6e5a5c4cbc6f0f375a44
|
||||
|
Loading…
Reference in New Issue
Block a user