Hack support for named library preload (need to revise this more)
This commit is contained in:
@@ -34,12 +34,14 @@ class Preloader #if flash extends Sprite #end {
|
|||||||
public var onComplete = new Event<Void->Void> ();
|
public var onComplete = new Event<Void->Void> ();
|
||||||
public var onProgress = new Event<Int->Int->Void> ();
|
public var onProgress = new Event<Int->Int->Void> ();
|
||||||
|
|
||||||
|
private var initLibraryNames:Bool;
|
||||||
|
private var itemsProgressLoaded:Int;
|
||||||
|
private var itemsProgressTotal:Int;
|
||||||
private var libraries:Array<AssetLibrary>;
|
private var libraries:Array<AssetLibrary>;
|
||||||
|
private var libraryNames:Array<String>;
|
||||||
private var loadedLibraries:Int;
|
private var loadedLibraries:Int;
|
||||||
private var loadedStage:Bool;
|
private var loadedStage:Bool;
|
||||||
|
|
||||||
private var itemsProgressLoaded:Int;
|
|
||||||
private var itemsProgressTotal:Int;
|
|
||||||
|
|
||||||
public function new () {
|
public function new () {
|
||||||
|
|
||||||
@@ -48,6 +50,7 @@ class Preloader #if flash extends Sprite #end {
|
|||||||
#end
|
#end
|
||||||
|
|
||||||
libraries = new Array<AssetLibrary> ();
|
libraries = new Array<AssetLibrary> ();
|
||||||
|
libraryNames = new Array<String> ();
|
||||||
|
|
||||||
onProgress.add (update);
|
onProgress.add (update);
|
||||||
|
|
||||||
@@ -61,6 +64,17 @@ class Preloader #if flash extends Sprite #end {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function addLibraryName (name:String):Void {
|
||||||
|
|
||||||
|
if (libraryNames.indexOf (name) == -1) {
|
||||||
|
|
||||||
|
libraryNames.push (name);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public function create (config:Config):Void {
|
public function create (config:Config):Void {
|
||||||
|
|
||||||
#if flash
|
#if flash
|
||||||
@@ -92,7 +106,7 @@ class Preloader #if flash extends Sprite #end {
|
|||||||
|
|
||||||
library.load ().onProgress (function (_, _) {
|
library.load ().onProgress (function (_, _) {
|
||||||
|
|
||||||
updateItemsProgress();
|
updateItemsProgress ();
|
||||||
|
|
||||||
}).onComplete (function (_) {
|
}).onComplete (function (_) {
|
||||||
|
|
||||||
@@ -101,12 +115,18 @@ class Preloader #if flash extends Sprite #end {
|
|||||||
|
|
||||||
}).onError (function (e) {
|
}).onError (function (e) {
|
||||||
|
|
||||||
trace(e);
|
trace (e);
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (name in libraryNames) {
|
||||||
|
|
||||||
|
itemsProgressTotal += 1;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
loadedLibraries++;
|
loadedLibraries++;
|
||||||
updateProgress ();
|
updateProgress ();
|
||||||
|
|
||||||
@@ -142,7 +162,32 @@ class Preloader #if flash extends Sprite #end {
|
|||||||
update (itemsProgressLoaded, itemsProgressTotal);
|
update (itemsProgressLoaded, itemsProgressTotal);
|
||||||
// update (loadedLibraries, libraries.length);
|
// update (loadedLibraries, libraries.length);
|
||||||
|
|
||||||
if (#if flash loadedStage && #end loadedLibraries == libraries.length) {
|
if (loadedLibraries == libraries.length && !initLibraryNames) {
|
||||||
|
|
||||||
|
initLibraryNames = true;
|
||||||
|
|
||||||
|
for (name in libraryNames) {
|
||||||
|
|
||||||
|
Assets.loadLibrary (name).onProgress (function (_, _) {
|
||||||
|
|
||||||
|
updateItemsProgress ();
|
||||||
|
|
||||||
|
}).onComplete (function (_) {
|
||||||
|
|
||||||
|
loadedLibraries++;
|
||||||
|
updateProgress ();
|
||||||
|
|
||||||
|
}).onError (function (e) {
|
||||||
|
|
||||||
|
trace (e);
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (#if flash loadedStage && #end loadedLibraries == (libraries.length + libraryNames.length)) {
|
||||||
|
|
||||||
start ();
|
start ();
|
||||||
|
|
||||||
|
|||||||
@@ -75,6 +75,8 @@ class ApplicationMain {
|
|||||||
|
|
||||||
preloader.create (config);
|
preloader.create (config);
|
||||||
preloader.addLibrary (library);
|
preloader.addLibrary (library);
|
||||||
|
::if (libraries != null)::::foreach libraries::::if (preload)::preloader.addLibraryName ("::name::");
|
||||||
|
::end::::end::::end::
|
||||||
preloader.load ();
|
preloader.load ();
|
||||||
|
|
||||||
start ();
|
start ();
|
||||||
|
|||||||
Reference in New Issue
Block a user