melonjs 15.1.6 → 15.2.1

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 (153) hide show
  1. package/README.md +6 -6
  2. package/dist/melonjs.mjs/_virtual/_commonjsHelpers.js +1 -1
  3. package/dist/melonjs.mjs/_virtual/earcut.js +1 -1
  4. package/dist/melonjs.mjs/_virtual/howler.js +1 -1
  5. package/dist/melonjs.mjs/_virtual/index.js +1 -1
  6. package/dist/melonjs.mjs/application/application.js +3 -3
  7. package/dist/melonjs.mjs/application/header.js +1 -1
  8. package/dist/melonjs.mjs/application/resize.js +1 -1
  9. package/dist/melonjs.mjs/application/settings.js +1 -1
  10. package/dist/melonjs.mjs/audio/audio.js +1 -1
  11. package/dist/melonjs.mjs/camera/camera2d.js +1 -1
  12. package/dist/melonjs.mjs/const.js +1 -1
  13. package/dist/melonjs.mjs/entity/entity.js +1 -1
  14. package/dist/melonjs.mjs/geometries/ellipse.js +1 -1
  15. package/dist/melonjs.mjs/geometries/line.js +1 -1
  16. package/dist/melonjs.mjs/geometries/path2d.js +1 -1
  17. package/dist/melonjs.mjs/geometries/point.js +1 -1
  18. package/dist/melonjs.mjs/geometries/poly.js +1 -1
  19. package/dist/melonjs.mjs/geometries/rectangle.js +1 -1
  20. package/dist/melonjs.mjs/geometries/roundrect.js +1 -1
  21. package/dist/melonjs.mjs/index.js +12 -6
  22. package/dist/melonjs.mjs/input/gamepad.js +1 -1
  23. package/dist/melonjs.mjs/input/input.js +1 -1
  24. package/dist/melonjs.mjs/input/keyboard.js +1 -1
  25. package/dist/melonjs.mjs/input/pointer.js +1 -1
  26. package/dist/melonjs.mjs/input/pointerevent.js +1 -1
  27. package/dist/melonjs.mjs/lang/console.js +1 -1
  28. package/dist/melonjs.mjs/lang/deprecated.js +1 -1
  29. package/dist/melonjs.mjs/level/level.js +5 -4
  30. package/dist/melonjs.mjs/level/tiled/TMXGroup.js +1 -1
  31. package/dist/melonjs.mjs/level/tiled/TMXLayer.js +1 -1
  32. package/dist/melonjs.mjs/level/tiled/TMXObject.js +1 -1
  33. package/dist/melonjs.mjs/level/tiled/TMXTile.js +1 -1
  34. package/dist/melonjs.mjs/level/tiled/TMXTileMap.js +3 -3
  35. package/dist/melonjs.mjs/level/tiled/TMXTileset.js +1 -1
  36. package/dist/melonjs.mjs/level/tiled/TMXTilesetGroup.js +1 -1
  37. package/dist/melonjs.mjs/level/tiled/TMXUtils.js +127 -95
  38. package/dist/melonjs.mjs/level/tiled/constants.js +1 -1
  39. package/dist/melonjs.mjs/level/tiled/renderer/TMXHexagonalRenderer.js +1 -1
  40. package/dist/melonjs.mjs/level/tiled/renderer/TMXIsometricRenderer.js +1 -1
  41. package/dist/melonjs.mjs/level/tiled/renderer/TMXOrthogonalRenderer.js +1 -1
  42. package/dist/melonjs.mjs/level/tiled/renderer/TMXRenderer.js +1 -1
  43. package/dist/melonjs.mjs/level/tiled/renderer/TMXStaggeredRenderer.js +1 -1
  44. package/dist/melonjs.mjs/level/tiled/renderer/autodetect.js +1 -1
  45. package/dist/melonjs.mjs/loader/cache.js +1 -1
  46. package/dist/melonjs.mjs/loader/loader.js +1 -1
  47. package/dist/melonjs.mjs/loader/loadingscreen.js +1 -1
  48. package/dist/melonjs.mjs/loader/melonjs_logo.png.js +1 -1
  49. package/dist/melonjs.mjs/loader/parser.js +1 -1
  50. package/dist/melonjs.mjs/loader/settings.js +1 -1
  51. package/dist/melonjs.mjs/math/color.js +1 -1
  52. package/dist/melonjs.mjs/math/math.js +1 -1
  53. package/dist/melonjs.mjs/math/matrix2.js +1 -1
  54. package/dist/melonjs.mjs/math/matrix3.js +1 -1
  55. package/dist/melonjs.mjs/math/observable_vector2.js +1 -1
  56. package/dist/melonjs.mjs/math/observable_vector3.js +1 -1
  57. package/dist/melonjs.mjs/math/vector2.js +1 -1
  58. package/dist/melonjs.mjs/math/vector3.js +1 -1
  59. package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/esm/arraymultimap.js +1 -1
  60. package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/esm/multimap.js +1 -1
  61. package/dist/melonjs.mjs/node_modules/earcut/src/earcut.js +1 -1
  62. package/dist/melonjs.mjs/node_modules/eventemitter3/index.js +1 -1
  63. package/dist/melonjs.mjs/node_modules/eventemitter3/index2.js +1 -1
  64. package/dist/melonjs.mjs/node_modules/howler/dist/howler.js +1 -1
  65. package/dist/melonjs.mjs/particles/emitter.js +1 -1
  66. package/dist/melonjs.mjs/particles/particle.js +1 -1
  67. package/dist/melonjs.mjs/particles/settings.js +1 -1
  68. package/dist/melonjs.mjs/physics/body.js +1 -1
  69. package/dist/melonjs.mjs/physics/bounds.js +1 -1
  70. package/dist/melonjs.mjs/physics/collision.js +1 -1
  71. package/dist/melonjs.mjs/physics/detector.js +1 -1
  72. package/dist/melonjs.mjs/physics/quadtree.js +1 -1
  73. package/dist/melonjs.mjs/physics/response.js +1 -1
  74. package/dist/melonjs.mjs/physics/sat.js +1 -1
  75. package/dist/melonjs.mjs/physics/world.js +1 -1
  76. package/dist/melonjs.mjs/plugin/plugin.js +106 -108
  77. package/dist/melonjs.mjs/renderable/collectable.js +1 -1
  78. package/dist/melonjs.mjs/renderable/colorlayer.js +1 -1
  79. package/dist/melonjs.mjs/renderable/container.js +7 -6
  80. package/dist/melonjs.mjs/renderable/draggable.js +1 -1
  81. package/dist/melonjs.mjs/renderable/dragndrop.js +1 -1
  82. package/dist/melonjs.mjs/renderable/imagelayer.js +1 -1
  83. package/dist/melonjs.mjs/renderable/light2d.js +1 -1
  84. package/dist/melonjs.mjs/renderable/nineslicesprite.js +1 -1
  85. package/dist/melonjs.mjs/renderable/renderable.js +1 -1
  86. package/dist/melonjs.mjs/renderable/sprite.js +1 -1
  87. package/dist/melonjs.mjs/renderable/trigger.js +1 -1
  88. package/dist/melonjs.mjs/renderable/ui/uibaseelement.js +1 -1
  89. package/dist/melonjs.mjs/renderable/ui/uispriteelement.js +1 -1
  90. package/dist/melonjs.mjs/renderable/ui/uitextbutton.js +1 -1
  91. package/dist/melonjs.mjs/state/stage.js +1 -1
  92. package/dist/melonjs.mjs/state/state.js +1 -1
  93. package/dist/melonjs.mjs/system/device.js +1 -1
  94. package/dist/melonjs.mjs/system/dom.js +1 -1
  95. package/dist/melonjs.mjs/system/event.js +1 -1
  96. package/dist/melonjs.mjs/system/platform.js +1 -1
  97. package/dist/melonjs.mjs/system/pooling.js +1 -1
  98. package/dist/melonjs.mjs/system/save.js +1 -1
  99. package/dist/melonjs.mjs/system/timer.js +4 -4
  100. package/dist/melonjs.mjs/text/bitmaptext.js +1 -1
  101. package/dist/melonjs.mjs/text/bitmaptextdata.js +1 -1
  102. package/dist/melonjs.mjs/text/glyph.js +1 -1
  103. package/dist/melonjs.mjs/text/text.js +1 -1
  104. package/dist/melonjs.mjs/text/textmetrics.js +1 -1
  105. package/dist/melonjs.mjs/text/textstyle.js +1 -1
  106. package/dist/melonjs.mjs/tweens/easing.js +1 -1
  107. package/dist/melonjs.mjs/tweens/interpolation.js +1 -1
  108. package/dist/melonjs.mjs/tweens/tween.js +1 -1
  109. package/dist/melonjs.mjs/utils/agent.js +1 -1
  110. package/dist/melonjs.mjs/utils/array.js +1 -1
  111. package/dist/melonjs.mjs/utils/file.js +1 -1
  112. package/dist/melonjs.mjs/utils/function.js +1 -1
  113. package/dist/melonjs.mjs/utils/string.js +1 -1
  114. package/dist/melonjs.mjs/utils/utils.js +105 -111
  115. package/dist/melonjs.mjs/video/canvas/canvas_renderer.js +1 -1
  116. package/dist/melonjs.mjs/video/renderer.js +1 -1
  117. package/dist/melonjs.mjs/video/texture/atlas.js +1 -1
  118. package/dist/melonjs.mjs/video/texture/cache.js +1 -1
  119. package/dist/melonjs.mjs/video/texture/canvas_texture.js +1 -1
  120. package/dist/melonjs.mjs/video/utils/autodetect.js +1 -1
  121. package/dist/melonjs.mjs/video/video.js +6 -32
  122. package/dist/melonjs.mjs/video/webgl/buffer/vertex.js +1 -1
  123. package/dist/melonjs.mjs/video/webgl/compositors/compositor.js +1 -1
  124. package/dist/melonjs.mjs/video/webgl/compositors/primitive_compositor.js +1 -1
  125. package/dist/melonjs.mjs/video/webgl/compositors/quad_compositor.js +1 -1
  126. package/dist/melonjs.mjs/video/webgl/glshader.js +1 -1
  127. package/dist/melonjs.mjs/video/webgl/shaders/primitive.frag.js +1 -1
  128. package/dist/melonjs.mjs/video/webgl/shaders/primitive.vert.js +1 -1
  129. package/dist/melonjs.mjs/video/webgl/shaders/quad.frag.js +1 -1
  130. package/dist/melonjs.mjs/video/webgl/shaders/quad.vert.js +1 -1
  131. package/dist/melonjs.mjs/video/webgl/utils/attributes.js +1 -1
  132. package/dist/melonjs.mjs/video/webgl/utils/precision.js +1 -1
  133. package/dist/melonjs.mjs/video/webgl/utils/program.js +1 -1
  134. package/dist/melonjs.mjs/video/webgl/utils/string.js +1 -1
  135. package/dist/melonjs.mjs/video/webgl/utils/uniforms.js +1 -1
  136. package/dist/melonjs.mjs/video/webgl/webgl_renderer.js +1 -1
  137. package/dist/melonjs.module.js +595 -570
  138. package/dist/types/index.d.ts +5 -4
  139. package/dist/types/level/tiled/TMXUtils.d.ts +19 -36
  140. package/dist/types/plugin/plugin.d.ts +60 -5
  141. package/dist/types/utils/utils.d.ts +56 -17
  142. package/dist/types/video/video.d.ts +1 -21
  143. package/package.json +5 -5
  144. package/src/application/application.js +2 -2
  145. package/src/index.js +5 -2
  146. package/src/level/level.js +4 -3
  147. package/src/level/tiled/TMXTileMap.js +2 -2
  148. package/src/level/tiled/TMXUtils.js +126 -94
  149. package/src/plugin/plugin.js +103 -105
  150. package/src/renderable/container.js +6 -5
  151. package/src/system/timer.js +3 -3
  152. package/src/utils/utils.js +102 -111
  153. package/src/video/video.js +6 -8
