Simplified JSON music/sound loading
This commit is contained in:
@@ -61,8 +61,6 @@ public class ContentParser{
|
||||
|
||||
ObjectMap<Class<?>, ContentType> contentTypes = new ObjectMap<>();
|
||||
ObjectSet<Class<?>> implicitNullable = ObjectSet.with(TextureRegion.class, TextureRegion[].class, TextureRegion[][].class, TextureRegion[][][].class);
|
||||
ObjectMap<String, AssetDescriptor<?>> sounds = new ObjectMap<>();
|
||||
ObjectMap<String, AssetDescriptor<?>> musics = new ObjectMap<>();
|
||||
Seq<ParseListener> listeners = new Seq<>();
|
||||
|
||||
ObjectMap<Class<?>, FieldParser> classParsers = new ObjectMap<>(){{
|
||||
@@ -273,32 +271,14 @@ public class ContentParser{
|
||||
return new Vec3(data.getFloat("x", 0f), data.getFloat("y", 0f), data.getFloat("z", 0f));
|
||||
});
|
||||
put(Sound.class, (type, data) -> {
|
||||
if(fieldOpt(Sounds.class, data) != null) return fieldOpt(Sounds.class, data);
|
||||
if(Vars.headless) return new Sound();
|
||||
var field = fieldOpt(Sounds.class, data);
|
||||
|
||||
String name = "sounds/" + data.asString();
|
||||
String path = Vars.tree.get(name + ".ogg").exists() ? name + ".ogg" : name + ".mp3";
|
||||
|
||||
if(sounds.containsKey(path)) return ((SoundParameter)sounds.get(path).params).sound;
|
||||
var sound = new Sound();
|
||||
AssetDescriptor<?> desc = Core.assets.load(path, Sound.class, new SoundParameter(sound));
|
||||
desc.errored = Throwable::printStackTrace;
|
||||
sounds.put(path, desc);
|
||||
return sound;
|
||||
return field != null ? field : Vars.tree.loadSound(data.asString());
|
||||
});
|
||||
put(Music.class, (type, data) -> {
|
||||
if(fieldOpt(Musics.class, data) != null) return fieldOpt(Musics.class, data);
|
||||
if(Vars.headless) return new Music();
|
||||
|
||||
String name = "music/" + data.asString();
|
||||
String path = Vars.tree.get(name + ".ogg").exists() ? name + ".ogg" : name + ".mp3";
|
||||
|
||||
if(musics.containsKey(path)) return ((MusicParameter)musics.get(path).params).music;
|
||||
var music = new Music();
|
||||
AssetDescriptor<?> desc = Core.assets.load(path, Music.class, new MusicParameter(music));
|
||||
desc.errored = Throwable::printStackTrace;
|
||||
musics.put(path, desc);
|
||||
return music;
|
||||
var field = fieldOpt(Musics.class, data);
|
||||
|
||||
return field != null ? field : Vars.tree.loadMusic(data.asString());
|
||||
});
|
||||
put(Objectives.Objective.class, (type, data) -> {
|
||||
if(data.isString()){
|
||||
@@ -1011,7 +991,6 @@ public class ContentParser{
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
Object fieldOpt(Class<?> type, JsonValue value){
|
||||
try{
|
||||
return type.getField(value.asString()).get(null);
|
||||
|
||||
Reference in New Issue
Block a user