Make custom Env flag reliably possible (#8019)
* Make custom Env flag reliably possible * screw you * "compatibility" for mods that don't use add()
This commit is contained in:
@@ -2,6 +2,7 @@ package mindustry.io;
|
||||
|
||||
import arc.graphics.*;
|
||||
import arc.math.geom.*;
|
||||
import arc.struct.*;
|
||||
import arc.util.*;
|
||||
import arc.util.serialization.*;
|
||||
import arc.util.serialization.Json.*;
|
||||
@@ -78,6 +79,30 @@ public class JsonIO{
|
||||
json.setElementType(Rules.class, "spawns", SpawnGroup.class);
|
||||
json.setElementType(Rules.class, "loadout", ItemStack.class);
|
||||
|
||||
json.setSerializer(Rules.class, new Serializer<>(){
|
||||
@Override
|
||||
public void write(Json json, Rules object, Class knownType){
|
||||
json.writeObjectStart();
|
||||
json.writeFields(object);
|
||||
json.writeValue("envMapping", Env.idToName, IntMap.class);
|
||||
json.writeObjectEnd();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Rules read(Json json, JsonValue jsonData, Class type){
|
||||
Rules out = new Rules();
|
||||
json.readFields(out, jsonData);
|
||||
|
||||
// Older Rules data doesn't have env mapping.
|
||||
if(jsonData.has("envMapping")){
|
||||
IntMap<String> idToName = json.readValue(IntMap.class, jsonData.get("envMapping"));
|
||||
out.env = Env.remap(out.env, idToName);
|
||||
}
|
||||
|
||||
return out;
|
||||
}
|
||||
});
|
||||
|
||||
json.setSerializer(Color.class, new Serializer<>(){
|
||||
@Override
|
||||
public void write(Json json, Color object, Class knownType){
|
||||
|
||||
Reference in New Issue
Block a user