@@ -1,132 +1,130 @@
1
- import utils from "./../utils/utils.js";
1
+ import { checkVersion } from "./../utils/utils.js";
2
2
  import { version } from "./../index.js";
3
3
 
4
4
  /**
5
- * This namespace is a container for all registered plugins.
6
- * @see plugin.register
7
- * @namespace plugins
5
+ * Contains all registered plugins.
6
+ * @name cache
7
+ * @memberof plugin
8
8
  */
9
- export let plugins = {};
9
+ export let cache = {};
10
10
 
11
+ /**
12
+ * @namespace plugin
13
+ */
11
14
 
12
- class BasePlugin {
15
+ /**
16
+ * a base Object class for plugin
17
+ * (plugin must be installed using the register function)
18
+ * @class
19
+ * @name BasePlugin
20
+ * @memberof plugin
21
+ */
22
+ export class BasePlugin {
13
23
 
14
24
  constructor() {
15
25
  /**
16
26
  * define the minimum required version of melonJS<br>
17
27
  * this can be overridden by the plugin
18
- * @public
19
28
  * @type {string}
20
29
  * @default "__VERSION__"
21
- * @name plugin.Base#version
22
30
  */
23
31
  this.version = "__VERSION__";
24
32
  }
25
33
  }
26
34
 
35
+
27
36
  /**
28
- * @namespace plugin
37
+ * @class
38
+ * @name Base
39
+ * @memberof plugin
40
+ * @deprecated since 15.1.6, see {@link plugin.BasePlugin}
29
41
  */
30
- export let plugin = {
31
-
32
- /**
33
- * a base Object for plugin <br>
34
- * plugin must be installed using the register function
35
- * @see plugin
36
- * @class
37
- * @name Base
38
- * @memberof plugin
39
- */
40
- Base : BasePlugin,
41
-
42
- /**
43
- * patch a melonJS function
44
- * @name patch
45
- * @memberof plugin
46
- * @public
47
- * @param {object} proto - target object
48
- * @param {string} name - target function
49
- * @param {Function} fn - replacement function
50
- * @example
51
- * // redefine the me.game.update function with a new one
52
- * me.plugin.patch(me.game, "update", function () {
53
- * // display something in the console
54
- * console.log("duh");
55
- * // call the original me.game.update function
56
- * this._patched();
57
- * });
58
- */
59
- patch : function (proto, name, fn) {
60
- // use the object prototype if possible
61
- if (typeof proto.prototype !== "undefined") {
62
- proto = proto.prototype;
63
- }
64
- // reuse the logic behind object extends
65
- if (typeof(proto[name]) === "function") {
66
- // save the original function
67
- let _parent = proto[name];
68
- // override the function with the new one
69
- Object.defineProperty(proto, name, {
70
- "configurable" : true,
71
- "value" : (function (name, fn) {
72
- return function () {
73
- this._patched = _parent;
74
- let ret = fn.apply(this, arguments);
75
- this._patched = null;
76
- return ret;
77
- };
78
- })(name, fn)
79
- });
80
- }
81
- else {
82
- throw new Error(name + " is not an existing function");
83
- }
84
- },
42
+ export class Base extends BasePlugin {}
85
43
 
86
- /**
87
- * Register a plugin.
88
- * @name register
89
- * @memberof plugin
90
- * @see Base
91
- * @public
92
- * @param {plugin.Base} pluginObj - Plugin object to instantiate and register
93
- * @param {string} [name=pluginObj.constructor.name] - a unique name for this plugin
94
- * @param {object} [...arguments] - all extra parameters will be passed to the plugin constructor
95
- * @example
96
- * // register a new plugin
97
- * me.plugin.register(TestPlugin, "testPlugin");
98
- * // the plugin then also become available
99
- * // under then me.plugins namespace
100
- * me.plugins.testPlugin.myfunction ();
101
- */
102
- register : function (pluginObj, name = pluginObj.toString().match(/ (\w+)/)[1]) {
103
- // ensure me.plugins[name] is not already "used"
104
- if (plugins[name]) {
105
- throw new Error("plugin " + name + " already registered");
106
- }
44
+ /**
45
+ * patch a melonJS function
46
+ * @name patch
47
+ * @memberof plugin
48
+ * @param {object} proto - target object
49
+ * @param {string} name - target function
50
+ * @param {Function} fn - replacement function
51
+ * @example
52
+ * // redefine the me.game.update function with a new one
53
+ * me.plugin.patch(me.game, "update", function () {
54
+ * // display something in the console
55
+ * console.log("duh");
56
+ * // call the original me.game.update function
57
+ * this._patched();
58
+ * });
59
+ */
60
+ export function patch(proto, name, fn) {
61
+ // use the object prototype if possible
62
+ if (typeof proto.prototype !== "undefined") {
63
+ proto = proto.prototype;
64
+ }
65
+ // reuse the logic behind object extends
66
+ if (typeof(proto[name]) === "function") {
67
+ // save the original function
68
+ let _parent = proto[name];
69
+ // override the function with the new one
70
+ Object.defineProperty(proto, name, {
71
+ "configurable" : true,
72
+ "value" : (function (name, fn) {
73
+ return function () {
74
+ this._patched = _parent;
75
+ let ret = fn.apply(this, arguments);
76
+ this._patched = null;
77
+ return ret;
78
+ };
79
+ })(name, fn)
80
+ });
81
+ }
82
+ else {
83
+ throw new Error(name + " is not an existing function");
84
+ }
85
+ }
107
86
 
108
- // get extra arguments
109
- let _args = [];
110
- if (arguments.length > 2) {
111
- // store extra arguments if any
112
- _args = Array.prototype.slice.call(arguments, 1);
113
- }
87
+ /**
88
+ * Register a plugin.
89
+ * @name register
90
+ * @memberof plugin
91
+ * @param {plugin.BasePlugin} plugin - Plugin object to instantiate and register
92
+ * @param {string} [name=plugin.constructor.name] - a unique name for this plugin
93
+ * @param {object} [...arguments] - all extra parameters will be passed to the plugin constructor
94
+ * @example
95
+ * // register a new plugin
96
+ * me.plugin.register(TestPlugin, "testPlugin");
97
+ * // the plugin then also become available
98
+ * // under then me.plugins namespace
99
+ * me.plugins.testPlugin.myfunction ();
100
+ */
101
+ export function register(plugin, name = plugin.toString().match(/ (\w+)/)[1]) {
102
+ // ensure me.plugins[name] is not already "used"
103
+ if (cache[name]) {
104
+ throw new Error("plugin " + name + " already registered");
105
+ }
114
106
 
115
- // try to instantiate the plugin
116
- _args[0] = pluginObj;
117
- let instance = new (pluginObj.bind.apply(pluginObj, _args))();
107
+ // get extra arguments
108
+ let _args = [];
109
+ if (arguments.length > 2) {
110
+ // store extra arguments if any
111
+ _args = Array.prototype.slice.call(arguments, 1);
112
+ }
118
113
 
119
- // inheritance check
120
- if (typeof instance === "undefined" || !(instance instanceof plugin.Base)) {
121
- throw new Error("Plugin should extend the me.plugin.Base Class !");
122
- }
114
+ // try to instantiate the plugin
115
+ _args[0] = plugin;
116
+ let instance = new (plugin.bind.apply(plugin, _args))();
123
117
 
124
- // compatibility testing
125
- if (utils.checkVersion(instance.version, version) > 0) {
126
- throw new Error("Plugin version mismatch, expected: " + instance.version + ", got: " + version);
127
- }
118
+ // inheritance check
119
+ if (typeof instance === "undefined" || !(instance instanceof BasePlugin)) {
120
+ throw new Error("Plugin should extend the BasePlugin Class !");
121
+ }
128
122
 
129
- // create a reference to the new plugin
130
- plugins[name] = instance;
123
+ // compatibility testing
124
+ if (checkVersion(instance.version, version) > 0) {
125
+ throw new Error("Plugin version mismatch, expected: " + instance.version + ", got: " + version);
131
126
  }
132
- };
127
+
128
+ // create a reference to the new plugin
129
+ cache[name] = instance;
130
+ }
@@ -1,5 +1,6 @@
1
1
  import Renderable from "./renderable";
2
- import utils from "../utils/utils.js";
2
+ import { createGUID } from "../utils/utils";
3
+ import { defer } from "../utils/function";
3
4
  import { game } from "../index.js";
4
5
  import * as event from "../system/event.js";
5
6
  import pool from "../system/pooling.js";
@@ -189,7 +190,7 @@ let globalFloatingCounter = 0;
189
190
  // (e.g. move one child from one container to another)
190
191
  if (child.isRenderable) {
191
192
  // allocated a GUID value (use child.id as based index if defined)
192
- child.GUID = utils.createGUID(child.id);
193
+ child.GUID = createGUID(child.id);
193
194
  }
194
195
  }
195
196
 
@@ -272,7 +273,7 @@ let globalFloatingCounter = 0;
272
273
  // (e.g. move one child from one container to another)
273
274
  if (child.isRenderable) {
274
275
  // allocated a GUID value
275
- child.GUID = utils.createGUID();
276
+ child.GUID = createGUID();
276
277
  }
277
278
  }
