diff --git a/lime/tools/helpers/AssetHelper.hx b/lime/tools/helpers/AssetHelper.hx index 5a0e27308..725400fee 100644 --- a/lime/tools/helpers/AssetHelper.hx +++ b/lime/tools/helpers/AssetHelper.hx @@ -20,67 +20,80 @@ class AssetHelper { public static function createManifest (project:HXProject, library:String = null, targetPath:String = null):AssetManifest { var manifest = new AssetManifest (); + var pathGroups = new Map> (); + var size, soundName; var assetData:Dynamic; for (asset in project.assets) { - if (asset.library != library) continue; + if (asset.library != library || asset.type == TEMPLATE) continue; - if (asset.type != AssetType.TEMPLATE) { + size = 100; + + if (FileSystem.exists (asset.sourcePath)) { - var size = 100; + size = FileSystem.stat (asset.sourcePath).size; - if (FileSystem.exists (asset.sourcePath)) { + } + + assetData = { + + id: asset.id, + size: size, + type: Std.string (asset.type) + + }; + + if (project.target != HTML5) { + + if (asset.embed == true || asset.type == FONT || (asset.embed == null && (project.platformType == WEB))) { - size = FileSystem.stat (asset.sourcePath).size; + assetData.className = "__ASSET__" + asset.flatName; + + } else { + + assetData.path = asset.resourceName; } - assetData = { - - id: asset.id, - type: Std.string (asset.type), - size: size - - }; + } else { if (asset.type == FONT) { assetData.className = "__ASSET__" + asset.flatName; - - if (project.target == HTML5) { - - assetData.preload = true; - - } + assetData.preload = true; } else { - if (asset.embed == true || (asset.embed == null && (project.platformType == WEB))) { + assetData.path = asset.resourceName; + assetData.preload = (asset.embed != false); + + if (asset.type == MUSIC || asset.type == SOUND) { - if (project.target == HTML5) { + soundName = Path.withoutExtension (assetData.path); + + if (!pathGroups.exists (soundName)) { - assetData.path = asset.resourceName; - assetData.preload = true; + pathGroups.set (soundName, [ assetData.path ]); } else { - assetData.className = "__ASSET__" + asset.flatName; + pathGroups[soundName].push (assetData.path); + assetData.preload = false; } - } else { - - assetData.path = asset.resourceName; + Reflect.deleteField (assetData, "path"); + assetData.pathGroup = pathGroups[soundName]; } } - manifest.assets.push (assetData); - } + manifest.assets.push (assetData); + } if (targetPath != null) { diff --git a/lime/utils/AssetLibrary.hx b/lime/utils/AssetLibrary.hx index f918e898f..5501c092d 100644 --- a/lime/utils/AssetLibrary.hx +++ b/lime/utils/AssetLibrary.hx @@ -38,16 +38,13 @@ class AssetLibrary { private var cachedText = new Map (); private var classTypes = new Map> (); private var loaded:Bool; + private var pathGroups = new Map> (); private var paths = new Map (); private var preload = new Map (); private var promise:Promise; private var sizes = new Map (); private var types = new Map (); - #if (js && html5) - private var pathGroups:Map>; - #end - public function new () { @@ -508,15 +505,15 @@ class AssetLibrary { } else { - #if (js && html5) if (pathGroups.exists (id)) { return AudioBuffer.loadFromFiles (pathGroups.get (id)); + } else { + + return AudioBuffer.loadFromFile (paths.get (id)); + } - #end - - return AudioBuffer.loadFromFile (paths.get (id)); } @@ -725,7 +722,7 @@ class AssetLibrary { private function __fromManifest (manifest:AssetManifest):Void { var hasSize = (manifest.version >= 2); - var size, id; + var size, id, pathGroup:Array; var basePath = manifest.rootPath; if (basePath == null) basePath = ""; @@ -742,6 +739,20 @@ class AssetLibrary { } + if (Reflect.hasField (asset, "pathGroup")) { + + pathGroup = Reflect.field (asset, "pathGroup"); + + for (i in 0...pathGroup.length) { + + pathGroup[i] = basePath + pathGroup[i]; + + } + + pathGroups.set (id, pathGroup); + + } + sizes.set (id, size); types.set (id, asset.type); @@ -759,58 +770,6 @@ class AssetLibrary { } - // TODO: Better solution - - #if (js && html5) - if (pathGroups == null) { - - pathGroups = new Map> (); - - } - - var sounds = new Map> (); - var preloadGroups = new Map (); - var type, path, soundName; - - for (id in types.keys ()) { - - type = types.get (id); - - if (type == MUSIC || type == SOUND) { - - path = paths.get (id); - if (path == null) continue; - - soundName = Path.withoutExtension (path); - - if (!sounds.exists (soundName)) { - - sounds.set (soundName, new Array ()); - - } - - sounds.get (soundName).push (path); - pathGroups.set (id, sounds.get (soundName)); - - if (preload.exists (id)) { - - if (preloadGroups.exists (soundName)) { - - preload.remove (id); - - } else { - - preloadGroups.set (soundName, true); - - } - - } - - } - - } - #end - bytesTotal = 0; for (asset in manifest.assets) { @@ -839,27 +798,20 @@ class AssetLibrary { cachedAudioBuffers.set (id, audioBuffer); - #if (js && html5) - var type, path, soundName; - - path = paths.get (id); - - if (path != null) { + if (pathGroups.exists (id)) { - soundName = Path.withoutExtension (path); + var pathGroup = pathGroups.get (id); - for (otherID in types.keys ()) { + for (otherID in pathGroups.keys ()) { - type = types.get (otherID); + if (otherID == id) continue; - if (type == MUSIC || type == SOUND) { + for (path in pathGroup) { - path = paths.get (otherID); - if (path == null) continue; - - if (soundName == Path.withoutExtension (path)) { + if (pathGroups.get (otherID).indexOf (path) > -1) { cachedAudioBuffers.set (otherID, audioBuffer); + break; } @@ -868,7 +820,6 @@ class AssetLibrary { } } - #end __assetLoaded (id);