melonjs 15.1.5 → 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 (168) 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 +3 -3
  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 -7
  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 +3 -2
  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 +3 -3
  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 +4 -4
  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 +9 -9
  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 +20 -19
  80. package/dist/melonjs.mjs/renderable/draggable.js +121 -0
  81. package/dist/melonjs.mjs/renderable/dragndrop.js +3 -113
  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 +2 -2
  86. package/dist/melonjs.mjs/renderable/sprite.js +1 -1
  87. package/dist/melonjs.mjs/renderable/trigger.js +2 -2
  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 +516 -500
  138. package/dist/types/camera/camera2d.d.ts +4 -4
  139. package/dist/types/index.d.ts +4 -4
  140. package/dist/types/physics/body.d.ts +4 -4
  141. package/dist/types/physics/detector.d.ts +5 -5
  142. package/dist/types/physics/sat.d.ts +12 -12
  143. package/dist/types/plugin/plugin.d.ts +60 -5
  144. package/dist/types/renderable/container.d.ts +25 -25
  145. package/dist/types/renderable/draggable.d.ts +53 -0
  146. package/dist/types/renderable/dragndrop.d.ts +0 -52
  147. package/dist/types/renderable/renderable.d.ts +2 -2
  148. package/dist/types/utils/utils.d.ts +56 -17
  149. package/package.json +8 -8
  150. package/src/application/application.js +2 -2
  151. package/src/camera/camera2d.js +2 -2
  152. package/src/index.js +5 -3
  153. package/src/lang/deprecated.js +2 -1
  154. package/src/level/level.js +4 -3
  155. package/src/level/tiled/TMXTileMap.js +2 -2
  156. package/src/level/tiled/TMXUtils.js +4 -3
  157. package/src/physics/body.js +2 -2
  158. package/src/physics/detector.js +3 -3
  159. package/src/physics/sat.js +8 -8
  160. package/src/plugin/plugin.js +103 -105
  161. package/src/renderable/container.js +19 -18
  162. package/src/renderable/draggable.js +114 -0
  163. package/src/renderable/dragndrop.js +0 -109
  164. package/src/renderable/renderable.js +1 -1
  165. package/src/renderable/trigger.js +1 -1
  166. package/src/system/timer.js +3 -3
  167. package/src/utils/utils.js +102 -111
  168. package/src/video/video.js +3 -3
package/src/index.js CHANGED
@@ -42,7 +42,8 @@ import Light2d from "./renderable/light2d.js";
42
42
  import Text from "./text/text.js";
43
43
  import BitmapText from "./text/bitmaptext.js";
44
44
  import BitmapTextData from "./text/bitmaptextdata.js";
45
- import { Draggable, DropTarget } from "./renderable/dragndrop.js";
45
+ import { Draggable } from "./renderable/draggable.js";
46
+ import { DropTarget } from "./renderable/dragndrop.js";
46
47
  import TMXRenderer from "./level/tiled/renderer/TMXRenderer.js";
47
48
  import TMXOrthogonalRenderer from "./level/tiled/renderer/TMXOrthogonalRenderer.js";
48
49
  import TMXIsometricRenderer from "./level/tiled/renderer/TMXIsometricRenderer.js";
@@ -71,9 +72,10 @@ import * as event from "./system/event.js";
71
72
  import * as device from "./system/device.js";
72
73
  import * as loader from "./loader/loader.js";
73
74
  import * as Math from "./math/math.js";
74
- import utils from "./utils/utils.js";
75
+ import * as utils from "./utils/utils.js";
75
76
  import * as input from "./input/input.js";
76
- import { plugin, plugins } from "./plugin/plugin.js";
77
+ import * as plugin from "./plugin/plugin.js";
78
+ import { cache as plugins } from "./plugin/plugin.js";
77
79
  import * as video from "./video/video.js";
78
80
  import save from "./system/save.js";
79
81
  import timer from "./system/timer.js";
@@ -1,6 +1,7 @@
1
1
  import { TextureAtlas } from "./../video/texture/atlas.js";
2
2
  import Renderer from "./../video/renderer.js";
3
- import { Draggable, DropTarget } from "./../renderable/dragndrop.js";
3
+ import { Draggable } from "./../renderable/draggable.js";
4
+ import { DropTarget } from "./../renderable/dragndrop.js";
4
5
  import UISpriteElement from "./../renderable/ui/uispriteelement.js";
5
6
  import { warning } from "./console.js";
6
7
 
@@ -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
  }
