melonjs 10.10.0 → 11.0.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.
Files changed (95) hide show
  1. package/README.md +4 -3
  2. package/dist/melonjs.js +1071 -2102
  3. package/dist/melonjs.min.js +4 -4
  4. package/dist/melonjs.module.d.ts +600 -1351
  5. package/dist/melonjs.module.js +996 -2029
  6. package/package.json +16 -19
  7. package/src/audio/audio.js +0 -1
  8. package/src/camera/camera2d.js +1 -16
  9. package/src/entity/entity.js +6 -11
  10. package/src/geometries/ellipse.js +3 -12
  11. package/src/geometries/line.js +1 -4
  12. package/src/geometries/path2d.js +4 -14
  13. package/src/geometries/poly.js +6 -24
  14. package/src/geometries/rectangle.js +3 -15
  15. package/src/geometries/roundrect.js +2 -6
  16. package/src/index.js +0 -1
  17. package/src/input/gamepad.js +3 -14
  18. package/src/input/keyboard.js +1 -9
  19. package/src/input/pointer.js +0 -1
  20. package/src/input/pointerevent.js +14 -23
  21. package/src/lang/deprecated.js +4 -3
  22. package/src/level/level.js +0 -9
  23. package/src/level/tiled/TMXGroup.js +0 -4
  24. package/src/level/tiled/TMXLayer.js +0 -8
  25. package/src/level/tiled/TMXObject.js +0 -3
  26. package/src/level/tiled/TMXTile.js +4 -5
  27. package/src/level/tiled/TMXTileMap.js +1 -7
  28. package/src/level/tiled/TMXTileset.js +0 -5
  29. package/src/level/tiled/TMXTilesetGroup.js +1 -4
  30. package/src/level/tiled/TMXUtils.js +0 -3
  31. package/src/level/tiled/renderer/TMXHexagonalRenderer.js +2 -3
  32. package/src/level/tiled/renderer/TMXIsometricRenderer.js +0 -1
  33. package/src/level/tiled/renderer/TMXRenderer.js +1 -7
  34. package/src/loader/loader.js +0 -11
  35. package/src/loader/loadingscreen.js +1 -1
  36. package/src/math/color.js +5 -26
  37. package/src/math/math.js +0 -10
  38. package/src/math/matrix2.js +12 -27
  39. package/src/math/matrix3.js +1 -22
  40. package/src/math/observable_vector2.js +0 -29
  41. package/src/math/observable_vector3.js +0 -29
  42. package/src/math/vector2.js +3 -40
  43. package/src/math/vector3.js +4 -41
  44. package/src/particles/emitter.js +1 -1
  45. package/src/physics/body.js +4 -5
  46. package/src/physics/bounds.js +5 -19
  47. package/src/physics/collision.js +1 -13
  48. package/src/physics/detector.js +6 -56
  49. package/src/physics/quadtree.js +0 -7
  50. package/src/physics/response.js +48 -0
  51. package/src/physics/sat.js +4 -4
  52. package/src/physics/world.js +0 -4
  53. package/src/plugin/plugin.js +0 -2
  54. package/src/polyfill/roundrect.js +4 -2
  55. package/src/renderable/GUI.js +6 -9
  56. package/src/renderable/collectable.js +1 -0
  57. package/src/renderable/colorlayer.js +9 -7
  58. package/src/renderable/container.js +12 -38
  59. package/src/renderable/dragndrop.js +1 -10
  60. package/src/renderable/imagelayer.js +6 -10
  61. package/src/renderable/light2d.js +48 -16
  62. package/src/renderable/renderable.js +6 -28
  63. package/src/renderable/sprite.js +4 -16
  64. package/src/renderable/trigger.js +10 -3
  65. package/src/state/stage.js +0 -4
  66. package/src/state/state.js +22 -23
  67. package/src/system/device.js +16 -119
  68. package/src/system/dom.js +69 -0
  69. package/src/system/event.js +22 -0
  70. package/src/system/pooling.js +20 -9
  71. package/src/system/save.js +9 -11
  72. package/src/system/timer.js +239 -218
  73. package/src/text/bitmaptextdata.js +1 -4
  74. package/src/text/glyph.js +2 -2
  75. package/src/text/text.js +13 -8
  76. package/src/text/textmetrics.js +0 -2
  77. package/src/tweens/easing.js +1 -1
  78. package/src/tweens/interpolation.js +2 -2
  79. package/src/tweens/tween.js +1 -13
  80. package/src/utils/agent.js +1 -3
  81. package/src/utils/array.js +0 -3
  82. package/src/utils/file.js +0 -2
  83. package/src/utils/function.js +0 -2
  84. package/src/utils/string.js +0 -6
  85. package/src/utils/utils.js +0 -3
  86. package/src/video/canvas/canvas_renderer.js +4 -39
  87. package/src/video/renderer.js +1 -23
  88. package/src/video/texture/atlas.js +2 -0
  89. package/src/video/texture/cache.js +0 -1
  90. package/src/video/texture/canvas_texture.js +16 -4
  91. package/src/video/video.js +3 -3
  92. package/src/video/webgl/glshader.js +0 -5
  93. package/src/video/webgl/utils/uniforms.js +3 -6
  94. package/src/video/webgl/webgl_compositor.js +0 -14
  95. package/src/video/webgl/webgl_renderer.js +0 -42
