@woosh/meep-engine 2.126.69 → 2.126.72

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.69",
8
+ "version": "2.126.72",
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;;;;;;;;;;;;;;;;;;;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;4BA78B2B,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;IAED;;;;;;OAMG;IACH,4DAJW,iBAAiB,GAEf,cAAc,CAY1B;IAED;;;;;;;;;OASG;IACH,qFAsCC;IAED;;;;;;;OAOG;IACH,gBAJW,MAAM,QACN,MAAM,GACL,OAAO,CAKlB;IAGD;;;;;;OAMG;IACH,eALW,MAAM,QACN,MAAM,GACJ,OAAO,CAOnB;IAED;;;;;;;OAOG;IACH,eAJW,MAAM,QACN,MAAM,GACL,OAAO,CAMlB;IAED;;;;;;;;;;;;;;;;;;;OAmBG;IACH,uBAZW,MAAM,QACN,MAAM,gBAEJ,mBAAiB,CA4D7B;IAED;;;;;;;;OAQG;IACH,kBAJW,MAAM,QACN,MAAM,2BAoChB;IA8QD;;;;;OAKG;IACH,sBA2BC;IAGD;;;;OAIG;IACH,uBAHW,MAAM,GACL,OAAO,CAIlB;IAED;;;;OAIG;IACH,sBAHW,MAAM,GACJ,wBAAY,SAAS,CAMjC;IAaD;;;;;;;;;;OAUG;IACH,+BALW,MAAM,uCAEJ,IAAI,CAqBhB;IAED;;;;;;OAMG;IACH,iCALW,MAAM,uCAEJ,OAAO,CAyBnB;IAED;;;;;;OAMG;IACH,6BAJW,MAAM,kCAEJ,QAAQ,OAAO,CAAC,CAU5B;IAED;;;;;OAKG;IACH,0BAJW,MAAM,iEAwChB;IAED;;;OAGG;IACH,uBAFW,MAAM,iBAkBhB;IAED;;;;;;;OAOG;IACH,yCAFa,aAAS,IAAI,CAYzB;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;4BA5/B2B,0CAA0C;iCAOrC,uBAAuB;6BAM3B,mBAAmB;kCAFd,6BAA6B;kCAD7B,wBAAwB;4BAE9B,0BAA0B"}
@@ -88,14 +88,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
 
@@ -316,6 +319,47 @@ export class AssetManager {
316
319
  }
317
320
  }
318
321
 
