@vpmedia/phaser 1.8.0 → 1.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/package.json +1 -1
- package/src/phaser/core/loader.js +30 -19
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
@vpmedia/phaser
|
|
2
2
|
===============
|
|
3
3
|
|
|
4
|
-
[](https://badge.fury.io/js/@vpmedia%2Fphaser)
|
|
5
5
|
[](https://github.com/vpmedia/phaser/actions/workflows/node.js.yml)
|
|
6
6
|
|
|
7
7
|
@vpmedia/phaser is the modern ECMAScript port of the popular Phaser game engine v2.6.2.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vpmedia/phaser",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.10.0",
|
|
4
4
|
"description": "@vpmedia/phaser is the modern ECMAScript port of the popular Phaser game engine v2.6.2",
|
|
5
5
|
"author": "Andras Csizmadia <andras@vpmedia.hu> (www.vpmedia.hu)",
|
|
6
6
|
"license": "MIT",
|
|
@@ -15,8 +15,8 @@ export default class {
|
|
|
15
15
|
this.game = game;
|
|
16
16
|
this.cache = game.cache;
|
|
17
17
|
this.isLoading = false;
|
|
18
|
-
this.
|
|
19
|
-
this.isUseRetry =
|
|
18
|
+
this.isUseLog = false;
|
|
19
|
+
this.isUseRetry = true;
|
|
20
20
|
this.maxRetry = 1;
|
|
21
21
|
this.hasLoaded = false;
|
|
22
22
|
this.preloadSprite = null;
|
|
@@ -430,9 +430,9 @@ export default class {
|
|
|
430
430
|
// Flight queue is empty but file list is not done being processed.
|
|
431
431
|
// This indicates a critical internal error with no known recovery.
|
|
432
432
|
console.warn('Loader - aborting: processing queue empty, loading may have stalled');
|
|
433
|
-
const
|
|
433
|
+
const scope = this;
|
|
434
434
|
setTimeout(() => {
|
|
435
|
-
|
|
435
|
+
scope.finishedLoading(true);
|
|
436
436
|
}, 2000);
|
|
437
437
|
}
|
|
438
438
|
}
|
|
@@ -557,7 +557,7 @@ export default class {
|
|
|
557
557
|
|
|
558
558
|
loadImageTag(file) {
|
|
559
559
|
this.log('loadImageTag', file);
|
|
560
|
-
const
|
|
560
|
+
const scope = this;
|
|
561
561
|
file.data = new Image();
|
|
562
562
|
file.data.name = file.key;
|
|
563
563
|
if (this.crossOrigin) {
|
|
@@ -567,17 +567,17 @@ export default class {
|
|
|
567
567
|
if (file.data.onload) {
|
|
568
568
|
file.data.onload = null;
|
|
569
569
|
file.data.onerror = null;
|
|
570
|
-
|
|
570
|
+
scope.fileComplete(file);
|
|
571
571
|
}
|
|
572
572
|
};
|
|
573
573
|
file.data.onerror = () => {
|
|
574
|
-
if (
|
|
574
|
+
if (scope.isUseRetry && (!file.numRetry || file.numRetry < scope.maxRetry)) {
|
|
575
575
|
file.numRetry = !file.numRetry ? 1 : file.numRetry += 1;
|
|
576
|
-
|
|
576
|
+
scope.loadImageTag(file);
|
|
577
577
|
} else if (file.data.onload) {
|
|
578
578
|
file.data.onload = null;
|
|
579
579
|
file.data.onerror = null;
|
|
580
|
-
|
|
580
|
+
scope.fileError(file);
|
|
581
581
|
}
|
|
582
582
|
};
|
|
583
583
|
file.data.src = this.transformUrl(file.url, file);
|
|
@@ -585,6 +585,7 @@ export default class {
|
|
|
585
585
|
|
|
586
586
|
xhrLoad(file, url, type, onload, onerror) {
|
|
587
587
|
this.log('xhrLoad', file);
|
|
588
|
+
const scope = this;
|
|
588
589
|
const xhr = new XMLHttpRequest();
|
|
589
590
|
xhr.open('GET', url, true);
|
|
590
591
|
xhr.responseType = type;
|
|
@@ -595,11 +596,16 @@ export default class {
|
|
|
595
596
|
xhr.setRequestHeader('Accept', this.headers[file.type]);
|
|
596
597
|
}
|
|
597
598
|
onerror = onerror || this.fileError;
|
|
598
|
-
const scope = this;
|
|
599
599
|
xhr.onload = () => {
|
|
600
600
|
try {
|
|
601
601
|
if (xhr.readyState === 4 && xhr.status >= 400 && xhr.status <= 599) { // Handle HTTP status codes of 4xx and 5xx as errors, even if xhr.onerror was not called.
|
|
602
|
-
|
|
602
|
+
if (scope.isUseRetry && (!file.numRetry || file.numRetry < scope.maxRetry)) {
|
|
603
|
+
file.numRetry = !file.numRetry ? 1 : file.numRetry += 1;
|
|
604
|
+
scope.xhrLoad(file, url, type, onload, onerror);
|
|
605
|
+
return null;
|
|
606
|
+
} else {
|
|
607
|
+
return onerror.call(scope, file, xhr);
|
|
608
|
+
}
|
|
603
609
|
}
|
|
604
610
|
return onload.call(scope, file, xhr);
|
|
605
611
|
} catch (e) {
|
|
@@ -614,13 +620,18 @@ export default class {
|
|
|
614
620
|
return null;
|
|
615
621
|
};
|
|
616
622
|
xhr.onerror = () => {
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
623
|
+
if (scope.isUseRetry && (!file.numRetry || file.numRetry < scope.maxRetry)) {
|
|
624
|
+
file.numRetry = !file.numRetry ? 1 : file.numRetry += 1;
|
|
625
|
+
scope.xhrLoad(file, url, type, onload, onerror);
|
|
626
|
+
} else {
|
|
627
|
+
try {
|
|
628
|
+
return onerror.call(scope, file, xhr);
|
|
629
|
+
} catch (e) {
|
|
630
|
+
if (!scope.hasLoaded) {
|
|
631
|
+
scope.asyncComplete(file, e.message || 'Exception');
|
|
632
|
+
} else {
|
|
633
|
+
scope.game.exceptionHandler(e);
|
|
634
|
+
}
|
|
624
635
|
}
|
|
625
636
|
}
|
|
626
637
|
return null;
|
|
@@ -824,7 +835,7 @@ export default class {
|
|
|
824
835
|
}
|
|
825
836
|
|
|
826
837
|
log(message, data = '') {
|
|
827
|
-
if (!this.
|
|
838
|
+
if (!this.isUseLog) {
|
|
828
839
|
return;
|
|
829
840
|
}
|
|
830
841
|
console.log(`[Loader] ${message}`, data);
|