@@ -1,14 +1,10 @@
1
1
  import { hasAudio } from "./../audio/audio.js";
2
2
  import { getParent } from "./../video/video.js";
3
- import save from "./../system/save.js";
3
+ import save from "./save.js";
4
4
  import { prefixed } from "./../utils/agent.js";
5
5
  import state from "./../state/state.js";
6
- import * as event from "./../system/event.js";
7
-
8
- /**
9
- * The device capabilities and specific events
10
- * @namespace device
11
- */
6
+ import * as event from "./event.js";
7
+ import { DOMContentLoaded } from "./dom.js";
12
8
 
13
9
  // private properties
14
10
  let accelInitialized = false;
@@ -28,45 +24,6 @@ function _disableSwipeFn(e) {
28
24
  return false;
29
25
  };
30
26
 
31
- // DOM loading stuff
32
- let readyBound = false, isReady = false, readyList = [];
33
-
34
- /**
35
- * // called to check if the device is ready
36
- * @ignore
37
- */
38
- function _domReady() {
39
- // Make sure that the DOM is not already loaded
40
- if (!isReady) {
41
- // be sure document.body is there
42
- if (!device.nodeJS && !document.body) {
43
- return setTimeout(_domReady, 13);
44
- }
45
-
46
- // clean up loading event
47
- if (typeof globalThis.document !== "undefined" && typeof globalThis.document.removeEventListener === "function") {
48
- globalThis.document.removeEventListener(
49
- "DOMContentLoaded",
50
- this._domReady,
51
- false
52
- );
53
- }
54
-
55
- if (typeof globalThis.removeEventListener === "function") {
56
- // remove the event on globalThis.onload (always added in `onReady`)
57
- globalThis.removeEventListener("load", _domReady, false);
58
- }
59
-
60
- // execute all callbacks
61
- while (readyList.length) {
62
- readyList.shift().call(globalThis, []);
63
- }
64
-
65
- // Remember that the DOM is ready
66
- isReady = true;
67
- }
68
- };
69
-
70
27
  // a cache DOMRect object
71
28
  let _domRect = {left: 0, top: 0, x: 0, y: 0, width: 0, height: 0, right: 0, bottom: 0};
72
29
 
