melonjs 15.1.6 → 15.2.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 +6 -6
- 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 +1 -1
- 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 -6
- 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 +1 -1
- 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 +127 -95
- 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 +1 -1
- 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 +1 -1
- 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 +1 -1
- 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 +7 -6
- package/dist/melonjs.mjs/renderable/draggable.js +1 -1
- package/dist/melonjs.mjs/renderable/dragndrop.js +1 -1
- 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 +1 -1
- package/dist/melonjs.mjs/renderable/sprite.js +1 -1
- package/dist/melonjs.mjs/renderable/trigger.js +1 -1
- 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 +6 -32
- 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 +595 -570
- package/dist/types/index.d.ts +5 -4
- package/dist/types/level/tiled/TMXUtils.d.ts +19 -36
- package/dist/types/plugin/plugin.d.ts +60 -5
- package/dist/types/utils/utils.d.ts +56 -17
- package/dist/types/video/video.d.ts +1 -21
- package/package.json +5 -5
- package/src/application/application.js +2 -2
- package/src/index.js +5 -2
- package/src/level/level.js +4 -3
- package/src/level/tiled/TMXTileMap.js +2 -2
- package/src/level/tiled/TMXUtils.js +126 -94
- package/src/plugin/plugin.js +103 -105
- package/src/renderable/container.js +6 -5
- package/src/system/timer.js +3 -3
- package/src/utils/utils.js +102 -111
- package/src/video/video.js +6 -8
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";
|
|
@@ -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
|
|
|
@@ -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
|
|
|
@@ -643,7 +644,7 @@ let globalFloatingCounter = 0;
|
|
|
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.");
|
|
@@ -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
|
package/src/system/timer.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { defer } from "./../utils/function.js";
|
|
2
2
|
import * as event from "./event.js";
|
|
3
3
|
import state from "./../state/state.js";
|
|
4
4
|
import { clamp } from "./../math/math.js";
|
|
@@ -161,7 +161,7 @@ class Timer {
|
|
|
161
161
|
*/
|
|
162
162
|
clearTimeout(timeoutID) {
|
|
163
163
|
if (timeoutID > 0) {
|
|
164
|
-
|
|
164
|
+
defer(this.clearTimer.bind(this), this, timeoutID);
|
|
165
165
|
}
|
|
166
166
|
}
|
|
167
167
|
|
|
@@ -171,7 +171,7 @@ class Timer {
|
|
|
171
171
|
*/
|
|
172
172
|
clearInterval(intervalID) {
|
|
173
173
|
if (intervalID > 0) {
|
|
174
|
-
|
|
174
|
+
defer(this.clearTimer.bind(this), this, intervalID);
|
|
175
175
|
}
|
|
176
176
|
}
|
|
177
177
|
|
package/src/utils/utils.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { toHex } from "./string.js";
|
|
2
|
+
|
|
3
|
+
export * as agent from "./agent.js";
|
|
4
|
+
export * as array from "./array.js";
|
|
5
|
+
export * as file from "./file.js";
|
|
6
|
+
export * as string from "./string.js";
|
|
7
|
+
export * as function from "./function.js";
|
|
6
8
|
|
|
7
9
|
/**
|
|
8
10
|
* a collection of utility functions
|
|
@@ -13,124 +15,113 @@ import * as fnUtils from "./function.js";
|
|
|
13
15
|
let GUID_base = "";
|
|
14
16
|
let GUID_index = 0;
|
|
15
17
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
* );
|
|
39
|
-
* }
|
|
40
|
-
*/
|
|
41
|
-
checkVersion : function (first, second) {
|
|
42
|
-
let a = first.split(".");
|
|
43
|
-
let b = second.split(".");
|
|
44
|
-
let len = Math.min(a.length, b.length);
|
|
45
|
-
let result = 0;
|
|
18
|
+
/**
|
|
19
|
+
* Compare two version strings
|
|
20
|
+
* @public
|
|
21
|
+
* @memberof utils
|
|
22
|
+
* @name checkVersion
|
|
23
|
+
* @param {string} first - First version string to compare
|
|
24
|
+
* @param {string} second - second version string to compare
|
|
25
|
+
* @returns {number} comparison result <br>< 0 : first < second<br>
|
|
26
|
+
* 0 : first == second<br>
|
|
27
|
+
* > 0 : first > second
|
|
28
|
+
* @example
|
|
29
|
+
* if (me.utils.checkVersion("7.0.0") > 0) {
|
|
30
|
+
* console.error(
|
|
31
|
+
* "melonJS is too old. Expected: 7.0.0, Got: 6.3.0"
|
|
32
|
+
* );
|
|
33
|
+
* }
|
|
34
|
+
*/
|
|
35
|
+
export function checkVersion(first, second) {
|
|
36
|
+
let a = first.split(".");
|
|
37
|
+
let b = second.split(".");
|
|
38
|
+
let len = Math.min(a.length, b.length);
|
|
39
|
+
let result = 0;
|
|
46
40
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
}
|
|
41
|
+
for (let i = 0; i < len; i++) {
|
|
42
|
+
if ((result = +a[i] - +b[i])) {
|
|
43
|
+
break;
|
|
51
44
|
}
|
|
45
|
+
}
|
|
52
46
|
|
|
53
|
-
|
|
54
|
-
|
|
47
|
+
return result ? result : a.length - b.length;
|
|
48
|
+
}
|
|
55
49
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
50
|
+
/**
|
|
51
|
+
* parse the fragment (hash) from a URL and returns them into
|
|
52
|
+
* @public
|
|
53
|
+
* @memberof utils
|
|
54
|
+
* @name getUriFragment
|
|
55
|
+
* @param {string} [url=document.location] - an optional params string or URL containing fragment (hash) params to be parsed
|
|
56
|
+
* @returns {object} an object representing the deserialized params string.
|
|
57
|
+
* @property {boolean} [hitbox=false] draw the hitbox in the debug panel (if enabled)
|
|
58
|
+
* @property {boolean} [velocity=false] draw the entities velocity in the debug panel (if enabled)
|
|
59
|
+
* @property {boolean} [quadtree=false] draw the quadtree in the debug panel (if enabled)
|
|
60
|
+
* @property {boolean} [webgl=false] force the renderer to WebGL
|
|
61
|
+
* @property {boolean} [debug=false] display the debug panel (if preloaded)
|
|
62
|
+
* @property {string} [debugToggleKey="s"] show/hide the debug panel (if preloaded)
|
|
63
|
+
* @example
|
|
64
|
+
* // http://www.example.com/index.html#debug&hitbox=true&mytag=value
|
|
65
|
+
* let UriFragment = me.utils.getUriFragment();
|
|
66
|
+
* console.log(UriFragment["mytag"]); //> "value"
|
|
67
|
+
*/
|
|
68
|
+
export function getUriFragment(url) {
|
|
69
|
+
let hash = {};
|
|
76
70
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
71
|
+
if (typeof url === "undefined") {
|
|
72
|
+
if (typeof globalThis.document !== "undefined") {
|
|
73
|
+
let location = globalThis.document.location;
|
|
80
74
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
} else {
|
|
84
|
-
// No "document.location" exist for Wechat mini game platform.
|
|
85
|
-
return hash;
|
|
86
|
-
}
|
|
75
|
+
if (location && location.hash) {
|
|
76
|
+
url = location.hash;
|
|
87
77
|
} else {
|
|
88
|
-
// "document"
|
|
78
|
+
// No "document.location" exist for Wechat mini game platform.
|
|
89
79
|
return hash;
|
|
90
80
|
}
|
|
91
81
|
} else {
|
|
92
|
-
//
|
|
93
|
-
|
|
94
|
-
if (index !== -1) {
|
|
95
|
-
url = url.slice(index, url.length);
|
|
96
|
-
} else {
|
|
97
|
-
return hash;
|
|
98
|
-
}
|
|
82
|
+
// "document" undefined on node.js
|
|
83
|
+
return hash;
|
|
99
84
|
}
|
|
85
|
+
} else {
|
|
86
|
+
// never cache if a url is passed as parameter
|
|
87
|
+
let index = url.indexOf("#");
|
|
88
|
+
if (index !== -1) {
|
|
89
|
+
url = url.slice(index, url.length);
|
|
90
|
+
} else {
|
|
91
|
+
return hash;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
100
94
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
return hash;
|
|
110
|
-
},
|
|
95
|
+
// parse the url
|
|
96
|
+
url.slice(1).split("&").filter((value) => value !== "").forEach((value) => {
|
|
97
|
+
let kv = value.split("=");
|
|
98
|
+
let k = kv.shift();
|
|
99
|
+
let v = kv.join("=");
|
|
100
|
+
hash[k] = v || true;
|
|
101
|
+
});
|
|
111
102
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
* the idea here being to have a unique ID
|
|
115
|
-
* per level / object
|
|
116
|
-
* @ignore
|
|
117
|
-
*/
|
|
118
|
-
resetGUID : function (base, index = 0) {
|
|
119
|
-
// also ensure it's only 8bit ASCII characters
|
|
120
|
-
GUID_base = stringUtils.toHex(base.toString().toUpperCase());
|
|
121
|
-
GUID_index = index;
|
|
122
|
-
},
|
|
103
|
+
return hash;
|
|
104
|
+
}
|
|
123
105
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
}
|
|
106
|
+
/**
|
|
107
|
+
* reset the GUID Base Name
|
|
108
|
+
* the idea here being to have a unique ID
|
|
109
|
+
* per level / object
|
|
110
|
+
* @ignore
|
|
111
|
+
*/
|
|
112
|
+
export function resetGUID(base, index = 0) {
|
|
113
|
+
// also ensure it's only 8bit ASCII characters
|
|
114
|
+
GUID_base = toHex(base.toString().toUpperCase());
|
|
115
|
+
GUID_index = index;
|
|
116
|
+
}
|
|
135
117
|
|
|
136
|
-
|
|
118
|
+
/**
|
|
119
|
+
* create and return a very simple GUID
|
|
120
|
+
* Game Unique ID
|
|
121
|
+
* @ignore
|
|
122
|
+
*/
|
|
123
|
+
export function createGUID(index = 1) {
|
|
124
|
+
// to cover the case of undefined id for groups
|
|
125
|
+
GUID_index += index;
|
|
126
|
+
return GUID_base + "-" + (index || GUID_index);
|
|
127
|
+
}
|
package/src/video/video.js
CHANGED
|
@@ -1,34 +1,32 @@
|
|
|
1
1
|
import * as event from "./../system/event.js";
|
|
2
2
|
import { initialized, game } from "./../index.js";
|
|
3
3
|
import * as device from "./../system/device.js";
|
|
4
|
-
import
|
|
5
|
-
import * as vc from "../const";
|
|
4
|
+
import { throttle } from "../utils/function.js";
|
|
6
5
|
|
|
7
6
|
/**
|
|
8
7
|
* @namespace video
|
|
9
8
|
*/
|
|
10
9
|
|
|
11
|
-
|
|
12
10
|
/**
|
|
13
11
|
* Select the HTML5 Canvas renderer
|
|
14
12
|
* @memberof video
|
|
15
13
|
* @static
|
|
16
14
|
*/
|
|
17
|
-
export
|
|
15
|
+
export { CANVAS } from "../const";
|
|
18
16
|
|
|
19
17
|
/**
|
|
20
18
|
* Select the WebGL renderer
|
|
21
19
|
* @memberof video
|
|
22
20
|
* @static
|
|
23
21
|
*/
|
|
24
|
-
export
|
|
22
|
+
export { WEBGL } from "../const";
|
|
25
23
|
|
|
26
24
|
/**
|
|
27
25
|
* Auto-select the renderer (Attempt WebGL first, with fallback to Canvas)
|
|
28
26
|
* @memberof video
|
|
29
27
|
* @static
|
|
30
28
|
*/
|
|
31
|
-
export
|
|
29
|
+
export { AUTO } from "../const";
|
|
32
30
|
|
|
33
31
|
/**
|
|
34
32
|
* A reference to the active Canvas or WebGL active renderer renderer
|
|
@@ -98,7 +96,7 @@ export function init(width, height, options) {
|
|
|
98
96
|
//add a channel for the onresize/onorientationchange event
|
|
99
97
|
globalThis.addEventListener(
|
|
100
98
|
"resize",
|
|
101
|
-
|
|
99
|
+
throttle(
|
|
102
100
|
(e) => {
|
|
103
101
|
event.emit(event.WINDOW_ONRESIZE, e);
|
|
104
102
|
}, 100
|
|
@@ -130,7 +128,7 @@ export function init(width, height, options) {
|
|
|
130
128
|
}
|
|
131
129
|
|
|
132
130
|
// Automatically update relative canvas position on scroll
|
|
133
|
-
globalThis.addEventListener("scroll",
|
|
131
|
+
globalThis.addEventListener("scroll", throttle((e) => {
|
|
134
132
|
event.emit(event.WINDOW_ONSCROLL, e);
|
|
135
133
|
}, 100), false);
|
|
136
134
|
|