melonjs 15.0.0 → 15.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -4
- package/dist/melonjs.mjs/_virtual/_commonjsHelpers.js +1 -1
- package/dist/melonjs.mjs/_virtual/arraymultimap.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 +7 -3
- package/dist/melonjs.mjs/_virtual/index2.js +1 -1
- package/dist/melonjs.mjs/_virtual/multimap.js +1 -1
- package/dist/melonjs.mjs/_virtual/setmultimap.js +1 -1
- package/dist/melonjs.mjs/application/application.js +27 -17
- package/dist/melonjs.mjs/application/header.js +6 -5
- package/dist/melonjs.mjs/application/resize.js +20 -20
- package/dist/melonjs.mjs/application/settings.js +1 -1
- package/dist/melonjs.mjs/audio/audio.js +17 -17
- package/dist/melonjs.mjs/camera/camera2d.js +10 -10
- package/dist/melonjs.mjs/const.js +1 -1
- package/dist/melonjs.mjs/entity/entity.js +4 -4
- package/dist/melonjs.mjs/geometries/ellipse.js +6 -6
- package/dist/melonjs.mjs/geometries/line.js +9 -9
- package/dist/melonjs.mjs/geometries/path2d.js +53 -53
- package/dist/melonjs.mjs/geometries/point.js +2 -2
- package/dist/melonjs.mjs/geometries/poly.js +29 -29
- package/dist/melonjs.mjs/geometries/rectangle.js +8 -8
- package/dist/melonjs.mjs/geometries/roundrect.js +6 -6
- package/dist/melonjs.mjs/index.js +5 -5
- package/dist/melonjs.mjs/input/gamepad.js +30 -30
- package/dist/melonjs.mjs/input/input.js +2 -2
- package/dist/melonjs.mjs/input/keyboard.js +15 -15
- package/dist/melonjs.mjs/input/pointer.js +2 -2
- package/dist/melonjs.mjs/input/pointerevent.js +58 -58
- package/dist/melonjs.mjs/lang/console.js +3 -3
- package/dist/melonjs.mjs/lang/deprecated.js +2 -2
- package/dist/melonjs.mjs/level/level.js +9 -9
- package/dist/melonjs.mjs/level/tiled/TMXGroup.js +3 -3
- package/dist/melonjs.mjs/level/tiled/TMXLayer.js +31 -31
- package/dist/melonjs.mjs/level/tiled/TMXObject.js +8 -8
- package/dist/melonjs.mjs/level/tiled/TMXTile.js +8 -8
- package/dist/melonjs.mjs/level/tiled/TMXTileMap.js +19 -19
- package/dist/melonjs.mjs/level/tiled/TMXTileset.js +15 -15
- package/dist/melonjs.mjs/level/tiled/TMXTilesetGroup.js +3 -3
- package/dist/melonjs.mjs/level/tiled/TMXUtils.js +46 -41
- package/dist/melonjs.mjs/level/tiled/constants.js +1 -1
- package/dist/melonjs.mjs/level/tiled/renderer/TMXHexagonalRenderer.js +30 -30
- package/dist/melonjs.mjs/level/tiled/renderer/TMXIsometricRenderer.js +21 -21
- package/dist/melonjs.mjs/level/tiled/renderer/TMXOrthogonalRenderer.js +10 -10
- package/dist/melonjs.mjs/level/tiled/renderer/TMXRenderer.js +2 -2
- package/dist/melonjs.mjs/level/tiled/renderer/TMXStaggeredRenderer.js +6 -6
- 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 +7 -7
- package/dist/melonjs.mjs/loader/loadingscreen.js +2 -2
- package/dist/melonjs.mjs/loader/melonjs_logo.png.js +1 -1
- package/dist/melonjs.mjs/loader/parser.js +13 -13
- package/dist/melonjs.mjs/loader/settings.js +3 -3
- package/dist/melonjs.mjs/math/color.js +21 -21
- package/dist/melonjs.mjs/math/math.js +2 -2
- package/dist/melonjs.mjs/math/matrix2.js +22 -22
- package/dist/melonjs.mjs/math/matrix3.js +52 -52
- package/dist/melonjs.mjs/math/observable_vector2.js +12 -12
- package/dist/melonjs.mjs/math/observable_vector3.js +22 -22
- package/dist/melonjs.mjs/math/vector2.js +11 -11
- package/dist/melonjs.mjs/math/vector3.js +21 -21
- package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/esm/arraymultimap.js +45 -0
- package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/esm/multimap.js +130 -0
- package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/src/arraymultimap.js +1 -1
- package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/src/index.js +1 -1
- package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/src/multimap.js +1 -1
- package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/src/setmultimap.js +1 -1
- package/dist/melonjs.mjs/node_modules/earcut/src/earcut.js +1 -1
- package/dist/melonjs.mjs/node_modules/eventemitter3/index.js +2 -2
- 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 +5 -5
- package/dist/melonjs.mjs/particles/particle.js +8 -8
- package/dist/melonjs.mjs/particles/settings.js +3 -3
- package/dist/melonjs.mjs/physics/body.js +17 -17
- package/dist/melonjs.mjs/physics/bounds.js +12 -12
- package/dist/melonjs.mjs/physics/collision.js +3 -3
- package/dist/melonjs.mjs/physics/detector.js +14 -14
- package/dist/melonjs.mjs/physics/quadtree.js +19 -19
- package/dist/melonjs.mjs/physics/response.js +1 -1
- package/dist/melonjs.mjs/physics/sat.js +60 -60
- package/dist/melonjs.mjs/physics/world.js +4 -4
- package/dist/melonjs.mjs/plugin/plugin.js +11 -11
- package/dist/melonjs.mjs/renderable/collectable.js +2 -2
- package/dist/melonjs.mjs/renderable/colorlayer.js +1 -1
- package/dist/melonjs.mjs/renderable/container.js +77 -59
- package/dist/melonjs.mjs/renderable/dragndrop.js +5 -5
- package/dist/melonjs.mjs/renderable/imagelayer.js +7 -6
- package/dist/melonjs.mjs/renderable/light2d.js +6 -6
- package/dist/melonjs.mjs/renderable/nineslicesprite.js +12 -12
- package/dist/melonjs.mjs/renderable/renderable.js +11 -11
- package/dist/melonjs.mjs/renderable/sprite.js +25 -25
- package/dist/melonjs.mjs/renderable/trigger.js +11 -9
- package/dist/melonjs.mjs/renderable/ui/uibaseelement.js +97 -27
- package/dist/melonjs.mjs/renderable/ui/uispriteelement.js +25 -25
- package/dist/melonjs.mjs/renderable/ui/uitextbutton.js +83 -63
- package/dist/melonjs.mjs/state/stage.js +7 -7
- package/dist/melonjs.mjs/state/state.js +15 -15
- package/dist/melonjs.mjs/system/device.js +2 -2
- package/dist/melonjs.mjs/system/dom.js +1 -1
- package/dist/melonjs.mjs/system/event.js +2 -2
- package/dist/melonjs.mjs/system/platform.js +1 -1
- package/dist/melonjs.mjs/system/pooling.js +9 -9
- package/dist/melonjs.mjs/system/save.js +6 -6
- package/dist/melonjs.mjs/system/timer.js +16 -12
- package/dist/melonjs.mjs/text/bitmaptext.js +20 -20
- package/dist/melonjs.mjs/text/bitmaptextdata.js +22 -22
- package/dist/melonjs.mjs/text/glyph.js +3 -3
- package/dist/melonjs.mjs/text/text.js +10 -9
- package/dist/melonjs.mjs/text/textmetrics.js +15 -15
- package/dist/melonjs.mjs/text/textstyle.js +1 -1
- package/dist/melonjs.mjs/tweens/easing.js +4 -4
- package/dist/melonjs.mjs/tweens/interpolation.js +8 -8
- package/dist/melonjs.mjs/tweens/tween.js +11 -11
- package/dist/melonjs.mjs/utils/agent.js +6 -6
- package/dist/melonjs.mjs/utils/array.js +4 -4
- package/dist/melonjs.mjs/utils/file.js +1 -1
- package/dist/melonjs.mjs/utils/function.js +5 -5
- package/dist/melonjs.mjs/utils/string.js +3 -3
- package/dist/melonjs.mjs/utils/utils.js +16 -16
- package/dist/melonjs.mjs/video/canvas/canvas_renderer.js +35 -109
- package/dist/melonjs.mjs/video/renderer.js +74 -7
- package/dist/melonjs.mjs/video/texture/atlas.js +37 -37
- package/dist/melonjs.mjs/video/texture/cache.js +9 -10
- package/dist/melonjs.mjs/video/texture/canvas_texture.js +63 -3
- package/dist/melonjs.mjs/video/utils/autodetect.js +1 -1
- package/dist/melonjs.mjs/video/video.js +2 -2
- package/dist/melonjs.mjs/video/webgl/buffer/vertex.js +3 -3
- package/dist/melonjs.mjs/video/webgl/compositors/compositor.js +5 -5
- package/dist/melonjs.mjs/video/webgl/compositors/primitive_compositor.js +5 -5
- package/dist/melonjs.mjs/video/webgl/compositors/quad_compositor.js +18 -15
- package/dist/melonjs.mjs/video/webgl/glshader.js +7 -7
- 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 +2 -2
- package/dist/melonjs.mjs/video/webgl/utils/precision.js +1 -1
- package/dist/melonjs.mjs/video/webgl/utils/program.js +7 -7
- package/dist/melonjs.mjs/video/webgl/utils/string.js +1 -1
- package/dist/melonjs.mjs/video/webgl/utils/uniforms.js +4 -4
- package/dist/melonjs.mjs/video/webgl/webgl_renderer.js +55 -38
- package/dist/melonjs.module.js +1747 -1809
- package/dist/types/application/application.d.ts +11 -8
- package/dist/types/audio/audio.d.ts +3 -3
- package/dist/types/index.d.ts +4 -3
- package/dist/types/input/input.d.ts +1 -1
- package/dist/types/input/keyboard.d.ts +1 -1
- package/dist/types/input/pointerevent.d.ts +6 -6
- package/dist/types/level/level.d.ts +2 -2
- package/dist/types/level/tiled/TMXLayer.d.ts +4 -4
- package/dist/types/level/tiled/TMXTileMap.d.ts +2 -2
- package/dist/types/level/tiled/TMXUtils.d.ts +5 -4
- package/dist/types/loader/loader.d.ts +2 -2
- package/dist/types/loader/settings.d.ts +2 -2
- package/dist/types/particles/emitter.d.ts +1 -1
- package/dist/types/physics/collision.d.ts +1 -1
- package/dist/types/physics/detector.d.ts +1 -1
- package/dist/types/plugin/plugin.d.ts +2 -2
- package/dist/types/renderable/container.d.ts +21 -17
- package/dist/types/renderable/sprite.d.ts +11 -11
- package/dist/types/renderable/trigger.d.ts +1 -1
- package/dist/types/renderable/ui/uibaseelement.d.ts +28 -6
- package/dist/types/renderable/ui/uispriteelement.d.ts +12 -14
- package/dist/types/renderable/ui/uitextbutton.d.ts +52 -11
- package/dist/types/state/stage.d.ts +1 -1
- package/dist/types/system/device.d.ts +1 -1
- package/dist/types/system/pooling.d.ts +3 -3
- package/dist/types/system/timer.d.ts +5 -5
- package/dist/types/text/bitmaptext.d.ts +1 -1
- package/dist/types/text/text.d.ts +1 -1
- package/dist/types/utils/array.d.ts +2 -2
- package/dist/types/video/canvas/canvas_renderer.d.ts +8 -76
- package/dist/types/video/renderer.d.ts +48 -0
- package/dist/types/video/texture/atlas.d.ts +3 -3
- package/dist/types/video/texture/canvas_texture.d.ts +40 -0
- package/dist/types/video/webgl/glshader.d.ts +1 -1
- package/dist/types/video/webgl/webgl_renderer.d.ts +13 -9
- package/package.json +14 -14
- package/src/application/application.js +26 -16
- package/src/application/header.js +5 -4
- package/src/application/resize.js +19 -19
- package/src/audio/audio.js +16 -16
- package/src/camera/camera2d.js +9 -9
- package/src/entity/entity.js +3 -3
- package/src/geometries/ellipse.js +5 -5
- package/src/geometries/line.js +8 -8
- package/src/geometries/path2d.js +52 -52
- package/src/geometries/point.js +1 -1
- package/src/geometries/poly.js +28 -28
- package/src/geometries/rectangle.js +7 -7
- package/src/geometries/roundrect.js +5 -5
- package/src/index.js +3 -2
- package/src/input/gamepad.js +29 -29
- package/src/input/input.js +1 -1
- package/src/input/keyboard.js +14 -14
- package/src/input/pointer.js +1 -1
- package/src/input/pointerevent.js +52 -52
- package/src/lang/console.js +2 -2
- package/src/lang/deprecated.js +1 -1
- package/src/level/level.js +8 -8
- package/src/level/tiled/TMXGroup.js +2 -2
- package/src/level/tiled/TMXLayer.js +30 -30
- package/src/level/tiled/TMXObject.js +7 -7
- package/src/level/tiled/TMXTile.js +7 -7
- package/src/level/tiled/TMXTileMap.js +18 -18
- package/src/level/tiled/TMXTileset.js +14 -14
- package/src/level/tiled/TMXTilesetGroup.js +2 -2
- package/src/level/tiled/TMXUtils.js +45 -40
- package/src/level/tiled/renderer/TMXHexagonalRenderer.js +29 -29
- package/src/level/tiled/renderer/TMXIsometricRenderer.js +20 -20
- package/src/level/tiled/renderer/TMXOrthogonalRenderer.js +9 -9
- package/src/level/tiled/renderer/TMXRenderer.js +1 -1
- package/src/level/tiled/renderer/TMXStaggeredRenderer.js +5 -5
- package/src/loader/loader.js +6 -6
- package/src/loader/loadingscreen.js +1 -1
- package/src/loader/parser.js +12 -12
- package/src/loader/settings.js +2 -2
- package/src/math/color.js +20 -20
- package/src/math/math.js +1 -1
- package/src/math/matrix2.js +21 -21
- package/src/math/matrix3.js +51 -51
- package/src/math/observable_vector2.js +11 -11
- package/src/math/observable_vector3.js +21 -21
- package/src/math/vector2.js +10 -10
- package/src/math/vector3.js +20 -20
- package/src/particles/emitter.js +4 -4
- package/src/particles/particle.js +7 -7
- package/src/particles/settings.js +2 -2
- package/src/physics/body.js +16 -16
- package/src/physics/bounds.js +11 -11
- package/src/physics/collision.js +2 -2
- package/src/physics/detector.js +13 -13
- package/src/physics/quadtree.js +18 -18
- package/src/physics/sat.js +59 -59
- package/src/physics/world.js +3 -3
- package/src/plugin/plugin.js +8 -8
- package/src/renderable/collectable.js +1 -1
- package/src/renderable/container.js +76 -58
- package/src/renderable/dragndrop.js +4 -4
- package/src/renderable/imagelayer.js +6 -5
- package/src/renderable/light2d.js +5 -5
- package/src/renderable/nineslicesprite.js +11 -11
- package/src/renderable/renderable.js +10 -10
- package/src/renderable/sprite.js +24 -24
- package/src/renderable/trigger.js +10 -8
- package/src/renderable/ui/uibaseelement.js +96 -26
- package/src/renderable/ui/uispriteelement.js +24 -24
- package/src/renderable/ui/uitextbutton.js +85 -65
- package/src/state/stage.js +6 -6
- package/src/state/state.js +14 -14
- package/src/system/device.js +1 -1
- package/src/system/event.js +1 -1
- package/src/system/pooling.js +8 -8
- package/src/system/save.js +5 -5
- package/src/system/timer.js +15 -11
- package/src/text/bitmaptext.js +19 -19
- package/src/text/bitmaptextdata.js +21 -21
- package/src/text/glyph.js +2 -2
- package/src/text/text.js +9 -8
- package/src/text/textmetrics.js +14 -14
- package/src/tweens/easing.js +3 -3
- package/src/tweens/interpolation.js +7 -7
- package/src/tweens/tween.js +10 -10
- package/src/utils/agent.js +5 -5
- package/src/utils/array.js +3 -3
- package/src/utils/function.js +4 -4
- package/src/utils/string.js +2 -2
- package/src/utils/utils.js +15 -15
- package/src/video/canvas/canvas_renderer.js +34 -108
- package/src/video/renderer.js +72 -5
- package/src/video/texture/atlas.js +36 -36
- package/src/video/texture/cache.js +6 -6
- package/src/video/texture/canvas_texture.js +62 -2
- package/src/video/video.js +1 -1
- package/src/video/webgl/buffer/vertex.js +2 -2
- package/src/video/webgl/compositors/compositor.js +4 -4
- package/src/video/webgl/compositors/primitive_compositor.js +4 -4
- package/src/video/webgl/compositors/quad_compositor.js +17 -14
- package/src/video/webgl/glshader.js +6 -6
- package/src/video/webgl/utils/attributes.js +1 -1
- package/src/video/webgl/utils/program.js +6 -6
- package/src/video/webgl/utils/uniforms.js +3 -3
- package/src/video/webgl/webgl_renderer.js +54 -37
|
@@ -8,7 +8,7 @@ const capChars = ["M", "N", "B", "D", "C", "E", "F", "K", "A", "G", "H", "I", "J
|
|
|
8
8
|
* @ignore
|
|
9
9
|
*/
|
|
10
10
|
function getValueFromPair(string, pattern) {
|
|
11
|
-
|
|
11
|
+
let value = string.match(pattern);
|
|
12
12
|
if (!value) {
|
|
13
13
|
throw new Error("Could not find pattern " + pattern + " in string: " + string);
|
|
14
14
|
}
|
|
@@ -25,8 +25,8 @@ function getValueFromPair(string, pattern) {
|
|
|
25
25
|
* @returns {Glyph}
|
|
26
26
|
*/
|
|
27
27
|
function getFirstGlyph(glyphs) {
|
|
28
|
-
|
|
29
|
-
for (
|
|
28
|
+
let keys = Object.keys(glyphs);
|
|
29
|
+
for (let i = 0; i < keys.length; i++) {
|
|
30
30
|
if (keys[i] > 32) {
|
|
31
31
|
return glyphs[keys[i]];
|
|
32
32
|
}
|
|
@@ -42,8 +42,8 @@ function getFirstGlyph(glyphs) {
|
|
|
42
42
|
* @param {object} glyphs - the map of glyphs, each key is a char code
|
|
43
43
|
*/
|
|
44
44
|
function createSpaceGlyph(glyphs) {
|
|
45
|
-
|
|
46
|
-
|
|
45
|
+
let spaceCharCode = " ".charCodeAt(0);
|
|
46
|
+
let glyph = glyphs[spaceCharCode];
|
|
47
47
|
if (!glyph) {
|
|
48
48
|
glyph = new Glyph();
|
|
49
49
|
glyph.id = spaceCharCode;
|
|
@@ -102,12 +102,12 @@ function createSpaceGlyph(glyphs) {
|
|
|
102
102
|
if (!fontData) {
|
|
103
103
|
throw new Error("File containing font data was empty, cannot load the bitmap font.");
|
|
104
104
|
}
|
|
105
|
-
|
|
106
|
-
|
|
105
|
+
let lines = fontData.split(/\r\n|\n/);
|
|
106
|
+
let padding = fontData.match(/padding\=\d+,\d+,\d+,\d+/g);
|
|
107
107
|
if (!padding) {
|
|
108
108
|
throw new Error("Padding not found in first line");
|
|
109
109
|
}
|
|
110
|
-
|
|
110
|
+
let paddingValues = padding[0].split("=")[1].split(",");
|
|
111
111
|
this.padTop = parseFloat(paddingValues[0]);
|
|
112
112
|
this.padLeft = parseFloat(paddingValues[1]);
|
|
113
113
|
this.padBottom = parseFloat(paddingValues[2]);
|
|
@@ -115,24 +115,24 @@ function createSpaceGlyph(glyphs) {
|
|
|
115
115
|
|
|
116
116
|
this.lineHeight = parseFloat(getValueFromPair(lines[1], /lineHeight\=\d+/g));
|
|
117
117
|
|
|
118
|
-
|
|
118
|
+
let baseLine = parseFloat(getValueFromPair(lines[1], /base\=\d+/g));
|
|
119
119
|
|
|
120
|
-
|
|
120
|
+
let padY = this.padTop + this.padBottom;
|
|
121
121
|
|
|
122
|
-
|
|
122
|
+
let glyph = null;
|
|
123
123
|
|
|
124
|
-
|
|
124
|
+
let i;
|
|
125
125
|
|
|
126
126
|
for (i = 4; i < lines.length; i++) {
|
|
127
|
-
|
|
128
|
-
|
|
127
|
+
let line = lines[i];
|
|
128
|
+
let characterValues = line.split(/=|\s+/);
|
|
129
129
|
if (!line || /^kernings/.test(line)) {
|
|
130
130
|
continue;
|
|
131
131
|
}
|
|
132
132
|
if (/^kerning\s/.test(line)) {
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
133
|
+
let first = parseFloat(characterValues[2]);
|
|
134
|
+
let second = parseFloat(characterValues[4]);
|
|
135
|
+
let amount = parseFloat(characterValues[6]);
|
|
136
136
|
|
|
137
137
|
glyph = this.glyphs[first];
|
|
138
138
|
if (glyph !== null && typeof glyph !== "undefined") {
|
|
@@ -141,7 +141,7 @@ function createSpaceGlyph(glyphs) {
|
|
|
141
141
|
} else {
|
|
142
142
|
glyph = new Glyph();
|
|
143
143
|
|
|
144
|
-
|
|
144
|
+
let ch = parseFloat(characterValues[2]);
|
|
145
145
|
glyph.id = ch;
|
|
146
146
|
glyph.x = parseFloat(characterValues[4]);
|
|
147
147
|
glyph.y = parseFloat(characterValues[6]);
|
|
@@ -163,16 +163,16 @@ function createSpaceGlyph(glyphs) {
|
|
|
163
163
|
|
|
164
164
|
createSpaceGlyph(this.glyphs);
|
|
165
165
|
|
|
166
|
-
|
|
166
|
+
let capGlyph = null;
|
|
167
167
|
for (i = 0; i < capChars.length; i++) {
|
|
168
|
-
|
|
168
|
+
let capChar = capChars[i];
|
|
169
169
|
capGlyph = this.glyphs[capChar.charCodeAt(0)];
|
|
170
170
|
if (capGlyph) {
|
|
171
171
|
break;
|
|
172
172
|
}
|
|
173
173
|
}
|
|
174
174
|
if (!capGlyph) {
|
|
175
|
-
for (
|
|
175
|
+
for (let charCode in this.glyphs) {
|
|
176
176
|
if (this.glyphs.hasOwnProperty(charCode)) {
|
|
177
177
|
glyph = this.glyphs[charCode];
|
|
178
178
|
if (glyph.height === 0 || glyph.width === 0) {
|
package/src/text/glyph.js
CHANGED
|
@@ -32,7 +32,7 @@ const PAGE_SIZE = 1 << LOG2_PAGE_SIZE;
|
|
|
32
32
|
*/
|
|
33
33
|
getKerning(ch) {
|
|
34
34
|
if (this.kerning) {
|
|
35
|
-
|
|
35
|
+
let page = this.kerning[ch >>> LOG2_PAGE_SIZE];
|
|
36
36
|
if (page) {
|
|
37
37
|
return page[ch & PAGE_SIZE - 1] || 0;
|
|
38
38
|
}
|
|
@@ -47,7 +47,7 @@ const PAGE_SIZE = 1 << LOG2_PAGE_SIZE;
|
|
|
47
47
|
if (!this.kerning) {
|
|
48
48
|
this.kerning = {};
|
|
49
49
|
}
|
|
50
|
-
|
|
50
|
+
let page = this.kerning[ch >>> LOG2_PAGE_SIZE];
|
|
51
51
|
if (typeof page === "undefined") {
|
|
52
52
|
this.kerning[ch >>> LOG2_PAGE_SIZE] = {};
|
|
53
53
|
page = this.kerning[ch >>> LOG2_PAGE_SIZE];
|
package/src/text/text.js
CHANGED
|
@@ -40,7 +40,7 @@ const toPX = [12, 24, 0.75, 1];
|
|
|
40
40
|
* @param {number} [settings.wordWrapWidth] - the maximum length in CSS pixel for a single segment of text
|
|
41
41
|
* @param {(string|string[])} [settings.text=""] - a string, or an array of strings
|
|
42
42
|
* @example
|
|
43
|
-
*
|
|
43
|
+
* let font = new me.Text(0, 0, {font: "Arial", size: 8, fillStyle: this.color});
|
|
44
44
|
*/
|
|
45
45
|
constructor(x, y, settings) {
|
|
46
46
|
// call the parent constructor
|
|
@@ -169,7 +169,8 @@ const toPX = [12, 24, 0.75, 1];
|
|
|
169
169
|
}
|
|
170
170
|
|
|
171
171
|
// the canvas Texture used to render this text
|
|
172
|
-
|
|
172
|
+
// XXX: offscreenCanvas is currently disabled for text rendering due to issue in WebGL mode
|
|
173
|
+
this.canvasTexture = pool.pull("CanvasTexture", 2, 2, { offscreenCanvas: false });
|
|
173
174
|
|
|
174
175
|
// instance to text metrics functions
|
|
175
176
|
this.metrics = new TextMetrics(this);
|
|
@@ -209,7 +210,7 @@ const toPX = [12, 24, 0.75, 1];
|
|
|
209
210
|
*/
|
|
210
211
|
setFont(font, size = 10) {
|
|
211
212
|
// font name and type
|
|
212
|
-
|
|
213
|
+
let font_names = font.split(",").map((value) => {
|
|
213
214
|
value = value.trim();
|
|
214
215
|
return (
|
|
215
216
|
!/(^".*"$)|(^'.*'$)/.test(value)
|
|
@@ -222,7 +223,7 @@ const toPX = [12, 24, 0.75, 1];
|
|
|
222
223
|
size += "px";
|
|
223
224
|
} else /* string */ {
|
|
224
225
|
// extract the units and convert if necessary
|
|
225
|
-
|
|
226
|
+
let CSSval = size.match(/([-+]?[\d.]*)(.*)/);
|
|
226
227
|
this.fontSize = parseFloat(CSSval[1]);
|
|
227
228
|
if (CSSval[2]) {
|
|
228
229
|
this.fontSize *= toPX[runits.indexOf(CSSval[2])];
|
|
@@ -245,7 +246,7 @@ const toPX = [12, 24, 0.75, 1];
|
|
|
245
246
|
* @returns {Text} this object for chaining
|
|
246
247
|
*/
|
|
247
248
|
setText(value = "") {
|
|
248
|
-
|
|
249
|
+
let bounds = this.getBounds();
|
|
249
250
|
|
|
250
251
|
// set the next text
|
|
251
252
|
if (this._text.toString() !== value.toString()) {
|
|
@@ -265,7 +266,7 @@ const toPX = [12, 24, 0.75, 1];
|
|
|
265
266
|
bounds.addBounds(this.metrics.measureText(this._text, this.canvasTexture.context), true);
|
|
266
267
|
|
|
267
268
|
// update the offScreenCanvas texture if required
|
|
268
|
-
|
|
269
|
+
let width = Math.ceil(this.metrics.width),
|
|
269
270
|
height = Math.ceil(this.metrics.height);
|
|
270
271
|
|
|
271
272
|
if (typeof globalRenderer.gl !== "undefined") {
|
|
@@ -373,8 +374,8 @@ const toPX = [12, 24, 0.75, 1];
|
|
|
373
374
|
_drawFont(context, text, x, y) {
|
|
374
375
|
setContextStyle(context, this);
|
|
375
376
|
|
|
376
|
-
for (
|
|
377
|
-
|
|
377
|
+
for (let i = 0; i < text.length; i++) {
|
|
378
|
+
let string = text[i].trimEnd();
|
|
378
379
|
// draw the string
|
|
379
380
|
if (this.fillStyle.alpha > 0) {
|
|
380
381
|
context.fillText(string, x, y);
|
package/src/text/textmetrics.js
CHANGED
|
@@ -50,14 +50,14 @@ import setContextStyle from "./textstyle.js";
|
|
|
50
50
|
if (this.ancestor instanceof Text) {
|
|
51
51
|
return context.measureText(text).width;
|
|
52
52
|
} else { // it's a BitmapText
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
for (
|
|
57
|
-
|
|
58
|
-
|
|
53
|
+
let characters = text.split("");
|
|
54
|
+
let width = 0;
|
|
55
|
+
let lastGlyph = null;
|
|
56
|
+
for (let i = 0; i < characters.length; i++) {
|
|
57
|
+
let ch = characters[i].charCodeAt(0);
|
|
58
|
+
let glyph = this.ancestor.fontData.glyphs[ch];
|
|
59
59
|
if (typeof glyph !== "undefined") {
|
|
60
|
-
|
|
60
|
+
let kerning = (lastGlyph && lastGlyph.kerning) ? lastGlyph.getKerning(ch) : 0;
|
|
61
61
|
width += (glyph.xadvance + kerning) * this.ancestor.fontScale.x;
|
|
62
62
|
lastGlyph = glyph;
|
|
63
63
|
}
|
|
@@ -73,7 +73,7 @@ import setContextStyle from "./textstyle.js";
|
|
|
73
73
|
* @returns {TextMetrics} this
|
|
74
74
|
*/
|
|
75
75
|
measureText(text, context) {
|
|
76
|
-
|
|
76
|
+
let strings;
|
|
77
77
|
|
|
78
78
|
if (!Array.isArray(text)) {
|
|
79
79
|
strings = ("" + text).split("\n");
|
|
@@ -92,7 +92,7 @@ import setContextStyle from "./textstyle.js";
|
|
|
92
92
|
// compute the bounding box size
|
|
93
93
|
this.width = this.height = 0;
|
|
94
94
|
|
|
95
|
-
for (
|
|
95
|
+
for (let i = 0; i < strings.length; i++) {
|
|
96
96
|
this.width = Math.max(this.lineWidth(strings[i].trimEnd(), context), this.width);
|
|
97
97
|
this.height += this.lineHeight();
|
|
98
98
|
}
|
|
@@ -123,9 +123,9 @@ import setContextStyle from "./textstyle.js";
|
|
|
123
123
|
* @returns {string[]} an array of string representing wrapped text
|
|
124
124
|
*/
|
|
125
125
|
wordWrap(text, width, context) {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
126
|
+
let words;
|
|
127
|
+
let currentLine = "";
|
|
128
|
+
let output = [];
|
|
129
129
|
|
|
130
130
|
if (Array.isArray(text)) {
|
|
131
131
|
// join into a single string
|
|
@@ -143,8 +143,8 @@ import setContextStyle from "./textstyle.js";
|
|
|
143
143
|
}
|
|
144
144
|
|
|
145
145
|
for (let i = 0; i < words.length; i++) {
|
|
146
|
-
|
|
147
|
-
|
|
146
|
+
let word = words[i];
|
|
147
|
+
let lineWidth = this.lineWidth(currentLine + word + " ", context);
|
|
148
148
|
if (lineWidth < width) {
|
|
149
149
|
// add the word to the current line
|
|
150
150
|
currentLine += word + " ";
|
package/src/tweens/easing.js
CHANGED
|
@@ -263,21 +263,21 @@ export let Easing = {
|
|
|
263
263
|
/** @ignore */
|
|
264
264
|
In: function ( k ) {
|
|
265
265
|
|
|
266
|
-
|
|
266
|
+
const s = 1.70158;
|
|
267
267
|
return k * k * ( ( s + 1 ) * k - s );
|
|
268
268
|
|
|
269
269
|
},
|
|
270
270
|
/** @ignore */
|
|
271
271
|
Out: function ( k ) {
|
|
272
272
|
|
|
273
|
-
|
|
273
|
+
const s = 1.70158;
|
|
274
274
|
return --k * k * ( ( s + 1 ) * k + s ) + 1;
|
|
275
275
|
|
|
276
276
|
},
|
|
277
277
|
/** @ignore */
|
|
278
278
|
InOut: function ( k ) {
|
|
279
279
|
|
|
280
|
-
|
|
280
|
+
const s = 1.70158 * 1.525;
|
|
281
281
|
if ( ( k *= 2 ) < 1 ) return 0.5 * ( k * k * ( ( s + 1 ) * k - s ) );
|
|
282
282
|
return 0.5 * ( ( k -= 2 ) * k * ( ( s + 1 ) * k + s ) + 2 );
|
|
283
283
|
|
|
@@ -20,7 +20,7 @@ export let Interpolation = {
|
|
|
20
20
|
/** @ignore */
|
|
21
21
|
Linear: function ( v, k ) {
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
let m = v.length - 1, f = m * k, i = Math.floor( f ), fn = Interpolation.Utils.Linear;
|
|
24
24
|
|
|
25
25
|
if ( k < 0 ) return fn( v[ 0 ], v[ 1 ], f );
|
|
26
26
|
if ( k > 1 ) return fn( v[ m ], v[ m - 1 ], m - f );
|
|
@@ -31,7 +31,7 @@ export let Interpolation = {
|
|
|
31
31
|
/** @ignore */
|
|
32
32
|
Bezier: function ( v, k ) {
|
|
33
33
|
|
|
34
|
-
|
|
34
|
+
let b = 0, n = v.length - 1, pw = Math.pow, bn = Interpolation.Utils.Bernstein, i;
|
|
35
35
|
|
|
36
36
|
for ( i = 0; i <= n; i++ ) {
|
|
37
37
|
b += pw( 1 - k, n - i ) * pw( k, i ) * v[ i ] * bn( n, i );
|
|
@@ -43,7 +43,7 @@ export let Interpolation = {
|
|
|
43
43
|
/** @ignore */
|
|
44
44
|
CatmullRom: function ( v, k ) {
|
|
45
45
|
|
|
46
|
-
|
|
46
|
+
let m = v.length - 1, f = m * k, i = Math.floor( f ), fn = Interpolation.Utils.CatmullRom;
|
|
47
47
|
|
|
48
48
|
if ( v[ 0 ] === v[ m ] ) {
|
|
49
49
|
|
|
@@ -72,18 +72,18 @@ export let Interpolation = {
|
|
|
72
72
|
/** @ignore */
|
|
73
73
|
Bernstein: function ( n, i ) {
|
|
74
74
|
|
|
75
|
-
|
|
75
|
+
let fc = Interpolation.Utils.Factorial;
|
|
76
76
|
return fc( n ) / fc( i ) / fc( n - i );
|
|
77
77
|
|
|
78
78
|
},
|
|
79
79
|
/* @ignore */
|
|
80
80
|
Factorial: ( function () {
|
|
81
81
|
|
|
82
|
-
|
|
82
|
+
let a = [ 1 ];
|
|
83
83
|
|
|
84
84
|
return function ( n ) {
|
|
85
85
|
|
|
86
|
-
|
|
86
|
+
let s = 1, i;
|
|
87
87
|
if ( a[ n ] ) return a[ n ];
|
|
88
88
|
for ( i = n; i > 1; i-- ) s *= i;
|
|
89
89
|
a[ n ] = s;
|
|
@@ -95,7 +95,7 @@ export let Interpolation = {
|
|
|
95
95
|
/** @ignore */
|
|
96
96
|
CatmullRom: function ( p0, p1, p2, p3, t ) {
|
|
97
97
|
|
|
98
|
-
|
|
98
|
+
let v0 = ( p2 - p0 ) * 0.5, v1 = ( p3 - p1 ) * 0.5, t2 = t * t, t3 = t * t2;
|
|
99
99
|
return ( 2 * p1 - 2 * p2 + v0 + v1 ) * t3 + ( - 3 * p1 + 3 * p2 - 2 * v0 - v1 ) * t2 + v0 * t + p1;
|
|
100
100
|
}
|
|
101
101
|
}
|
package/src/tweens/tween.js
CHANGED
|
@@ -82,7 +82,7 @@ import { Interpolation } from "./interpolation.js";
|
|
|
82
82
|
this.isRenderable = false;
|
|
83
83
|
|
|
84
84
|
// Set all starting values present on the target object
|
|
85
|
-
for (
|
|
85
|
+
for ( let field in object ) {
|
|
86
86
|
if (typeof object !== "object") {
|
|
87
87
|
this._valuesStart[ field ] = parseFloat(object[field]);
|
|
88
88
|
}
|
|
@@ -174,7 +174,7 @@ import { Interpolation } from "./interpolation.js";
|
|
|
174
174
|
|
|
175
175
|
this._startTime = time + this._delayTime;
|
|
176
176
|
|
|
177
|
-
for (
|
|
177
|
+
for ( let property in this._valuesEnd ) {
|
|
178
178
|
|
|
179
179
|
// check if an Array was provided as property value
|
|
180
180
|
if ( this._valuesEnd[ property ] instanceof Array ) {
|
|
@@ -350,9 +350,9 @@ import { Interpolation } from "./interpolation.js";
|
|
|
350
350
|
// the original Tween implementation expect
|
|
351
351
|
// a timestamp and not a time delta
|
|
352
352
|
this._tweenTimeTracker = (game.lastUpdate > this._tweenTimeTracker) ? game.lastUpdate : this._tweenTimeTracker + dt;
|
|
353
|
-
|
|
353
|
+
let time = this._tweenTimeTracker;
|
|
354
354
|
|
|
355
|
-
|
|
355
|
+
let property;
|
|
356
356
|
|
|
357
357
|
if ( time < this._startTime ) {
|
|
358
358
|
|
|
@@ -372,15 +372,15 @@ import { Interpolation } from "./interpolation.js";
|
|
|
372
372
|
|
|
373
373
|
}
|
|
374
374
|
|
|
375
|
-
|
|
375
|
+
let elapsed = ( time - this._startTime ) / this._duration;
|
|
376
376
|
elapsed = elapsed > 1 ? 1 : elapsed;
|
|
377
377
|
|
|
378
|
-
|
|
378
|
+
let value = this._easingFunction( elapsed );
|
|
379
379
|
|
|
380
380
|
for ( property in this._valuesEnd ) {
|
|
381
381
|
|
|
382
|
-
|
|
383
|
-
|
|
382
|
+
let start = this._valuesStart[ property ] || 0;
|
|
383
|
+
let end = this._valuesEnd[ property ];
|
|
384
384
|
|
|
385
385
|
if ( end instanceof Array ) {
|
|
386
386
|
|
|
@@ -424,7 +424,7 @@ import { Interpolation } from "./interpolation.js";
|
|
|
424
424
|
}
|
|
425
425
|
|
|
426
426
|
if (this._yoyo) {
|
|
427
|
-
|
|
427
|
+
let tmp = this._valuesStartRepeat[ property ];
|
|
428
428
|
this._valuesStartRepeat[ property ] = this._valuesEnd[ property ];
|
|
429
429
|
this._valuesEnd[ property ] = tmp;
|
|
430
430
|
}
|
|
@@ -450,7 +450,7 @@ import { Interpolation } from "./interpolation.js";
|
|
|
450
450
|
|
|
451
451
|
}
|
|
452
452
|
|
|
453
|
-
for (
|
|
453
|
+
for ( let i = 0, numChainedTweens = this._chainedTweens.length; i < numChainedTweens; i ++ ) {
|
|
454
454
|
|
|
455
455
|
this._chainedTweens[ i ].start( time );
|
|
456
456
|
|
package/src/utils/agent.js
CHANGED
|
@@ -26,11 +26,11 @@ export function prefixed(name, obj) {
|
|
|
26
26
|
return obj[name];
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
|
|
29
|
+
let uc_name = capitalize(name);
|
|
30
30
|
|
|
31
|
-
|
|
31
|
+
let result;
|
|
32
32
|
vendors.some((vendor) => {
|
|
33
|
-
|
|
33
|
+
let name = vendor + uc_name;
|
|
34
34
|
return (result = (name in obj) ? obj[name] : undefined);
|
|
35
35
|
});
|
|
36
36
|
return result;
|
|
@@ -53,10 +53,10 @@ export function setPrefixed(name, value, obj) {
|
|
|
53
53
|
return;
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
-
|
|
56
|
+
let uc_name = capitalize(name);
|
|
57
57
|
|
|
58
58
|
vendors.some((vendor) => {
|
|
59
|
-
|
|
59
|
+
let name = vendor + uc_name;
|
|
60
60
|
if (name in obj) {
|
|
61
61
|
obj[name] = value;
|
|
62
62
|
return true;
|
package/src/utils/array.js
CHANGED
|
@@ -13,12 +13,12 @@ import {random as mathRandom, weightedRandom as mathWeightedRandom} from "./../m
|
|
|
13
13
|
* @param {Array} arr - array from which to remove an object
|
|
14
14
|
* @param {object} obj - to be removed
|
|
15
15
|
* @returns {Array} the modified Array
|
|
16
|
-
*
|
|
16
|
+
* let arr = [ "foo", "bar", "baz" ];
|
|
17
17
|
* // remove "foo" from the array
|
|
18
18
|
* me.utils.array.remove(arr, "foo");
|
|
19
19
|
*/
|
|
20
20
|
export function remove(arr, obj) {
|
|
21
|
-
|
|
21
|
+
let i = Array.prototype.indexOf.call(arr, obj);
|
|
22
22
|
if (i !== -1) {
|
|
23
23
|
Array.prototype.splice.call(arr, i, 1);
|
|
24
24
|
}
|
|
@@ -34,7 +34,7 @@ export function remove(arr, obj) {
|
|
|
34
34
|
* @returns {any} random member of array
|
|
35
35
|
* @example
|
|
36
36
|
* // Select a random array element
|
|
37
|
-
*
|
|
37
|
+
* let arr = [ "foo", "bar", "baz" ];
|
|
38
38
|
* console.log(me.utils.array.random(arr));
|
|
39
39
|
*/
|
|
40
40
|
export function random(arr) {
|
package/src/utils/function.js
CHANGED
|
@@ -34,15 +34,15 @@ export function defer(func, thisArg, ...args) {
|
|
|
34
34
|
* @returns {Function} the function that will be throttled
|
|
35
35
|
*/
|
|
36
36
|
export function throttle(fn, delay, no_trailing) {
|
|
37
|
-
|
|
37
|
+
let last = globalThis.performance.now(), deferTimer;
|
|
38
38
|
// `no_trailing` defaults to false.
|
|
39
39
|
if (typeof no_trailing !== "boolean") {
|
|
40
40
|
no_trailing = false;
|
|
41
41
|
}
|
|
42
42
|
return function () {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
43
|
+
let now = globalThis.performance.now();
|
|
44
|
+
let elasped = now - last;
|
|
45
|
+
let args = arguments;
|
|
46
46
|
if (elasped < delay) {
|
|
47
47
|
if (no_trailing === false) {
|
|
48
48
|
// hold on to it
|
package/src/utils/string.js
CHANGED
|
@@ -39,7 +39,7 @@ export function isNumeric(str) {
|
|
|
39
39
|
* @returns {boolean} true if the string is either true or false
|
|
40
40
|
*/
|
|
41
41
|
export function isBoolean(str) {
|
|
42
|
-
|
|
42
|
+
const trimmed = str.trim();
|
|
43
43
|
return (trimmed === "true") || (trimmed === "false");
|
|
44
44
|
}
|
|
45
45
|
|
|
@@ -52,7 +52,7 @@ export function isBoolean(str) {
|
|
|
52
52
|
* @returns {string} the converted hexadecimal value
|
|
53
53
|
*/
|
|
54
54
|
export function toHex(str) {
|
|
55
|
-
|
|
55
|
+
let res = "", c = 0;
|
|
56
56
|
while (c < str.length) {
|
|
57
57
|
res += str.charCodeAt(c++).toString(16);
|
|
58
58
|
}
|
package/src/utils/utils.js
CHANGED
|
@@ -10,10 +10,10 @@ import * as fnUtils from "./function.js";
|
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
12
|
// guid default value
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
let GUID_base = "";
|
|
14
|
+
let GUID_index = 0;
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
let utils = {
|
|
17
17
|
|
|
18
18
|
agent : agentUtils,
|
|
19
19
|
array : arrayUtils,
|
|
@@ -39,12 +39,12 @@ var utils = {
|
|
|
39
39
|
* }
|
|
40
40
|
*/
|
|
41
41
|
checkVersion : function (first, second) {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
42
|
+
let a = first.split(".");
|
|
43
|
+
let b = second.split(".");
|
|
44
|
+
let len = Math.min(a.length, b.length);
|
|
45
|
+
let result = 0;
|
|
46
46
|
|
|
47
|
-
for (
|
|
47
|
+
for (let i = 0; i < len; i++) {
|
|
48
48
|
if ((result = +a[i] - +b[i])) {
|
|
49
49
|
break;
|
|
50
50
|
}
|
|
@@ -68,15 +68,15 @@ var utils = {
|
|
|
68
68
|
* @property {string} [debugToggleKey="s"] show/hide the debug panel (if preloaded)
|
|
69
69
|
* @example
|
|
70
70
|
* // http://www.example.com/index.html#debug&hitbox=true&mytag=value
|
|
71
|
-
*
|
|
71
|
+
* let UriFragment = me.utils.getUriFragment();
|
|
72
72
|
* console.log(UriFragment["mytag"]); //> "value"
|
|
73
73
|
*/
|
|
74
74
|
getUriFragment : function (url) {
|
|
75
|
-
|
|
75
|
+
let hash = {};
|
|
76
76
|
|
|
77
77
|
if (typeof url === "undefined") {
|
|
78
78
|
if (typeof globalThis.document !== "undefined") {
|
|
79
|
-
|
|
79
|
+
let location = globalThis.document.location;
|
|
80
80
|
|
|
81
81
|
if (location && location.hash) {
|
|
82
82
|
url = location.hash;
|
|
@@ -90,7 +90,7 @@ var utils = {
|
|
|
90
90
|
}
|
|
91
91
|
} else {
|
|
92
92
|
// never cache if a url is passed as parameter
|
|
93
|
-
|
|
93
|
+
let index = url.indexOf("#");
|
|
94
94
|
if (index !== -1) {
|
|
95
95
|
url = url.slice(index, url.length);
|
|
96
96
|
} else {
|
|
@@ -100,9 +100,9 @@ var utils = {
|
|
|
100
100
|
|
|
101
101
|
// parse the url
|
|
102
102
|
url.slice(1).split("&").filter((value) => value !== "").forEach((value) => {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
103
|
+
let kv = value.split("=");
|
|
104
|
+
let k = kv.shift();
|
|
105
|
+
let v = kv.join("=");
|
|
106
106
|
hash[k] = v || true;
|
|
107
107
|
});
|
|
108
108
|
|