@vpmedia/phaser 1.7.0 → 1.9.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  @vpmedia/phaser
2
2
  ===============
3
3
 
4
- [![npm version](https://badge.fury.io/js/@vpmedia%2Fphaser.svg?v=1.7.0)](https://badge.fury.io/js/@vpmedia%2Fphaser)
4
+ [![npm version](https://badge.fury.io/js/@vpmedia%2Fphaser.svg?v=1.9.0)](https://badge.fury.io/js/@vpmedia%2Fphaser)
5
5
  [![Node.js CI](https://github.com/vpmedia/phaser/actions/workflows/node.js.yml/badge.svg)](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.7.0",
3
+ "version": "1.9.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",
@@ -21,16 +21,16 @@
21
21
  ],
22
22
  "main": "./src/index.js",
23
23
  "devDependencies": {
24
- "eslint": "^8.33.0",
25
- "eslint-config-prettier": "^8.6.0",
24
+ "eslint": "^8.36.0",
25
+ "eslint-config-prettier": "^8.7.0",
26
26
  "eslint-plugin-import": "^2.27.5",
27
27
  "eslint-plugin-jest": "^27.2.1",
28
- "eslint-plugin-jsdoc": "^39.7.4",
28
+ "eslint-plugin-jsdoc": "^40.1.0",
29
29
  "eslint-plugin-prettier": "^4.2.1",
30
30
  "husky": "^8.0.3",
31
- "jest": "^29.4.1",
32
- "lint-staged": "^13.1.0",
33
- "prettier": "^2.8.3"
31
+ "jest": "^29.5.0",
32
+ "lint-staged": "^13.2.0",
33
+ "prettier": "^2.8.5"
34
34
  },
35
35
  "scripts": {
36
36
  "test": "NODE_OPTIONS=--experimental-vm-modules jest --passWithNoTests",
@@ -15,6 +15,9 @@ export default class {
15
15
  this.game = game;
16
16
  this.cache = game.cache;
17
17
  this.isLoading = false;
18
+ this.isUseLog = false;
19
+ this.isUseRetry = true;
20
+ this.maxRetry = 1;
18
21
  this.hasLoaded = false;
19
22
  this.preloadSprite = null;
20
23
  this.crossOrigin = false;
@@ -427,9 +430,9 @@ export default class {
427
430
  // Flight queue is empty but file list is not done being processed.
428
431
  // This indicates a critical internal error with no known recovery.
429
432
  console.warn('Loader - aborting: processing queue empty, loading may have stalled');
430
- const _this = this;
433
+ const scope = this;
431
434
  setTimeout(() => {
432
- _this.finishedLoading(true);
435
+ scope.finishedLoading(true);
433
436
  }, 2000);
434
437
  }
435
438
  }
@@ -456,10 +459,11 @@ export default class {
456
459
  asyncComplete(file, errorMessage = '') {
457
460
  file.loaded = true;
458
461
  file.error = !!errorMessage;
459
- if (errorMessage) {
462
+ if (file.error) {
460
463
  file.errorMessage = errorMessage;
461
464
  console.warn(file, errorMessage);
462
465
  }
466
+ this.log('asyncComplete', file);
463
467
  this.processLoadQueue();
464
468
  }
465
469
 
@@ -552,7 +556,8 @@ export default class {
552
556
  }
553
557
 
554
558
  loadImageTag(file) {
555
- const _this = this;
559
+ this.log('loadImageTag', file);
560
+ const scope = this;
556
561
  file.data = new Image();
557
562
  file.data.name = file.key;
558
563
  if (this.crossOrigin) {
@@ -562,20 +567,24 @@ export default class {
562
567
  if (file.data.onload) {
563
568
  file.data.onload = null;
564
569
  file.data.onerror = null;
565
- _this.fileComplete(file);
570
+ scope.fileComplete(file);
566
571
  }
567
572
  };
568
573
  file.data.onerror = () => {
569
- if (file.data.onload) {
574
+ if (scope.isUseRetry && (!file.numRetry || file.numRetry < scope.maxRetry)) {
575
+ file.numRetry = !file.numRetry ? 1 : file.numRetry += 1;
576
+ scope.loadImageTag(file);
577
+ } else if (file.data.onload) {
570
578
  file.data.onload = null;
571
579
  file.data.onerror = null;
572
- _this.fileError(file);
580
+ scope.fileError(file);
573
581
  }
574
582
  };
575
583
  file.data.src = this.transformUrl(file.url, file);
576
584
  }
577
585
 
578
586
  xhrLoad(file, url, type, onload, onerror) {
587
+ this.log('xhrLoad', file);
579
588
  const xhr = new XMLHttpRequest();
580
589
  xhr.open('GET', url, true);
581
590
  xhr.responseType = type;
@@ -605,13 +614,18 @@ export default class {
605
614
  return null;
606
615
  };
607
616
  xhr.onerror = () => {
608
- try {
609
- return onerror.call(scope, file, xhr);
610
- } catch (e) {
611
- if (!scope.hasLoaded) {
612
- scope.asyncComplete(file, e.message || 'Exception');
613
- } else {
614
- scope.game.exceptionHandler(e);
617
+ if (scope.isUseRetry && (!file.numRetry || file.numRetry < scope.maxRetry)) {
618
+ file.numRetry = !file.numRetry ? 1 : file.numRetry += 1;
619
+ scope.xhrLoad(file, url, type, onload, onerror);
620
+ } else {
621
+ try {
622
+ return onerror.call(scope, file, xhr);
623
+ } catch (e) {
624
+ if (!scope.hasLoaded) {
625
+ scope.asyncComplete(file, e.message || 'Exception');
626
+ } else {
627
+ scope.game.exceptionHandler(e);
628
+ }
615
629
  }
616
630
  }
617
631
  return null;
@@ -814,6 +828,13 @@ export default class {
814
828
  }
815
829
  }
816
830
 
831
+ log(message, data = '') {
832
+ if (!this.isUseLog) {
833
+ return;
834
+ }
835
+ console.log(`[Loader] ${message}`, data);
836
+ }
837
+
817
838
  totalLoadedFiles() {
818
839
  return this._loadedFileCount;
819
840
  }