melonjs 10.8.0 → 10.11.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/LICENSE.md +1 -1
- package/README.md +32 -25
- package/dist/melonjs.js +1833 -2267
- package/dist/melonjs.min.js +4 -4
- package/dist/melonjs.module.d.ts +642 -1416
- package/dist/melonjs.module.js +1778 -2237
- package/package.json +16 -16
- package/src/audio/audio.js +0 -1
- package/src/camera/camera2d.js +1 -16
- package/src/entity/entity.js +1 -4
- package/src/game.js +2 -2
- package/src/geometries/ellipse.js +18 -27
- package/src/geometries/line.js +5 -8
- package/src/geometries/path2d.js +10 -20
- package/src/geometries/poly.js +28 -45
- package/src/geometries/rectangle.js +24 -36
- package/src/geometries/roundrect.js +96 -3
- package/src/index.js +7 -2
- package/src/input/gamepad.js +5 -16
- package/src/input/keyboard.js +1 -9
- package/src/input/pointer.js +0 -1
- package/src/input/pointerevent.js +14 -23
- package/src/lang/deprecated.js +9 -6
- package/src/level/level.js +0 -9
- package/src/level/tiled/TMXGroup.js +0 -4
- package/src/level/tiled/TMXLayer.js +0 -8
- package/src/level/tiled/TMXObject.js +0 -3
- package/src/level/tiled/TMXTile.js +4 -5
- package/src/level/tiled/TMXTileMap.js +1 -7
- package/src/level/tiled/TMXTileset.js +0 -5
- package/src/level/tiled/TMXTilesetGroup.js +1 -4
- package/src/level/tiled/TMXUtils.js +1 -4
- package/src/level/tiled/renderer/TMXHexagonalRenderer.js +2 -3
- package/src/level/tiled/renderer/TMXIsometricRenderer.js +0 -1
- package/src/level/tiled/renderer/TMXRenderer.js +1 -7
- package/src/loader/loader.js +0 -11
- package/src/loader/loadingscreen.js +16 -5
- package/src/math/color.js +10 -30
- package/src/math/math.js +0 -10
- package/src/math/matrix2.js +12 -27
- package/src/math/matrix3.js +1 -22
- package/src/math/observable_vector2.js +0 -29
- package/src/math/observable_vector3.js +0 -29
- package/src/math/vector2.js +3 -40
- package/src/math/vector3.js +4 -41
- package/src/particles/emitter.js +11 -12
- package/src/physics/body.js +1 -1
- package/src/physics/bounds.js +5 -19
- package/src/physics/collision.js +0 -1
- package/src/physics/detector.js +0 -4
- package/src/physics/quadtree.js +0 -7
- package/src/physics/sat.js +3 -3
- package/src/physics/world.js +0 -4
- package/src/plugin/plugin.js +0 -2
- package/src/polyfill/index.js +1 -0
- package/src/polyfill/roundrect.js +237 -0
- package/src/renderable/GUI.js +5 -10
- package/src/renderable/collectable.js +1 -0
- package/src/renderable/container.js +26 -54
- package/src/renderable/dragndrop.js +0 -9
- package/src/renderable/imagelayer.js +3 -7
- package/src/renderable/light2d.js +114 -0
- package/src/renderable/renderable.js +22 -43
- package/src/renderable/sprite.js +13 -25
- package/src/renderable/trigger.js +1 -1
- package/src/state/stage.js +72 -6
- package/src/state/state.js +3 -20
- package/src/system/device.js +14 -53
- package/src/system/event.js +11 -0
- package/src/system/pooling.js +19 -8
- package/src/system/save.js +9 -11
- package/src/system/timer.js +239 -218
- package/src/text/bitmaptextdata.js +1 -4
- package/src/text/glyph.js +2 -2
- package/src/text/text.js +19 -21
- package/src/text/textmetrics.js +0 -2
- package/src/tweens/easing.js +1 -1
- package/src/tweens/interpolation.js +2 -2
- package/src/tweens/tween.js +1 -13
- package/src/utils/agent.js +1 -3
- package/src/utils/array.js +0 -3
- package/src/utils/file.js +0 -2
- package/src/utils/function.js +0 -2
- package/src/utils/string.js +0 -6
- package/src/utils/utils.js +2 -5
- package/src/video/canvas/canvas_renderer.js +76 -103
- package/src/video/renderer.js +43 -50
- package/src/video/{texture.js → texture/atlas.js} +8 -8
- package/src/video/{texture_cache.js → texture/cache.js} +4 -5
- package/src/video/texture/canvas_texture.js +99 -0
- package/src/video/video.js +3 -3
- package/src/video/webgl/glshader.js +0 -5
- package/src/video/webgl/utils/uniforms.js +4 -7
- package/src/video/webgl/webgl_compositor.js +0 -14
- package/src/video/webgl/webgl_renderer.js +73 -97
package/src/physics/bounds.js
CHANGED
|
@@ -34,7 +34,6 @@ class Bounds {
|
|
|
34
34
|
* reset the bound
|
|
35
35
|
* @name clear
|
|
36
36
|
* @memberof Bounds
|
|
37
|
-
* @function
|
|
38
37
|
*/
|
|
39
38
|
clear() {
|
|
40
39
|
this.setMinMax(Infinity, Infinity, -Infinity, -Infinity);
|
|
@@ -45,7 +44,6 @@ class Bounds {
|
|
|
45
44
|
* sets the bounds to the given min and max value
|
|
46
45
|
* @name setMinMax
|
|
47
46
|
* @memberof Bounds
|
|
48
|
-
* @function
|
|
49
47
|
* @param {number} minX
|
|
50
48
|
* @param {number} minY
|
|
51
49
|
* @param {number} maxX
|
|
@@ -205,7 +203,6 @@ class Bounds {
|
|
|
205
203
|
* Updates bounds using the given vertices
|
|
206
204
|
* @name update
|
|
207
205
|
* @memberof Bounds
|
|
208
|
-
* @function
|
|
209
206
|
* @param {Vector2d[]} vertices an array of me.Vector2d points
|
|
210
207
|
*/
|
|
211
208
|
update(vertices) {
|
|
@@ -216,7 +213,6 @@ class Bounds {
|
|
|
216
213
|
* add the given vertices to the bounds definition.
|
|
217
214
|
* @name add
|
|
218
215
|
* @memberof Bounds
|
|
219
|
-
* @function
|
|
220
216
|
* @param {Vector2d[]} vertices an array of me.Vector2d points
|
|
221
217
|
* @param {boolean} [clear=false] either to reset the bounds before adding the new vertices
|
|
222
218
|
*/
|
|
@@ -237,7 +233,6 @@ class Bounds {
|
|
|
237
233
|
* add the given bounds to the bounds definition.
|
|
238
234
|
* @name addBounds
|
|
239
235
|
* @memberof Bounds
|
|
240
|
-
* @function
|
|
241
236
|
* @param {Bounds} bounds
|
|
242
237
|
* @param {boolean} [clear=false] either to reset the bounds before adding the new vertices
|
|
243
238
|
*/
|
|
@@ -256,7 +251,6 @@ class Bounds {
|
|
|
256
251
|
* add the given point to the bounds definition.
|
|
257
252
|
* @name addPoint
|
|
258
253
|
* @memberof Bounds
|
|
259
|
-
* @function
|
|
260
254
|
* @param {Vector2d} v
|
|
261
255
|
* @param {Matrix2d} [m] an optional transform to apply to the given point
|
|
262
256
|
*/
|
|
@@ -274,7 +268,6 @@ class Bounds {
|
|
|
274
268
|
* add the given quad coordinates to this bound definition, multiplied by the given matrix
|
|
275
269
|
* @name addFrame
|
|
276
270
|
* @memberof Bounds
|
|
277
|
-
* @function
|
|
278
271
|
* @param {number} x0 - left X coordinates of the quad
|
|
279
272
|
* @param {number} y0 - top Y coordinates of the quad
|
|
280
273
|
* @param {number} x1 - right X coordinates of the quad
|
|
@@ -282,7 +275,7 @@ class Bounds {
|
|
|
282
275
|
* @param {Matrix2d} [m] an optional transform to apply to the given frame coordinates
|
|
283
276
|
*/
|
|
284
277
|
addFrame(x0, y0, x1, y1, m) {
|
|
285
|
-
var v =
|
|
278
|
+
var v = pool.pull("Vector2d");
|
|
286
279
|
|
|
287
280
|
// transform all points and add to the bound definition
|
|
288
281
|
this.addPoint(v.set(x0, y0), m);
|
|
@@ -290,14 +283,14 @@ class Bounds {
|
|
|
290
283
|
this.addPoint(v.set(x0, y1), m);
|
|
291
284
|
this.addPoint(v.set(x1, y1), m);
|
|
292
285
|
|
|
293
|
-
|
|
286
|
+
pool.push(v);
|
|
294
287
|
}
|
|
295
288
|
|
|
296
289
|
/**
|
|
297
290
|
* Returns true if the bounds contains the given point.
|
|
298
291
|
* @name contains
|
|
299
292
|
* @memberof Bounds
|
|
300
|
-
* @
|
|
293
|
+
* @method
|
|
301
294
|
* @param {Vector2d} point
|
|
302
295
|
* @returns {boolean} True if the bounds contain the point, otherwise false
|
|
303
296
|
*/
|
|
@@ -305,7 +298,6 @@ class Bounds {
|
|
|
305
298
|
* Returns true if the bounds contains the given point.
|
|
306
299
|
* @name contains
|
|
307
300
|
* @memberof Bounds
|
|
308
|
-
* @function
|
|
309
301
|
* @param {number} x
|
|
310
302
|
* @param {number} y
|
|
311
303
|
* @returns {boolean} True if the bounds contain the point, otherwise false
|
|
@@ -339,7 +331,6 @@ class Bounds {
|
|
|
339
331
|
* Returns true if the two bounds intersect.
|
|
340
332
|
* @name overlaps
|
|
341
333
|
* @memberof Bounds
|
|
342
|
-
* @function
|
|
343
334
|
* @param {Bounds|Rect} bounds
|
|
344
335
|
* @returns {boolean} True if the bounds overlap, otherwise false
|
|
345
336
|
*/
|
|
@@ -352,7 +343,6 @@ class Bounds {
|
|
|
352
343
|
* determines whether all coordinates of this bounds are finite numbers.
|
|
353
344
|
* @name isFinite
|
|
354
345
|
* @memberof Bounds
|
|
355
|
-
* @function
|
|
356
346
|
* @returns {boolean} false if all coordinates are positive or negative Infinity or NaN; otherwise, true.
|
|
357
347
|
*/
|
|
358
348
|
isFinite() {
|
|
@@ -363,14 +353,13 @@ class Bounds {
|
|
|
363
353
|
* Translates the bounds by the given vector.
|
|
364
354
|
* @name translate
|
|
365
355
|
* @memberof Bounds
|
|
366
|
-
* @
|
|
356
|
+
* @method
|
|
367
357
|
* @param {Vector2d} vector
|
|
368
358
|
*/
|
|
369
359
|
/**
|
|
370
360
|
* Translates the bounds by x on the x axis, and y on the y axis
|
|
371
361
|
* @name translate
|
|
372
362
|
* @memberof Bounds
|
|
373
|
-
* @function
|
|
374
363
|
* @param {number} x
|
|
375
364
|
* @param {number} y
|
|
376
365
|
*/
|
|
@@ -395,14 +384,13 @@ class Bounds {
|
|
|
395
384
|
* Shifts the bounds to the given position vector.
|
|
396
385
|
* @name shift
|
|
397
386
|
* @memberof Bounds
|
|
398
|
-
* @
|
|
387
|
+
* @method
|
|
399
388
|
* @param {Vector2d} position
|
|
400
389
|
*/
|
|
401
390
|
/**
|
|
402
391
|
* Shifts the bounds to the given x, y position.
|
|
403
392
|
* @name shift
|
|
404
393
|
* @memberof Bounds
|
|
405
|
-
* @function
|
|
406
394
|
* @param {number} x
|
|
407
395
|
* @param {number} y
|
|
408
396
|
*/
|
|
@@ -432,7 +420,6 @@ class Bounds {
|
|
|
432
420
|
* clone this bounds
|
|
433
421
|
* @name clone
|
|
434
422
|
* @memberof Bounds
|
|
435
|
-
* @function
|
|
436
423
|
* @returns {Bounds}
|
|
437
424
|
*/
|
|
438
425
|
clone() {
|
|
@@ -445,7 +432,6 @@ class Bounds {
|
|
|
445
432
|
* Returns a polygon whose edges are the same as this bounds.
|
|
446
433
|
* @name toPolygon
|
|
447
434
|
* @memberof Bounds
|
|
448
|
-
* @function
|
|
449
435
|
* @returns {Polygon} a new Polygon that represents this bounds.
|
|
450
436
|
*/
|
|
451
437
|
toPolygon () {
|
package/src/physics/collision.js
CHANGED
|
@@ -107,7 +107,6 @@ var collision = {
|
|
|
107
107
|
* @name rayCast
|
|
108
108
|
* @memberof collision
|
|
109
109
|
* @public
|
|
110
|
-
* @function
|
|
111
110
|
* @param {Line} line line to be tested for collision
|
|
112
111
|
* @param {Array.<Renderable>} [result] a user defined array that will be populated with intersecting physic objects.
|
|
113
112
|
* @returns {Array.<Renderable>} an array of intersecting physic objects
|
package/src/physics/detector.js
CHANGED
|
@@ -19,7 +19,6 @@ var dummyObj = {
|
|
|
19
19
|
* @name shouldCollide
|
|
20
20
|
* @memberof collision
|
|
21
21
|
* @ignore
|
|
22
|
-
* @function
|
|
23
22
|
* @param {Renderable} a a reference to the object A.
|
|
24
23
|
* @param {Renderable} b a reference to the object B.
|
|
25
24
|
* @returns {boolean} true if they should collide, false otherwise
|
|
@@ -71,7 +70,6 @@ class ResponseObject {
|
|
|
71
70
|
* @name clear
|
|
72
71
|
* @memberof collision.ResponseObject
|
|
73
72
|
* @public
|
|
74
|
-
* @function
|
|
75
73
|
* @returns {object} this object for chaining
|
|
76
74
|
*/
|
|
77
75
|
clear () {
|
|
@@ -91,7 +89,6 @@ export var globalResponse = new ResponseObject();
|
|
|
91
89
|
* find all the collisions for the specified object
|
|
92
90
|
* @name collisionCheck
|
|
93
91
|
* @ignore
|
|
94
|
-
* @function
|
|
95
92
|
* @param {Renderable} objA object to be tested for collision
|
|
96
93
|
* @param {collision.ResponseObject} [response=collision.response] a user defined response object that will be populated if they intersect.
|
|
97
94
|
* @returns {boolean} in case of collision, false otherwise
|
|
@@ -163,7 +160,6 @@ export function collisionCheck(objA, response = globalResponse) {
|
|
|
163
160
|
* Checks for object colliding with the given line
|
|
164
161
|
* @name rayCast
|
|
165
162
|
* @ignore
|
|
166
|
-
* @function
|
|
167
163
|
* @param {Line} line line to be tested for collision
|
|
168
164
|
* @param {Array.<Renderable>} [result] a user defined array that will be populated with intersecting physic objects.
|
|
169
165
|
* @returns {Array.<Renderable>} an array of intersecting physic objects
|
package/src/physics/quadtree.js
CHANGED
|
@@ -165,7 +165,6 @@ class QuadTree {
|
|
|
165
165
|
* Insert the given object container into the node.
|
|
166
166
|
* @name insertContainer
|
|
167
167
|
* @memberof QuadTree
|
|
168
|
-
* @function
|
|
169
168
|
* @param {Container} container group of objects to be added
|
|
170
169
|
*/
|
|
171
170
|
insertContainer(container) {
|
|
@@ -194,7 +193,6 @@ class QuadTree {
|
|
|
194
193
|
* objects to their corresponding subnodes.
|
|
195
194
|
* @name insert
|
|
196
195
|
* @memberof QuadTree
|
|
197
|
-
* @function
|
|
198
196
|
* @param {object} item object to be added
|
|
199
197
|
*/
|
|
200
198
|
insert(item) {
|
|
@@ -239,7 +237,6 @@ class QuadTree {
|
|
|
239
237
|
* Return all objects that could collide with the given object
|
|
240
238
|
* @name retrieve
|
|
241
239
|
* @memberof QuadTree
|
|
242
|
-
* @function
|
|
243
240
|
* @param {object} item object to be checked against
|
|
244
241
|
* @param {object} [fn] a sorting function for the returned array
|
|
245
242
|
* @returns {object[]} array with all detected objects
|
|
@@ -275,7 +272,6 @@ class QuadTree {
|
|
|
275
272
|
* (this function won't recalculate the impacted node)
|
|
276
273
|
* @name remove
|
|
277
274
|
* @memberof QuadTree
|
|
278
|
-
* @function
|
|
279
275
|
* @param {object} item object to be removed
|
|
280
276
|
* @returns {boolean} true if the item was found and removed.
|
|
281
277
|
*/
|
|
@@ -316,7 +312,6 @@ class QuadTree {
|
|
|
316
312
|
* return true if the node is prunable
|
|
317
313
|
* @name isPrunable
|
|
318
314
|
* @memberof QuadTree
|
|
319
|
-
* @function
|
|
320
315
|
* @returns {boolean} true if the node is prunable
|
|
321
316
|
*/
|
|
322
317
|
isPrunable() {
|
|
@@ -327,7 +322,6 @@ class QuadTree {
|
|
|
327
322
|
* return true if the node has any children
|
|
328
323
|
* @name hasChildren
|
|
329
324
|
* @memberof QuadTree
|
|
330
|
-
* @function
|
|
331
325
|
* @returns {boolean} true if the node has any children
|
|
332
326
|
*/
|
|
333
327
|
hasChildren() {
|
|
@@ -344,7 +338,6 @@ class QuadTree {
|
|
|
344
338
|
* clear the quadtree
|
|
345
339
|
* @name clear
|
|
346
340
|
* @memberof QuadTree
|
|
347
|
-
* @function
|
|
348
341
|
* @param {Bounds} [bounds=this.bounds] the bounds to be cleared
|
|
349
342
|
*/
|
|
350
343
|
clear(bounds) {
|
package/src/physics/sat.js
CHANGED
|
@@ -9,19 +9,19 @@ import Vector2d from "./../math/vector2.js";
|
|
|
9
9
|
* Constants for Vornoi regions
|
|
10
10
|
* @ignore
|
|
11
11
|
*/
|
|
12
|
-
|
|
12
|
+
const LEFT_VORNOI_REGION = -1;
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* Constants for Vornoi regions
|
|
16
16
|
* @ignore
|
|
17
17
|
*/
|
|
18
|
-
|
|
18
|
+
const MIDDLE_VORNOI_REGION = 0;
|
|
19
19
|
|
|
20
20
|
/**
|
|
21
21
|
* Constants for Vornoi regions
|
|
22
22
|
* @ignore
|
|
23
23
|
*/
|
|
24
|
-
|
|
24
|
+
const RIGHT_VORNOI_REGION = 1;
|
|
25
25
|
|
|
26
26
|
|
|
27
27
|
/**
|
package/src/physics/world.js
CHANGED
|
@@ -96,7 +96,6 @@ class World extends Container {
|
|
|
96
96
|
* reset the game world
|
|
97
97
|
* @name reset
|
|
98
98
|
* @memberof World
|
|
99
|
-
* @function
|
|
100
99
|
*/
|
|
101
100
|
reset() {
|
|
102
101
|
// clear the quadtree
|
|
@@ -118,7 +117,6 @@ class World extends Container {
|
|
|
118
117
|
* @name addBody
|
|
119
118
|
* @memberof World
|
|
120
119
|
* @see Container.addChild
|
|
121
|
-
* @function
|
|
122
120
|
* @param {Body} body
|
|
123
121
|
* @returns {World} this game world
|
|
124
122
|
*/
|
|
@@ -133,7 +131,6 @@ class World extends Container {
|
|
|
133
131
|
* @name removeBody
|
|
134
132
|
* @memberof World
|
|
135
133
|
* @see Container.removeChild
|
|
136
|
-
* @function
|
|
137
134
|
* @param {Body} body
|
|
138
135
|
* @returns {World} this game world
|
|
139
136
|
*/
|
|
@@ -147,7 +144,6 @@ class World extends Container {
|
|
|
147
144
|
* update the game world
|
|
148
145
|
* @name reset
|
|
149
146
|
* @memberof World
|
|
150
|
-
* @function
|
|
151
147
|
* @param {number} dt the time passed since the last frame update
|
|
152
148
|
* @returns {boolean} true if the word is dirty
|
|
153
149
|
*/
|
package/src/plugin/plugin.js
CHANGED
|
@@ -44,7 +44,6 @@ export var plugin = {
|
|
|
44
44
|
* @name patch
|
|
45
45
|
* @memberof plugin
|
|
46
46
|
* @public
|
|
47
|
-
* @function
|
|
48
47
|
* @param {object} proto target object
|
|
49
48
|
* @param {string} name target function
|
|
50
49
|
* @param {Function} fn replacement function
|
|
@@ -90,7 +89,6 @@ export var plugin = {
|
|
|
90
89
|
* @memberof plugin
|
|
91
90
|
* @see Base
|
|
92
91
|
* @public
|
|
93
|
-
* @function
|
|
94
92
|
* @param {plugin.Base} pluginObj Plugin object to instantiate and register
|
|
95
93
|
* @param {string} name
|
|
96
94
|
* @param {object} [...arguments] all extra parameters will be passed to the plugin constructor
|
package/src/polyfill/index.js
CHANGED
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* based on https://www.npmjs.com/package/canvas-roundrect-polyfill
|
|
3
|
+
* @version 0.0.1
|
|
4
|
+
*/
|
|
5
|
+
(() => {
|
|
6
|
+
|
|
7
|
+
"use strict";
|
|
8
|
+
|
|
9
|
+
/** @ignore */
|
|
10
|
+
function roundRect(x, y, w, h, radii) {
|
|
11
|
+
|
|
12
|
+
if (!([x, y, w, h].every((input) => Number.isFinite(input)))) {
|
|
13
|
+
|
|
14
|
+
return;
|
|
15
|
+
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
radii = parseRadiiArgument(radii);
|
|
19
|
+
|
|
20
|
+
let upperLeft, upperRight, lowerRight, lowerLeft;
|
|
21
|
+
|
|
22
|
+
if (radii.length === 4) {
|
|
23
|
+
|
|
24
|
+
upperLeft = toCornerPoint(radii[0]);
|
|
25
|
+
upperRight = toCornerPoint(radii[1]);
|
|
26
|
+
lowerRight = toCornerPoint(radii[2]);
|
|
27
|
+
lowerLeft = toCornerPoint(radii[3]);
|
|
28
|
+
|
|
29
|
+
} else if (radii.length === 3) {
|
|
30
|
+
|
|
31
|
+
upperLeft = toCornerPoint(radii[0]);
|
|
32
|
+
upperRight = toCornerPoint(radii[1]);
|
|
33
|
+
lowerLeft = toCornerPoint(radii[1]);
|
|
34
|
+
lowerRight = toCornerPoint(radii[2]);
|
|
35
|
+
|
|
36
|
+
} else if (radii.length === 2) {
|
|
37
|
+
|
|
38
|
+
upperLeft = toCornerPoint(radii[0]);
|
|
39
|
+
lowerRight = toCornerPoint(radii[0]);
|
|
40
|
+
upperRight = toCornerPoint(radii[1]);
|
|
41
|
+
lowerLeft = toCornerPoint(radii[1]);
|
|
42
|
+
|
|
43
|
+
} else if (radii.length === 1) {
|
|
44
|
+
|
|
45
|
+
upperLeft = toCornerPoint(radii[0]);
|
|
46
|
+
upperRight = toCornerPoint(radii[0]);
|
|
47
|
+
lowerRight = toCornerPoint(radii[0]);
|
|
48
|
+
lowerLeft = toCornerPoint(radii[0]);
|
|
49
|
+
|
|
50
|
+
} else {
|
|
51
|
+
|
|
52
|
+
throw new Error(radii.length + " is not a valid size for radii sequence.");
|
|
53
|
+
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const corners = [upperLeft, upperRight, lowerRight, lowerLeft];
|
|
57
|
+
const negativeCorner = corners.find(({x, y}) => x < 0 || y < 0);
|
|
58
|
+
//const negativeValue = negativeCorner?.x < 0 ? negativeCorner.x : negativeCorner?.y
|
|
59
|
+
|
|
60
|
+
if (corners.some(({x, y}) => !Number.isFinite(x) || !Number.isFinite(y))) {
|
|
61
|
+
|
|
62
|
+
return;
|
|
63
|
+
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (negativeCorner) {
|
|
67
|
+
|
|
68
|
+
throw new Error("Radius value " + negativeCorner + " is negative.");
|
|
69
|
+
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
fixOverlappingCorners(corners);
|
|
73
|
+
|
|
74
|
+
if (w < 0 && h < 0) {
|
|
75
|
+
|
|
76
|
+
this.moveTo(x - upperLeft.x, y);
|
|
77
|
+
this.ellipse(x + w + upperRight.x, y - upperRight.y, upperRight.x, upperRight.y, 0, -Math.PI * 1.5, -Math.PI);
|
|
78
|
+
this.ellipse(x + w + lowerRight.x, y + h + lowerRight.y, lowerRight.x, lowerRight.y, 0, -Math.PI, -Math.PI / 2);
|
|
79
|
+
this.ellipse(x - lowerLeft.x, y + h + lowerLeft.y, lowerLeft.x, lowerLeft.y, 0, -Math.PI / 2, 0);
|
|
80
|
+
this.ellipse(x - upperLeft.x, y - upperLeft.y, upperLeft.x, upperLeft.y, 0, 0, -Math.PI / 2);
|
|
81
|
+
|
|
82
|
+
} else if (w < 0) {
|
|
83
|
+
|
|
84
|
+
this.moveTo(x - upperLeft.x, y);
|
|
85
|
+
this.ellipse(x + w + upperRight.x, y + upperRight.y, upperRight.x, upperRight.y, 0, -Math.PI / 2, -Math.PI, 1);
|
|
86
|
+
this.ellipse(x + w + lowerRight.x, y + h - lowerRight.y, lowerRight.x, lowerRight.y, 0, -Math.PI, -Math.PI * 1.5, 1);
|
|
87
|
+
this.ellipse(x - lowerLeft.x, y + h - lowerLeft.y, lowerLeft.x, lowerLeft.y, 0, Math.PI / 2, 0, 1);
|
|
88
|
+
this.ellipse(x - upperLeft.x, y + upperLeft.y, upperLeft.x, upperLeft.y, 0, 0, -Math.PI / 2, 1);
|
|
89
|
+
|
|
90
|
+
} else if (h < 0) {
|
|
91
|
+
|
|
92
|
+
this.moveTo(x + upperLeft.x, y);
|
|
93
|
+
this.ellipse(x + w - upperRight.x, y - upperRight.y, upperRight.x, upperRight.y, 0, Math.PI / 2, 0, 1);
|
|
94
|
+
this.ellipse(x + w - lowerRight.x, y + h + lowerRight.y, lowerRight.x, lowerRight.y, 0, 0, -Math.PI / 2, 1);
|
|
95
|
+
this.ellipse(x + lowerLeft.x, y + h + lowerLeft.y, lowerLeft.x, lowerLeft.y, 0, -Math.PI / 2, -Math.PI, 1);
|
|
96
|
+
this.ellipse(x + upperLeft.x, y - upperLeft.y, upperLeft.x, upperLeft.y, 0, -Math.PI, -Math.PI * 1.5, 1);
|
|
97
|
+
|
|
98
|
+
} else {
|
|
99
|
+
|
|
100
|
+
this.moveTo(x + upperLeft.x, y);
|
|
101
|
+
this.ellipse(x + w - upperRight.x, y + upperRight.y, upperRight.x, upperRight.y, 0, -Math.PI / 2, 0);
|
|
102
|
+
this.ellipse(x + w - lowerRight.x, y + h - lowerRight.y, lowerRight.x, lowerRight.y, 0, 0, Math.PI / 2);
|
|
103
|
+
this.ellipse(x + lowerLeft.x, y + h - lowerLeft.y, lowerLeft.x, lowerLeft.y, 0, Math.PI / 2, Math.PI);
|
|
104
|
+
this.ellipse(x + upperLeft.x, y + upperLeft.y, upperLeft.x, upperLeft.y, 0, Math.PI, Math.PI * 1.5);
|
|
105
|
+
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
this.closePath();
|
|
109
|
+
this.moveTo(x, y);
|
|
110
|
+
|
|
111
|
+
/** @ignore */
|
|
112
|
+
function toDOMPointInit(value) {
|
|
113
|
+
|
|
114
|
+
const {x, y, z, w} = value;
|
|
115
|
+
return {x, y, z, w};
|
|
116
|
+
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/** @ignore */
|
|
120
|
+
function parseRadiiArgument(value) {
|
|
121
|
+
|
|
122
|
+
// https://webidl.spec.whatwg.org/#es-union
|
|
123
|
+
// with 'optional (unrestricted double or DOMPointInit
|
|
124
|
+
// or sequence<(unrestricted double or DOMPointInit)>) radii = 0'
|
|
125
|
+
const type = typeof value;
|
|
126
|
+
|
|
127
|
+
if (type === "undefined" || value === null) {
|
|
128
|
+
|
|
129
|
+
return [0];
|
|
130
|
+
|
|
131
|
+
}
|
|
132
|
+
if (type === "function") {
|
|
133
|
+
|
|
134
|
+
return [NaN];
|
|
135
|
+
|
|
136
|
+
}
|
|
137
|
+
if (type === "object") {
|
|
138
|
+
|
|
139
|
+
if (typeof value[Symbol.iterator] === "function") {
|
|
140
|
+
|
|
141
|
+
return [...value].map((elem) => {
|
|
142
|
+
// https://webidl.spec.whatwg.org/#es-union
|
|
143
|
+
// with '(unrestricted double or DOMPointInit)'
|
|
144
|
+
const elemType = typeof elem;
|
|
145
|
+
if (elemType === "undefined" || elem === null) {
|
|
146
|
+
return 0;
|
|
147
|
+
}
|
|
148
|
+
if (elemType === "function") {
|
|
149
|
+
return NaN;
|
|
150
|
+
}
|
|
151
|
+
if (elemType === "object") {
|
|
152
|
+
return toDOMPointInit(elem);
|
|
153
|
+
}
|
|
154
|
+
return toUnrestrictedNumber(elem);
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
return [toDOMPointInit(value)];
|
|
160
|
+
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
return [toUnrestrictedNumber(value)];
|
|
164
|
+
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/** @ignore */
|
|
168
|
+
function toUnrestrictedNumber(value) {
|
|
169
|
+
|
|
170
|
+
return +value;
|
|
171
|
+
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/** @ignore */
|
|
175
|
+
function toCornerPoint(value) {
|
|
176
|
+
|
|
177
|
+
const asNumber = toUnrestrictedNumber(value);
|
|
178
|
+
if (Number.isFinite(asNumber)) {
|
|
179
|
+
|
|
180
|
+
return {
|
|
181
|
+
x: asNumber,
|
|
182
|
+
y: asNumber
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
}
|
|
186
|
+
if (Object(value) === value) {
|
|
187
|
+
|
|
188
|
+
return {
|
|
189
|
+
x: toUnrestrictedNumber(value.x || 0),
|
|
190
|
+
y: toUnrestrictedNumber(value.y || 0)
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
return {
|
|
196
|
+
x: NaN,
|
|
197
|
+
y: NaN
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/** @ignore */
|
|
203
|
+
function fixOverlappingCorners(corners) {
|
|
204
|
+
const [upperLeft, upperRight, lowerRight, lowerLeft] = corners;
|
|
205
|
+
const factors = [
|
|
206
|
+
Math.abs(w) / (upperLeft.x + upperRight.x),
|
|
207
|
+
Math.abs(h) / (upperRight.y + lowerRight.y),
|
|
208
|
+
Math.abs(w) / (lowerRight.x + lowerLeft.x),
|
|
209
|
+
Math.abs(h) / (upperLeft.y + lowerLeft.y)
|
|
210
|
+
];
|
|
211
|
+
const minFactor = Math.min(...factors);
|
|
212
|
+
if (minFactor <= 1) {
|
|
213
|
+
corners.forEach((radii) => {
|
|
214
|
+
radii.x *= minFactor;
|
|
215
|
+
radii.y *= minFactor;
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
if (globalThis.CanvasRenderingContext2D) {
|
|
222
|
+
if (typeof globalThis.Path2D.prototype.roundRect === "undefined") {
|
|
223
|
+
globalThis.Path2D.prototype.roundRect = roundRect;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
if (globalThis.CanvasRenderingContext2D) {
|
|
227
|
+
if (typeof globalThis.CanvasRenderingContext2D.prototype.roundRect === "undefined") {
|
|
228
|
+
globalThis.CanvasRenderingContext2D.prototype.roundRect = roundRect;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
if (globalThis.OffscreenCanvasRenderingContext2D) {
|
|
232
|
+
if (typeof globalThis.OffscreenCanvasRenderingContext2D.prototype.roundRect === "undefined") {
|
|
233
|
+
globalThis.OffscreenCanvasRenderingContext2D.prototype.roundRect = roundRect;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
})();
|
package/src/renderable/GUI.js
CHANGED
|
@@ -116,9 +116,8 @@ class GUI_Object extends Sprite {
|
|
|
116
116
|
/**
|
|
117
117
|
* function called when the object is pressed (to be extended)
|
|
118
118
|
* @name onClick
|
|
119
|
-
* @memberof GUI_Object
|
|
119
|
+
* @memberof GUI_Object
|
|
120
120
|
* @public
|
|
121
|
-
* @function
|
|
122
121
|
* @param {Pointer} event the event object
|
|
123
122
|
* @returns {boolean} return false if we need to stop propagating the event
|
|
124
123
|
*/
|
|
@@ -139,9 +138,8 @@ class GUI_Object extends Sprite {
|
|
|
139
138
|
/**
|
|
140
139
|
* function called when the pointer is over the object
|
|
141
140
|
* @name onOver
|
|
142
|
-
* @memberof GUI_Object
|
|
141
|
+
* @memberof GUI_Object
|
|
143
142
|
* @public
|
|
144
|
-
* @function
|
|
145
143
|
* @param {Pointer} event the event object
|
|
146
144
|
*/
|
|
147
145
|
onOver(/* event */) {}
|
|
@@ -160,9 +158,8 @@ class GUI_Object extends Sprite {
|
|
|
160
158
|
/**
|
|
161
159
|
* function called when the pointer is leaving the object area
|
|
162
160
|
* @name onOut
|
|
163
|
-
* @memberof GUI_Object
|
|
161
|
+
* @memberof GUI_Object
|
|
164
162
|
* @public
|
|
165
|
-
* @function
|
|
166
163
|
* @param {Pointer} event the event object
|
|
167
164
|
*/
|
|
168
165
|
onOut(/* event */) {
|
|
@@ -185,9 +182,8 @@ class GUI_Object extends Sprite {
|
|
|
185
182
|
/**
|
|
186
183
|
* function called when the object is pressed and released (to be extended)
|
|
187
184
|
* @name onRelease
|
|
188
|
-
* @memberof GUI_Object
|
|
185
|
+
* @memberof GUI_Object
|
|
189
186
|
* @public
|
|
190
|
-
* @function
|
|
191
187
|
* @returns {boolean} return false if we need to stop propagating the event
|
|
192
188
|
*/
|
|
193
189
|
onRelease() {
|
|
@@ -210,9 +206,8 @@ class GUI_Object extends Sprite {
|
|
|
210
206
|
* function called when the object is pressed and held<br>
|
|
211
207
|
* to be extended <br>
|
|
212
208
|
* @name onHold
|
|
213
|
-
* @memberof GUI_Object
|
|
209
|
+
* @memberof GUI_Object
|
|
214
210
|
* @public
|
|
215
|
-
* @function
|
|
216
211
|
*/
|
|
217
212
|
onHold() {}
|
|
218
213
|
|