Workaround to allow similar sounds to load as one group on HTML5 (close #883)
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package lime.utils;
|
||||
|
||||
|
||||
import haxe.io.Path;
|
||||
import lime.app.Event;
|
||||
import lime.app.Future;
|
||||
import lime.app.Promise;
|
||||
@@ -41,6 +42,10 @@ class AssetLibrary {
|
||||
private var promise:Promise<AssetLibrary>;
|
||||
private var types = new Map<String, AssetType> ();
|
||||
|
||||
#if (js && html5)
|
||||
private var pathGroups:Map<String, Array<String>>;
|
||||
#end
|
||||
|
||||
|
||||
public function new () {
|
||||
|
||||
@@ -471,6 +476,41 @@ class AssetLibrary {
|
||||
|
||||
public function loadAudioBuffer (id:String):Future<AudioBuffer> {
|
||||
|
||||
// TODO: Better solution
|
||||
|
||||
#if (js && html5)
|
||||
if (pathGroups == null) {
|
||||
|
||||
pathGroups = new Map<String, Array<String>> ();
|
||||
|
||||
var sounds = new Map<String, Array<String>> ();
|
||||
var type, path, soundName;
|
||||
|
||||
for (id in types.keys ()) {
|
||||
|
||||
type = types.get (id);
|
||||
|
||||
if (type == MUSIC || type == SOUND) {
|
||||
|
||||
path = paths.get (id);
|
||||
soundName = Path.withoutExtension (path);
|
||||
|
||||
if (!sounds.exists (soundName)) {
|
||||
|
||||
sounds.set (soundName, new Array ());
|
||||
|
||||
}
|
||||
|
||||
sounds.get (soundName).push (path);
|
||||
pathGroups.set (id, sounds.get (soundName));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
#end
|
||||
|
||||
if (cachedAudioBuffers.exists (id)) {
|
||||
|
||||
return Future.withValue (cachedAudioBuffers.get (id));
|
||||
@@ -481,7 +521,11 @@ class AssetLibrary {
|
||||
|
||||
} else {
|
||||
|
||||
#if (js && html5)
|
||||
return AudioBuffer.loadFromFiles (pathGroups.get (id));
|
||||
#else
|
||||
return AudioBuffer.loadFromFile (paths.get (id));
|
||||
#end
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user