From 6b4f70027ff287a4d2c705551b65053e5087e4ba Mon Sep 17 00:00:00 2001 From: Joshua Granick Date: Sat, 24 Dec 2016 00:42:02 -0800 Subject: [PATCH] Hack support for named library preload (need to revise this more) --- lime/app/Preloader.hx | 55 ++++++++++++++++++++++++++++--- templates/haxe/ApplicationMain.hx | 2 ++ 2 files changed, 52 insertions(+), 5 deletions(-) diff --git a/lime/app/Preloader.hx b/lime/app/Preloader.hx index a1ebca52b..68decdb56 100644 --- a/lime/app/Preloader.hx +++ b/lime/app/Preloader.hx @@ -34,12 +34,14 @@ class Preloader #if flash extends Sprite #end { public var onComplete = new EventVoid> (); public var onProgress = new EventInt->Void> (); + private var initLibraryNames:Bool; + private var itemsProgressLoaded:Int; + private var itemsProgressTotal:Int; private var libraries:Array; + private var libraryNames:Array; private var loadedLibraries:Int; private var loadedStage:Bool; - private var itemsProgressLoaded:Int; - private var itemsProgressTotal:Int; public function new () { @@ -48,6 +50,7 @@ class Preloader #if flash extends Sprite #end { #end libraries = new Array (); + libraryNames = new Array (); 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 { #if flash @@ -92,7 +106,7 @@ class Preloader #if flash extends Sprite #end { library.load ().onProgress (function (_, _) { - updateItemsProgress(); + updateItemsProgress (); }).onComplete (function (_) { @@ -101,12 +115,18 @@ class Preloader #if flash extends Sprite #end { }).onError (function (e) { - trace(e); + trace (e); }); } + for (name in libraryNames) { + + itemsProgressTotal += 1; + + } + loadedLibraries++; updateProgress (); @@ -142,7 +162,32 @@ class Preloader #if flash extends Sprite #end { update (itemsProgressLoaded, itemsProgressTotal); // 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 (); diff --git a/templates/haxe/ApplicationMain.hx b/templates/haxe/ApplicationMain.hx index 11f49092e..1473b6591 100644 --- a/templates/haxe/ApplicationMain.hx +++ b/templates/haxe/ApplicationMain.hx @@ -75,6 +75,8 @@ class ApplicationMain { preloader.create (config); preloader.addLibrary (library); + ::if (libraries != null)::::foreach libraries::::if (preload)::preloader.addLibraryName ("::name::"); + ::end::::end::::end:: preloader.load (); start ();