@woosh/meep-engine 2.126.71 → 2.126.73

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/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "description": "Pure JavaScript game engine. Fully featured and production ready.",
6
6
  "type": "module",
7
7
  "author": "Alexander Goldring",
8
- "version": "2.126.71",
8
+ "version": "2.126.73",
9
9
  "main": "build/meep.module.js",
10
10
  "module": "build/meep.module.js",
11
11
  "exports": {
@@ -1 +1 @@
1
- {"version":3,"file":"AssetManager.d.ts","sourceRoot":"","sources":["../../../../src/engine/asset/AssetManager.js"],"names":[],"mappings":"AA8CA;;;;GAIG;AACH;IAgII;;;;;OAKG;IACH,oCAJW,GAAG,EAYb;IA7ID;;;;OAIG;IACH,eAEG;IAEH;;;OAGG;IACH,aAFU,YAAY,gBAAgB,EAAE,YAAY,CAAC,CAER;IAe7C;;;;;;OAMG;IACH,kBAFU,MAAM,CAEY;IAyB5B;;;;OAIG;IACH,iBAAc;IAEd;;;OAGG;IACH,mBAFU,iBAAiB,CAEiB;IAwE5C,gBAQC;IAED;;;;OAIG;IACH,qBAHW,MAAM,GACL,QAAQ,IAAI,CAAC,CAexB;IAED;;;;;OAKG;IACH,oCAFa,OAAO,CAOnB;IAED;;OAEG;IACH,cAEC;IAED,8BAEC;IAED;;;;;;OAMG;IACH,4DAJW,iBAAiB,GAEf,cAAc,CAY1B;IAED;;;;;;;;;OASG;IACH,qFAsCC;IAED;;;;;;;OAOG;IACH,gBAJW,MAAM,QACN,MAAM,GACL,OAAO,CAKlB;IAED;;;;;;;;;;;;;;;;;;;OAmBG;IACH,uBAZW,MAAM,QACN,MAAM,gBAEJ,mBAAiB,CA4D7B;IAED;;;;;;;;OAQG;IACH,kBAJW,MAAM,QACN,MAAM,2BAiChB;IA2QD;;;;;OAKG;IACH,sBA2BC;IAGD;;;;OAIG;IACH,uBAHW,MAAM,GACL,OAAO,CAIlB;IAED;;;;OAIG;IACH,sBAHW,MAAM,GACJ,wBAAY,SAAS,CAMjC;IAaD;;;;OAIG;IACH,+BAHW,MAAM,4CAqBhB;IAED;;;;OAIG;IACH,iCAHW,MAAM,+CAyBhB;IAED;;;;;;OAMG;IACH,6BAJW,MAAM,kCAEJ,QAAQ,OAAO,CAAC,CAU5B;IAED;;;;;OAKG;IACH,0BAJW,MAAM,iEAwChB;IAED;;;OAGG;IACH,uBAFW,MAAM,iBAkBhB;IAED;;;;;;OAMG;IACH,yCAFa,aAAS,IAAI,CAYzB;IAED;;;;;OAKG;IACH,eAJW,MAAM,QACN,MAAM,GACJ,OAAO,CAMnB;IAED;;;;OAIG;IACH,2BAHW,MAAM,GACL,mBAAiB,CAa5B;IAED;;;;OAIG;IACH,oBAHW,MAAM,GACL,gBAAgB,GAAC,SAAS,CAQrC;IAED;;;;;OAKG;IACH,mBAJW,MAAM,QACN,MAAM,QACN,MAAM,QAUhB;IAGL;;;OAGG;IACH,yBAFU,OAAO,CAEoB;;CANpC;4BA19B2B,0CAA0C;iCAOrC,uBAAuB;6BAM3B,mBAAmB;kCAFd,6BAA6B;kCAD7B,wBAAwB;4BAE9B,0BAA0B"}
1
+ {"version":3,"file":"AssetManager.d.ts","sourceRoot":"","sources":["../../../../src/engine/asset/AssetManager.js"],"names":[],"mappings":"AA8CA;;;;GAIG;AACH;IAmII;;;;;OAKG;IACH,oCAJW,GAAG,EAYb;IAhJD;;;;OAIG;IACH,eAEG;IAEH;;;OAGG;IACH,aAFU,YAAY,gBAAgB,EAAE,YAAY,CAAC,CAER;IAe7C;;;;;;OAMG;IACH,kBAFU,MAAM,CAEY;IA4B5B;;;;OAIG;IACH,iBAAc;IAEd;;;OAGG;IACH,mBAFU,iBAAiB,CAEiB;IAwE5C,gBAQC;IAED;;;;OAIG;IACH,qBAHW,MAAM,GACL,QAAQ,IAAI,CAAC,CAexB;IAED;;;;;OAKG;IACH,oCAFa,OAAO,CAOnB;IAED;;OAEG;IACH,cAEC;IAED,8BAEC;I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,14 @@ export class AssetManager {
88
88
  load_concurrency = Infinity;
89
89
 
90
90
  /**
91
- * Registered #loaders
91
+ * Registered asset loaders
92
92
  * @private
93
93
  * @type {Object<AssetLoader>}
94
94
  */
95
95
  #loaders = {};
96
96
 
97
97
  /**
98
- * After asset is loaded, a chain of transforms can be applied to it, these are registered here
98
+ * After an asset is loaded, a chain of transforms can be applied to it, these are registered here
99
99
  * Transformers are executed in the order in which they are added
100
100
  * Identified by asset "type" string
101
101
  * @type {Object<AssetTransformer[]>}
@@ -107,6 +107,9 @@ export class AssetManager {
107
107
  * Named links to specific assets. Useful to later re-mapping assets and having meaningful names for them
108
108
  * @type {Map<string, AssetDescription>}
109
109
  * @private
110
+ * @see resolveAlias
111
+ * @see assignAlias
112
+ * @see promiseByAlias
110
113
  */
111
114
  #aliases = new Map();
112
115
 
@@ -329,6 +332,34 @@ export class AssetManager {
329
332
  return this.request_map.has(assetDescription);
330
333
  }
331
334
 
335
+
336
+ /**
337
+ *
338
+ * @param {string} path
339
+ * @param {string} type
340
+ * @returns {boolean}
341
+ * @see isPending
342
+ */
343
+ isFailed(path, type) {
344
+ const ad = new AssetDescription(path, type);
345
+
346
+ return this.#failures.has(ad);
347
+ }
348
+
349
+ /**
350
+ * Checks if an asset is loaded.
351
+ * If the asset is loaded, calls to {@link tryGet} are guaranteed to succeed.
352
+ *
353
+ * @param {string} path
354
+ * @param {string} type
355
+ * @return {boolean}
356
+ */
357
+ isLoaded(path, type) {
358
+ const ad = new AssetDescription(path, type);
359
+
360
+ return this.assets.has(ad);
361
+ }
362
+
332
363
  /**
333
364
  * Same as {@link insert}, but will register the asset as pending until loader function resolves.
334
365
  *
@@ -387,13 +418,17 @@ export class AssetManager {
387
418
  }
388
419
 
389
420
  return asset_promise.then(asset => {
390
- if (cleanup()) {
391
- this.insert(path, type, asset);
421
+ const existing = this.request_map.get(asset_descriptor);
392
422
 
393
- return asset;
394
- } else {
423
+ if (existing !== pending) {
424
+ // looks like another resolution is pending, this completely invalidates current insersion request
425
+ // Likely reason is that something else was inserted later on
395
426
  throw new Error(`Race condition. Asset with path '${path}' and type '${type}' was already resolved somewhere else.`);
396
427
  }
428
+
429
+ this.insert(path, type, asset);
430
+
431
+ return asset;
397
432
  }, error => {
398
433
  cleanup();
399
434
 
@@ -424,6 +459,9 @@ export class AssetManager {
424
459
  console.warn(`Another asset under ${asset_descritptor} already exists and will be replaced`);
425
460
  }
426
461
 
462
+ // clear failures
463
+ this.#failures.delete(asset_descritptor);
464
+
427
465
  // check for assets in-flight
428
466
  const pending = this.request_map.get(asset_descritptor);
429
467
  if (pending !== undefined) {
@@ -464,6 +502,8 @@ export class AssetManager {
464
502
  * @private
465
503
  */
466
504
  #schedule_response(asset, request) {
505
+ assert.equal(this.#is_running, true, 'AssetManager must be running to schedule responses');
506
+
467
507
  this.#response_queue.add(new Response(asset, request));
468
508
  }
469
509
 
@@ -586,7 +626,7 @@ export class AssetManager {
586
626
 
587
627
  let asset = loaded_asset;
588
628
 
589
- // apply transform chain
629
+ // apply the transform chain
590
630
  const transformers = this.#transformers[type];
591
631
  if (transformers !== undefined) {
592
632
  const transformer_count = transformers.length;
@@ -603,13 +643,16 @@ export class AssetManager {
603
643
  }
604
644
  }
605
645
 
606
- //link asset description
646
+ // link asset description
607
647
  asset.description = assetDescription;
608
648
 
609
- //register asset
649
+ // clear possible failure
650
+ this.#failures.delete(assetDescription);
651
+
652
+ // register asset
610
653
  assets.set(assetDescription, asset);
611
654
 
612
- //clear callbacks etc.
655
+ // clear callbacks etc.
613
656
  this.#handle_asset_resolved(pendingAsset);
614
657
 
615
658
 
@@ -776,9 +819,15 @@ export class AssetManager {
776
819
  }
777
820
 
778
821
  /**
822
+ * Transformer will be applied to all assets of the given type in order of registration.
823
+ *
824
+ * Does not apply retroactively, assets that were already loaded will not be transformed.
825
+ *
779
826
  * @template T
780
827
  * @param {string} type
781
828
  * @param {AssetTransformer<T>} transformer
829
+ * @returns {void}
830
+ * @see removeTransformer
782
831
  */
783
832
  registerTransformer(type, transformer) {
784
833
  let transformers = this.#transformers[type];
@@ -804,6 +853,8 @@ export class AssetManager {
804
853
  * @template T
805
854
  * @param {string} type
806
855
  * @param {AssetTransformer<T>} transformer
856
+ * @returns {boolean} true if removed, false if not found
857
+ * @see registerTransformer
807
858
  */
808
859
  unregisterTransformer(type, transformer) {
809
860
 
@@ -834,7 +885,7 @@ export class AssetManager {
834
885
  * @template T
835
886
  * @param {string} type
836
887
  * @param {AssetLoader<T>} loader
837
- * @returns {Promise<boolean>} true if registered , false otherwise
888
+ * @returns {Promise<boolean>} true if registered, false otherwise
838
889
  */
839
890
  async tryRegisterLoader(type, loader) {
840
891
  if (this.hasLoaderForType(type)) {
@@ -850,7 +901,7 @@ export class AssetManager {
850
901
  * @template T
851
902
  * @param {string} type
852
903
  * @param {AssetLoader<T>} loader
853
- * @throws if a loader is already registered for the given type
904
+ * @throws {Error} if a loader is already registered for the given type
854
905
  */
855
906
  async registerLoader(type, loader) {
856
907
  assert.isString(type, 'type');
@@ -913,8 +964,9 @@ export class AssetManager {
913
964
  }
914
965
 
915
966
  /**
967
+ * Retrieve an asset if it is loaded, returns null if the asset is not loaded.
968
+ * Does not trigger loading if the asset is not loaded.
916
969
  * @template T
917
- * Retrieve an asset if it is loaded, returns null if asset is not loaded.
918
970
  * @param {String} path
919
971
  * @param {String} type
920
972
  * @returns {Asset<T>|null}
@@ -931,18 +983,6 @@ export class AssetManager {
931
983
  }
932
984
  }
933
985
 
934
- /**
935
- *
936
- * @param {string} path
937
- * @param {string} type
938
- * @returns {boolean}
939
- */
940
- isFailed(path, type) {
941
- const ad = new AssetDescription(path, type);
942
-
943
- return this.#failures.has(ad);
944
- }
945
-
946
986
  /**
947
987
  * @template T
948
988
  * @param {string} alias