Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 28 additions & 2 deletions lime/app/Preloader.hx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ class Preloader #if flash extends Sprite #end {
private var loadedLibraries:Int;
private var loadedStage:Bool;

private var itemsProgressLoaded:Int;
private var itemsProgressTotal:Int;

public function new () {

Expand Down Expand Up @@ -75,15 +77,32 @@ class Preloader #if flash extends Sprite #end {

public function load ():Void {

itemsProgressLoaded = 0;
itemsProgressTotal = 0;

for (library in libraries) {

itemsProgressTotal += library.computeProgressTotal ();

}

loadedLibraries = -1;

for (library in libraries) {

library.load ().onComplete (function (_) {
library.load ().onProgress (function (_, _) {

updateItemsProgress();

}).onComplete (function (_) {

loadedLibraries++;
updateProgress ();

}).onError (function (e) {

trace(e);

});

}
Expand Down Expand Up @@ -120,7 +139,8 @@ class Preloader #if flash extends Sprite #end {

private function updateProgress ():Void {

update (loadedLibraries, libraries.length);
update (itemsProgressLoaded, itemsProgressTotal);
// update (loadedLibraries, libraries.length);

if (#if flash loadedStage && #end loadedLibraries == libraries.length) {

Expand All @@ -130,6 +150,12 @@ class Preloader #if flash extends Sprite #end {

}

private function updateItemsProgress ():Void {

itemsProgressLoaded++;
updateProgress();

}

#if flash
private function current_onEnter (event:flash.events.Event):Void {
Expand Down
9 changes: 8 additions & 1 deletion lime/text/Font.hx
Original file line number Diff line number Diff line change
Expand Up @@ -446,8 +446,15 @@ class Font {

this.name = name;
var font = name;
var ua = Browser.navigator.userAgent.toLowerCase();

if (untyped (Browser.document).fonts && untyped (Browser.document).fonts.load) {
// When Safari reports that font is loaded, actually font IS NOT loaded.
// If you try to use this font immediately after preloader completes,
// default font will be used instead.
//
// We detect Safari, and use old font loading for it.

if (!(ua.indexOf(" safari/") >= 0 && ua.indexOf(" chrome/") < 0) && untyped (Browser.document).fonts && untyped (Browser.document).fonts.load) {

untyped (Browser.document).fonts.load ("1em '" + font + "'").then (function (_) {

Expand Down
22 changes: 22 additions & 0 deletions lime/utils/AssetLibrary.hx
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,27 @@ class AssetLibrary {

}

public function computeProgressTotal ():Int {

var result = 1;

for (id in preload.keys ()) {

switch (types.get (id)) {

case BINARY, FONT, IMAGE, MUSIC, SOUND, TEXT:

result++;

default:

}

}

return result;

}

public function load ():Future<AssetLibrary> {

Expand Down Expand Up @@ -575,6 +596,7 @@ class AssetLibrary {
private function updateProgressLoaded ():Void {

progressLoaded++;
promise.progress(progressLoaded, progressTotal);

if (progressLoaded == progressTotal) {

Expand Down