Moved Scripts loaders to Vars.tree.loadSound/Music
This commit is contained in:
@@ -1,9 +1,14 @@
|
|||||||
package mindustry.core;
|
package mindustry.core;
|
||||||
|
|
||||||
import arc.*;
|
import arc.*;
|
||||||
|
import arc.assets.*;
|
||||||
import arc.assets.loaders.*;
|
import arc.assets.loaders.*;
|
||||||
|
import arc.assets.loaders.MusicLoader.*;
|
||||||
|
import arc.assets.loaders.SoundLoader.*;
|
||||||
|
import arc.audio.*;
|
||||||
import arc.files.*;
|
import arc.files.*;
|
||||||
import arc.struct.*;
|
import arc.struct.*;
|
||||||
|
import mindustry.*;
|
||||||
|
|
||||||
/** Handles files in a modded context. */
|
/** Handles files in a modded context. */
|
||||||
public class FileTree implements FileHandleResolver{
|
public class FileTree implements FileHandleResolver{
|
||||||
@@ -40,4 +45,30 @@ public class FileTree implements FileHandleResolver{
|
|||||||
public Fi resolve(String fileName){
|
public Fi resolve(String fileName){
|
||||||
return get(fileName);
|
return get(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Sound loadSound(String soundName){
|
||||||
|
if(Vars.headless) return new Sound();
|
||||||
|
|
||||||
|
String name = "sounds/" + soundName;
|
||||||
|
String path = Vars.tree.get(name + ".ogg").exists() ? name + ".ogg" : name + ".mp3";
|
||||||
|
|
||||||
|
var sound = new Sound();
|
||||||
|
AssetDescriptor<?> desc = Core.assets.load(path, Sound.class, new SoundParameter(sound));
|
||||||
|
desc.errored = Throwable::printStackTrace;
|
||||||
|
|
||||||
|
return sound;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Music loadMusic(String soundName){
|
||||||
|
if(Vars.headless) return new Music();
|
||||||
|
|
||||||
|
String name = "music/" + soundName;
|
||||||
|
String path = Vars.tree.get(name + ".ogg").exists() ? name + ".ogg" : name + ".mp3";
|
||||||
|
|
||||||
|
var music = new Music();
|
||||||
|
AssetDescriptor<?> desc = Core.assets.load(path, Music.class, new MusicParameter(music));
|
||||||
|
desc.errored = Throwable::printStackTrace;
|
||||||
|
|
||||||
|
return music;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,6 @@
|
|||||||
package mindustry.mod;
|
package mindustry.mod;
|
||||||
|
|
||||||
import arc.*;
|
import arc.*;
|
||||||
import arc.assets.*;
|
|
||||||
import arc.assets.loaders.MusicLoader.*;
|
|
||||||
import arc.assets.loaders.SoundLoader.*;
|
|
||||||
import arc.audio.*;
|
import arc.audio.*;
|
||||||
import arc.files.*;
|
import arc.files.*;
|
||||||
import arc.func.*;
|
import arc.func.*;
|
||||||
@@ -85,30 +82,14 @@ public class Scripts implements Disposable{
|
|||||||
return Vars.tree.get(path, true).readBytes();
|
return Vars.tree.get(path, true).readBytes();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//kept for backwards compatibility
|
||||||
public Sound loadSound(String soundName){
|
public Sound loadSound(String soundName){
|
||||||
if(Vars.headless) return new Sound();
|
return Vars.tree.loadSound(soundName);
|
||||||
|
|
||||||
String name = "sounds/" + soundName;
|
|
||||||
String path = Vars.tree.get(name + ".ogg").exists() ? name + ".ogg" : name + ".mp3";
|
|
||||||
|
|
||||||
var sound = new Sound();
|
|
||||||
AssetDescriptor<?> desc = Core.assets.load(path, Sound.class, new SoundParameter(sound));
|
|
||||||
desc.errored = Throwable::printStackTrace;
|
|
||||||
|
|
||||||
return sound;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//kept for backwards compatibility
|
||||||
public Music loadMusic(String soundName){
|
public Music loadMusic(String soundName){
|
||||||
if(Vars.headless) return new Music();
|
return Vars.tree.loadMusic(soundName);
|
||||||
|
|
||||||
String name = "music/" + soundName;
|
|
||||||
String path = Vars.tree.get(name + ".ogg").exists() ? name + ".ogg" : name + ".mp3";
|
|
||||||
|
|
||||||
var music = new Music();
|
|
||||||
AssetDescriptor<?> desc = Core.assets.load(path, Music.class, new MusicParameter(music));
|
|
||||||
desc.errored = Throwable::printStackTrace;
|
|
||||||
|
|
||||||
return music;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Ask the user to select a file to read for a certain purpose like "Please upload a sprite" */
|
/** Ask the user to select a file to read for a certain purpose like "Please upload a sprite" */
|
||||||
|
|||||||
Reference in New Issue
Block a user