@@ -16,7 +16,7 @@ import Point from "../geometries/point.js";
16
16
  */
17
17
  export default class Body {
18
18
  /**
19
- * @param {Renderable} ancestor - the parent object this body is attached to
19
+ * @param {Renderable|Container|Entity|Sprite|NineSliceSprite} ancestor - the parent object this body is attached to
20
20
  * @param {Rect|Rect[]|Polygon|Polygon[]|Line|Line[]|Ellipse|Ellipse[]|Point|Point[]|Bounds|Bounds[]|object} [shapes] - a initial shape, list of shapes, or JSON object defining the body
21
21
  * @param {Function} [onBodyUpdate] - callback for when the body is updated (e.g. add/remove shapes)
22
22
  */
@@ -26,7 +26,7 @@ import Point from "../geometries/point.js";
26
26
  * a reference to the parent object that contains this body,
27
27
  * or undefined if it has not been added to one.
28
28
  * @public
29
- * @type {Renderable}
29
+ * @type {Renderable|Container|Entity|Sprite|NineSliceSprite}
30
30
  * @default undefined
31
31
  */
32
32
  this.ancestor = ancestor;
@@ -40,8 +40,8 @@ export default class Detector {
40
40
  /**
41
41
  * determine if two objects should collide (based on both respective objects body collision mask and type).<br>
42
42
  * you can redefine this function if you need any specific rules over what should collide with what.
43
- * @param {Renderable} a - a reference to the object A.
44
- * @param {Renderable} b - a reference to the object B.
43
+ * @param {Renderable|Container|Entity|Sprite|NineSliceSprite} a - a reference to the object A.
44
+ * @param {Renderable|Container|Entity|Sprite|NineSliceSprite} b - a reference to the object B.
45
45
  * @returns {boolean} true if they should collide, false otherwise
46
46
  */
47
47
  shouldCollide(a, b) {
@@ -94,7 +94,7 @@ export default class Detector {
94
94
  /**
95
95
  * find all the collisions for the specified object using a broadphase algorithm
96
96
  * @ignore
97
- * @param {Renderable} objA - object to be tested for collision
97
+ * @param {Renderable|Container|Entity|Sprite|NineSliceSprite} objA - object to be tested for collision
98
98
  * @returns {boolean} in case of collision, false otherwise
99
99
  */
100
100
  collisions(objA) {
@@ -187,9 +187,9 @@ function vornoiRegion(line, point) {
187
187
  /**
188
188
  * Checks whether polygons collide.
189
189
  * @ignore
190
- * @param {Renderable} a - a reference to the object A.
190
+ * @param {Renderable|Container|Entity|Sprite|NineSliceSprite} a - a reference to the object A.
191
191
  * @param {Polygon} polyA - a reference to the object A Polygon to be tested
192
- * @param {Renderable} b - a reference to the object B.
192
+ * @param {Renderable|Container|Entity|Sprite|NineSliceSprite} b - a reference to the object B.
193
193
  * @param {Polygon} polyB - a reference to the object B Polygon to be tested
194
194
  * @param {Response=} response - Response object (optional) that will be populated if they intersect.
195
195
  * @returns {boolean} true if they intersect, false if they don't.
@@ -241,9 +241,9 @@ export function testPolygonPolygon(a, polyA, b, polyB, response) {
241
241
  /**
242
242
  * Check if two Ellipse collide.
243
243
  * @ignore
244
- * @param {Renderable} a - a reference to the object A.
244
+ * @param {Renderable|Container|Entity|Sprite|NineSliceSprite} a - a reference to the object A.
245
245
  * @param {Ellipse} ellipseA - a reference to the object A Ellipse to be tested
246
- * @param {Renderable} b - a reference to the object B.
246
+ * @param {Renderable|Container|Entity|Sprite|NineSliceSprite} b - a reference to the object B.
247
247
  * @param {Ellipse} ellipseB - a reference to the object B Ellipse to be tested
248
248
  * @param {Response=} response - Response object (optional) that will be populated if
249
249
  * the circles intersect.
@@ -282,9 +282,9 @@ export function testEllipseEllipse(a, ellipseA, b, ellipseB, response) {
282
282
  /**
283
283
  * Check if a polygon and an ellipse collide.
284
284
  * @ignore
285
- * @param {Renderable} a - a reference to the object A.
285
+ * @param {Renderable|Container|Entity|Sprite|NineSliceSprite} a - a reference to the object A.
286
286
  * @param {Polygon} polyA - a reference to the object A Polygon to be tested
287
- * @param {Renderable} b - a reference to the object B.
287
+ * @param {Renderable|Container|Entity|Sprite|NineSliceSprite} b - a reference to the object B.
288
288
  * @param {Ellipse} ellipseB - a reference to the object B Ellipse to be tested
289
289
  * @param {Response=} response - Response object (optional) that will be populated if they intersect.
290
290
  * @returns {boolean} true if they intersect, false if they don't.
@@ -448,9 +448,9 @@ export function testPolygonEllipse(a, polyA, b, ellipseB, response) {
448
448
  * **NOTE:** This is slightly less efficient than testPolygonEllipse as it just
449
449
  * runs testPolygonEllipse and reverses the response at the end.
450
450
  * @ignore
451
- * @param {Renderable} a - a reference to the object A.
451
+ * @param {Renderable|Container|Entity|Sprite|NineSliceSprite} a - a reference to the object A.
452
452
  * @param {Ellipse} ellipseA - a reference to the object A Ellipse to be tested
453
- * @param {Renderable} b - a reference to the object B.
453
+ * @param {Renderable|Container|Entity|Sprite|NineSliceSprite} b - a reference to the object B.
454
454
  * @param {Polygon} polyB - a reference to the object B Polygon to be tested
455
455
  * @param {Response=} response - Response object (optional) that will be populated if
456
456
  * they intersect.
@@ -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";
@@ -176,7 +177,7 @@ let globalFloatingCounter = 0;
176
177
  * will not be in any container. <br>
177
178
  * if the given child implements a onActivateEvent method, that method will be called
178
179
  * once the child is added to this container.
179
- * @param {Renderable} child
180
+ * @param {Renderable|Entity|Sprite|Collectable|Trigger|Draggable|DropTarget|NineSliceSprite|ImageLayer|ColorLayer|Light2d|UIBaseElement|UISpriteElement|UITextButton|Text|BitmapText} child
180
181
  * @param {number} [z] - forces the z index of the child to the specified value
181
182
  * @returns {Renderable} the added child
182
183
  */
@@ -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
 
@@ -258,7 +259,7 @@ let globalFloatingCounter = 0;
258
259
  /**
259
260
  * Add a child to the container at the specified index<br>
260
261
  * (the list won't be sorted after insertion)
261
- * @param {Renderable} child
262
+ * @param {Renderable|Entity|Sprite|Collectable|Trigger|Draggable|DropTarget|NineSliceSprite|ImageLayer|ColorLayer|Light2d|UIBaseElement|UISpriteElement|UITextButton|Text|BitmapText} child
262
263
  * @param {number} index
263
264
  * @returns {Renderable} the added child
264
265
  */
@@ -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
 
@@ -369,8 +370,8 @@ let globalFloatingCounter = 0;
369
370
 
370
371
  /**
371
372
  * Swaps the position (z-index) of 2 children
372
- * @param {Renderable} child
373
- * @param {Renderable} child2
373
+ * @param {Renderable|Entity|Sprite|Collectable|Trigger|Draggable|DropTarget|NineSliceSprite|ImageLayer|ColorLayer|Light2d|UIBaseElement|UISpriteElement|UITextButton|Text|BitmapText} child
374
+ * @param {Renderable|Entity|Sprite|Collectable|Trigger|Draggable|DropTarget|NineSliceSprite|ImageLayer|ColorLayer|Light2d|UIBaseElement|UISpriteElement|UITextButton|Text|BitmapText} child2
374
375
  */
375
376
  swapChildren(child, child2) {
376
377
  let index = this.getChildIndex(child);
@@ -408,7 +409,7 @@ let globalFloatingCounter = 0;
408
409
 
409
410
  /**
410
411
  * Returns the index of the given Child
411
- * @param {Renderable} child
412
+ * @param {Renderable|Entity|Sprite|Collectable|Trigger|Draggable|DropTarget|NineSliceSprite|ImageLayer|ColorLayer|Light2d|UIBaseElement|UISpriteElement|UITextButton|Text|BitmapText} child
412
413
  * @returns {number} index
413
414
  */
414
415
  getChildIndex(child) {
@@ -417,7 +418,7 @@ let globalFloatingCounter = 0;
417
418
 
418
419
  /**
419
420
  * Returns the next child within the container or undefined if none
420
- * @param {Renderable} child
421
+ * @param {Renderable|Entity|Sprite|Collectable|Trigger|Draggable|DropTarget|NineSliceSprite|ImageLayer|ColorLayer|Light2d|UIBaseElement|UISpriteElement|UITextButton|Text|BitmapText} child
421
422
  * @returns {Renderable} child
422
423
  */
423
424
  getNextChild(child) {
@@ -430,7 +431,7 @@ let globalFloatingCounter = 0;
430
431
 
431
432
  /**
432
433
  * Returns true if contains the specified Child
433
- * @param {Renderable} child
434
+ * @param {Renderable|Entity|Sprite|Collectable|Trigger|Draggable|DropTarget|NineSliceSprite|ImageLayer|ColorLayer|Light2d|UIBaseElement|UISpriteElement|UITextButton|Text|BitmapText} child
434
435
  * @returns {boolean}
435
436
  */
436
437
  hasChild(child) {
@@ -638,12 +639,12 @@ let globalFloatingCounter = 0;
638
639
  /**
639
640
  * Invokes the removeChildNow in a defer, to ensure the child is removed safely after the update & draw stack has completed. <br>
640
641
  * if the given child implements a onDeactivateEvent() method, that method will be called once the child is removed from this container.
641
- * @param {Renderable} child
642
+ * @param {RendRenderable|Sprite|Collectable|Trigger|Draggable|DropTarget|NineSliceSprite|ImageLayer|ColorLayer|Light2d|UIBaseElement|UISpriteElement|UITextButton|Text|BitmapTexterable} child
642
643
  * @param {boolean} [keepalive=false] - true to prevent calling child.destroy()
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.");
@@ -654,7 +655,7 @@ let globalFloatingCounter = 0;
654
655
  * Removes (and optionally destroys) a child from the container.<br>
655
656
  * (removal is immediate and unconditional)<br>
656
657
  * Never use keepalive=true with objects from {@link pool}. Doing so will create a memory leak.
657
- * @param {Renderable} child
658
+ * @param {Renderable|Entity|Sprite|Collectable|Trigger|Draggable|DropTarget|NineSliceSprite|ImageLayer|ColorLayer|Light2d|UIBaseElement|UISpriteElement|UITextButton|Text|BitmapText} child
658
659
  * @param {boolean} [keepalive=False] - True to prevent calling child.destroy()
659
660
  */
660
661
  removeChildNow(child, keepalive) {
@@ -717,7 +718,7 @@ let globalFloatingCounter = 0;
717
718
 
718
719
  /**
719
720
  * Move the child in the group one step forward (z depth).
720
- * @param {Renderable} child
721
+ * @param {Renderable|Entity|Sprite|Collectable|Trigger|Draggable|DropTarget|NineSliceSprite|ImageLayer|ColorLayer|Light2d|UIBaseElement|UISpriteElement|UITextButton|Text|BitmapText} child
721
722
  */
722
723
  moveUp(child) {
723
724
  let childIndex = this.getChildIndex(child);
@@ -731,7 +732,7 @@ let globalFloatingCounter = 0;
731
732
 
732
733
  /**
733
734
  * Move the child in the group one step backward (z depth).
734
- * @param {Renderable} child
735
+ * @param {Renderable|Entity|Sprite|Collectable|Trigger|Draggable|DropTarget|NineSliceSprite|ImageLayer|ColorLayer|Light2d|UIBaseElement|UISpriteElement|UITextButton|Text|BitmapText} child
735
736
  */
736
737
  moveDown(child) {
737
738
  let childIndex = this.getChildIndex(child);
@@ -745,7 +746,7 @@ let globalFloatingCounter = 0;
745
746
 
746
747
  /**
747
748
  * Move the specified child to the top(z depth).
748
- * @param {Renderable} child
749
+ * @param {Renderable|Entity|Sprite|Collectable|Trigger|Draggable|DropTarget|NineSliceSprite|ImageLayer|ColorLayer|Light2d|UIBaseElement|UISpriteElement|UITextButton|Text|BitmapText} child
749
750
  */
750
751
  moveToTop(child) {
751
752
  let childIndex = this.getChildIndex(child);
@@ -762,7 +763,7 @@ let globalFloatingCounter = 0;
762
763
 
763
764
  /**
764
765
  * Move the specified child the bottom (z depth).
765
- * @param {Renderable} child
766
+ * @param {Renderable|Entity|Sprite|Collectable|Trigger|Draggable|DropTarget|NineSliceSprite|ImageLayer|ColorLayer|Light2d|UIBaseElement|UISpriteElement|UITextButton|Text|BitmapText} child
766
767
  */
767
768
  moveToBottom(child) {
768
769
  let childIndex = this.getChildIndex(child);
@@ -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