melonjs 15.1.4 → 15.1.6
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/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 +1 -1
- 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 +3 -6
- 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 +5 -5
- package/dist/melonjs.mjs/geometries/point.js +1 -1
- package/dist/melonjs.mjs/geometries/poly.js +3 -3
- package/dist/melonjs.mjs/geometries/rectangle.js +1 -1
- package/dist/melonjs.mjs/geometries/roundrect.js +1 -1
- package/dist/melonjs.mjs/index.js +4 -3
- 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 +10 -10
- 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 +1 -1
- package/dist/melonjs.mjs/level/tiled/TMXGroup.js +1 -1
- package/dist/melonjs.mjs/level/tiled/TMXLayer.js +4 -4
- 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 +1 -1
- 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 +4 -4
- package/dist/melonjs.mjs/level/tiled/constants.js +1 -1
- package/dist/melonjs.mjs/level/tiled/renderer/TMXHexagonalRenderer.js +2 -2
- 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 +2 -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 +4 -3
- 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 +2 -2
- package/dist/melonjs.mjs/physics/collision.js +1 -1
- package/dist/melonjs.mjs/physics/detector.js +5 -5
- package/dist/melonjs.mjs/physics/quadtree.js +2 -2
- package/dist/melonjs.mjs/physics/response.js +1 -1
- package/dist/melonjs.mjs/physics/sat.js +13 -12
- package/dist/melonjs.mjs/physics/world.js +1 -1
- package/dist/melonjs.mjs/plugin/plugin.js +3 -3
- 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 +48 -38
- 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 +7 -10
- 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 +7 -4
- package/dist/melonjs.mjs/renderable/ui/uispriteelement.js +8 -2
- 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 +1 -1
- package/dist/melonjs.mjs/text/bitmaptext.js +3 -3
- 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 +2 -2
- 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 +1 -1
- package/dist/melonjs.mjs/video/canvas/canvas_renderer.js +3 -6
- 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 +2 -2
- package/dist/melonjs.mjs/video/utils/autodetect.js +1 -1
- package/dist/melonjs.mjs/video/video.js +1 -1
- 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 +153 -135
- package/dist/types/camera/camera2d.d.ts +4 -4
- package/dist/types/index.d.ts +1 -1
- package/dist/types/loader/loader.d.ts +9 -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/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 +3 -3
- package/package.json +11 -11
- package/src/camera/camera2d.js +2 -2
- package/src/entity/entity.js +2 -5
- package/src/geometries/path2d.js +4 -4
- package/src/geometries/poly.js +2 -2
- package/src/index.js +2 -1
- package/src/input/pointerevent.js +9 -9
- package/src/lang/deprecated.js +2 -1
- package/src/level/tiled/TMXLayer.js +3 -3
- package/src/level/tiled/TMXUtils.js +3 -3
- package/src/level/tiled/renderer/TMXHexagonalRenderer.js +1 -1
- package/src/loader/loader.js +3 -2
- package/src/physics/body.js +2 -2
- package/src/physics/bounds.js +1 -1
- package/src/physics/detector.js +4 -4
- package/src/physics/quadtree.js +1 -1
- package/src/physics/sat.js +11 -11
- package/src/renderable/container.js +47 -37
- package/src/renderable/draggable.js +114 -0
- package/src/renderable/dragndrop.js +0 -109
- package/src/renderable/renderable.js +6 -9
- package/src/renderable/trigger.js +1 -1
- package/src/renderable/ui/uibaseelement.js +6 -3
- package/src/renderable/ui/uispriteelement.js +7 -1
- package/src/text/bitmaptext.js +2 -2
- package/src/text/text.js +1 -1
- package/src/video/canvas/canvas_renderer.js +2 -5
- package/src/video/texture/canvas_texture.js +1 -1
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
|
|
|
@@ -42,7 +42,7 @@ function setLayerData(layer, bounds, data) {
|
|
|
42
42
|
for (let y = 0; y < height; y++) {
|
|
43
43
|
for (let x = 0; x < width; x++) {
|
|
44
44
|
// get the value of the gid
|
|
45
|
-
|
|
45
|
+
const gid = data[idx++];
|
|
46
46
|
// fill the array
|
|
47
47
|
if (gid !== 0) {
|
|
48
48
|
// add a new tile to the layer
|
|
@@ -61,7 +61,7 @@ function preRenderLayer(layer, renderer) {
|
|
|
61
61
|
for (let y = 0; y < layer.rows; y++) {
|
|
62
62
|
for (let x = 0; x < layer.cols; x++) {
|
|
63
63
|
// get the value of the gid
|
|
64
|
-
|
|
64
|
+
const tile = layer.layerData[x][y];
|
|
65
65
|
// draw the tile if defined
|
|
66
66
|
if (tile instanceof Tile) {
|
|
67
67
|
// add a new tile to the layer
|
|
@@ -128,7 +128,7 @@ function preRenderLayer(layer, renderer) {
|
|
|
128
128
|
"height" : 0
|
|
129
129
|
};
|
|
130
130
|
for (let i = 0; i < this.tilesets.length; i++) {
|
|
131
|
-
|
|
131
|
+
const tileset = this.tilesets.getTilesetByIndex(i);
|
|
132
132
|
this.maxTileSize.width = Math.max(this.maxTileSize.width, tileset.tilewidth);
|
|
133
133
|
this.maxTileSize.height = Math.max(this.maxTileSize.height, tileset.tileheight);
|
|
134
134
|
}
|
|
@@ -83,7 +83,7 @@ function parseAttributes(obj, elt) {
|
|
|
83
83
|
// do attributes
|
|
84
84
|
if (elt.attributes && elt.attributes.length > 0) {
|
|
85
85
|
for (let j = 0; j < elt.attributes.length; j++) {
|
|
86
|
-
|
|
86
|
+
const attribute = elt.attributes.item(j);
|
|
87
87
|
if (typeof(attribute.name) !== "undefined") {
|
|
88
88
|
// DOM4 (Attr no longer inherit from Node)
|
|
89
89
|
obj[attribute.name] = attribute.value;
|
|
@@ -282,8 +282,8 @@ export function normalize(obj, item) {
|
|
|
282
282
|
var points = parse(item).points.split(" "); // <= "Unexpected lexical declaration in case block" if using let
|
|
283
283
|
|
|
284
284
|
// And normalize them into an array of vectors
|
|
285
|
-
for (let i = 0
|
|
286
|
-
v = points[i].split(",");
|
|
285
|
+
for (let i = 0; i < points.length; i++) {
|
|
286
|
+
const v = points[i].split(",");
|
|
287
287
|
obj[nodeName].push({
|
|
288
288
|
"x" : +v[0],
|
|
289
289
|
"y" : +v[1]
|
|
@@ -284,7 +284,7 @@ const offsetsStaggerY = [
|
|
|
284
284
|
let nearest = 0;
|
|
285
285
|
let minDist = Number.MAX_VALUE;
|
|
286
286
|
for (let i = 0; i < 4; ++i) {
|
|
287
|
-
|
|
287
|
+
const dc = this.centers[i].sub(rel).length2();
|
|
288
288
|
if (dc < minDist) {
|
|
289
289
|
minDist = dc;
|
|
290
290
|
nearest = i;
|
package/src/loader/loader.js
CHANGED
|
@@ -104,8 +104,9 @@ function onLoadingError(res) {
|
|
|
104
104
|
* an asset definition to be used with the loader
|
|
105
105
|
* @typedef {object} loader.Asset
|
|
106
106
|
* @property {string} name - name of the asset
|
|
107
|
-
* @property {string} type - the type of the asset : "audio", binary", "image", "json","js", "tmx", "tsx", "fontface"
|
|
108
|
-
* @property {string} src - path and/or file name of the resource (for audio assets only the path is required)
|
|
107
|
+
* @property {string} type - the type of the asset : "audio", binary", "image", "json", "js", "tmx", "tmj", "tsx", "tsj", "fontface"
|
|
108
|
+
* @property {string} [src] - path and/or file name of the resource (for audio assets only the path is required)
|
|
109
|
+
* @property {string} [data] - TMX data if not provided through a src url
|
|
109
110
|
* @property {boolean} [stream] - Set to true to force HTML5 Audio, which allows not to wait for large file to be downloaded before playing.
|
|
110
111
|
* @see loader.preload
|
|
111
112
|
* @see loader.load
|
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/bounds.js
CHANGED
|
@@ -190,7 +190,7 @@ import Vector2d from "./../math/vector2.js";
|
|
|
190
190
|
this.clear();
|
|
191
191
|
}
|
|
192
192
|
for (let i = 0; i < vertices.length; i++) {
|
|
193
|
-
|
|
193
|
+
const vertex = vertices[i];
|
|
194
194
|
if (vertex.x > this.max.x) this.max.x = vertex.x;
|
|
195
195
|
if (vertex.x < this.min.x) this.min.x = vertex.x;
|
|
196
196
|
if (vertex.y > this.max.y) this.max.y = vertex.y;
|
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) {
|
|
@@ -170,7 +170,7 @@ export default class Detector {
|
|
|
170
170
|
if (objB.body && line.getBounds().overlaps(objB.getBounds())) {
|
|
171
171
|
|
|
172
172
|
// go trough all defined shapes in B (if any)
|
|
173
|
-
|
|
173
|
+
const bLen = objB.body.shapes.length;
|
|
174
174
|
if ( objB.body.shapes.length === 0) {
|
|
175
175
|
continue;
|
|
176
176
|
}
|
package/src/physics/quadtree.js
CHANGED
|
@@ -352,7 +352,7 @@ let QT_VECTOR = new Vector2d();
|
|
|
352
352
|
*/
|
|
353
353
|
hasChildren() {
|
|
354
354
|
for (let i = 0; i < this.nodes.length; i = i + 1) {
|
|
355
|
-
|
|
355
|
+
const subnode = this.nodes[i];
|
|
356
356
|
if (subnode.length > 0 || subnode.objects.length > 0) {
|
|
357
357
|
return true;
|
|
358
358
|
}
|
package/src/physics/sat.js
CHANGED
|
@@ -58,7 +58,7 @@ function flattenPointsOn(points, normal, result) {
|
|
|
58
58
|
let len = points.length;
|
|
59
59
|
for (let i = 0; i < len; i++) {
|
|
60
60
|
// The magnitude of the projection of the point onto the normal
|
|
61
|
-
|
|
61
|
+
const dot = points[i].dot(normal);
|
|
62
62
|
if (dot < min) { min = dot; }
|
|
63
63
|
if (dot > max) { max = dot; }
|
|
64
64
|
}
|
|
@@ -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.
|
|
@@ -305,8 +305,8 @@ export function testPolygonEllipse(a, polyA, b, ellipseB, response) {
|
|
|
305
305
|
|
|
306
306
|
// For each edge in the polygon:
|
|
307
307
|
for (let i = 0; i < len; i++) {
|
|
308
|
-
|
|
309
|
-
|
|
308
|
+
const next = i === len - 1 ? 0 : i + 1;
|
|
309
|
+
const prev = i === 0 ? len - 1 : i - 1;
|
|
310
310
|
let overlap = 0;
|
|
311
311
|
let overlapN = null;
|
|
312
312
|
|
|
@@ -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.
|
|
@@ -176,7 +176,7 @@ let globalFloatingCounter = 0;
|
|
|
176
176
|
* will not be in any container. <br>
|
|
177
177
|
* if the given child implements a onActivateEvent method, that method will be called
|
|
178
178
|
* once the child is added to this container.
|
|
179
|
-
* @param {Renderable} child
|
|
179
|
+
* @param {Renderable|Entity|Sprite|Collectable|Trigger|Draggable|DropTarget|NineSliceSprite|ImageLayer|ColorLayer|Light2d|UIBaseElement|UISpriteElement|UITextButton|Text|BitmapText} child
|
|
180
180
|
* @param {number} [z] - forces the z index of the child to the specified value
|
|
181
181
|
* @returns {Renderable} the added child
|
|
182
182
|
*/
|
|
@@ -193,10 +193,16 @@ let globalFloatingCounter = 0;
|
|
|
193
193
|
}
|
|
194
194
|
}
|
|
195
195
|
|
|
196
|
+
// add the new child
|
|
196
197
|
child.ancestor = this;
|
|
197
198
|
this.getChildren().push(child);
|
|
199
|
+
|
|
200
|
+
// update child bounds to reflect the new ancestor
|
|
198
201
|
if (typeof child.updateBounds === "function") {
|
|
199
|
-
|
|
202
|
+
if (this.isFloating === true) {
|
|
203
|
+
// only parent container can be floating
|
|
204
|
+
child.floating = false;
|
|
205
|
+
}
|
|
200
206
|
child.updateBounds();
|
|
201
207
|
}
|
|
202
208
|
|
|
@@ -217,12 +223,7 @@ let globalFloatingCounter = 0;
|
|
|
217
223
|
child.onActivateEvent();
|
|
218
224
|
}
|
|
219
225
|
|
|
220
|
-
// force
|
|
221
|
-
if (this.isAttachedToRoot() === true) {
|
|
222
|
-
this.isDirty = true;
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
// force bounds update if required
|
|
226
|
+
// force container bounds update if required
|
|
226
227
|
if (this.enableChildBoundsUpdate === true) {
|
|
227
228
|
this.updateBounds();
|
|
228
229
|
}
|
|
@@ -245,6 +246,9 @@ let globalFloatingCounter = 0;
|
|
|
245
246
|
}
|
|
246
247
|
}
|
|
247
248
|
|
|
249
|
+
// mark the container for repaint
|
|
250
|
+
this.isDirty = true;
|
|
251
|
+
|
|
248
252
|
// triggered callback if defined
|
|
249
253
|
this.onChildChange.call(this, this.getChildren().length - 1);
|
|
250
254
|
|
|
@@ -254,7 +258,7 @@ let globalFloatingCounter = 0;
|
|
|
254
258
|
/**
|
|
255
259
|
* Add a child to the container at the specified index<br>
|
|
256
260
|
* (the list won't be sorted after insertion)
|
|
257
|
-
* @param {Renderable} child
|
|
261
|
+
* @param {Renderable|Entity|Sprite|Collectable|Trigger|Draggable|DropTarget|NineSliceSprite|ImageLayer|ColorLayer|Light2d|UIBaseElement|UISpriteElement|UITextButton|Text|BitmapText} child
|
|
258
262
|
* @param {number} index
|
|
259
263
|
* @returns {Renderable} the added child
|
|
260
264
|
*/
|
|
@@ -271,20 +275,25 @@ let globalFloatingCounter = 0;
|
|
|
271
275
|
child.GUID = utils.createGUID();
|
|
272
276
|
}
|
|
273
277
|
}
|
|
274
|
-
child.ancestor = this;
|
|
275
278
|
|
|
279
|
+
// add the new child
|
|
280
|
+
child.ancestor = this;
|
|
276
281
|
this.getChildren().splice(index, 0, child);
|
|
277
282
|
|
|
278
|
-
|
|
279
|
-
|
|
283
|
+
// update child bounds to reflect the new ancestor
|
|
284
|
+
if (typeof child.updateBounds === "function") {
|
|
285
|
+
if (this.isFloating === true) {
|
|
286
|
+
// only parent container can be floating
|
|
287
|
+
child.floating = false;
|
|
288
|
+
}
|
|
289
|
+
child.updateBounds();
|
|
280
290
|
}
|
|
281
291
|
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
this.isDirty = true;
|
|
292
|
+
if (typeof child.onActivateEvent === "function" && this.isAttachedToRoot()) {
|
|
293
|
+
child.onActivateEvent();
|
|
285
294
|
}
|
|
286
295
|
|
|
287
|
-
// force bounds update if required
|
|
296
|
+
// force container bounds update if required
|
|
288
297
|
if (this.enableChildBoundsUpdate === true) {
|
|
289
298
|
this.updateBounds();
|
|
290
299
|
}
|
|
@@ -307,6 +316,9 @@ let globalFloatingCounter = 0;
|
|
|
307
316
|
}
|
|
308
317
|
}
|
|
309
318
|
|
|
319
|
+
// mark the container for repaint
|
|
320
|
+
this.isDirty = true;
|
|
321
|
+
|
|
310
322
|
// triggered callback if defined
|
|
311
323
|
this.onChildChange.call(this, index);
|
|
312
324
|
|
|
@@ -357,8 +369,8 @@ let globalFloatingCounter = 0;
|
|
|
357
369
|
|
|
358
370
|
/**
|
|
359
371
|
* Swaps the position (z-index) of 2 children
|
|
360
|
-
* @param {Renderable} child
|
|
361
|
-
* @param {Renderable} child2
|
|
372
|
+
* @param {Renderable|Entity|Sprite|Collectable|Trigger|Draggable|DropTarget|NineSliceSprite|ImageLayer|ColorLayer|Light2d|UIBaseElement|UISpriteElement|UITextButton|Text|BitmapText} child
|
|
373
|
+
* @param {Renderable|Entity|Sprite|Collectable|Trigger|Draggable|DropTarget|NineSliceSprite|ImageLayer|ColorLayer|Light2d|UIBaseElement|UISpriteElement|UITextButton|Text|BitmapText} child2
|
|
362
374
|
*/
|
|
363
375
|
swapChildren(child, child2) {
|
|
364
376
|
let index = this.getChildIndex(child);
|
|
@@ -396,7 +408,7 @@ let globalFloatingCounter = 0;
|
|
|
396
408
|
|
|
397
409
|
/**
|
|
398
410
|
* Returns the index of the given Child
|
|
399
|
-
* @param {Renderable} child
|
|
411
|
+
* @param {Renderable|Entity|Sprite|Collectable|Trigger|Draggable|DropTarget|NineSliceSprite|ImageLayer|ColorLayer|Light2d|UIBaseElement|UISpriteElement|UITextButton|Text|BitmapText} child
|
|
400
412
|
* @returns {number} index
|
|
401
413
|
*/
|
|
402
414
|
getChildIndex(child) {
|
|
@@ -405,7 +417,7 @@ let globalFloatingCounter = 0;
|
|
|
405
417
|
|
|
406
418
|
/**
|
|
407
419
|
* Returns the next child within the container or undefined if none
|
|
408
|
-
* @param {Renderable} child
|
|
420
|
+
* @param {Renderable|Entity|Sprite|Collectable|Trigger|Draggable|DropTarget|NineSliceSprite|ImageLayer|ColorLayer|Light2d|UIBaseElement|UISpriteElement|UITextButton|Text|BitmapText} child
|
|
409
421
|
* @returns {Renderable} child
|
|
410
422
|
*/
|
|
411
423
|
getNextChild(child) {
|
|
@@ -418,7 +430,7 @@ let globalFloatingCounter = 0;
|
|
|
418
430
|
|
|
419
431
|
/**
|
|
420
432
|
* Returns true if contains the specified Child
|
|
421
|
-
* @param {Renderable} child
|
|
433
|
+
* @param {Renderable|Entity|Sprite|Collectable|Trigger|Draggable|DropTarget|NineSliceSprite|ImageLayer|ColorLayer|Light2d|UIBaseElement|UISpriteElement|UITextButton|Text|BitmapText} child
|
|
422
434
|
* @returns {boolean}
|
|
423
435
|
*/
|
|
424
436
|
hasChild(child) {
|
|
@@ -531,10 +543,9 @@ let globalFloatingCounter = 0;
|
|
|
531
543
|
}
|
|
532
544
|
|
|
533
545
|
/**
|
|
534
|
-
* update the bounding box for this
|
|
535
|
-
* @
|
|
536
|
-
* @
|
|
537
|
-
* @returns {Bounds} this shape bounding box Rectangle object
|
|
546
|
+
* update the bounding box for this container.
|
|
547
|
+
* @param {boolean} [absolute=true] - update the bounds size and position in (world) absolute coordinates
|
|
548
|
+
* @returns {Bounds} this container bounding box Rectangle object
|
|
538
549
|
*/
|
|
539
550
|
updateBounds(absolute = true) {
|
|
540
551
|
let bounds = this.getBounds();
|
|
@@ -545,13 +556,14 @@ let globalFloatingCounter = 0;
|
|
|
545
556
|
if (this.enableChildBoundsUpdate === true) {
|
|
546
557
|
this.forEach((child) => {
|
|
547
558
|
if (child.isRenderable) {
|
|
548
|
-
let childBounds = child.
|
|
559
|
+
let childBounds = child.updateBounds(true);
|
|
549
560
|
if (childBounds.isFinite()) {
|
|
550
561
|
bounds.addBounds(childBounds);
|
|
551
562
|
}
|
|
552
563
|
}
|
|
553
564
|
});
|
|
554
565
|
}
|
|
566
|
+
|
|
555
567
|
return bounds;
|
|
556
568
|
}
|
|
557
569
|
|
|
@@ -626,7 +638,7 @@ let globalFloatingCounter = 0;
|
|
|
626
638
|
/**
|
|
627
639
|
* Invokes the removeChildNow in a defer, to ensure the child is removed safely after the update & draw stack has completed. <br>
|
|
628
640
|
* if the given child implements a onDeactivateEvent() method, that method will be called once the child is removed from this container.
|
|
629
|
-
* @param {
|
|
641
|
+
* @param {RendRenderable|Sprite|Collectable|Trigger|Draggable|DropTarget|NineSliceSprite|ImageLayer|ColorLayer|Light2d|UIBaseElement|UISpriteElement|UITextButton|Text|BitmapTexterable} child
|
|
630
642
|
* @param {boolean} [keepalive=false] - true to prevent calling child.destroy()
|
|
631
643
|
*/
|
|
632
644
|
removeChild(child, keepalive) {
|
|
@@ -642,7 +654,7 @@ let globalFloatingCounter = 0;
|
|
|
642
654
|
* Removes (and optionally destroys) a child from the container.<br>
|
|
643
655
|
* (removal is immediate and unconditional)<br>
|
|
644
656
|
* Never use keepalive=true with objects from {@link pool}. Doing so will create a memory leak.
|
|
645
|
-
* @param {Renderable} child
|
|
657
|
+
* @param {Renderable|Entity|Sprite|Collectable|Trigger|Draggable|DropTarget|NineSliceSprite|ImageLayer|ColorLayer|Light2d|UIBaseElement|UISpriteElement|UITextButton|Text|BitmapText} child
|
|
646
658
|
* @param {boolean} [keepalive=False] - True to prevent calling child.destroy()
|
|
647
659
|
*/
|
|
648
660
|
removeChildNow(child, keepalive) {
|
|
@@ -675,16 +687,14 @@ let globalFloatingCounter = 0;
|
|
|
675
687
|
child.ancestor = undefined;
|
|
676
688
|
}
|
|
677
689
|
|
|
678
|
-
// force repaint in case this is a static non-animated object
|
|
679
|
-
if (this.isAttachedToRoot() === true) {
|
|
680
|
-
this.isDirty = true;
|
|
681
|
-
}
|
|
682
|
-
|
|
683
690
|
// force bounds update if required
|
|
684
691
|
if (this.enableChildBoundsUpdate === true) {
|
|
685
692
|
this.updateBounds();
|
|
686
693
|
}
|
|
687
694
|
|
|
695
|
+
// mark the container for repaint
|
|
696
|
+
this.isDirty = true;
|
|
697
|
+
|
|
688
698
|
// triggered callback if defined
|
|
689
699
|
this.onChildChange.call(this, childIndex);
|
|
690
700
|
}
|
|
@@ -707,7 +717,7 @@ let globalFloatingCounter = 0;
|
|
|
707
717
|
|
|
708
718
|
/**
|
|
709
719
|
* Move the child in the group one step forward (z depth).
|
|
710
|
-
* @param {Renderable} child
|
|
720
|
+
* @param {Renderable|Entity|Sprite|Collectable|Trigger|Draggable|DropTarget|NineSliceSprite|ImageLayer|ColorLayer|Light2d|UIBaseElement|UISpriteElement|UITextButton|Text|BitmapText} child
|
|
711
721
|
*/
|
|
712
722
|
moveUp(child) {
|
|
713
723
|
let childIndex = this.getChildIndex(child);
|
|
@@ -721,7 +731,7 @@ let globalFloatingCounter = 0;
|
|
|
721
731
|
|
|
722
732
|
/**
|
|
723
733
|
* Move the child in the group one step backward (z depth).
|
|
724
|
-
* @param {Renderable} child
|
|
734
|
+
* @param {Renderable|Entity|Sprite|Collectable|Trigger|Draggable|DropTarget|NineSliceSprite|ImageLayer|ColorLayer|Light2d|UIBaseElement|UISpriteElement|UITextButton|Text|BitmapText} child
|
|
725
735
|
*/
|
|
726
736
|
moveDown(child) {
|
|
727
737
|
let childIndex = this.getChildIndex(child);
|
|
@@ -735,7 +745,7 @@ let globalFloatingCounter = 0;
|
|
|
735
745
|
|
|
736
746
|
/**
|
|
737
747
|
* Move the specified child to the top(z depth).
|
|
738
|
-
* @param {Renderable} child
|
|
748
|
+
* @param {Renderable|Entity|Sprite|Collectable|Trigger|Draggable|DropTarget|NineSliceSprite|ImageLayer|ColorLayer|Light2d|UIBaseElement|UISpriteElement|UITextButton|Text|BitmapText} child
|
|
739
749
|
*/
|
|
740
750
|
moveToTop(child) {
|
|
741
751
|
let childIndex = this.getChildIndex(child);
|
|
@@ -752,7 +762,7 @@ let globalFloatingCounter = 0;
|
|
|
752
762
|
|
|
753
763
|
/**
|
|
754
764
|
* Move the specified child the bottom (z depth).
|
|
755
|
-
* @param {Renderable} child
|
|
765
|
+
* @param {Renderable|Entity|Sprite|Collectable|Trigger|Draggable|DropTarget|NineSliceSprite|ImageLayer|ColorLayer|Light2d|UIBaseElement|UISpriteElement|UITextButton|Text|BitmapText} child
|
|
756
766
|
*/
|
|
757
767
|
moveToBottom(child) {
|
|
758
768
|
let childIndex = this.getChildIndex(child);
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import Vector2d from "./../math/vector2.js";
|
|
2
|
+
import * as input from "./../input/input.js";
|
|
3
|
+
import * as event from "./../system/event.js";
|
|
4
|
+
import Renderable from "./../renderable/renderable.js";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @classdesc
|
|
8
|
+
* A Draggable base object
|
|
9
|
+
* @see DropTarget
|
|
10
|
+
* @augments Renderable
|
|
11
|
+
*/
|
|
12
|
+
export class Draggable extends Renderable {
|
|
13
|
+
/**
|
|
14
|
+
* @param {number} x - the x coordinates of the draggable object
|
|
15
|
+
* @param {number} y - the y coordinates of the draggable object
|
|
16
|
+
* @param {number} width - draggable object width
|
|
17
|
+
* @param {number} height - draggable object height
|
|
18
|
+
*/
|
|
19
|
+
constructor(x, y, width, height) {
|
|
20
|
+
super(x, y, width, height);
|
|
21
|
+
this.isKinematic = false;
|
|
22
|
+
this.dragging = false;
|
|
23
|
+
this.dragId = null;
|
|
24
|
+
this.grabOffset = new Vector2d(0, 0);
|
|
25
|
+
this.initEvents();
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Initializes the events the modules needs to listen to
|
|
30
|
+
* It translates the pointer events to me.events
|
|
31
|
+
* in order to make them pass through the system and to make
|
|
32
|
+
* this module testable. Then we subscribe this module to the
|
|
33
|
+
* transformed events.
|
|
34
|
+
* @name initEvents
|
|
35
|
+
* @memberof Draggable
|
|
36
|
+
* @private
|
|
37
|
+
*/
|
|
38
|
+
initEvents() {
|
|
39
|
+
input.registerPointerEvent("pointerdown", this, (e) => event.emit(event.DRAGSTART, e, this));
|
|
40
|
+
input.registerPointerEvent("pointerup", this, (e) => event.emit(event.DRAGEND, e, this));
|
|
41
|
+
input.registerPointerEvent("pointercancel", this, (e) => event.emit(event.DRAGEND, e, this));
|
|
42
|
+
event.on(event.POINTERMOVE, (e) => this.dragMove(e));
|
|
43
|
+
event.on(event.DRAGSTART, (e, draggable) => {
|
|
44
|
+
if (draggable === this) {
|
|
45
|
+
this.dragStart(e);
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
event.on(event.DRAGEND, (e, draggable) => {
|
|
49
|
+
if (draggable === this) {
|
|
50
|
+
this.dragEnd(e);
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Gets called when the user starts dragging the entity
|
|
57
|
+
* @name dragStart
|
|
58
|
+
* @memberof Draggable
|
|
59
|
+
* @param {object} e - the pointer event
|
|
60
|
+
* @returns {boolean} false if the object is being dragged
|
|
61
|
+
*/
|
|
62
|
+
dragStart(e) {
|
|
63
|
+
if (this.dragging === false) {
|
|
64
|
+
this.dragging = true;
|
|
65
|
+
this.grabOffset.set(e.gameX, e.gameY);
|
|
66
|
+
this.grabOffset.sub(this.pos);
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Gets called when the user drags this entity around
|
|
73
|
+
* @name dragMove
|
|
74
|
+
* @memberof Draggable
|
|
75
|
+
* @param {object} e - the pointer event
|
|
76
|
+
*/
|
|
77
|
+
dragMove(e) {
|
|
78
|
+
if (this.dragging === true) {
|
|
79
|
+
this.pos.set(e.gameX, e.gameY, this.pos.z); //TODO : z ?
|
|
80
|
+
this.pos.sub(this.grabOffset);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Gets called when the user stops dragging the entity
|
|
86
|
+
* @name dragEnd
|
|
87
|
+
* @memberof Draggable
|
|
88
|
+
* @returns {boolean} false if the object stopped being dragged
|
|
89
|
+
*/
|
|
90
|
+
dragEnd() {
|
|
91
|
+
if (this.dragging === true) {
|
|
92
|
+
this.dragging = false;
|
|
93
|
+
return false;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Destructor
|
|
99
|
+
* @name destroy
|
|
100
|
+
* @memberof Draggable
|
|
101
|
+
* @ignore
|
|
102
|
+
*/
|
|
103
|
+
destroy() {
|
|
104
|
+
event.off(event.POINTERMOVE, this.dragMove);
|
|
105
|
+
event.off(event.DRAGSTART, this.dragStart);
|
|
106
|
+
event.off(event.DRAGEND, this.dragEnd);
|
|
107
|
+
input.releasePointerEvent("pointerdown", this);
|
|
108
|
+
input.releasePointerEvent("pointerup", this);
|
|
109
|
+
input.releasePointerEvent("pointercancel", this);
|
|
110
|
+
super.destroy();
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
|