278
279
 
@@ -643,7 +644,7 @@ let globalFloatingCounter = 0;
643
644
  */
644
645
  removeChild(child, keepalive) {
645
646
  if (this.hasChild(child)) {
646
- utils.function.defer(deferredRemove, this, child, keepalive);
647
+ defer(deferredRemove, this, child, keepalive);
647
648
  }
648
649
  else {
649
650
  throw new Error("Child is not mine.");
@@ -794,7 +795,7 @@ let globalFloatingCounter = 0;
794
795
  });
795
796
  }
796
797
  /** @ignore */
797
- this.pendingSort = utils.function.defer(function () {
798
+ this.pendingSort = defer(function () {
798
799
  // sort everything in this container
799
800
  this.getChildren().sort(this["_sort" + this.sortOn.toUpperCase()]);
800
801
  // clear the defer id
@@ -1,4 +1,4 @@
1
- import utils from "./../utils/utils.js";
1
+ import { defer } from "./../utils/function.js";
2
2
  import * as event from "./event.js";
3
3
  import state from "./../state/state.js";
4
4
  import { clamp } from "./../math/math.js";
@@ -161,7 +161,7 @@ class Timer {
161
161
  */
162
162
  clearTimeout(timeoutID) {
163
163
  if (timeoutID > 0) {
164
- utils.function.defer(this.clearTimer.bind(this), this, timeoutID);
164
+ defer(this.clearTimer.bind(this), this, timeoutID);
165
165
  }
166
166
  }
167
167
 
@@ -171,7 +171,7 @@ class Timer {
171
171
  */
172
172
  clearInterval(intervalID) {
173
173
  if (intervalID > 0) {
174
- utils.function.defer(this.clearTimer.bind(this), this, intervalID);
174
+ defer(this.clearTimer.bind(this), this, intervalID);
175
175
  }
176
176
  }
177
177
 
@@ -1,8 +1,10 @@
1
- import * as agentUtils from "./agent.js";
2
- import * as arrayUtils from "./array.js";
3
- import * as fileUtils from "./file.js";
4
- import * as stringUtils from "./string.js";
5
- import * as fnUtils from "./function.js";
1
+ import { toHex } from "./string.js";
2
+
3
+ export * as agent from "./agent.js";
4
+ export * as array from "./array.js";
5
+ export * as file from "./file.js";
6
+ export * as string from "./string.js";
7
+ export * as function from "./function.js";
6
8
 
7
9
  /**
8
10
  * a collection of utility functions
@@ -13,124 +15,113 @@ import * as fnUtils from "./function.js";
13
15
  let GUID_base = "";
14
16
  let GUID_index = 0;
15
17
 
16
- let utils = {
17
-
18
- agent : agentUtils,
19
- array : arrayUtils,
20
- file : fileUtils,
21
- string : stringUtils,
22
- function : fnUtils,
23
-
24
- /**
25
- * Compare two version strings
26
- * @public
27
- * @memberof utils
28
- * @name checkVersion
29
- * @param {string} first - First version string to compare
30
- * @param {string} second - second version string to compare
31
- * @returns {number} comparison result <br>&lt; 0 : first &lt; second<br>
32
- * 0 : first == second<br>
33
- * &gt; 0 : first &gt; second
34
- * @example
35
- * if (me.utils.checkVersion("7.0.0") > 0) {
36
- * console.error(
37
- * "melonJS is too old. Expected: 7.0.0, Got: 6.3.0"
38
- * );
39
- * }
40
- */
41
- checkVersion : function (first, second) {
42
- let a = first.split(".");
43
- let b = second.split(".");
44
- let len = Math.min(a.length, b.length);
45
- let result = 0;
18
+ /**
19
+ * Compare two version strings
20
+ * @public
21
+ * @memberof utils
22
+ * @name checkVersion
23
+ * @param {string} first - First version string to compare
24
+ * @param {string} second - second version string to compare
25
+ * @returns {number} comparison result <br>&lt; 0 : first &lt; second<br>
26
+ * 0 : first == second<br>
27
+ * &gt; 0 : first &gt; second
28
+ * @example
29
+ * if (me.utils.checkVersion("7.0.0") > 0) {
30
+ * console.error(
31
+ * "melonJS is too old. Expected: 7.0.0, Got: 6.3.0"
32
+ * );
33
+ * }
34
+ */
35
+ export function checkVersion(first, second) {
36
+ let a = first.split(".");
37
+ let b = second.split(".");
38
+ let len = Math.min(a.length, b.length);
39
+ let result = 0;
46
40
 
47
- for (let i = 0; i < len; i++) {
48
- if ((result = +a[i] - +b[i])) {
49
- break;
50
- }
41
+ for (let i = 0; i < len; i++) {
42
+ if ((result = +a[i] - +b[i])) {
43
+ break;
51
44
  }
45
+ }
52
46
 
53
- return result ? result : a.length - b.length;
54
- },
47
+ return result ? result : a.length - b.length;
48
+ }
55
49
 
56
- /**
57
- * parse the fragment (hash) from a URL and returns them into
58
- * @public
59
- * @memberof utils
60
- * @name getUriFragment
61
- * @param {string} [url=document.location] - an optional params string or URL containing fragment (hash) params to be parsed
62
- * @returns {object} an object representing the deserialized params string.
63
- * @property {boolean} [hitbox=false] draw the hitbox in the debug panel (if enabled)
64
- * @property {boolean} [velocity=false] draw the entities velocity in the debug panel (if enabled)
65
- * @property {boolean} [quadtree=false] draw the quadtree in the debug panel (if enabled)
66
- * @property {boolean} [webgl=false] force the renderer to WebGL
67
- * @property {boolean} [debug=false] display the debug panel (if preloaded)
68
- * @property {string} [debugToggleKey="s"] show/hide the debug panel (if preloaded)
69
- * @example
70
- * // http://www.example.com/index.html#debug&hitbox=true&mytag=value
71
- * let UriFragment = me.utils.getUriFragment();
72
- * console.log(UriFragment["mytag"]); //> "value"
73
- */
74
- getUriFragment : function (url) {
75
- let hash = {};
50
+ /**
51
+ * parse the fragment (hash) from a URL and returns them into
52
+ * @public
53
+ * @memberof utils
54
+ * @name getUriFragment
55
+ * @param {string} [url=document.location] - an optional params string or URL containing fragment (hash) params to be parsed
56
+ * @returns {object} an object representing the deserialized params string.
57
+ * @property {boolean} [hitbox=false] draw the hitbox in the debug panel (if enabled)
58
+ * @property {boolean} [velocity=false] draw the entities velocity in the debug panel (if enabled)
59
+ * @property {boolean} [quadtree=false] draw the quadtree in the debug panel (if enabled)
60
+ * @property {boolean} [webgl=false] force the renderer to WebGL
61
+ * @property {boolean} [debug=false] display the debug panel (if preloaded)
62
+ * @property {string} [debugToggleKey="s"] show/hide the debug panel (if preloaded)
63
+ * @example
64
+ * // http://www.example.com/index.html#debug&hitbox=true&mytag=value
65
+ * let UriFragment = me.utils.getUriFragment();
66
+ * console.log(UriFragment["mytag"]); //> "value"
67
+ */
68
+ export function getUriFragment(url) {
69
+ let hash = {};
76
70
 
77
- if (typeof url === "undefined") {
78
- if (typeof globalThis.document !== "undefined") {
79
- let location = globalThis.document.location;
71
+ if (typeof url === "undefined") {
72
+ if (typeof globalThis.document !== "undefined") {
73
+ let location = globalThis.document.location;
80
74
 
81
- if (location && location.hash) {
82
- url = location.hash;
83
- } else {
84
- // No "document.location" exist for Wechat mini game platform.
85
- return hash;
86
- }
75
+ if (location && location.hash) {
76
+ url = location.hash;
87
77
  } else {
88
- // "document" undefined on node.js
78
+ // No "document.location" exist for Wechat mini game platform.
89
79
  return hash;
90
80
  }
91
81
  } else {
92
- // never cache if a url is passed as parameter
93
- let index = url.indexOf("#");
94
- if (index !== -1) {
95
- url = url.slice(index, url.length);
96
- } else {
97
- return hash;
98
- }
82
+ // "document" undefined on node.js
83
+ return hash;
99
84
  }
85
+ } else {
86
+ // never cache if a url is passed as parameter
87
+ let index = url.indexOf("#");
88
+ if (index !== -1) {
89
+ url = url.slice(index, url.length);
90
+ } else {
91
+ return hash;
92
+ }
93
+ }
100
94
 
101
- // parse the url
102
- url.slice(1).split("&").filter((value) => value !== "").forEach((value) => {
103
- let kv = value.split("=");
104
- let k = kv.shift();
105
- let v = kv.join("=");
106
- hash[k] = v || true;
107
- });
108
-
109
- return hash;
110
- },
95
+ // parse the url
96
+ url.slice(1).split("&").filter((value) => value !== "").forEach((value) => {
97
+ let kv = value.split("=");
98
+ let k = kv.shift();
99
+ let v = kv.join("=");
100
+ hash[k] = v || true;
101
+ });
111
102
 
112
- /**
113
- * reset the GUID Base Name
114
- * the idea here being to have a unique ID
115
- * per level / object
116
- * @ignore
117
- */
118
- resetGUID : function (base, index = 0) {
119
- // also ensure it's only 8bit ASCII characters
120
- GUID_base = stringUtils.toHex(base.toString().toUpperCase());
121
- GUID_index = index;
122
- },
103
+ return hash;
104
+ }
123
105
 
124
- /**
125
- * create and return a very simple GUID
126
- * Game Unique ID
127
- * @ignore
128
- */
129
- createGUID : function (index = 1) {
130
- // to cover the case of undefined id for groups
131
- GUID_index += index;
132
- return GUID_base + "-" + (index || GUID_index);
133
- }
134
- };
106
+ /**
107
+ * reset the GUID Base Name
108
+ * the idea here being to have a unique ID
109
+ * per level / object
110
+ * @ignore
111
+ */
112
+ export function resetGUID(base, index = 0) {
113
+ // also ensure it's only 8bit ASCII characters
114
+ GUID_base = toHex(base.toString().toUpperCase());
115
+ GUID_index = index;
116
+ }
135
117
 
136
- export default utils;
118
+ /**
119
+ * create and return a very simple GUID
120
+ * Game Unique ID
121
+ * @ignore
122
+ */
123
+ export function createGUID(index = 1) {
124
+ // to cover the case of undefined id for groups
125
+ GUID_index += index;
126
+ return GUID_base + "-" + (index || GUID_index);
127
+ }
@@ -1,34 +1,32 @@
1
1
  import * as event from "./../system/event.js";
2
2
  import { initialized, game } from "./../index.js";
3
3
  import * as device from "./../system/device.js";
4
- import utils from "./../utils/utils.js";
5
- import * as vc from "../const";
4
+ import { throttle } from "../utils/function.js";
6
5
 
7
6
  /**
8
7
  * @namespace video
9
8
  */
10
9
 
11
-
12
10
  /**
13
11
  * Select the HTML5 Canvas renderer
14
12
  * @memberof video
15
13
  * @static
16
14
  */
17
- export const CANVAS = vc.CANVAS;
15
+ export { CANVAS } from "../const";
18
16
 
19
17
  /**
20
18
  * Select the WebGL renderer
21
19
  * @memberof video
22
20
  * @static
23
21
  */
24
- export const WEBGL = vc.WEBGL;
22
+ export { WEBGL } from "../const";
25
23
 
26
24
  /**
27
25
  * Auto-select the renderer (Attempt WebGL first, with fallback to Canvas)
28
26
  * @memberof video
29
27
  * @static
30
28
  */
31
- export const AUTO = vc.AUTO;
29
+ export { AUTO } from "../const";
32
30
 
33
31
  /**
34
32
  * A reference to the active Canvas or WebGL active renderer renderer
@@ -98,7 +96,7 @@ export function init(width, height, options) {
98
96
  //add a channel for the onresize/onorientationchange event
99
97
  globalThis.addEventListener(
100
98
  "resize",
101
- utils.function.throttle(
99
+ throttle(
102
100
  (e) => {
103
101
  event.emit(event.WINDOW_ONRESIZE, e);
104
102
  }, 100
@@ -130,7 +128,7 @@ export function init(width, height, options) {
130
128
  }
131
129
 
132
130
  // Automatically update relative canvas position on scroll
133
- globalThis.addEventListener("scroll", utils.function.throttle((e) => {
131
+ globalThis.addEventListener("scroll", throttle((e) => {
134
132
  event.emit(event.WINDOW_ONSCROLL, e);
135
133
  }, 100), false);
136
134