melonjs 15.1.6 → 15.2.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 (151) hide show
  1. package/README.md +2 -2
  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 +10 -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 +6 -8
  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 +4 -4
  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 +460 -449
  138. package/dist/types/index.d.ts +3 -3
  139. package/dist/types/plugin/plugin.d.ts +60 -5
  140. package/dist/types/utils/utils.d.ts +56 -17
  141. package/package.json +3 -3
  142. package/src/application/application.js +2 -2
  143. package/src/index.js +3 -2
  144. package/src/level/level.js +4 -3
  145. package/src/level/tiled/TMXTileMap.js +2 -2
  146. package/src/level/tiled/TMXUtils.js +4 -3
  147. package/src/plugin/plugin.js +103 -105
  148. package/src/renderable/container.js +6 -5
  149. package/src/system/timer.js +3 -3
  150. package/src/utils/utils.js +102 -111
  151. package/src/video/video.js +3 -3
@@ -40,9 +40,9 @@ import * as loader from "./loader/loader.js";
40
40
  import level from "./level/level.js";
41
41
  import * as input from "./input/input.js";
42
42
  import * as Math from "./math/math.js";
43
- import { plugin } from "./plugin/plugin.js";
44
- import { plugins } from "./plugin/plugin.js";
45
- import utils from "./utils/utils.js";
43
+ import * as plugin from "./plugin/plugin.js";
44
+ import { cache as plugins } from "./plugin/plugin.js";
45
+ import * as utils from "./utils/utils.js";
46
46
  import save from "./system/save.js";
47
47
  import timer from "./system/timer.js";
48
48
  import pool from "./system/pooling.js";
@@ -1,10 +1,65 @@
1
1
  /**
2
- * This namespace is a container for all registered plugins.
3
- * @see plugin.register
4
- * @namespace plugins
2
+ * patch a melonJS function
3
+ * @name patch
4
+ * @memberof plugin
5
+ * @param {object} proto - target object
6
+ * @param {string} name - target function
7
+ * @param {Function} fn - replacement function
8
+ * @example
9
+ * // redefine the me.game.update function with a new one
10
+ * me.plugin.patch(me.game, "update", function () {
11
+ * // display something in the console
12
+ * console.log("duh");
13
+ * // call the original me.game.update function
14
+ * this._patched();
15
+ * });
5
16
  */
6
- export let plugins: {};
17
+ export function patch(proto: object, name: string, fn: Function): void;
18
+ /**
19
+ * Register a plugin.
20
+ * @name register
21
+ * @memberof plugin
22
+ * @param {plugin.BasePlugin} plugin - Plugin object to instantiate and register
23
+ * @param {string} [name=plugin.constructor.name] - a unique name for this plugin
24
+ * @param {object} [...arguments] - all extra parameters will be passed to the plugin constructor
25
+ * @example
26
+ * // register a new plugin
27
+ * me.plugin.register(TestPlugin, "testPlugin");
28
+ * // the plugin then also become available
29
+ * // under then me.plugins namespace
30
+ * me.plugins.testPlugin.myfunction ();
31
+ */
32
+ export function register(plugin: plugin.BasePlugin, name?: string | undefined, ...args: any[]): void;
33
+ /**
34
+ * Contains all registered plugins.
35
+ * @name cache
36
+ * @memberof plugin
37
+ */
38
+ export let cache: {};
7
39
  /**
8
40
  * @namespace plugin
9
41
  */
