Simplified JSON music/sound loading
This commit is contained in:
@@ -587,3 +587,4 @@
|
|||||||
63095=ranai|ranai
|
63095=ranai|ranai
|
||||||
63094=cat|cat
|
63094=cat|cat
|
||||||
63093=world-switch|block-world-switch-ui
|
63093=world-switch|block-world-switch-ui
|
||||||
|
63092=dynamic|status-dynamic-ui
|
||||||
|
|||||||
Binary file not shown.
@@ -61,8 +61,6 @@ public class ContentParser{
|
|||||||
|
|
||||||
ObjectMap<Class<?>, ContentType> contentTypes = new ObjectMap<>();
|
ObjectMap<Class<?>, ContentType> contentTypes = new ObjectMap<>();
|
||||||
ObjectSet<Class<?>> implicitNullable = ObjectSet.with(TextureRegion.class, TextureRegion[].class, TextureRegion[][].class, TextureRegion[][][].class);
|
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<>();
|
Seq<ParseListener> listeners = new Seq<>();
|
||||||
|
|
||||||
ObjectMap<Class<?>, FieldParser> classParsers = new ObjectMap<>(){{
|
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));
|
return new Vec3(data.getFloat("x", 0f), data.getFloat("y", 0f), data.getFloat("z", 0f));
|
||||||
});
|
});
|
||||||
put(Sound.class, (type, data) -> {
|
put(Sound.class, (type, data) -> {
|
||||||
if(fieldOpt(Sounds.class, data) != null) return fieldOpt(Sounds.class, data);
|
var field = fieldOpt(Sounds.class, data);
|
||||||
if(Vars.headless) return new Sound();
|
|
||||||
|
|
||||||
String name = "sounds/" + data.asString();
|
return field != null ? field : Vars.tree.loadSound(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;
|
|
||||||
});
|
});
|
||||||
put(Music.class, (type, data) -> {
|
put(Music.class, (type, data) -> {
|
||||||
if(fieldOpt(Musics.class, data) != null) return fieldOpt(Musics.class, data);
|
var field = fieldOpt(Musics.class, data);
|
||||||
if(Vars.headless) return new Music();
|
|
||||||
|
|
||||||
String name = "music/" + data.asString();
|
return field != null ? field : Vars.tree.loadMusic(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;
|
|
||||||
});
|
});
|
||||||
put(Objectives.Objective.class, (type, data) -> {
|
put(Objectives.Objective.class, (type, data) -> {
|
||||||
if(data.isString()){
|
if(data.isString()){
|
||||||
@@ -1011,7 +991,6 @@ public class ContentParser{
|
|||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Object fieldOpt(Class<?> type, JsonValue value){
|
Object fieldOpt(Class<?> type, JsonValue value){
|
||||||
try{
|
try{
|
||||||
return type.getField(value.asString()).get(null);
|
return type.getField(value.asString()).get(null);
|
||||||
|
|||||||
@@ -25,4 +25,4 @@ org.gradle.caching=true
|
|||||||
#used for slow jitpack builds; TODO see if this actually works
|
#used for slow jitpack builds; TODO see if this actually works
|
||||||
org.gradle.internal.http.socketTimeout=100000
|
org.gradle.internal.http.socketTimeout=100000
|
||||||
org.gradle.internal.http.connectionTimeout=100000
|
org.gradle.internal.http.connectionTimeout=100000
|
||||||
archash=34775c79250cab391499fac8f4747365984c6923
|
archash=f1e4bdee85
|
||||||
|
|||||||
Reference in New Issue
Block a user