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.
- package/README.md +2 -2
- package/dist/melonjs.mjs/_virtual/_commonjsHelpers.js +1 -1
- package/dist/melonjs.mjs/_virtual/earcut.js +1 -1
- package/dist/melonjs.mjs/_virtual/howler.js +1 -1
- package/dist/melonjs.mjs/_virtual/index.js +1 -1
- package/dist/melonjs.mjs/application/application.js +3 -3
- package/dist/melonjs.mjs/application/header.js +1 -1
- package/dist/melonjs.mjs/application/resize.js +1 -1
- package/dist/melonjs.mjs/application/settings.js +1 -1
- package/dist/melonjs.mjs/audio/audio.js +1 -1
- package/dist/melonjs.mjs/camera/camera2d.js +3 -3
- package/dist/melonjs.mjs/const.js +1 -1
- package/dist/melonjs.mjs/entity/entity.js +1 -1
- package/dist/melonjs.mjs/geometries/ellipse.js +1 -1
- package/dist/melonjs.mjs/geometries/line.js +1 -1
- package/dist/melonjs.mjs/geometries/path2d.js +1 -1
- package/dist/melonjs.mjs/geometries/point.js +1 -1
- package/dist/melonjs.mjs/geometries/poly.js +1 -1
- package/dist/melonjs.mjs/geometries/rectangle.js +1 -1
- package/dist/melonjs.mjs/geometries/roundrect.js +1 -1
- package/dist/melonjs.mjs/index.js +12 -7
- package/dist/melonjs.mjs/input/gamepad.js +1 -1
- package/dist/melonjs.mjs/input/input.js +1 -1
- package/dist/melonjs.mjs/input/keyboard.js +1 -1
- package/dist/melonjs.mjs/input/pointer.js +1 -1
- package/dist/melonjs.mjs/input/pointerevent.js +1 -1
- package/dist/melonjs.mjs/lang/console.js +1 -1
- package/dist/melonjs.mjs/lang/deprecated.js +3 -2
- package/dist/melonjs.mjs/level/level.js +5 -4
- package/dist/melonjs.mjs/level/tiled/TMXGroup.js +1 -1
- package/dist/melonjs.mjs/level/tiled/TMXLayer.js +1 -1
- package/dist/melonjs.mjs/level/tiled/TMXObject.js +1 -1
- package/dist/melonjs.mjs/level/tiled/TMXTile.js +1 -1
- package/dist/melonjs.mjs/level/tiled/TMXTileMap.js +3 -3
- package/dist/melonjs.mjs/level/tiled/TMXTileset.js +1 -1
- package/dist/melonjs.mjs/level/tiled/TMXTilesetGroup.js +1 -1
- package/dist/melonjs.mjs/level/tiled/TMXUtils.js +6 -8
- package/dist/melonjs.mjs/level/tiled/constants.js +1 -1
- package/dist/melonjs.mjs/level/tiled/renderer/TMXHexagonalRenderer.js +1 -1
- package/dist/melonjs.mjs/level/tiled/renderer/TMXIsometricRenderer.js +1 -1
- package/dist/melonjs.mjs/level/tiled/renderer/TMXOrthogonalRenderer.js +1 -1
- package/dist/melonjs.mjs/level/tiled/renderer/TMXRenderer.js +1 -1
- package/dist/melonjs.mjs/level/tiled/renderer/TMXStaggeredRenderer.js +1 -1
- package/dist/melonjs.mjs/level/tiled/renderer/autodetect.js +1 -1
- package/dist/melonjs.mjs/loader/cache.js +1 -1
- package/dist/melonjs.mjs/loader/loader.js +1 -1
- package/dist/melonjs.mjs/loader/loadingscreen.js +1 -1
- package/dist/melonjs.mjs/loader/melonjs_logo.png.js +1 -1
- package/dist/melonjs.mjs/loader/parser.js +1 -1
- package/dist/melonjs.mjs/loader/settings.js +1 -1
- package/dist/melonjs.mjs/math/color.js +1 -1
- package/dist/melonjs.mjs/math/math.js +1 -1
- package/dist/melonjs.mjs/math/matrix2.js +1 -1
- package/dist/melonjs.mjs/math/matrix3.js +1 -1
- package/dist/melonjs.mjs/math/observable_vector2.js +1 -1
- package/dist/melonjs.mjs/math/observable_vector3.js +1 -1
- package/dist/melonjs.mjs/math/vector2.js +1 -1
- package/dist/melonjs.mjs/math/vector3.js +1 -1
- package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/esm/arraymultimap.js +1 -1
- package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/esm/multimap.js +1 -1
- package/dist/melonjs.mjs/node_modules/earcut/src/earcut.js +1 -1
- package/dist/melonjs.mjs/node_modules/eventemitter3/index.js +1 -1
- package/dist/melonjs.mjs/node_modules/eventemitter3/index2.js +1 -1
- package/dist/melonjs.mjs/node_modules/howler/dist/howler.js +1 -1
- package/dist/melonjs.mjs/particles/emitter.js +1 -1
- package/dist/melonjs.mjs/particles/particle.js +1 -1
- package/dist/melonjs.mjs/particles/settings.js +1 -1
- package/dist/melonjs.mjs/physics/body.js +3 -3
- package/dist/melonjs.mjs/physics/bounds.js +1 -1
- package/dist/melonjs.mjs/physics/collision.js +1 -1
- package/dist/melonjs.mjs/physics/detector.js +4 -4
- package/dist/melonjs.mjs/physics/quadtree.js +1 -1
- package/dist/melonjs.mjs/physics/response.js +1 -1
- package/dist/melonjs.mjs/physics/sat.js +9 -9
- package/dist/melonjs.mjs/physics/world.js +1 -1
- package/dist/melonjs.mjs/plugin/plugin.js +106 -108
- package/dist/melonjs.mjs/renderable/collectable.js +1 -1
- package/dist/melonjs.mjs/renderable/colorlayer.js +1 -1
- package/dist/melonjs.mjs/renderable/container.js +20 -19
- package/dist/melonjs.mjs/renderable/draggable.js +121 -0
- package/dist/melonjs.mjs/renderable/dragndrop.js +3 -113
- package/dist/melonjs.mjs/renderable/imagelayer.js +1 -1
- package/dist/melonjs.mjs/renderable/light2d.js +1 -1
- package/dist/melonjs.mjs/renderable/nineslicesprite.js +1 -1
- package/dist/melonjs.mjs/renderable/renderable.js +2 -2
- package/dist/melonjs.mjs/renderable/sprite.js +1 -1
- package/dist/melonjs.mjs/renderable/trigger.js +2 -2
- package/dist/melonjs.mjs/renderable/ui/uibaseelement.js +1 -1
- package/dist/melonjs.mjs/renderable/ui/uispriteelement.js +1 -1
- package/dist/melonjs.mjs/renderable/ui/uitextbutton.js +1 -1
- package/dist/melonjs.mjs/state/stage.js +1 -1
- package/dist/melonjs.mjs/state/state.js +1 -1
- package/dist/melonjs.mjs/system/device.js +1 -1
- package/dist/melonjs.mjs/system/dom.js +1 -1
- package/dist/melonjs.mjs/system/event.js +1 -1
- package/dist/melonjs.mjs/system/platform.js +1 -1
- package/dist/melonjs.mjs/system/pooling.js +1 -1
- package/dist/melonjs.mjs/system/save.js +1 -1
- package/dist/melonjs.mjs/system/timer.js +4 -4
- package/dist/melonjs.mjs/text/bitmaptext.js +1 -1
- package/dist/melonjs.mjs/text/bitmaptextdata.js +1 -1
- package/dist/melonjs.mjs/text/glyph.js +1 -1
- package/dist/melonjs.mjs/text/text.js +1 -1
- package/dist/melonjs.mjs/text/textmetrics.js +1 -1
- package/dist/melonjs.mjs/text/textstyle.js +1 -1
- package/dist/melonjs.mjs/tweens/easing.js +1 -1
- package/dist/melonjs.mjs/tweens/interpolation.js +1 -1
- package/dist/melonjs.mjs/tweens/tween.js +1 -1
- package/dist/melonjs.mjs/utils/agent.js +1 -1
- package/dist/melonjs.mjs/utils/array.js +1 -1
- package/dist/melonjs.mjs/utils/file.js +1 -1
- package/dist/melonjs.mjs/utils/function.js +1 -1
- package/dist/melonjs.mjs/utils/string.js +1 -1
- package/dist/melonjs.mjs/utils/utils.js +105 -111
- package/dist/melonjs.mjs/video/canvas/canvas_renderer.js +1 -1
- package/dist/melonjs.mjs/video/renderer.js +1 -1
- package/dist/melonjs.mjs/video/texture/atlas.js +1 -1
- package/dist/melonjs.mjs/video/texture/cache.js +1 -1
- package/dist/melonjs.mjs/video/texture/canvas_texture.js +1 -1
- package/dist/melonjs.mjs/video/utils/autodetect.js +1 -1
- package/dist/melonjs.mjs/video/video.js +4 -4
- package/dist/melonjs.mjs/video/webgl/buffer/vertex.js +1 -1
- package/dist/melonjs.mjs/video/webgl/compositors/compositor.js +1 -1
- package/dist/melonjs.mjs/video/webgl/compositors/primitive_compositor.js +1 -1
- package/dist/melonjs.mjs/video/webgl/compositors/quad_compositor.js +1 -1
- package/dist/melonjs.mjs/video/webgl/glshader.js +1 -1
- package/dist/melonjs.mjs/video/webgl/shaders/primitive.frag.js +1 -1
- package/dist/melonjs.mjs/video/webgl/shaders/primitive.vert.js +1 -1
- package/dist/melonjs.mjs/video/webgl/shaders/quad.frag.js +1 -1
- package/dist/melonjs.mjs/video/webgl/shaders/quad.vert.js +1 -1
- package/dist/melonjs.mjs/video/webgl/utils/attributes.js +1 -1
- package/dist/melonjs.mjs/video/webgl/utils/precision.js +1 -1
- package/dist/melonjs.mjs/video/webgl/utils/program.js +1 -1
- package/dist/melonjs.mjs/video/webgl/utils/string.js +1 -1
- package/dist/melonjs.mjs/video/webgl/utils/uniforms.js +1 -1
- package/dist/melonjs.mjs/video/webgl/webgl_renderer.js +1 -1
- package/dist/melonjs.module.js +516 -500
- package/dist/types/camera/camera2d.d.ts +4 -4
- package/dist/types/index.d.ts +4 -4
- package/dist/types/physics/body.d.ts +4 -4
- package/dist/types/physics/detector.d.ts +5 -5
- package/dist/types/physics/sat.d.ts +12 -12
- package/dist/types/plugin/plugin.d.ts +60 -5
- package/dist/types/renderable/container.d.ts +25 -25
- package/dist/types/renderable/draggable.d.ts +53 -0
- package/dist/types/renderable/dragndrop.d.ts +0 -52
- package/dist/types/renderable/renderable.d.ts +2 -2
- package/dist/types/utils/utils.d.ts +56 -17
- package/package.json +8 -8
- package/src/application/application.js +2 -2
- package/src/camera/camera2d.js +2 -2
- package/src/index.js +5 -3
- package/src/lang/deprecated.js +2 -1
- package/src/level/level.js +4 -3
- package/src/level/tiled/TMXTileMap.js +2 -2
- package/src/level/tiled/TMXUtils.js +4 -3
- package/src/physics/body.js +2 -2
- package/src/physics/detector.js +3 -3
- package/src/physics/sat.js +8 -8
- package/src/plugin/plugin.js +103 -105
- package/src/renderable/container.js +19 -18
- package/src/renderable/draggable.js +114 -0
- package/src/renderable/dragndrop.js +0 -109
- package/src/renderable/renderable.js +1 -1
- package/src/renderable/trigger.js +1 -1
- package/src/system/timer.js +3 -3
- package/src/utils/utils.js +102 -111
- 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
|
|
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
|
|
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";
|
package/src/lang/deprecated.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { TextureAtlas } from "./../video/texture/atlas.js";
|
|
2
2
|
import Renderer from "./../video/renderer.js";
|
|
3
|
-
import { Draggable
|
|
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
|
|
package/src/level/level.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
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 (
|
|
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
|
|
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 ||
|
|
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 (
|
|
33
|
+
else if (isNumeric(value)) {
|
|
33
34
|
// check if numeric
|
|
34
35
|
value = Number(value);
|
|
35
36
|
}
|
package/src/physics/body.js
CHANGED
|
@@ -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;
|
package/src/physics/detector.js
CHANGED
|
@@ -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) {
|
package/src/physics/sat.js
CHANGED
|
@@ -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.
|
package/src/plugin/plugin.js
CHANGED
|
@@ -1,132 +1,130 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { checkVersion } from "./../utils/utils.js";
|
|
2
2
|
import { version } from "./../index.js";
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
6
|
-
* @
|
|
7
|
-
* @
|
|
5
|
+
* Contains all registered plugins.
|
|
6
|
+
* @name cache
|
|
7
|
+
* @memberof plugin
|
|
8
8
|
*/
|
|
9
|
-
export let
|
|
9
|
+
export let cache = {};
|
|
10
10
|
|
|
11
|
+
/**
|
|
12
|
+
* @namespace plugin
|
|
13
|
+
*/
|
|
11
14
|
|
|
12
|
-
|
|
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
|
-
* @
|
|
37
|
+
* @class
|
|
38
|
+
* @name Base
|
|
39
|
+
* @memberof plugin
|
|
40
|
+
* @deprecated since 15.1.6, see {@link plugin.BasePlugin}
|
|
29
41
|
*/
|
|
30
|
-
export
|
|
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
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
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
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
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
|
-
|
|
116
|
-
|
|
117
|
-
|
|
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
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
}
|
|
114
|
+
// try to instantiate the plugin
|
|
115
|
+
_args[0] = plugin;
|
|
116
|
+
let instance = new (plugin.bind.apply(plugin, _args))();
|
|
123
117
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
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
|
-
|
|
130
|
-
|
|
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
|
|
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 =
|
|
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 =
|
|
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 {
|
|
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
|
-
|
|
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 =
|
|
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
|