Content parser listener
This commit is contained in:
@@ -48,6 +48,7 @@ public class ContentParser{
|
||||
ObjectMap<Class<?>, ContentType> contentTypes = new ObjectMap<>();
|
||||
ObjectSet<Class<?>> implicitNullable = ObjectSet.with(TextureRegion.class, TextureRegion[].class, TextureRegion[][].class);
|
||||
ObjectMap<String, AssetDescriptor<?>> sounds = new ObjectMap<>();
|
||||
Seq<ParseListener> listeners = new Seq<>();
|
||||
|
||||
ObjectMap<Class<?>, FieldParser> classParsers = new ObjectMap<>(){{
|
||||
put(Effect.class, (type, data) -> {
|
||||
@@ -178,7 +179,10 @@ public class ContentParser{
|
||||
@Override
|
||||
public <T> T readValue(Class<T> type, Class elementType, JsonValue jsonData, Class keyType){
|
||||
T t = internalRead(type, elementType, jsonData, keyType);
|
||||
if(t != null) checkNullFields(t);
|
||||
if(t != null && !Reflect.isWrapper(t.getClass()) && (type == null || !type.isPrimitive())){
|
||||
checkNullFields(t);
|
||||
listeners.each(hook -> hook.parsed(type, jsonData, t));
|
||||
}
|
||||
return t;
|
||||
}
|
||||
|
||||
@@ -805,4 +809,8 @@ public class ContentParser{
|
||||
public float time = 60f * 10f;
|
||||
}
|
||||
|
||||
public interface ParseListener{
|
||||
void parsed(Class<?> type, JsonValue jsonData, Object result);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ import mindustry.game.EventType.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.graphics.*;
|
||||
import mindustry.graphics.MultiPacker.*;
|
||||
import mindustry.mod.ContentParser.*;
|
||||
import mindustry.type.*;
|
||||
import mindustry.ui.*;
|
||||
|
||||
@@ -651,6 +652,11 @@ public class Mods implements Loadable{
|
||||
parser.markError(content, error);
|
||||
}
|
||||
|
||||
/** Adds a listener for parsed JSON objects. */
|
||||
public void addParseListener(ParseListener hook){
|
||||
parser.listeners.add(hook);
|
||||
}
|
||||
|
||||
/** @return a list of mods and versions, in the format name:version. */
|
||||
public Seq<String> getModStrings(){
|
||||
return mods.select(l -> !l.meta.hidden && l.enabled()).map(l -> l.name + ":" + l.meta.version);
|
||||
|
||||
Reference in New Issue
Block a user