Handle pathGroup behavior in AssetManifest
This commit is contained in:
@@ -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<String, Array<String>> ();
|
||||
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) {
|
||||
|
||||
@@ -38,16 +38,13 @@ class AssetLibrary {
|
||||
private var cachedText = new Map<String, String> ();
|
||||
private var classTypes = new Map<String, Class<Dynamic>> ();
|
||||
private var loaded:Bool;
|
||||
private var pathGroups = new Map<String, Array<String>> ();
|
||||
private var paths = new Map<String, String> ();
|
||||
private var preload = new Map<String, Bool> ();
|
||||
private var promise:Promise<AssetLibrary>;
|
||||
private var sizes = new Map<String, Int> ();
|
||||
private var types = new Map<String, AssetType> ();
|
||||
|
||||
#if (js && html5)
|
||||
private var pathGroups:Map<String, Array<String>>;
|
||||
#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<String>;
|
||||
|
||||
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<String, Array<String>> ();
|
||||
|
||||
}
|
||||
|
||||
var sounds = new Map<String, Array<String>> ();
|
||||
var preloadGroups = new Map<String, Bool> ();
|
||||
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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user