Tree-like objective node structure (#7152)

* overall structure

* overall layout

* field interpreter

* less bloated UI

* scroll pan't

* strip off the 'Marker' suffix

* e

* all (hopefully all...) interpreters finished.

* onset

* two, four

* i don't understand how icon mappings work.

* separate remover and indexer

* some cleanups

* untested mobile support

* contrib

* ok anuke

* fix conflicts 2

* hidden
This commit is contained in:
GlennFolker
2022-07-15 21:41:18 +07:00
committed by GitHub
parent 3b1c8baca9
commit 695c19d0b0
26 changed files with 1733 additions and 810 deletions

View File

@@ -1,6 +1,7 @@
package mindustry.io;
import arc.graphics.*;
import arc.math.geom.*;
import arc.util.*;
import arc.util.serialization.*;
import arc.util.serialization.Json.*;
@@ -8,6 +9,7 @@ import mindustry.*;
import mindustry.content.*;
import mindustry.ctype.*;
import mindustry.game.*;
import mindustry.game.MapObjectives.*;
import mindustry.maps.*;
import mindustry.type.*;
import mindustry.world.*;
@@ -24,9 +26,9 @@ public class JsonIO{
@Override
public void writeValue(Object value, Class knownType, Class elementType){
if(value instanceof MappableContent){
if(value instanceof MappableContent c){
try{
getWriter().value(((MappableContent)value).name);
getWriter().value(c.name);
}catch(IOException e){
throw new RuntimeException(e);
}
@@ -37,9 +39,7 @@ public class JsonIO{
@Override
protected String convertToString(Object object){
if(object instanceof MappableContent){
return ((MappableContent)object).name;
}
if(object instanceof MappableContent c) return c.name;
return super.convertToString(object);
}
};
@@ -69,6 +69,11 @@ public class JsonIO{
return json.prettyPrint(in);
}
public static void classTag(String tag, Class<?> type){
json.addClassTag(tag, type);
jsonBase.addClassTag(tag, type);
}
static void apply(Json json){
json.setElementType(Rules.class, "spawns", SpawnGroup.class);
json.setElementType(Rules.class, "loadout", ItemStack.class);
@@ -255,23 +260,61 @@ public class JsonIO{
}
});
json.setSerializer(MapObjectives.class, new Serializer<>(){
@Override
public void write(Json json, MapObjectives exec, Class knownType){
json.writeArrayStart();
for(var obj : exec){
json.writeObjectStart(obj.getClass().isAnonymousClass() ? obj.getClass().getSuperclass() : obj.getClass(), null);
json.writeFields(obj);
json.writeArrayStart("parents");
for(var parent : obj.parents){
json.writeValue(exec.all.indexOf(parent));
}
json.writeArrayEnd();
json.writeValue("editorPos", Point2.pack(obj.editorX, obj.editorY));
json.writeObjectEnd();
}
json.writeArrayEnd();
}
@Override
public MapObjectives read(Json json, JsonValue data, Class type){
var exec = new MapObjectives();
// First iteration to instantiate the objectives.
for(var value = data.child; value != null; value = value.next){
MapObjective obj = json.readValue(MapObjective.class, value);
int pos = value.getInt("editorPos");
obj.editorX = Point2.x(pos);
obj.editorY = Point2.y(pos);
exec.all.add(obj);
}
// Second iteration to map the parents.
int i = 0;
for(var value = data.child; value != null; value = value.next, i++){
for(var parent = value.get("parents").child; parent != null; parent = parent.next){
exec.all.get(i).parents.add(exec.all.get(parent.asInt()));
}
}
return exec;
}
});
//use short names for all filter types
for(var filter : Maps.allFilterTypes){
var i = filter.get();
json.addClassTag(Strings.camelize(i.getClass().getSimpleName().replace("Filter", "")), i.getClass());
}
//use short names for all objective types
for(var obj : MapObjectives.allObjectiveTypes){
var i = obj.get();
json.addClassTag(Strings.camelize(i.getClass().getSimpleName().replace("Objective", "")), i.getClass());
}
//use short names for all marker types
for(var obj : MapObjectives.allMarkerTypes){
var i = obj.get();
json.addClassTag(Strings.camelize(i.getClass().getSimpleName().replace("Marker", "")), i.getClass());
}
}
static class CustomJson extends Json{

View File

@@ -546,6 +546,19 @@ public class TypeIO{
return JsonIO.read(Rules.class, string);
}
public static void writeObjectives(Writes write, MapObjectives executor){
String string = JsonIO.write(executor);
byte[] bytes = string.getBytes(charset);
write.i(bytes.length);
write.b(bytes);
}
public static MapObjectives readObjectives(Reads read){
int length = read.i();
String string = new String(read.b(new byte[length]), charset);
return JsonIO.read(MapObjectives.class, string);
}
public static void writeVecNullable(Writes write, @Nullable Vec2 v){
if(v == null){
write.f(Float.NaN);