10
- export let plugin: any;
42
+ /**
43
+ * a base Object class for plugin
44
+ * (plugin must be installed using the register function)
45
+ * @class
46
+ * @name BasePlugin
47
+ * @memberof plugin
48
+ */
49
+ export class BasePlugin {
50
+ /**
51
+ * define the minimum required version of melonJS<br>
52
+ * this can be overridden by the plugin
53
+ * @type {string}
54
+ * @default "__VERSION__"
55
+ */
56
+ version: string;
57
+ }
58
+ /**
59
+ * @class
60
+ * @name Base
61
+ * @memberof plugin
62
+ * @deprecated since 15.1.6, see {@link plugin.BasePlugin}
63
+ */
64
+ export class Base extends BasePlugin {
65
+ }
@@ -1,17 +1,56 @@
1
- export default utils;
2
- declare namespace utils {
3
- export { agentUtils as agent };
4
- export { arrayUtils as array };
5
- export { fileUtils as file };
6
- export { stringUtils as string };
7
- export { fnUtils as function };
8
- export function checkVersion(first: string, second: string): number;
9
- export function getUriFragment(url?: string | undefined): object;
10
- export function resetGUID(base: any, index?: number): void;
11
- export function createGUID(index?: number): string;
12
- }
13
- import * as agentUtils from "./agent.js";
14
- import * as arrayUtils from "./array.js";
15
- import * as fileUtils from "./file.js";
16
- import * as stringUtils from "./string.js";
17
- import * as fnUtils from "./function.js";
1
+ /**
2
+ * Compare two version strings
3
+ * @public
4
+ * @memberof utils
5
+ * @name checkVersion
6
+ * @param {string} first - First version string to compare
7
+ * @param {string} second - second version string to compare
8
+ * @returns {number} comparison result <br>&lt; 0 : first &lt; second<br>
9
+ * 0 : first == second<br>
10
+ * &gt; 0 : first &gt; second
11
+ * @example
12
+ * if (me.utils.checkVersion("7.0.0") > 0) {
13
+ * console.error(
14
+ * "melonJS is too old. Expected: 7.0.0, Got: 6.3.0"
15
+ * );
16
+ * }
17
+ */
18
+ export function checkVersion(first: string, second: string): number;
19
+ /**
20
+ * parse the fragment (hash) from a URL and returns them into
21
+ * @public
22
+ * @memberof utils
23
+ * @name getUriFragment
24
+ * @param {string} [url=document.location] - an optional params string or URL containing fragment (hash) params to be parsed
25
+ * @returns {object} an object representing the deserialized params string.
26
+ * @property {boolean} [hitbox=false] draw the hitbox in the debug panel (if enabled)
27
+ * @property {boolean} [velocity=false] draw the entities velocity in the debug panel (if enabled)
28
+ * @property {boolean} [quadtree=false] draw the quadtree in the debug panel (if enabled)
29
+ * @property {boolean} [webgl=false] force the renderer to WebGL
30
+ * @property {boolean} [debug=false] display the debug panel (if preloaded)
31
+ * @property {string} [debugToggleKey="s"] show/hide the debug panel (if preloaded)
32
+ * @example
33
+ * // http://www.example.com/index.html#debug&hitbox=true&mytag=value
34
+ * let UriFragment = me.utils.getUriFragment();
35
+ * console.log(UriFragment["mytag"]); //> "value"
36
+ */
37
+ export function getUriFragment(url?: string | undefined): object;
38
+ /**
39
+ * reset the GUID Base Name
40
+ * the idea here being to have a unique ID
41
+ * per level / object
42
+ * @ignore
43
+ */
44
+ export function resetGUID(base: any, index?: number): void;
45
+ /**
46
+ * create and return a very simple GUID
47
+ * Game Unique ID
48
+ * @ignore
49
+ */
50
+ export function createGUID(index?: number): string;
51
+ export * as agent from "./agent.js";
52
+ export * as array from "./array.js";
53
+ export * as file from "./file.js";
54
+ export * as string from "./string.js";
55
+ export * as _function from "./function.js";
56
+ export { _function as function };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "melonjs",
3
- "version": "15.1.6",
3
+ "version": "15.2.0",
4
4
  "description": "melonJS Game Engine",
5
5
  "homepage": "http://www.melonjs.org/",
6
6
  "type": "module",
@@ -72,13 +72,13 @@
72
72
  "cross-env": "^7.0.3",
73
73
  "del-cli": "^5.0.0",
74
74
  "eslint": "^8.40.0",
75
- "eslint-plugin-jsdoc": "^44.1.0",
75
+ "eslint-plugin-jsdoc": "^44.2.3",
76
76
  "expect": "^29.5.0",
77
77
  "expect-mocha-image-snapshot": "^3.0.13",
78
78
  "fastify": "^4.17.0",
79
79
  "mocha": "^10.2.0",
80
80
  "npm-self-link": "^1.1.7",
81
- "puppeteer": "^20.1.2",
81
+ "puppeteer": "^20.2.0",
82
82
  "rollup": "^3.21.6",
83
83
  "rollup-plugin-bundle-size": "^1.0.3",
84
84
  "rollup-plugin-string": "^3.0.0",
@@ -2,7 +2,7 @@ import { autoDetectRenderer } from "../video/utils/autodetect.js";
2
2
  import CanvasRenderer from "./../video/canvas/canvas_renderer.js";
3
3
  import * as device from "./../system/device.js";
4
4
  import * as event from "./../system/event.js";
5
- import utils from "./../utils/utils.js";
5
+ import { getUriFragment } from "./../utils/utils.js";
6
6
  import timer from "./../system/timer.js";