@@ -250,6 +207,11 @@ event.on(event.BOOT, () => {
250
207
 
251
208
 
252
209
  // public export
210
+ /**
211
+ * The device capabilities and specific events
212
+ *
213
+ * @namespace
214
+ */
253
215
  let device = {
254
216
 
255
217
  /**
@@ -257,7 +219,6 @@ let device = {
257
219
  * @type {string}
258
220
  * @readonly
259
221
  * @name ua
260
- * @memberof device
261
222
  */
262
223
  ua : typeof globalThis.navigator !== "undefined" ? globalThis.navigator.userAgent : "",
263
224
 
@@ -267,7 +228,6 @@ let device = {
267
228
  * @type {boolean}
268
229
  * @readonly
269
230
  * @name localStorage
270
- * @memberof device
271
231
  */
272
232
  localStorage : false,
273
233
 
@@ -276,7 +236,6 @@ let device = {
276
236
  * @type {boolean}
277
237
  * @readonly
278
238
  * @name hasAccelerometer
279
- * @memberof device
280
239
  */
281
240
  hasAccelerometer : false,
282
241
 
@@ -285,7 +244,6 @@ let device = {
285
244
  * @type {boolean}
286
245
  * @readonly
287
246
  * @name hasDeviceOrientation
288
- * @memberof device
289
247
  */
290
248
  hasDeviceOrientation : false,
291
249
 
@@ -295,7 +253,6 @@ let device = {
295
253
  * @type {boolean}
296
254
  * @readonly
297
255
  * @name ScreenOrientation
298
- * @memberof device
299
256
  */
300
257
  ScreenOrientation : false,
301
258
 
@@ -304,7 +261,6 @@ let device = {
304
261
  * @type {boolean}
305
262
  * @readonly
306
263
  * @name hasFullscreenSupport
307
- * @memberof device
308
264
  */
309
265
  hasFullscreenSupport : false,
310
266
 
@@ -313,7 +269,6 @@ let device = {
313
269
  * @type {boolean}
314
270
  * @readonly
315
271
  * @name hasPointerLockSupport
316
- * @memberof device
317
272
  */
318
273
  hasPointerLockSupport : false,
319
274
 
@@ -322,7 +277,6 @@ let device = {
322
277
  * @type {boolean}
323
278
  * @readonly
324
279
  * @name hasWebAudio
325
- * @memberof device
326
280
  */
327
281
  hasWebAudio : false,
328
282
 
@@ -331,7 +285,6 @@ let device = {
331
285
  * @type {boolean}
332
286
  * @readonly
333
287
  * @name nativeBase64
334
- * @memberof device
335
288
  */
336
289
  nativeBase64 : (typeof(globalThis.atob) === "function"),
337
290
 
@@ -340,7 +293,6 @@ let device = {
340
293
  * @type {number}
341
294
  * @readonly
342
295
  * @name maxTouchPoints
343
- * @memberof device
344
296
  * @example
345
297
  * if (me.device.maxTouchPoints > 1) {
346
298
  * // device supports multi-touch
@@ -353,7 +305,6 @@ let device = {
353
305
  * @type {boolean}
354
306
  * @readonly
355
307
  * @name touch
356
- * @memberof device
357
308
  */
358
309
  touch : false,
359
310
 
@@ -362,7 +313,6 @@ let device = {
362
313
  * @type {boolean}
363
314
  * @readonly
364
315
  * @name wheel
365
- * @memberof device
366
316
  */
367
317
  wheel : false,
368
318
 
@@ -372,7 +322,6 @@ let device = {
372
322
  * @type {boolean}
373
323
  * @readonly
374
324
  * @name isMobile
375
- * @memberof device
376
325
  */
377
326
  isMobile : false,
378
327
 
@@ -381,7 +330,6 @@ let device = {
381
330
  * @type {boolean}
382
331
  * @readonly
383
332
  * @name iOS
384
- * @memberof device
385
333
  */
386
334
  iOS : false,
387
335
 
@@ -390,7 +338,6 @@ let device = {
390
338
  * @type {boolean}
391
339
  * @readonly
392
340
  * @name android
393
- * @memberof device
394
341
  */
395
342
  android : false,
396
343
 
@@ -399,7 +346,6 @@ let device = {
399
346
  * @type {boolean}
400
347
  * @readonly
401
348
  * @name android2
402
- * @memberof device
403
349
  */
404
350
  android2 : false,
405
351
 
@@ -408,7 +354,6 @@ let device = {
408
354
  * @type {boolean}
409
355
  * @readonly
410
356
  * @name linux
411
- * @memberof device
412
357
  */
413
358
  linux : false,
414
359
 
@@ -418,7 +363,6 @@ let device = {
418
363
  * @readonly
419
364
  * @see http://impactjs.com/ejecta
420
365
  * @name ejecta
421
- * @memberof device
422
366
  */
423
367
  ejecta : false,
424
368
 
@@ -427,7 +371,6 @@ let device = {
427
371
  * @type {boolean}
428
372
  * @readonly
429
373
  * @name isWeixin
430
- * @memberof device
431
374
  */
432
375
  isWeixin : false,
433
376
 
@@ -436,16 +379,14 @@ let device = {
436
379
  * @type {boolean}
437
380
  * @readonly
438
381
  * @name nodeJS
439
- * @memberof device
440
382
  */
441
- nodeJS : (typeof process !== "undefined") && (process.release.name === "node"),
383
+ nodeJS : (typeof globalThis.process !== "undefined") && (typeof globalThis.process.release !== "undefined") && (globalThis.process.release.name === "node"),
442
384
 
443
385
  /**
444
386
  * equals to true if the device is running on ChromeOS.
445
387
  * @type {boolean}
446
388
  * @readonly
447
389
  * @name chromeOS
448
- * @memberof device
449
390
  */
450
391
  chromeOS : false,
451
392
 
@@ -454,7 +395,6 @@ let device = {
454
395
  * @type {boolean}
455
396
  * @readonly
456
397
  * @name wp
457
- * @memberof device
458
398
  */
459
399
  wp : false,
460
400
 
@@ -463,7 +403,6 @@ let device = {
463
403
  * @type {boolean}
464
404
  * @readonly
465
405
  * @name BlackBerry
466
- * @memberof device
467
406
  */
468
407
  BlackBerry : false,
469
408
 
@@ -472,7 +411,6 @@ let device = {
472
411
  * @type {boolean}
473
412
  * @readonly
474
413
  * @name Kindle
475
- * @memberof device
476
414
  */
477
415
  Kindle : false,
478
416
 
@@ -483,7 +421,6 @@ let device = {
483
421
  * @readonly
484
422
  * @name accelerationX
485
423
  * @see device.watchAccelerometer
486
- * @memberof device
487
424
  */
488
425
  accelerationX : 0,
489
426
 
@@ -494,7 +431,6 @@ let device = {
494
431
  * @readonly
495
432
  * @name accelerationY
496
433
  * @see device.watchAccelerometer
497
- * @memberof device
498
434
  */
499
435
  accelerationY : 0,
500
436
 
@@ -505,7 +441,6 @@ let device = {
505
441
  * @readonly
506
442
  * @name accelerationZ
507
443
  * @see device.watchAccelerometer
508
- * @memberof device
509
444
  */
510
445
  accelerationZ : 0,
511
446
 
@@ -516,7 +451,6 @@ let device = {
516
451
  * @readonly
517
452
  * @name gamma
518
453
  * @see device.watchDeviceOrientation
519
- * @memberof device
520
454
  */
521
455
  gamma : 0,
522
456
 
@@ -527,7 +461,6 @@ let device = {
527
461
  * @readonly
528
462
  * @name beta
529
463
  * @see device.watchDeviceOrientation
530
- * @memberof device
531
464
  */
532
465
  beta: 0,
533
466
 
@@ -539,7 +472,6 @@ let device = {
539
472
  * @readonly
540
473
  * @name alpha
541
474
  * @see device.watchDeviceOrientation
542
- * @memberof device
543
475
  */
544
476
  alpha : 0,
545
477
 
@@ -551,7 +483,6 @@ let device = {
551
483
  * @readonly
552
484
  * @see http://www.w3schools.com/tags/ref_language_codes.asp
553
485
  * @name language
554
- * @memberof device
555
486
  */
556
487
  language : typeof globalThis.navigator !== "undefined" ? globalThis.navigator.language || globalThis.navigator.browserLanguage || globalThis.navigator.userLanguage || "en" : "en",
557
488
 
@@ -559,7 +490,6 @@ let device = {
559
490
  * Specify whether to pause the game when losing focus
560
491
  * @type {boolean}
561
492
  * @default true
562
- * @memberof device
563
493
  */
564
494
  pauseOnBlur : true,
565
495
 
@@ -567,7 +497,6 @@ let device = {
567
497
  * Specify whether to unpause the game when gaining focus
568
498
  * @type {boolean}
569
499
  * @default true
570
- * @memberof device
571
500
  */
572
501
  resumeOnFocus : true,
573
502
 
@@ -575,7 +504,6 @@ let device = {
575
504
  * Specify whether to automatically bring the window to the front
576
505
  * @type {boolean}
577
506
  * @default true
578
- * @memberof device
579
507
  */
580
508
  autoFocus : true,
581
509
 
@@ -584,7 +512,6 @@ let device = {
584
512
  * The engine restarts on focus if this is enabled.
585
513
  * @type {boolean}
586
514
  * @default false
587
- * @memberof device
588
515
  */
589
516
  stopOnBlur : false,
590
517
 
@@ -593,7 +520,6 @@ let device = {
593
520
  * @type {boolean}
594
521
  * @readonly
595
522
  * @name OffScreenCanvas
596
- * @memberof device
597
523
  */
598
524
  OffscreenCanvas : false,
599
525
 
@@ -642,33 +568,7 @@ let device = {
642
568
  * });
643
569
  */
644
570
  onReady(fn) {
645
- // If the DOM is already ready
646
- if (isReady) {
647
- // Execute the function immediately
648
- fn.call(globalThis, []);
649
- }
650
- else {
651
- // Add the function to the wait list
652
- readyList.push(fn);
653
-
654
- // attach listeners if not yet done
655
- if (!readyBound) {
656
- // directly call domReady if document is already "ready"
657
- if (device.nodeJS === true || (typeof globalThis.document !== "undefined" && globalThis.document.readyState === "complete")) {
658
- // defer the fn call to ensure our script is fully loaded
659
- globalThis.setTimeout(_domReady, 0);
660
- }
661
- else {
662
- if (typeof globalThis.document !== "undefined" && typeof globalThis.document.addEventListener === "function") {
663
- // Use the handy event callback
664
- globalThis.document.addEventListener("DOMContentLoaded", _domReady, false);
665
- }
666
- // A fallback to globalThis.onload, that will always work
667
- globalThis.addEventListener("load", _domReady, false);
668
- }
669
- readyBound = true;
670
- }
671
- }
571
+ DOMContentLoaded(fn);
672
572
  },
673
573
 
674
574
  /**
@@ -1110,10 +1010,9 @@ let device = {
1110
1010
 
1111
1011
  /**
1112
1012
  * Ratio of the resolution in physical pixels to the resolution in CSS pixels for the current display device.
1113
- * @name devicePixelRatio
1114
- * @memberof device
1013
+ * @name device.devicePixelRatio
1115
1014
  * @public
1116
- * @type {number}
1015
+ * @member {number}
1117
1016
  * @readonly
1118
1017
  * @returns {number}
1119
1018
  */
@@ -1128,10 +1027,9 @@ Object.defineProperty(device, "devicePixelRatio", {
1128
1027
 
1129
1028
  /**
1130
1029
  * Returns true if the browser/device is in full screen mode.
1131
- * @name isFullscreen
1132
- * @memberof device
1030
+ * @name device.isFullscreen
1133
1031
  * @public
1134
- * @type {boolean}
1032
+ * @member {boolean}
1135
1033
  * @readonly
1136
1034
  * @returns {boolean}
1137
1035
  */
@@ -1151,10 +1049,9 @@ Object.defineProperty(device, "isFullscreen", {
1151
1049
 
1152
1050
  /**
1153
1051
  * Returns true if the browser/device has audio capabilities.
1154
- * @name sound
1155
- * @memberof device
1052
+ * @name device.sound
1156
1053
  * @public
1157
- * @type {boolean}
1054
+ * @member {boolean}
1158
1055
  * @readonly
1159
1056
  * @returns {boolean}
1160
1057
  */
@@ -0,0 +1,69 @@
1
+ import * as event from "./event.js";
2
+
3
+ // track if DOMContentLoaded was called already
4
+ let readyBound = false;
5
+
6
+ // is the DOM ready ?
7
+ let isDOMReady = false;
8
+
9
+ // check if the dom is ready
10
+ function _domReady() {
11
+
12
+ // Make sure that the DOM is not already loaded
13
+ if (!isDOMReady) {
14
+ // be sure document.body is there
15
+ if (typeof globalThis.document !== "undefined" && !globalThis.document.body) {
16
+ return setTimeout(_domReady, 13);
17
+ }
18
+
19
+ // clean up loading event
20
+ if (typeof globalThis.document !== "undefined" && typeof globalThis.document.removeEventListener === "function") {
21
+ globalThis.document.removeEventListener(
22
+ "DOMContentLoaded",
23
+ _domReady,
24
+ false
25
+ );
26
+ }
27
+
28
+ if (typeof globalThis.removeEventListener === "function") {
29
+ // remove the event on globalThis.onload (always added in `onReady`)
30
+ globalThis.removeEventListener("load", _domReady, false);
31
+ }
32
+
33
+ // execute all callbacks
34
+ event.emit(event.DOM_READY);
35
+
36
+ // Remember that the DOM is ready
37
+ isDOMReady = true;
38
+ }
39
+ };
40
+
41
+ // https://developer.mozilla.org/en-US/docs/Web/API/Window/DOMContentLoaded_event
42
+ export function DOMContentLoaded(fn) {
43
+ // If the DOM is already ready
44
+ if (isDOMReady) {
45
+ // Execute the function immediately
46
+ fn.call(globalThis, []);
47
+ }
48
+ else {
49
+ // else add the function to the DOM_READY event
50
+ event.once(event.DOM_READY, fn, globalThis);
51
+ // bind dom load event if not done yet
52
+ if (!readyBound) {
53
+ // directly call domReady if document is already "ready"
54
+ if (((typeof process !== "undefined") && (process.release.name === "node")) || (typeof globalThis.document !== "undefined" && globalThis.document.readyState === "complete")) {
55
+ // defer the fn call to ensure our script is fully loaded
56
+ globalThis.setTimeout(_domReady, 0);
57
+ }
58
+ else {
59
+ if (typeof globalThis.document !== "undefined" && typeof globalThis.document.addEventListener === "function") {
60
+ // Use the handy event callback
61
+ globalThis.document.addEventListener("DOMContentLoaded", _domReady, false);
62
+ }
63
+ // A fallback to globalThis.onload, that will always work
64
+ globalThis.addEventListener("load", _domReady, false);
65
+ }
66
+ readyBound = true;
67
+ }
68
+ }
69
+ }
@@ -8,6 +8,17 @@ import EventEmitter from "eventemitter3";
8
8
  // internal instance of the event emiter
9
9
  var eventEmitter = new EventEmitter();
10
10
 
11
+ /**
12
+ * event when the DOM is Ready is booting
13
+ * @public
14
+ * @constant
15
+ * @type {string}
16
+ * @name DOM_READY
17
+ * @memberof event
18
+ * @see event.on
19
+ */
20
+ export const DOM_READY = "dom_ready";
21
+
11
22
  /**
12
23
  * event when the system is booting
13
24
  * @public
@@ -67,6 +78,17 @@ export const STATE_STOP = "me.state.onStop";
67
78
  */
68
79
  export const STATE_RESTART = "me.state.onRestart";
69
80
 
81
+ /**
82
+ * event for when the changing to a different stage
83
+ * @public
84
+ * @constant
85
+ * @type {string}
86
+ * @name STATE_CHANGE
87
+ * @memberof event
88
+ * @see event.on
89
+ */
90
+ export const STATE_CHANGE = "me.state.onChange";
91
+
70
92
  /**
71
93
  * event for when the video is initialized<br>
72
94
  * Data passed : none <br>
@@ -1,16 +1,16 @@
1
1
  /**
2
2
  * @classdesc
3
- * This object is used for object pooling - a technique that might speed up your game if used properly.<br>
3
+ * Object pooling - a technique that might speed up your game if used properly.<br>
4
4
  * If some of your classes will be instantiated and removed a lot at a time, it is a
5
5
  * good idea to add the class to this object pool. A separate pool for that class
6
6
  * will be created, which will reuse objects of the class. That way they won't be instantiated
7
7
  * each time you need a new one (slowing your game), but stored into that pool and taking one
8
8
  * already instantiated when you need it.<br><br>
9
- * This object is also used by the engine to instantiate objects defined in the map,
9
+ * This technique is also used by the engine to instantiate objects defined in the map,
10
10
  * which means, that on level loading the engine will try to instantiate every object
11
11
  * found in the map, based on the user defined name in each Object Properties<br>
12
12
  * <img src="images/object_properties.png"/><br>
13
- * @see {@link pool} a default global instance of ObjectPool
13
+ * @see {@link pool} the default global instance of ObjectPool
14
14
  */
15
15
  class ObjectPool {
16
16
 
@@ -167,7 +167,7 @@ class ObjectPool {
167
167
  return (typeof className !== "undefined") &&
168
168
  (typeof obj.onResetEvent === "function") &&
169
169
  (className in this.objectClass) &&
170
- (this.objectClass[className].pool !== "undefined");
170
+ (typeof this.objectClass[className].pool !== "undefined");
171
171
 
172
172
  }
173
173
 
@@ -180,11 +180,22 @@ class ObjectPool {
180
180
  }
181
181
  };
182
182
 
183
- /**
184
- * a default global object pool instance
185
- * @public
186
- * @type {ObjectPool}
187
- */
183
+
188
184
  var pool = new ObjectPool();
189
185
 
186
+ /**
187
+ * a default global ObjectPool instance
188
+ * @namespace pool
189
+ * @see ObjectPool
190
+ * @example
191
+ * // register our bullet object into the object pool
192
+ * pool.register("bullet", BulletEntity, true);
193
+ * // ...
194
+ * // when we need to manually create a new bullet:
195
+ * var bullet = pool.pull("bullet", x, y, direction, velocity);
196
+ * // ...
197
+ * // when we want to destroy existing object, the remove
198
+ * // function will ensure the object can then be reallocated later
199
+ * game.world.removeChild(bullet);
200
+ */
190
201
  export default pool;
@@ -1,5 +1,5 @@
1
- import device from "./../system/device.js";
2
- import * as event from "./../system/event.js";
1
+ import device from "./device.js";
2
+ import * as event from "./event.js";
3
3
 
4
4
  /**
5
5
  * allow to access and manage the device localStorage
@@ -47,13 +47,13 @@ import * as event from "./../system/event.js";
47
47
  // Initialize me.save on Boot event
48
48
  event.on(event.BOOT, () => {
49
49
  // Load previous data if local Storage is supported
50
- if (device.localStorage === true) {
51
- var me_save_content = localStorage.getItem("me.save");
50
+ if (typeof globalThis.localStorage !== "undefined") {
51
+ var me_save_content = globalThis.localStorage.getItem("me.save");
52
52
 
53
53
  if (typeof me_save_content === "string" && me_save_content.length > 0) {
54
54
  var keys = JSON.parse(me_save_content) || [];
55
55
  keys.forEach(function (key) {
56
- data[key] = JSON.parse(localStorage.getItem("me.save." + key));
56
+ data[key] = JSON.parse(globalThis.localStorage.getItem("me.save." + key));
57
57
  });
58
58
  }
59
59
  }
@@ -65,7 +65,6 @@ var save = {
65
65
  * Add new keys to localStorage and set them to the given default values if they do not exist
66
66
  * @name add
67
67
  * @memberof save
68
- * @function
69
68
  * @param {object} props key and corresponding values
70
69
  * @example
71
70
  * // Initialize "score" and "lives" with default values
@@ -97,7 +96,7 @@ var save = {
97
96
  set (value) {
98
97
  data[prop] = value;
99
98
  if (device.localStorage === true) {
100
- localStorage.setItem("me.save." + prop, JSON.stringify(value));
99
+ globalThis.localStorage.setItem("me.save." + prop, JSON.stringify(value));
101
100
  }
102
101
  }
103
102
  });
@@ -111,7 +110,7 @@ var save = {
111
110
 
112
111
  // Save keys
113
112
  if (device.localStorage === true) {
114
- localStorage.setItem("me.save", JSON.stringify(Object.keys(data)));
113
+ globalThis.localStorage.setItem("me.save", JSON.stringify(Object.keys(data)));
115
114
  }
116
115
  },
117
116
 
@@ -119,7 +118,6 @@ var save = {
119
118
  * Remove a key from localStorage
120
119
  * @name remove
121
120
  * @memberof save
122
- * @function
123
121
  * @param {string} key key to be removed
124
122
  * @example
125
123
  * // Remove the "score" key from localStorage
@@ -130,8 +128,8 @@ var save = {
130
128
  if (typeof data[key] !== "undefined") {
131
129
  delete data[key];
132
130
  if (device.localStorage === true) {
133
- localStorage.removeItem("me.save." + key);
134
- localStorage.setItem("me.save", JSON.stringify(Object.keys(data)));
131
+ globalThis.localStorage.removeItem("me.save." + key);
132
+ globalThis.localStorage.setItem("me.save", JSON.stringify(Object.keys(data)));
135
133
  }
136
134
  }
137
135
  }