mirror of
https://github.com/Anuken/Mindustry.git
synced 2026-10-01 10:40:38 +03:00
Removed writer field from Json
This commit is contained in:
@@ -801,8 +801,8 @@ public class MapObjectives implements Iterable<MapObjective>, Eachable<MapObject
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(Json json){
|
||||
json.writeFields(this);
|
||||
public void write(Json json, JsonWriter writer){
|
||||
json.writeFields(writer, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1431,13 +1431,13 @@ public class MapObjectives implements Iterable<MapObjective>, Eachable<MapObject
|
||||
public Object value = "white";
|
||||
|
||||
@Override
|
||||
public void write(Json json){
|
||||
public void write(Json json, JsonWriter writer){
|
||||
if(value instanceof String s){
|
||||
json.writeValue("string", s);
|
||||
json.writeValue(writer, "string", s);
|
||||
}else if(value instanceof UnlockableContent c){
|
||||
json.writeValue("content", c.name);
|
||||
json.writeValue(writer, "content", c.name);
|
||||
}else if(value instanceof Building b){
|
||||
json.writeValue("building", b.pos());
|
||||
json.writeValue(writer, "building", b.pos());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -417,10 +417,10 @@ public class Rules{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(Json json){
|
||||
public void write(Json json, JsonWriter writer){
|
||||
for(Team team : Team.all){
|
||||
if(values[team.id] != null){
|
||||
json.writeValue(team.id + "", values[team.id], TeamRule.class);
|
||||
json.writeValue(writer, team.id + "", values[team.id], TeamRule.class);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -109,22 +109,22 @@ public class SpawnGroup implements JsonSerializable, Cloneable{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(Json json){
|
||||
public void write(Json json, JsonWriter writer){
|
||||
if(type == null) type = UnitTypes.dagger;
|
||||
json.writeValue("type", type.name);
|
||||
if(begin != 0) json.writeValue("begin", begin);
|
||||
if(end != never) json.writeValue("end", end);
|
||||
if(spacing != 1) json.writeValue("spacing", spacing);
|
||||
if(max != 40) json.writeValue("max", max);
|
||||
if(unitScaling != never) json.writeValue("scaling", unitScaling);
|
||||
if(shields != 0) json.writeValue("shields", shields);
|
||||
if(shieldScaling != 0) json.writeValue("shieldScaling", shieldScaling);
|
||||
if(unitAmount != 1) json.writeValue("amount", unitAmount);
|
||||
if(effect != null) json.writeValue("effect", effect.name);
|
||||
if(spawn != -1) json.writeValue("spawn", spawn);
|
||||
if(payloads != null && payloads.any()) json.writeValue("payloads", payloads.map(u -> u.name).toArray(String.class));
|
||||
if(items != null && items.amount > 0) json.writeValue("items", items);
|
||||
if(team != null) json.writeValue("team", team.id);
|
||||
json.writeValue(writer, "type", type.name);
|
||||
if(begin != 0) json.writeValue(writer, "begin", begin);
|
||||
if(end != never) json.writeValue(writer, "end", end);
|
||||
if(spacing != 1) json.writeValue(writer, "spacing", spacing);
|
||||
if(max != 40) json.writeValue(writer, "max", max);
|
||||
if(unitScaling != never) json.writeValue(writer, "scaling", unitScaling);
|
||||
if(shields != 0) json.writeValue(writer, "shields", shields);
|
||||
if(shieldScaling != 0) json.writeValue(writer, "shieldScaling", shieldScaling);
|
||||
if(unitAmount != 1) json.writeValue(writer, "amount", unitAmount);
|
||||
if(effect != null) json.writeValue(writer, "effect", effect.name);
|
||||
if(spawn != -1) json.writeValue(writer, "spawn", spawn);
|
||||
if(payloads != null && payloads.any()) json.writeValue(writer, "payloads", payloads.map(u -> u.name).toArray(String.class));
|
||||
if(items != null && items.amount > 0) json.writeValue(writer, "items", items);
|
||||
if(team != null) json.writeValue(writer, "team", team.id);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -23,15 +23,11 @@ import java.io.*;
|
||||
public class JsonIO{
|
||||
public static final Json json = new Json(){
|
||||
@Override
|
||||
public void writeValue(Object value, Class knownType, Class elementType){
|
||||
public void writeValue(JsonWriter writer, Object value, Class knownType, Class elementType){
|
||||
if(value instanceof MappableContent c){
|
||||
try{
|
||||
writer.value(c.name);
|
||||
}catch(IOException e){
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
writer.value(c.name);
|
||||
}else{
|
||||
super.writeValue(value, knownType, elementType);
|
||||
super.writeValue(writer, value, knownType, elementType);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,20 +36,10 @@ public class JsonIO{
|
||||
if(object instanceof MappableContent c) return c.name;
|
||||
return super.convertToString(object);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected <T> Class<T> resolveClass(String className){
|
||||
Class<T> result = super.resolveClass(className);
|
||||
if(Serializable.class.isAssignableFrom(result) || JsonSerializable.class.isAssignableFrom(result)){
|
||||
return result;
|
||||
}
|
||||
throw new SerializationException("Class deserialization not allowed: " + result);
|
||||
}
|
||||
};
|
||||
|
||||
public static void writeBytes(Object value, Class<?> elementType, DataOutputStream output){
|
||||
json.setWriter(new UBJsonWriter(output));
|
||||
json.writeValue(value, value == null ? null : value.getClass(), elementType);
|
||||
json.toUBJson(value, value == null ? null : value.getClass(), elementType, output);
|
||||
}
|
||||
|
||||
public static <T> T readBytes(Class<T> type, Class<?> elementType, DataInputStream input) throws IOException{
|
||||
@@ -96,8 +82,8 @@ public class JsonIO{
|
||||
|
||||
json.setSerializer(MusicContainer.class, new JsonSerializer<>(){
|
||||
@Override
|
||||
public void write(Json json, MusicContainer object, Class knownType){
|
||||
json.writeValue(object.name);
|
||||
public void write(Json json, JsonWriter writer, MusicContainer object, Class knownType){
|
||||
json.writeValue(writer, object.name);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -108,8 +94,8 @@ public class JsonIO{
|
||||
|
||||
json.setSerializer(Color.class, new JsonSerializer<>(){
|
||||
@Override
|
||||
public void write(Json json, Color object, Class knownType){
|
||||
json.writeValue(object.toString());
|
||||
public void write(Json json, JsonWriter writer, Color object, Class knownType){
|
||||
json.writeValue(writer, object.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -125,8 +111,8 @@ public class JsonIO{
|
||||
|
||||
json.setSerializer(Sector.class, new JsonSerializer<>(){
|
||||
@Override
|
||||
public void write(Json json, Sector object, Class knownType){
|
||||
json.writeValue(object.planet.name + "-" + object.id);
|
||||
public void write(Json json, JsonWriter writer, Sector object, Class knownType){
|
||||
json.writeValue(writer, object.planet.name + "-" + object.id);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -139,8 +125,8 @@ public class JsonIO{
|
||||
|
||||
json.setSerializer(SectorPreset.class, new JsonSerializer<>(){
|
||||
@Override
|
||||
public void write(Json json, SectorPreset object, Class knownType){
|
||||
json.writeValue(object.name);
|
||||
public void write(Json json, JsonWriter writer, SectorPreset object, Class knownType){
|
||||
json.writeValue(writer, object.name);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -151,8 +137,8 @@ public class JsonIO{
|
||||
|
||||
json.setSerializer(Liquid.class, new JsonSerializer<>(){
|
||||
@Override
|
||||
public void write(Json json, Liquid object, Class knownType){
|
||||
json.writeValue(object.name);
|
||||
public void write(Json json, JsonWriter writer, Liquid object, Class knownType){
|
||||
json.writeValue(writer, object.name);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -165,8 +151,8 @@ public class JsonIO{
|
||||
|
||||
json.setSerializer(Attribute.class, new JsonSerializer<>(){
|
||||
@Override
|
||||
public void write(Json json, Attribute object, Class knownType){
|
||||
json.writeValue(object.name);
|
||||
public void write(Json json, JsonWriter writer, Attribute object, Class knownType){
|
||||
json.writeValue(writer, object.name);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -177,8 +163,8 @@ public class JsonIO{
|
||||
|
||||
json.setSerializer(Item.class, new JsonSerializer<>(){
|
||||
@Override
|
||||
public void write(Json json, Item object, Class knownType){
|
||||
json.writeValue(object.name);
|
||||
public void write(Json json, JsonWriter writer, Item object, Class knownType){
|
||||
json.writeValue(writer, object.name);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -191,8 +177,8 @@ public class JsonIO{
|
||||
|
||||
json.setSerializer(Team.class, new JsonSerializer<>(){
|
||||
@Override
|
||||
public void write(Json json, Team object, Class knownType){
|
||||
json.writeValue(object.id);
|
||||
public void write(Json json, JsonWriter writer, Team object, Class knownType){
|
||||
json.writeValue(writer, object.id);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -203,8 +189,8 @@ public class JsonIO{
|
||||
|
||||
json.setSerializer(Block.class, new JsonSerializer<>(){
|
||||
@Override
|
||||
public void write(Json json, Block object, Class knownType){
|
||||
json.writeValue(object.name);
|
||||
public void write(Json json, JsonWriter writer, Block object, Class knownType){
|
||||
json.writeValue(writer, object.name);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -217,8 +203,8 @@ public class JsonIO{
|
||||
|
||||
json.setSerializer(Planet.class, new JsonSerializer<>(){
|
||||
@Override
|
||||
public void write(Json json, Planet object, Class knownType){
|
||||
json.writeValue(object.name);
|
||||
public void write(Json json, JsonWriter writer, Planet object, Class knownType){
|
||||
json.writeValue(writer, object.name);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -233,8 +219,8 @@ public class JsonIO{
|
||||
|
||||
json.setSerializer(Weather.class, new JsonSerializer<>(){
|
||||
@Override
|
||||
public void write(Json json, Weather object, Class knownType){
|
||||
json.writeValue(object.name);
|
||||
public void write(Json json, JsonWriter writer, Weather object, Class knownType){
|
||||
json.writeValue(writer, object.name);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -245,8 +231,8 @@ public class JsonIO{
|
||||
|
||||
json.setSerializer(UnitType.class, new JsonSerializer<>(){
|
||||
@Override
|
||||
public void write(Json json, UnitType object, Class knownType){
|
||||
json.writeValue(object.name);
|
||||
public void write(Json json, JsonWriter writer, UnitType object, Class knownType){
|
||||
json.writeValue(writer, object.name);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -259,11 +245,11 @@ public class JsonIO{
|
||||
|
||||
json.setSerializer(ItemStack.class, new JsonSerializer<>(){
|
||||
@Override
|
||||
public void write(Json json, ItemStack object, Class knownType){
|
||||
json.writeObjectStart();
|
||||
json.writeValue("item", object.item);
|
||||
json.writeValue("amount", object.amount);
|
||||
json.writeObjectEnd();
|
||||
public void write(Json json, JsonWriter writer, ItemStack object, Class knownType){
|
||||
writer.writeObjectStart();
|
||||
json.writeValue(writer, "item", object.item);
|
||||
json.writeValue(writer, "amount", object.amount);
|
||||
writer.writeObjectEnd();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -274,8 +260,8 @@ public class JsonIO{
|
||||
|
||||
json.setSerializer(UnlockableContent.class, new JsonSerializer<>(){
|
||||
@Override
|
||||
public void write(Json json, UnlockableContent object, Class knownType){
|
||||
json.writeValue(object == null ? null : object.name);
|
||||
public void write(Json json, JsonWriter writer, UnlockableContent object, Class knownType){
|
||||
json.writeValue(writer, object == null ? null : object.name);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -289,24 +275,24 @@ public class JsonIO{
|
||||
|
||||
json.setSerializer(MapObjectives.class, new JsonSerializer<>(){
|
||||
@Override
|
||||
public void write(Json json, MapObjectives exec, Class knownType){
|
||||
json.writeArrayStart();
|
||||
public void write(Json json, JsonWriter writer, MapObjectives exec, Class knownType){
|
||||
writer.writeArrayStart();
|
||||
for(var obj : exec){
|
||||
json.writeObjectStart(obj.getClass().isAnonymousClass() ? obj.getClass().getSuperclass() : obj.getClass(), null);
|
||||
json.writeFields(obj);
|
||||
json.writeObjectStart(writer, obj.getClass().isAnonymousClass() ? obj.getClass().getSuperclass() : obj.getClass(), null);
|
||||
json.writeFields(writer, obj);
|
||||
|
||||
json.writeArrayStart("parents");
|
||||
writer.writeArrayStart("parents");
|
||||
for(var parent : obj.parents){
|
||||
json.writeValue(exec.all.indexOf(parent));
|
||||
json.writeValue(writer, exec.all.indexOf(parent));
|
||||
}
|
||||
|
||||
json.writeArrayEnd();
|
||||
writer.writeArrayEnd();
|
||||
|
||||
json.writeValue("editorPos", Point2.pack(obj.editorX, obj.editorY));
|
||||
json.writeObjectEnd();
|
||||
json.writeValue(writer, "editorPos", Point2.pack(obj.editorX, obj.editorY));
|
||||
json.writeObjectEnd(writer);
|
||||
}
|
||||
|
||||
json.writeArrayEnd();
|
||||
writer.writeArrayEnd();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -57,10 +57,10 @@ public class LogicScript implements JsonSerializable{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(Json json){
|
||||
json.writeValue("script", script);
|
||||
if(timeout > 0) json.writeValue("timeout", timeout);
|
||||
if(resetVars) json.writeValue("resetVars", resetVars);
|
||||
public void write(Json json, JsonWriter writer){
|
||||
json.writeValue(writer, "script", script);
|
||||
if(timeout > 0) json.writeValue(writer, "timeout", timeout);
|
||||
if(resetVars) json.writeValue(writer, "resetVars", resetVars);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -366,15 +366,17 @@ public class Maps{
|
||||
if(groups == null) return "[]";
|
||||
|
||||
StringWriter buffer = new StringWriter();
|
||||
JsonIO.json.setWriter(new StringJsonWriter(buffer));
|
||||
StringJsonWriter writer = new StringJsonWriter(buffer);
|
||||
|
||||
writer.writeArrayStart();
|
||||
|
||||
JsonIO.json.writeArrayStart();
|
||||
for(int i = 0; i < groups.size; i++){
|
||||
JsonIO.json.writeObjectStart(SpawnGroup.class, SpawnGroup.class);
|
||||
groups.get(i).write(JsonIO.json);
|
||||
JsonIO.json.writeObjectEnd();
|
||||
JsonIO.json.writeObjectStart(writer, SpawnGroup.class, SpawnGroup.class);
|
||||
groups.get(i).write(JsonIO.json, writer);
|
||||
JsonIO.json.writeObjectEnd(writer);
|
||||
}
|
||||
JsonIO.json.writeArrayEnd();
|
||||
|
||||
writer.writeArrayEnd();
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
|
||||
@@ -141,10 +141,10 @@ public class ItemSeq implements Iterable<ItemStack>, JsonSerializable{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(Json json){
|
||||
public void write(Json json, JsonWriter writer){
|
||||
for(Item item : Vars.content.items()){
|
||||
if(values[item.id] != 0){
|
||||
json.writeValue(item.name, values[item.id]);
|
||||
json.writeValue(writer, item.name, values[item.id]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,9 +12,9 @@ import static arc.Core.*;
|
||||
public class MapLocales extends ObjectMap<String, StringMap> implements JsonSerializable{
|
||||
|
||||
@Override
|
||||
public void write(Json json){
|
||||
public void write(Json json, JsonWriter writer){
|
||||
for(var entry : entries()){
|
||||
json.writeValue(entry.key, entry.value, StringMap.class, String.class);
|
||||
json.writeValue(writer, entry.key, entry.value, StringMap.class, String.class);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -40,11 +40,11 @@ public class Attributes implements JsonSerializable{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(Json json){
|
||||
public void write(Json json, JsonWriter writer){
|
||||
check();
|
||||
for(Attribute at : Attribute.all){
|
||||
if(arr[at.id] != 0){
|
||||
json.writeValue(at.name, arr[at.id]);
|
||||
json.writeValue(writer, at.name, arr[at.id]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -26,4 +26,4 @@ org.gradle.caching=true
|
||||
org.gradle.internal.http.socketTimeout=100000
|
||||
org.gradle.internal.http.connectionTimeout=100000
|
||||
android.enableR8.fullMode=false
|
||||
archash=f02370b666
|
||||
archash=df6eb7c8b8
|
||||
|
||||
Reference in New Issue
Block a user