Simplified JSON music/sound loading

This commit is contained in:
Anuken 2023-11-30 14:19:30 -05:00
parent 5fe28254e7
commit ed96b2eec8
4 changed files with 7 additions and 27 deletions

View File

@ -587,3 +587,4 @@
63095=ranai|ranai
63094=cat|cat
63093=world-switch|block-world-switch-ui
63092=dynamic|status-dynamic-ui

Binary file not shown.

View File

@ -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);

View File

@ -25,4 +25,4 @@ org.gradle.caching=true
#used for slow jitpack builds; TODO see if this actually works
org.gradle.internal.http.socketTimeout=100000
org.gradle.internal.http.connectionTimeout=100000
archash=34775c79250cab391499fac8f4747365984c6923
archash=f1e4bdee85