7
7
  import state from "./../state/state.js";
8
8
  import World from "./../physics/world.js";
@@ -149,7 +149,7 @@ import { CANVAS, WEBGL, AUTO } from "../const.js";
149
149
  }
150
150
 
151
151
  // override renderer settings if &webgl or &canvas is defined in the URL
152
- let uriFragment = utils.getUriFragment();
152
+ let uriFragment = getUriFragment();
153
153
  if (uriFragment.webgl === true || uriFragment.webgl1 === true || uriFragment.webgl2 === true) {
154
154
  this.settings.renderer = WEBGL;
155
155
  if (uriFragment.webgl1 === true) {
package/src/index.js CHANGED
@@ -72,9 +72,10 @@ import * as event from "./system/event.js";
72
72
  import * as device from "./system/device.js";
73
73
  import * as loader from "./loader/loader.js";
74
74
  import * as Math from "./math/math.js";
75
- import utils from "./utils/utils.js";
75
+ import * as utils from "./utils/utils.js";
76
76
  import * as input from "./input/input.js";
77
- import { plugin, plugins } from "./plugin/plugin.js";
77
+ import * as plugin from "./plugin/plugin.js";
78
+ import { cache as plugins } from "./plugin/plugin.js";
78
79
  import * as video from "./video/video.js";
79
80
  import save from "./system/save.js";
80
81
  import timer from "./system/timer.js";
@@ -1,4 +1,5 @@
1
- import utils from "./../utils/utils.js";
1
+ import { resetGUID } from "./../utils/utils.js";
2
+ import { defer } from "../utils/function.js";
2
3
  import * as event from "./../system/event.js";
3
4
  import state from "./../state/state.js";
4
5
  import { getTMX } from "./../loader/loader.js";
@@ -62,7 +63,7 @@ function loadTMXLevel(levelId, container, flatten, setViewportBounds) {
62
63
 
63
64
  // reset the GUID generator
64
65
  // and pass the level id as parameter
65
- utils.resetGUID(levelId, level.nextobjectid);
66
+ resetGUID(levelId, level.nextobjectid);
66
67
 
67
68
  // Tiled use 0,0 anchor coordinates
68
69
  container.anchorPoint.set(0, 0);
@@ -178,7 +179,7 @@ let level = {
178
179
  // some silly side effects
179
180
  state.stop();
180
181
 
181
- utils.function.defer(safeLoadLevel, this, levelId, options, true);
182
+ defer(safeLoadLevel, this, levelId, options, true);
182
183
  }
183
184
  else {
184
185
  safeLoadLevel(levelId, options);
@@ -1,7 +1,7 @@
1
1
  import pool from "./../../system/pooling.js";
2
2
  import * as event from "./../../system/event.js";
3
3
  import { game } from "../../index.js";
4
- import utils from "./../../utils/utils.js";
4
+ import { checkVersion } from "./../../utils/utils.js";
5
5
  import collision from "./../../physics/collision.js";
6
6
  import Body from "./../../physics/body.js";
7
7
  import TMXTileset from "./TMXTileset.js";
@@ -198,7 +198,7 @@ function readObjectGroup(map, data, z) {
198
198
  // if version is undefined or empty it usually means the map was not created with Tiled
199
199
  if (this.version !== "undefined" && this.version !== "") {
200
200
  // deprecation warning if map tiled version is older than 1.5
201
- if (utils.checkVersion(this.version, "1.5") < 0) {
201
+ if (checkVersion(this.version, "1.5") < 0) {
202
202
  warning("("+this.name+") Tiled Map format version 1.4 and below", "format 1.5 or higher", "10.4.4");
203
203
  }
204
204
  }
@@ -1,4 +1,5 @@
1
- import utils from "../../utils/utils.js";
1
+ import { isBoolean, isNumeric } from "../../utils/string.js";
2
+ import * as utils from "../../utils/utils.js";
2
3
 
3
4
  /**
4
5
  * set and interpret a TMX property value
@@ -25,11 +26,11 @@ function setTMXValue(name, type, value) {
25
26
 
26
27
  default :
27
28
  // try to parse it anyway
28
- if (!value || utils.string.isBoolean(value)) {
29
+ if (!value || isBoolean(value)) {
29
30
  // if value not defined or boolean
30
31
  value = value ? (value === "true") : true;
31
32
  }
32
- else if (utils.string.isNumeric(value)) {
33
+ else if (isNumeric(value)) {
33
34
  // check if numeric
34
35
  value = Number(value);
35
36
  }
@@ -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