322
+ /**
323
+ * Checks if an asset is currently being loaded.
324
+ * Useful for avoiding redundant requests.
325
+ *
326
+ * @param {string} path
327
+ * @param {string} type
328
+ * @return {boolean}
329
+ */
330
+ isPending(path, type) {
331
+ const assetDescription = new AssetDescription(path, type);
332
+ return this.request_map.has(assetDescription);
333
+ }
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
+
319
363
  /**
320
364
  * Same as {@link insert}, but will register the asset as pending until loader function resolves.
321
365
  *
@@ -341,7 +385,7 @@ export class AssetManager {
341
385
  const asset_descriptor = new AssetDescription(path, type);
342
386
 
343
387
  if (this.request_map.get(asset_descriptor)) {
344
- throw new Error(`Asset with path ${path} and type ${type} is already pending`);
388
+ throw new Error(`Asset with path '${path}' and type '${type}' is already pending`);
345
389
  }
346
390
 
347
391
  const pending = new PendingAsset(asset_descriptor);
@@ -379,7 +423,7 @@ export class AssetManager {
379
423
 
380
424
  return asset;
381
425
  } else {
382
- throw new Error(`Race condition. Asset with path ${path} and type ${type} was already resolved somewhere else.`);
426
+ throw new Error(`Race condition. Asset with path '${path}' and type '${type}' was already resolved somewhere else.`);
383
427
  }
384
428
  }, error => {
385
429
  cleanup();
@@ -411,10 +455,13 @@ export class AssetManager {
411
455
  console.warn(`Another asset under ${asset_descritptor} already exists and will be replaced`);
412
456
  }
413
457
 
458
+ // clear failures
459
+ this.#failures.delete(asset_descritptor);
460
+
414
461
  // check for assets in-flight
415
462
  const pending = this.request_map.get(asset_descritptor);
416
463
  if (pending !== undefined) {
417
- console.warn(`Asset with path ${path} and type ${type} is already pending, this operation will squash the asset in-flight`);
464
+ console.warn(`Asset with path '${path}' and type '${type}' is already pending, this operation will squash the asset in-flight`);
418
465
 
419
466
  this.request_map.delete(asset_descritptor);
420
467
 
@@ -573,7 +620,7 @@ export class AssetManager {
573
620
 
574
621
  let asset = loaded_asset;
575
622
 
576
- // apply transform chain
623
+ // apply the transform chain
577
624
  const transformers = this.#transformers[type];
578
625
  if (transformers !== undefined) {
579
626
  const transformer_count = transformers.length;
@@ -590,13 +637,16 @@ export class AssetManager {
590
637
  }
591
638
  }
592
639
 
593
- //link asset description
640
+ // link asset description
594
641
  asset.description = assetDescription;
595
642
 
596
- //register asset
643
+ // clear possible failure
644
+ this.#failures.delete(assetDescription);
645
+
646
+ // register asset
597
647
  assets.set(assetDescription, asset);
598
648
 
599
- //clear callbacks etc.
649
+ // clear callbacks etc.
600
650
  this.#handle_asset_resolved(pendingAsset);
601
651
 
602
652
 
@@ -763,9 +813,15 @@ export class AssetManager {
763
813
  }
764
814
 
765
815
  /**
816
+ * Transformer will be applied to all assets of the given type in order of registration.
817
+ *
818
+ * Does not apply retroactively, assets that were already loaded will not be transformed.
819
+ *
766
820
  * @template T
767
821
  * @param {string} type
768
822
  * @param {AssetTransformer<T>} transformer
823
+ * @returns {void}
824
+ * @see removeTransformer
769
825
  */
770
826
  registerTransformer(type, transformer) {
771
827
  let transformers = this.#transformers[type];
@@ -791,6 +847,8 @@ export class AssetManager {
791
847
  * @template T
792
848
  * @param {string} type
793
849
  * @param {AssetTransformer<T>} transformer
850
+ * @returns {boolean} true if removed, false if not found
851
+ * @see registerTransformer
794
852
  */
795
853
  unregisterTransformer(type, transformer) {
796
854
 
@@ -821,7 +879,7 @@ export class AssetManager {
821
879
  * @template T
822
880
  * @param {string} type
823
881
  * @param {AssetLoader<T>} loader
824
- * @returns {Promise<boolean>} true if registered , false otherwise
882
+ * @returns {Promise<boolean>} true if registered, false otherwise
825
883
  */
826
884
  async tryRegisterLoader(type, loader) {
827
885
  if (this.hasLoaderForType(type)) {
@@ -837,7 +895,7 @@ export class AssetManager {
837
895
  * @template T
838
896
  * @param {string} type
839
897
  * @param {AssetLoader<T>} loader
840
- * @throws if a loader is already registered for the given type
898
+ * @throws {Error} if a loader is already registered for the given type
841
899
  */
842
900
  async registerLoader(type, loader) {
843
901
  assert.isString(type, 'type');
@@ -900,8 +958,9 @@ export class AssetManager {
900
958
  }
901
959
 
902
960
  /**
961
+ * Retrieve an asset if it is loaded, returns null if the asset is not loaded.
962
+ * Does not trigger loading if the asset is not loaded.
903
963
  * @template T
904
- * Retrieve an asset if it is loaded, returns null if asset is not loaded.
905
964
  * @param {String} path
906
965
  * @param {String} type
907
966
  * @returns {Asset<T>|null}
@@ -918,18 +977,6 @@ export class AssetManager {
918
977
  }
919
978
  }
920
979
 
921
- /**
922
- *
923
- * @param {string} path
924
- * @param {string} type
925
- * @returns {boolean}
926
- */
927
- isFailed(path, type) {
928
- const ad = new AssetDescription(path, type);
929
-
930
- return this.#failures.has(ad);
931
- }
932
-
933
980
  /**
934
981
  * @template T
935
982
  * @param {string} alias