melonjs 13.4.0 → 14.0.1
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 +4 -6
- package/dist/melonjs.module.d.ts +13108 -11652
- package/dist/melonjs.module.js +642 -187
- package/package.json +21 -21
- package/src/application/application.js +3 -3
- package/src/audio/audio.js +27 -27
- package/src/camera/camera2d.js +1 -2
- package/src/entity/entity.js +1 -2
- package/src/geometries/ellipse.js +1 -2
- package/src/geometries/line.js +2 -3
- package/src/geometries/poly.js +2 -2
- package/src/geometries/rectangle.js +1 -3
- package/src/geometries/roundrect.js +1 -2
- package/src/index.js +8 -4
- package/src/input/gamepad.js +12 -12
- package/src/input/keyboard.js +8 -8
- package/src/input/pointer.js +1 -1
- package/src/input/pointerevent.js +9 -9
- package/src/lang/deprecated.js +21 -2
- package/src/level/level.js +2 -2
- package/src/level/tiled/TMXGroup.js +1 -1
- package/src/level/tiled/TMXLayer.js +1 -1
- package/src/level/tiled/TMXTile.js +2 -2
- package/src/level/tiled/TMXTileMap.js +4 -4
- package/src/level/tiled/TMXTileset.js +2 -2
- package/src/level/tiled/TMXTilesetGroup.js +1 -1
- package/src/level/tiled/TMXUtils.js +7 -7
- package/src/level/tiled/renderer/TMXHexagonalRenderer.js +1 -1
- package/src/level/tiled/renderer/TMXIsometricRenderer.js +1 -1
- package/src/level/tiled/renderer/TMXOrthogonalRenderer.js +1 -1
- package/src/level/tiled/renderer/TMXRenderer.js +1 -1
- package/src/level/tiled/renderer/TMXStaggeredRenderer.js +1 -1
- package/src/loader/loader.js +9 -9
- package/src/loader/loadingscreen.js +2 -2
- package/src/math/color.js +3 -3
- package/src/math/math.js +10 -10
- package/src/math/matrix2.js +1 -1
- package/src/math/matrix3.js +1 -1
- package/src/math/observable_vector2.js +1 -1
- package/src/math/observable_vector3.js +1 -1
- package/src/math/vector2.js +1 -1
- package/src/math/vector3.js +1 -1
- package/src/particles/emitter.js +2 -2
- package/src/particles/particle.js +1 -1
- package/src/physics/body.js +2 -2
- package/src/physics/bounds.js +10 -7
- package/src/physics/detector.js +56 -55
- package/src/physics/quadtree.js +3 -3
- package/src/physics/world.js +2 -2
- package/src/polyfill/performance.js +1 -1
- package/src/polyfill/requestAnimationFrame.js +1 -1
- package/src/renderable/collectable.js +1 -1
- package/src/renderable/colorlayer.js +1 -1
- package/src/renderable/container.js +10 -6
- package/src/renderable/dragndrop.js +2 -2
- package/src/renderable/imagelayer.js +1 -2
- package/src/renderable/light2d.js +1 -1
- package/src/renderable/nineslicesprite.js +1 -2
- package/src/renderable/renderable.js +1 -3
- package/src/renderable/sprite.js +3 -4
- package/src/renderable/trigger.js +3 -4
- package/src/renderable/ui/uibaseelement.js +204 -0
- package/src/renderable/{GUI.js → ui/uispriteelement.js} +8 -35
- package/src/renderable/ui/uitextbutton.js +121 -0
- package/src/state/stage.js +4 -5
- package/src/system/device.js +27 -27
- package/src/system/dom.js +1 -1
- package/src/system/event.js +4 -4
- package/src/system/pooling.js +2 -3
- package/src/system/save.js +2 -2
- package/src/system/timer.js +1 -1
- package/src/text/bitmaptext.js +2 -3
- package/src/text/bitmaptextdata.js +4 -7
- package/src/text/glyph.js +1 -2
- package/src/text/text.js +2 -3
- package/src/text/textstyle.js +1 -1
- package/src/tweens/tween.js +2 -3
- package/src/utils/agent.js +4 -4
- package/src/utils/array.js +3 -3
- package/src/utils/file.js +2 -2
- package/src/utils/function.js +3 -3
- package/src/utils/string.js +5 -5
- package/src/utils/utils.js +2 -2
- package/src/video/canvas/canvas_renderer.js +1 -2
- package/src/video/renderer.js +2 -3
- package/src/video/texture/atlas.js +2 -2
- package/src/video/texture/cache.js +1 -2
- package/src/video/video.js +12 -14
- package/src/video/webgl/buffer/vertex.js +1 -2
- package/src/video/webgl/glshader.js +1 -2
- package/src/video/webgl/utils/attributes.js +1 -1
- package/src/video/webgl/utils/precision.js +1 -1
- package/src/video/webgl/utils/program.js +2 -2
- package/src/video/webgl/utils/string.js +1 -1
- package/src/video/webgl/utils/uniforms.js +3 -3
- package/src/video/webgl/webgl_compositor.js +1 -2
- package/src/video/webgl/webgl_renderer.js +1 -2
- package/dist/melonjs.js +0 -37922
- package/dist/melonjs.min.js +0 -29
package/src/utils/agent.js
CHANGED
|
@@ -29,12 +29,12 @@ export function prefixed(name, obj) {
|
|
|
29
29
|
var uc_name = capitalize(name);
|
|
30
30
|
|
|
31
31
|
var result;
|
|
32
|
-
vendors.some(
|
|
32
|
+
vendors.some((vendor) => {
|
|
33
33
|
var name = vendor + uc_name;
|
|
34
34
|
return (result = (name in obj) ? obj[name] : undefined);
|
|
35
35
|
});
|
|
36
36
|
return result;
|
|
37
|
-
}
|
|
37
|
+
}
|
|
38
38
|
|
|
39
39
|
/**
|
|
40
40
|
* Set a vendor-prefixed property
|
|
@@ -55,7 +55,7 @@ export function setPrefixed(name, value, obj) {
|
|
|
55
55
|
|
|
56
56
|
var uc_name = capitalize(name);
|
|
57
57
|
|
|
58
|
-
vendors.some(
|
|
58
|
+
vendors.some((vendor) => {
|
|
59
59
|
var name = vendor + uc_name;
|
|
60
60
|
if (name in obj) {
|
|
61
61
|
obj[name] = value;
|
|
@@ -64,4 +64,4 @@ export function setPrefixed(name, value, obj) {
|
|
|
64
64
|
});
|
|
65
65
|
|
|
66
66
|
return false;
|
|
67
|
-
}
|
|
67
|
+
}
|
package/src/utils/array.js
CHANGED
|
@@ -23,7 +23,7 @@ export function remove(arr, obj) {
|
|
|
23
23
|
Array.prototype.splice.call(arr, i, 1);
|
|
24
24
|
}
|
|
25
25
|
return arr;
|
|
26
|
-
}
|
|
26
|
+
}
|
|
27
27
|
|
|
28
28
|
/**
|
|
29
29
|
* return a random array element
|
|
@@ -39,7 +39,7 @@ export function remove(arr, obj) {
|
|
|
39
39
|
*/
|
|
40
40
|
export function random(arr) {
|
|
41
41
|
return arr[mathRandom(0, arr.length)];
|
|
42
|
-
}
|
|
42
|
+
}
|
|
43
43
|
|
|
44
44
|
/**
|
|
45
45
|
* return a weighted random array element, favoring the earlier entries
|
|
@@ -51,4 +51,4 @@ export function random(arr) {
|
|
|
51
51
|
*/
|
|
52
52
|
export function weightedRandom(arr) {
|
|
53
53
|
return arr[mathWeightedRandom(0, arr.length)];
|
|
54
|
-
}
|
|
54
|
+
}
|
package/src/utils/file.js
CHANGED
|
@@ -19,7 +19,7 @@ const REMOVE_EXT = /\.[^\.]*$/;
|
|
|
19
19
|
*/
|
|
20
20
|
export function getBasename(path) {
|
|
21
21
|
return path.replace(REMOVE_PATH, "").replace(REMOVE_EXT, "");
|
|
22
|
-
}
|
|
22
|
+
}
|
|
23
23
|
|
|
24
24
|
/**
|
|
25
25
|
* return the extension of the file in the given path
|
|
@@ -31,4 +31,4 @@ export function getBasename(path) {
|
|
|
31
31
|
*/
|
|
32
32
|
export function getExtension(path) {
|
|
33
33
|
return path.substring(path.lastIndexOf(".") + 1, path.length);
|
|
34
|
-
}
|
|
34
|
+
}
|
package/src/utils/function.js
CHANGED
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
*/
|
|
21
21
|
export function defer(func, thisArg, ...args) {
|
|
22
22
|
return setTimeout(func.bind(thisArg), 0.01, ...args);
|
|
23
|
-
}
|
|
23
|
+
}
|
|
24
24
|
|
|
25
25
|
/**
|
|
26
26
|
* returns a function that, when invoked will only be triggered at most
|
|
@@ -47,7 +47,7 @@ export function throttle(fn, delay, no_trailing) {
|
|
|
47
47
|
if (no_trailing === false) {
|
|
48
48
|
// hold on to it
|
|
49
49
|
clearTimeout(deferTimer);
|
|
50
|
-
deferTimer = setTimeout(
|
|
50
|
+
deferTimer = setTimeout(() => {
|
|
51
51
|
last = now;
|
|
52
52
|
return fn.apply(null, args);
|
|
53
53
|
}, elasped);
|
|
@@ -58,4 +58,4 @@ export function throttle(fn, delay, no_trailing) {
|
|
|
58
58
|
return fn.apply(null, args);
|
|
59
59
|
}
|
|
60
60
|
};
|
|
61
|
-
}
|
|
61
|
+
}
|
package/src/utils/string.js
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
*/
|
|
14
14
|
export function capitalize(str) {
|
|
15
15
|
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
16
|
-
}
|
|
16
|
+
}
|
|
17
17
|
|
|
18
18
|
/**
|
|
19
19
|
* returns true if the given string contains a numeric integer or float value
|
|
@@ -28,7 +28,7 @@ export function isNumeric(str) {
|
|
|
28
28
|
str = str.trim();
|
|
29
29
|
}
|
|
30
30
|
return !isNaN(str) && /[+-]?([0-9]*[.])?[0-9]+/.test(str);
|
|
31
|
-
}
|
|
31
|
+
}
|
|
32
32
|
|
|
33
33
|
/**
|
|
34
34
|
* returns true if the given string contains a true or false
|
|
@@ -41,7 +41,7 @@ export function isNumeric(str) {
|
|
|
41
41
|
export function isBoolean(str) {
|
|
42
42
|
var trimmed = str.trim();
|
|
43
43
|
return (trimmed === "true") || (trimmed === "false");
|
|
44
|
-
}
|
|
44
|
+
}
|
|
45
45
|
|
|
46
46
|
/**
|
|
47
47
|
* convert a string to the corresponding hexadecimal value
|
|
@@ -57,7 +57,7 @@ export function toHex(str) {
|
|
|
57
57
|
res += str.charCodeAt(c++).toString(16);
|
|
58
58
|
}
|
|
59
59
|
return res;
|
|
60
|
-
}
|
|
60
|
+
}
|
|
61
61
|
|
|
62
62
|
/**
|
|
63
63
|
* returns true if the given string is a data url in the `data:[<mediatype>][;base64],<data>` format.
|
|
@@ -70,4 +70,4 @@ export function toHex(str) {
|
|
|
70
70
|
*/
|
|
71
71
|
export function isDataUrl(str) {
|
|
72
72
|
return /^data:(.+);base64,(.+)$/.test(str);
|
|
73
|
-
}
|
|
73
|
+
}
|
package/src/utils/utils.js
CHANGED
|
@@ -124,9 +124,9 @@ var utils = {
|
|
|
124
124
|
}
|
|
125
125
|
|
|
126
126
|
// parse the url
|
|
127
|
-
url.slice(1).split("&").filter(
|
|
127
|
+
url.slice(1).split("&").filter((value) => {
|
|
128
128
|
return (value !== "");
|
|
129
|
-
}).forEach(
|
|
129
|
+
}).forEach((value) => {
|
|
130
130
|
var kv = value.split("=");
|
|
131
131
|
var k = kv.shift();
|
|
132
132
|
var v = kv.join("=");
|
package/src/video/renderer.js
CHANGED
|
@@ -70,7 +70,7 @@ class Renderer {
|
|
|
70
70
|
this.currentBlendMode = "none";
|
|
71
71
|
|
|
72
72
|
// create the main screen canvas
|
|
73
|
-
if (device.ejecta === true) {
|
|
73
|
+
if (device.platform.ejecta === true) {
|
|
74
74
|
// a main canvas is already automatically created by Ejecta
|
|
75
75
|
this.canvas = document.getElementById("canvas");
|
|
76
76
|
} else if (typeof globalThis.canvas !== "undefined") {
|
|
@@ -398,6 +398,5 @@ class Renderer {
|
|
|
398
398
|
*/
|
|
399
399
|
drawFont(/*bounds*/) {}
|
|
400
400
|
|
|
401
|
-
}
|
|
402
|
-
|
|
401
|
+
}
|
|
403
402
|
export default Renderer;
|
|
@@ -346,7 +346,7 @@ export class TextureAtlas {
|
|
|
346
346
|
region = this.getAtlas(atlas)[name];
|
|
347
347
|
} else {
|
|
348
348
|
// look for the given region in each existing atlas
|
|
349
|
-
this.atlases.forEach(
|
|
349
|
+
this.atlases.forEach((atlas) => {
|
|
350
350
|
if (typeof atlas[name] !== "undefined") {
|
|
351
351
|
// there should be only one
|
|
352
352
|
region = atlas[name];
|
|
@@ -507,4 +507,4 @@ export class TextureAtlas {
|
|
|
507
507
|
atlasIndices: indices
|
|
508
508
|
}, settings || {}));
|
|
509
509
|
}
|
|
510
|
-
}
|
|
510
|
+
}
|
package/src/video/video.js
CHANGED
|
@@ -48,7 +48,7 @@ function autoDetectRenderer(options) {
|
|
|
48
48
|
console.log("Error creating WebGL renderer :" + e.message);
|
|
49
49
|
}
|
|
50
50
|
return new CanvasRenderer(options);
|
|
51
|
-
}
|
|
51
|
+
}
|
|
52
52
|
|
|
53
53
|
/**
|
|
54
54
|
* callback for window resize event
|
|
@@ -123,7 +123,7 @@ function onresize() {
|
|
|
123
123
|
// adjust scaling ratio based on the given settings
|
|
124
124
|
scale(settings.scale, settings.scale);
|
|
125
125
|
}
|
|
126
|
-
}
|
|
126
|
+
}
|
|
127
127
|
|
|
128
128
|
/**
|
|
129
129
|
* Select the HTML5 Canvas renderer
|
|
@@ -276,7 +276,7 @@ export function init(width, height, options) {
|
|
|
276
276
|
globalThis.addEventListener(
|
|
277
277
|
"resize",
|
|
278
278
|
utils.function.throttle(
|
|
279
|
-
|
|
279
|
+
(e) => {
|
|
280
280
|
event.emit(event.WINDOW_ONRESIZE, e);
|
|
281
281
|
}, 100
|
|
282
282
|
), false
|
|
@@ -285,7 +285,7 @@ export function init(width, height, options) {
|
|
|
285
285
|
// Screen Orientation API
|
|
286
286
|
globalThis.addEventListener(
|
|
287
287
|
"orientationchange",
|
|
288
|
-
|
|
288
|
+
(e) => {
|
|
289
289
|
event.emit(event.WINDOW_ONORIENTATION_CHANGE, e);
|
|
290
290
|
},
|
|
291
291
|
false
|
|
@@ -293,7 +293,7 @@ export function init(width, height, options) {
|
|
|
293
293
|
// pre-fixed implementation on mozzila
|
|
294
294
|
globalThis.addEventListener(
|
|
295
295
|
"onmozorientationchange",
|
|
296
|
-
|
|
296
|
+
(e) => {
|
|
297
297
|
event.emit(event.WINDOW_ONORIENTATION_CHANGE, e);
|
|
298
298
|
},
|
|
299
299
|
false
|
|
@@ -306,11 +306,9 @@ export function init(width, height, options) {
|
|
|
306
306
|
}
|
|
307
307
|
|
|
308
308
|
// Automatically update relative canvas position on scroll
|
|
309
|
-
globalThis.addEventListener("scroll", utils.function.throttle(
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
}, 100
|
|
313
|
-
), false);
|
|
309
|
+
globalThis.addEventListener("scroll", utils.function.throttle((e) => {
|
|
310
|
+
event.emit(event.WINDOW_ONSCROLL, e);
|
|
311
|
+
}, 100), false);
|
|
314
312
|
|
|
315
313
|
// register to the channel
|
|
316
314
|
event.on(event.WINDOW_ONRESIZE, onresize, this);
|
|
@@ -378,7 +376,7 @@ export function init(width, height, options) {
|
|
|
378
376
|
event.emit(event.VIDEO_INIT);
|
|
379
377
|
|
|
380
378
|
return true;
|
|
381
|
-
}
|
|
379
|
+
}
|
|
382
380
|
|
|
383
381
|
/**
|
|
384
382
|
* Create and return a new Canvas element
|
|
@@ -410,7 +408,7 @@ export function createCanvas(width, height, returnOffscreenCanvas = false) {
|
|
|
410
408
|
_canvas.height = height;
|
|
411
409
|
|
|
412
410
|
return _canvas;
|
|
413
|
-
}
|
|
411
|
+
}
|
|
414
412
|
|
|
415
413
|
/**
|
|
416
414
|
* return a reference to the parent DOM element holding the main canvas
|
|
@@ -419,7 +417,7 @@ export function createCanvas(width, height, returnOffscreenCanvas = false) {
|
|
|
419
417
|
*/
|
|
420
418
|
export function getParent() {
|
|
421
419
|
return parent;
|
|
422
|
-
}
|
|
420
|
+
}
|
|
423
421
|
|
|
424
422
|
/**
|
|
425
423
|
* scale the "displayed" canvas by the given scalar.
|
|
@@ -452,4 +450,4 @@ export function scale(x, y) {
|
|
|
452
450
|
|
|
453
451
|
// force repaint
|
|
454
452
|
game.repaint();
|
|
455
|
-
}
|
|
453
|
+
}
|
|
@@ -11,7 +11,7 @@ function compileShader(gl, type, source) {
|
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
return shader;
|
|
14
|
-
}
|
|
14
|
+
}
|
|
15
15
|
|
|
16
16
|
/**
|
|
17
17
|
* Compile GLSL into a shader object
|
|
@@ -55,4 +55,4 @@ export function compileProgram(gl, vertex, fragment, attributes) {
|
|
|
55
55
|
gl.deleteShader(fragShader);
|
|
56
56
|
|
|
57
57
|
return program;
|
|
58
|
-
}
|
|
58
|
+
}
|
|
@@ -34,14 +34,14 @@ export function extractUniforms(gl, shader) {
|
|
|
34
34
|
match;
|
|
35
35
|
|
|
36
36
|
// Detect all uniform names and types
|
|
37
|
-
[ shader.vertex, shader.fragment ].forEach(
|
|
37
|
+
[ shader.vertex, shader.fragment ].forEach((shader) => {
|
|
38
38
|
while ((match = uniRx.exec(shader))) {
|
|
39
39
|
uniformsData[match[2]] = match[1];
|
|
40
40
|
}
|
|
41
41
|
});
|
|
42
42
|
|
|
43
43
|
// Get uniform references
|
|
44
|
-
Object.keys(uniformsData).forEach(
|
|
44
|
+
Object.keys(uniformsData).forEach((name) => {
|
|
45
45
|
var type = uniformsData[name];
|
|
46
46
|
locations[name] = gl.getUniformLocation(shader.program, name);
|
|
47
47
|
|
|
@@ -81,4 +81,4 @@ export function extractUniforms(gl, shader) {
|
|
|
81
81
|
Object.defineProperties(uniforms, descriptor);
|
|
82
82
|
|
|
83
83
|
return uniforms;
|
|
84
|
-
}
|
|
84
|
+
}
|