melonjs 15.2.1 → 15.4.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 +1 -1
- 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 +75 -23
- package/dist/melonjs.mjs/application/header.js +2 -2
- package/dist/melonjs.mjs/application/resize.js +13 -11
- package/dist/melonjs.mjs/application/settings.js +37 -1
- package/dist/melonjs.mjs/audio/audio.js +4 -6
- package/dist/melonjs.mjs/camera/camera2d.js +12 -14
- package/dist/melonjs.mjs/const.js +1 -1
- package/dist/melonjs.mjs/entity/entity.js +3 -4
- package/dist/melonjs.mjs/geometries/ellipse.js +26 -59
- package/dist/melonjs.mjs/geometries/line.js +18 -25
- package/dist/melonjs.mjs/geometries/path2d.js +16 -13
- package/dist/melonjs.mjs/geometries/point.js +8 -16
- package/dist/melonjs.mjs/geometries/poly.js +40 -97
- package/dist/melonjs.mjs/geometries/rectangle.js +37 -91
- package/dist/melonjs.mjs/geometries/roundrect.js +26 -35
- package/dist/melonjs.mjs/index.js +6 -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 +3 -3
- package/dist/melonjs.mjs/input/pointer.js +4 -4
- package/dist/melonjs.mjs/input/pointerevent.js +6 -7
- package/dist/melonjs.mjs/lang/console.js +1 -1
- package/dist/melonjs.mjs/lang/deprecated.js +2 -2
- package/dist/melonjs.mjs/level/level.js +1 -1
- package/dist/melonjs.mjs/level/tiled/TMXGroup.js +1 -1
- package/dist/melonjs.mjs/level/tiled/TMXLayer.js +16 -33
- package/dist/melonjs.mjs/level/tiled/TMXObject.js +3 -4
- package/dist/melonjs.mjs/level/tiled/TMXTile.js +4 -4
- package/dist/melonjs.mjs/level/tiled/TMXTileMap.js +3 -3
- package/dist/melonjs.mjs/level/tiled/TMXTileset.js +4 -7
- package/dist/melonjs.mjs/level/tiled/TMXTilesetGroup.js +2 -2
- package/dist/melonjs.mjs/level/tiled/TMXUtils.js +37 -47
- package/dist/melonjs.mjs/level/tiled/constants.js +1 -1
- package/dist/melonjs.mjs/level/tiled/renderer/TMXHexagonalRenderer.js +3 -3
- package/dist/melonjs.mjs/level/tiled/renderer/TMXIsometricRenderer.js +2 -2
- package/dist/melonjs.mjs/level/tiled/renderer/TMXOrthogonalRenderer.js +2 -2
- package/dist/melonjs.mjs/level/tiled/renderer/TMXRenderer.js +2 -2
- package/dist/melonjs.mjs/level/tiled/renderer/TMXStaggeredRenderer.js +2 -2
- 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 +4 -5
- package/dist/melonjs.mjs/loader/settings.js +1 -1
- package/dist/melonjs.mjs/math/color.js +5 -5
- package/dist/melonjs.mjs/math/math.js +1 -1
- package/dist/melonjs.mjs/math/matrix2.js +5 -59
- package/dist/melonjs.mjs/math/matrix3.js +82 -141
- package/dist/melonjs.mjs/math/observable_vector2.js +7 -7
- package/dist/melonjs.mjs/math/observable_vector3.js +5 -5
- package/dist/melonjs.mjs/math/vector2.js +7 -91
- package/dist/melonjs.mjs/math/vector3.js +6 -90
- 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 +2 -2
- package/dist/melonjs.mjs/particles/particle.js +2 -2
- package/dist/melonjs.mjs/particles/settings.js +1 -1
- package/dist/melonjs.mjs/physics/body.js +22 -20
- package/dist/melonjs.mjs/physics/bounds.js +27 -33
- package/dist/melonjs.mjs/physics/collision.js +5 -5
- package/dist/melonjs.mjs/physics/detector.js +10 -10
- package/dist/melonjs.mjs/physics/quadtree.js +5 -5
- package/dist/melonjs.mjs/physics/response.js +1 -1
- package/dist/melonjs.mjs/physics/sat.js +3 -4
- package/dist/melonjs.mjs/physics/world.js +6 -9
- package/dist/melonjs.mjs/plugin/plugin.js +3 -3
- package/dist/melonjs.mjs/renderable/collectable.js +2 -2
- package/dist/melonjs.mjs/renderable/colorlayer.js +4 -4
- package/dist/melonjs.mjs/renderable/container.js +25 -25
- 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 +4 -4
- package/dist/melonjs.mjs/renderable/light2d.js +3 -3
- package/dist/melonjs.mjs/renderable/nineslicesprite.js +2 -2
- package/dist/melonjs.mjs/renderable/renderable.js +31 -39
- package/dist/melonjs.mjs/renderable/sprite.js +3 -3
- package/dist/melonjs.mjs/renderable/text/bitmaptext.js +421 -0
- package/dist/melonjs.mjs/renderable/text/bitmaptextdata.js +195 -0
- package/dist/melonjs.mjs/renderable/text/glyph.js +65 -0
- package/dist/melonjs.mjs/renderable/text/text.js +422 -0
- package/dist/melonjs.mjs/renderable/text/textmetrics.js +175 -0
- package/dist/melonjs.mjs/renderable/text/textstyle.js +21 -0
- package/dist/melonjs.mjs/renderable/trigger.js +10 -10
- package/dist/melonjs.mjs/renderable/ui/uibaseelement.js +7 -7
- package/dist/melonjs.mjs/renderable/ui/uispriteelement.js +7 -7
- package/dist/melonjs.mjs/renderable/ui/uitextbutton.js +3 -3
- package/dist/melonjs.mjs/state/stage.js +13 -14
- package/dist/melonjs.mjs/state/state.js +4 -51
- package/dist/melonjs.mjs/system/device.js +51 -10
- package/dist/melonjs.mjs/system/dom.js +1 -1
- package/dist/melonjs.mjs/system/event.js +46 -2
- package/dist/melonjs.mjs/system/platform.js +18 -18
- package/dist/melonjs.mjs/system/pooling.js +10 -10
- package/dist/melonjs.mjs/system/save.js +1 -1
- package/dist/melonjs.mjs/system/timer.js +1 -1
- package/dist/melonjs.mjs/text/bitmaptext.js +1 -1
- package/dist/melonjs.mjs/text/bitmaptextdata.js +3 -6
- 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 +2 -2
- 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 +2 -3
- package/dist/melonjs.mjs/utils/string.js +1 -1
- package/dist/melonjs.mjs/utils/utils.js +1 -1
- package/dist/melonjs.mjs/video/canvas/canvas_renderer.js +5 -18
- package/dist/melonjs.mjs/video/renderer.js +17 -30
- package/dist/melonjs.mjs/video/texture/atlas.js +13 -13
- package/dist/melonjs.mjs/video/texture/cache.js +1 -1
- package/dist/melonjs.mjs/video/texture/canvas_texture.js +15 -15
- package/dist/melonjs.mjs/video/utils/autodetect.js +1 -1
- package/dist/melonjs.mjs/video/video.js +5 -29
- package/dist/melonjs.mjs/video/webgl/buffer/vertex.js +3 -3
- package/dist/melonjs.mjs/video/webgl/compositors/compositor.js +13 -14
- package/dist/melonjs.mjs/video/webgl/compositors/primitive_compositor.js +5 -5
- package/dist/melonjs.mjs/video/webgl/compositors/quad_compositor.js +2 -3
- package/dist/melonjs.mjs/video/webgl/glshader.js +2 -2
- 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 +4 -4
- 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 +62 -67
- package/dist/melonjs.module.js +1272 -1713
- package/dist/types/application/application.d.ts +32 -31
- package/dist/types/application/header.d.ts +2 -2
- package/dist/types/application/settings.d.ts +80 -16
- package/dist/types/audio/audio.d.ts +4 -6
- package/dist/types/camera/camera2d.d.ts +13 -16
- package/dist/types/entity/entity.d.ts +0 -1
- package/dist/types/geometries/ellipse.d.ts +18 -50
- package/dist/types/geometries/path2d.d.ts +1 -1
- package/dist/types/geometries/point.d.ts +5 -13
- package/dist/types/geometries/poly.d.ts +26 -75
- package/dist/types/geometries/rectangle.d.ts +12 -58
- package/dist/types/geometries/roundrect.d.ts +2 -11
- package/dist/types/index.d.ts +3 -3
- package/dist/types/input/gamepad.d.ts +31 -31
- package/dist/types/input/keyboard.d.ts +105 -105
- package/dist/types/input/pointer.d.ts +21 -21
- package/dist/types/input/pointerevent.d.ts +6 -6
- package/dist/types/level/tiled/TMXLayer.d.ts +1 -1
- package/dist/types/level/tiled/TMXUtils.d.ts +4 -6
- package/dist/types/math/matrix2.d.ts +9 -63
- package/dist/types/math/matrix3.d.ts +9 -68
- package/dist/types/math/observable_vector2.d.ts +2 -2
- package/dist/types/math/observable_vector3.d.ts +2 -2
- package/dist/types/math/vector2.d.ts +8 -92
- package/dist/types/math/vector3.d.ts +8 -92
- package/dist/types/particles/settings.d.ts +29 -29
- package/dist/types/physics/body.d.ts +10 -8
- package/dist/types/physics/bounds.d.ts +24 -30
- package/dist/types/physics/collision.d.ts +12 -12
- package/dist/types/physics/detector.d.ts +1 -1
- package/dist/types/physics/world.d.ts +4 -7
- package/dist/types/renderable/container.d.ts +19 -19
- package/dist/types/renderable/imagelayer.d.ts +6 -6
- package/dist/types/renderable/light2d.d.ts +7 -7
- package/dist/types/renderable/renderable.d.ts +10 -18
- package/dist/types/renderable/text/bitmaptext.d.ts +151 -0
- package/dist/types/renderable/text/bitmaptextdata.d.ts +35 -0
- package/dist/types/renderable/text/glyph.d.ts +28 -0
- package/dist/types/renderable/text/text.d.ts +159 -0
- package/dist/types/renderable/text/textmetrics.d.ts +47 -0
- package/dist/types/renderable/text/textstyle.d.ts +5 -0
- package/dist/types/renderable/ui/uibaseelement.d.ts +0 -1
- package/dist/types/renderable/ui/uispriteelement.d.ts +0 -1
- package/dist/types/renderable/ui/uitextbutton.d.ts +2 -7
- package/dist/types/state/stage.d.ts +3 -2
- package/dist/types/state/state.d.ts +11 -11
- package/dist/types/system/device.d.ts +16 -9
- package/dist/types/system/event.d.ts +40 -0
- package/dist/types/system/platform.d.ts +17 -17
- package/dist/types/utils/function.d.ts +1 -2
- package/dist/types/video/canvas/canvas_renderer.d.ts +0 -23
- package/dist/types/video/renderer.d.ts +16 -43
- package/dist/types/video/texture/canvas_texture.d.ts +14 -14
- package/dist/types/video/video.d.ts +4 -38
- package/dist/types/video/webgl/buffer/vertex.d.ts +2 -2
- package/dist/types/video/webgl/compositors/compositor.d.ts +24 -13
- package/dist/types/video/webgl/compositors/primitive_compositor.d.ts +0 -1
- package/dist/types/video/webgl/compositors/quad_compositor.d.ts +0 -1
- package/dist/types/video/webgl/utils/precision.d.ts +1 -1
- package/dist/types/video/webgl/webgl_renderer.d.ts +48 -84
- package/package.json +15 -15
- package/src/application/application.js +73 -21
- package/src/application/header.js +1 -1
- package/src/application/resize.js +11 -9
- package/src/application/settings.js +36 -0
- package/src/audio/audio.js +3 -5
- package/src/camera/camera2d.js +11 -13
- package/src/entity/entity.js +2 -3
- package/src/geometries/ellipse.js +25 -58
- package/src/geometries/line.js +17 -24
- package/src/geometries/path2d.js +15 -12
- package/src/geometries/point.js +7 -15
- package/src/geometries/poly.js +39 -96
- package/src/geometries/rectangle.js +36 -90
- package/src/geometries/roundrect.js +25 -34
- package/src/index.js +4 -4
- package/src/input/keyboard.js +2 -2
- package/src/input/pointer.js +3 -3
- package/src/input/pointerevent.js +5 -6
- package/src/lang/deprecated.js +1 -1
- package/src/level/tiled/TMXLayer.js +15 -32
- package/src/level/tiled/TMXObject.js +2 -3
- package/src/level/tiled/TMXTile.js +3 -3
- package/src/level/tiled/TMXTileMap.js +2 -2
- package/src/level/tiled/TMXTileset.js +3 -6
- package/src/level/tiled/TMXTilesetGroup.js +1 -1
- package/src/level/tiled/TMXUtils.js +36 -46
- package/src/level/tiled/renderer/TMXHexagonalRenderer.js +2 -2
- 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/parser.js +3 -4
- package/src/math/color.js +4 -4
- package/src/math/matrix2.js +4 -58
- package/src/math/matrix3.js +81 -140
- package/src/math/observable_vector2.js +6 -6
- package/src/math/observable_vector3.js +4 -4
- package/src/math/vector2.js +6 -90
- package/src/math/vector3.js +5 -89
- package/src/particles/emitter.js +1 -1
- package/src/particles/particle.js +1 -1
- package/src/physics/body.js +21 -19
- package/src/physics/bounds.js +26 -32
- package/src/physics/collision.js +4 -4
- package/src/physics/detector.js +9 -9
- package/src/physics/quadtree.js +4 -4
- package/src/physics/sat.js +2 -3
- package/src/physics/world.js +5 -8
- package/src/polyfill/roundrect.js +163 -163
- package/src/renderable/collectable.js +1 -1
- package/src/renderable/colorlayer.js +3 -3
- package/src/renderable/container.js +24 -24
- package/src/renderable/imagelayer.js +3 -3
- package/src/renderable/light2d.js +2 -2
- package/src/renderable/nineslicesprite.js +1 -1
- package/src/renderable/renderable.js +30 -38
- package/src/renderable/sprite.js +2 -2
- package/src/{text → renderable/text}/bitmaptext.js +8 -8
- package/src/{text → renderable/text}/bitmaptextdata.js +4 -7
- package/src/{text → renderable/text}/glyph.js +1 -1
- package/src/{text → renderable/text}/text.js +16 -17
- package/src/{text → renderable/text}/textmetrics.js +2 -2
- package/src/renderable/trigger.js +9 -9
- package/src/renderable/ui/uibaseelement.js +6 -6
- package/src/renderable/ui/uispriteelement.js +6 -6
- package/src/renderable/ui/uitextbutton.js +2 -2
- package/src/state/stage.js +12 -13
- package/src/state/state.js +2 -61
- package/src/system/device.js +50 -9
- package/src/system/event.js +44 -0
- package/src/system/platform.js +18 -18
- package/src/system/pooling.js +9 -9
- package/src/tweens/tween.js +1 -1
- package/src/utils/function.js +1 -2
- package/src/video/canvas/canvas_renderer.js +4 -17
- package/src/video/renderer.js +16 -29
- package/src/video/texture/atlas.js +12 -12
- package/src/video/texture/canvas_texture.js +14 -14
- package/src/video/video.js +7 -28
- package/src/video/webgl/buffer/vertex.js +2 -2
- package/src/video/webgl/compositors/compositor.js +12 -13
- package/src/video/webgl/compositors/primitive_compositor.js +4 -4
- package/src/video/webgl/compositors/quad_compositor.js +1 -2
- package/src/video/webgl/glshader.js +1 -1
- package/src/video/webgl/utils/precision.js +3 -3
- package/src/video/webgl/webgl_renderer.js +61 -66
- /package/src/{text → renderable/text}/textstyle.js +0 -0
|
@@ -0,0 +1,422 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* melonJS Game Engine - v15.4.0
|
|
3
|
+
* http://www.melonjs.org
|
|
4
|
+
* melonjs is licensed under the MIT License.
|
|
5
|
+
* http://www.opensource.org/licenses/mit-license
|
|
6
|
+
* @copyright (C) 2011 - 2023 Olivier Biot (AltByte Pte Ltd)
|
|
7
|
+
*/
|
|
8
|
+
import Color from '../../math/color.js';
|
|
9
|
+
import { renderer } from '../../video/video.js';
|
|
10
|
+
import pool from '../../system/pooling.js';
|
|
11
|
+
import Renderable from '../renderable.js';
|
|
12
|
+
import { nextPowerOfTwo } from '../../math/math.js';
|
|
13
|
+
import setContextStyle from './textstyle.js';
|
|
14
|
+
import TextMetrics from './textmetrics.js';
|
|
15
|
+
|
|
16
|
+
/*
|
|
17
|
+
* ASCII Table
|
|
18
|
+
* http://www.asciitable.com/
|
|
19
|
+
* [ !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz]
|
|
20
|
+
*
|
|
21
|
+
* -> first char " " 32d (0x20);
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
const runits = ["ex", "em", "pt", "px"];
|
|
25
|
+
const toPX = [12, 24, 0.75, 1];
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* @classdesc
|
|
29
|
+
* a generic system font object.
|
|
30
|
+
* @augments Renderable
|
|
31
|
+
*/
|
|
32
|
+
class Text extends Renderable {
|
|
33
|
+
/**
|
|
34
|
+
* @param {number} x - position of the text object
|
|
35
|
+
* @param {number} y - position of the text object
|
|
36
|
+
* @param {object} settings - the text configuration
|
|
37
|
+
* @param {string} settings.font - a CSS family font name
|
|
38
|
+
* @param {number|string} settings.size - size, or size + suffix (px, em, pt)
|
|
39
|
+
* @param {Color|string} [settings.fillStyle="#000000"] - a CSS color value
|
|
40
|
+
* @param {Color|string} [settings.strokeStyle="#000000"] - a CSS color value
|
|
41
|
+
* @param {number} [settings.lineWidth=0] - line width, in pixels, when drawing stroke
|
|
42
|
+
* @param {string} [settings.textAlign="left"] - horizontal text alignment
|
|
43
|
+
* @param {string} [settings.textBaseline="top"] - the text baseline
|
|
44
|
+
* @param {number} [settings.lineHeight=1.0] - line spacing height
|
|
45
|
+
* @param {Vector2d} [settings.anchorPoint={x:0.0, y:0.0}] - anchor point to draw the text at
|
|
46
|
+
* @param {number} [settings.wordWrapWidth] - the maximum length in CSS pixel for a single segment of text
|
|
47
|
+
* @param {(string|string[])} [settings.text=""] - a string, or an array of strings
|
|
48
|
+
* @example
|
|
49
|
+
* let font = new me.Text(0, 0, {font: "Arial", size: 8, fillStyle: this.color});
|
|
50
|
+
*/
|
|
51
|
+
constructor(x, y, settings) {
|
|
52
|
+
// call the parent constructor
|
|
53
|
+
super(x, y, settings.width || 0, settings.height || 0);
|
|
54
|
+
this.onResetEvent(x, y, settings);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** @ignore */
|
|
58
|
+
onResetEvent(x, y, settings) {
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* defines the color used to draw the font.<br>
|
|
62
|
+
* @public
|
|
63
|
+
* @member {Color}
|
|
64
|
+
* @name Text#fillStyle
|
|
65
|
+
* @default black
|
|
66
|
+
*/
|
|
67
|
+
if (typeof settings.fillStyle !== "undefined") {
|
|
68
|
+
if (settings.fillStyle instanceof Color) {
|
|
69
|
+
this.fillStyle = settings.fillStyle;
|
|
70
|
+
} else {
|
|
71
|
+
// string (#RGB, #ARGB, #RRGGBB, #AARRGGBB)
|
|
72
|
+
this.fillStyle = pool.pull("Color").parseCSS(settings.fillStyle);
|
|
73
|
+
}
|
|
74
|
+
} else {
|
|
75
|
+
this.fillStyle = pool.pull("Color", 0, 0, 0);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* defines the color used to draw the font stroke.<br>
|
|
80
|
+
* @public
|
|
81
|
+
* @member {Color}
|
|
82
|
+
* @name strokeStyle
|
|
83
|
+
* @default black
|
|
84
|
+
*/
|
|
85
|
+
if (typeof settings.strokeStyle !== "undefined") {
|
|
86
|
+
if (settings.strokeStyle instanceof Color) {
|
|
87
|
+
this.strokeStyle = settings.strokeStyle;
|
|
88
|
+
} else {
|
|
89
|
+
// string (#RGB, #ARGB, #RRGGBB, #AARRGGBB)
|
|
90
|
+
this.strokeStyle = pool.pull("Color").parseCSS(settings.strokeStyle);
|
|
91
|
+
}
|
|
92
|
+
} else {
|
|
93
|
+
this.strokeStyle = pool.pull("Color", 0, 0, 0);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* sets the current line width, in pixels, when drawing stroke
|
|
98
|
+
* @public
|
|
99
|
+
* @type {number}
|
|
100
|
+
* @default 0
|
|
101
|
+
*/
|
|
102
|
+
this.lineWidth = settings.lineWidth || 0;
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Set the default text alignment (or justification),<br>
|
|
106
|
+
* possible values are "left", "right", and "center".<br>
|
|
107
|
+
* @public
|
|
108
|
+
* @type {string}
|
|
109
|
+
* @default "left"
|
|
110
|
+
*/
|
|
111
|
+
this.textAlign = settings.textAlign || "left";
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Set the text baseline (e.g. the Y-coordinate for the draw operation), <br>
|
|
115
|
+
* possible values are "top", "hanging, "middle, "alphabetic, "ideographic, "bottom"<br>
|
|
116
|
+
* @public
|
|
117
|
+
* @type {string}
|
|
118
|
+
* @default "top"
|
|
119
|
+
*/
|
|
120
|
+
this.textBaseline = settings.textBaseline || "top";
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Set the line spacing height (when displaying multi-line strings). <br>
|
|
124
|
+
* Current font height will be multiplied with this value to set the line height.
|
|
125
|
+
* @public
|
|
126
|
+
* @type {number}
|
|
127
|
+
* @default 1.0
|
|
128
|
+
*/
|
|
129
|
+
this.lineHeight = settings.lineHeight || 1.0;
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* the maximum length in CSS pixel for a single segment of text.
|
|
133
|
+
* (use -1 to disable word wrapping)
|
|
134
|
+
* @public
|
|
135
|
+
* @type {number}
|
|
136
|
+
* @default -1
|
|
137
|
+
*/
|
|
138
|
+
this.wordWrapWidth = settings.wordWrapWidth || -1;
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* the text to be displayed
|
|
142
|
+
* @private
|
|
143
|
+
*/
|
|
144
|
+
this._text = [];
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* the font size (in px)
|
|
148
|
+
* @public
|
|
149
|
+
* @type {number}
|
|
150
|
+
* @default 10
|
|
151
|
+
*/
|
|
152
|
+
this.fontSize = 10;
|
|
153
|
+
|
|
154
|
+
// anchor point
|
|
155
|
+
if (typeof settings.anchorPoint !== "undefined") {
|
|
156
|
+
this.anchorPoint.setV(settings.anchorPoint);
|
|
157
|
+
} else {
|
|
158
|
+
this.anchorPoint.set(0, 0);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// if floating was specified through settings
|
|
162
|
+
if (typeof settings.floating !== "undefined") {
|
|
163
|
+
this.floating = !!settings.floating;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// font name and type
|
|
167
|
+
this.setFont(settings.font, settings.size);
|
|
168
|
+
|
|
169
|
+
// aditional
|
|
170
|
+
if (settings.bold === true) {
|
|
171
|
+
this.bold();
|
|
172
|
+
}
|
|
173
|
+
if (settings.italic === true) {
|
|
174
|
+
this.italic();
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
// the canvas Texture used to render this text
|
|
178
|
+
// XXX: offscreenCanvas is currently disabled for text rendering due to issue in WebGL mode
|
|
179
|
+
this.canvasTexture = pool.pull("CanvasTexture", 2, 2, { offscreenCanvas: false });
|
|
180
|
+
|
|
181
|
+
// instance to text metrics functions
|
|
182
|
+
this.metrics = new TextMetrics(this);
|
|
183
|
+
|
|
184
|
+
// set the text
|
|
185
|
+
this.setText(settings.text);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* make the font bold
|
|
190
|
+
* @returns {Text} this object for chaining
|
|
191
|
+
*/
|
|
192
|
+
bold() {
|
|
193
|
+
this.font = "bold " + this.font;
|
|
194
|
+
this.isDirty = true;
|
|
195
|
+
return this;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* make the font italic
|
|
200
|
+
* @returns {Text} this object for chaining
|
|
201
|
+
*/
|
|
202
|
+
italic() {
|
|
203
|
+
this.font = "italic " + this.font;
|
|
204
|
+
this.isDirty = true;
|
|
205
|
+
return this;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* set the font family and size
|
|
210
|
+
* @param {string} font - a CSS font name
|
|
211
|
+
* @param {number|string} [size=10] - size in px, or size + suffix (px, em, pt)
|
|
212
|
+
* @returns {Text} this object for chaining
|
|
213
|
+
* @example
|
|
214
|
+
* font.setFont("Arial", 20);
|
|
215
|
+
* font.setFont("Arial", "1.5em");
|
|
216
|
+
*/
|
|
217
|
+
setFont(font, size = 10) {
|
|
218
|
+
// font name and type
|
|
219
|
+
let font_names = font.split(",").map((value) => {
|
|
220
|
+
value = value.trim();
|
|
221
|
+
return (
|
|
222
|
+
!/(^".*"$)|(^'.*'$)/.test(value)
|
|
223
|
+
) ? "\"" + value + "\"" : value;
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
// font size
|
|
227
|
+
if (typeof size === "number") {
|
|
228
|
+
this.fontSize = size;
|
|
229
|
+
size += "px";
|
|
230
|
+
} else /* string */ {
|
|
231
|
+
// extract the units and convert if necessary
|
|
232
|
+
let CSSval = size.match(/([-+]?[\d.]*)(.*)/);
|
|
233
|
+
this.fontSize = parseFloat(CSSval[1]);
|
|
234
|
+
if (CSSval[2]) {
|
|
235
|
+
this.fontSize *= toPX[runits.indexOf(CSSval[2])];
|
|
236
|
+
} else {
|
|
237
|
+
// no unit define, assume px
|
|
238
|
+
size += "px";
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
this.height = this.fontSize;
|
|
242
|
+
this.font = size + " " + font_names.join(",");
|
|
243
|
+
|
|
244
|
+
this.isDirty = true;
|
|
245
|
+
|
|
246
|
+
return this;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/**
|
|
250
|
+
* change the text to be displayed
|
|
251
|
+
* @param {number|string|string[]} value - a string, or an array of strings
|
|
252
|
+
* @returns {Text} this object for chaining
|
|
253
|
+
*/
|
|
254
|
+
setText(value = "") {
|
|
255
|
+
let bounds = this.getBounds();
|
|
256
|
+
|
|
257
|
+
// set the next text
|
|
258
|
+
if (this._text.toString() !== value.toString()) {
|
|
259
|
+
if (!Array.isArray(value)) {
|
|
260
|
+
this._text = ("" + value).split("\n");
|
|
261
|
+
} else {
|
|
262
|
+
this._text = value;
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
// word wrap if necessary
|
|
267
|
+
if (this._text.length > 0 && this.wordWrapWidth > 0) {
|
|
268
|
+
this._text = this.metrics.wordWrap(this._text, this.wordWrapWidth, this.canvasTexture.context);
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
// calculcate the text size and update the bounds accordingly
|
|
272
|
+
bounds.addBounds(this.metrics.measureText(this._text, this.canvasTexture.context), true);
|
|
273
|
+
|
|
274
|
+
// update the offScreenCanvas texture if required
|
|
275
|
+
let width = Math.ceil(this.metrics.width),
|
|
276
|
+
height = Math.ceil(this.metrics.height);
|
|
277
|
+
|
|
278
|
+
if (typeof renderer.gl !== "undefined") {
|
|
279
|
+
// make sure the right compositor is active
|
|
280
|
+
renderer.setCompositor("quad");
|
|
281
|
+
// invalidate the previous corresponding texture so that it can reuploaded once changed
|
|
282
|
+
this.glTextureUnit = renderer.cache.getUnit(renderer.cache.get(this.canvasTexture.canvas));
|
|
283
|
+
renderer.currentCompositor.unbindTexture2D(null, this.glTextureUnit);
|
|
284
|
+
|
|
285
|
+
if (renderer.WebGLVersion === 1) {
|
|
286
|
+
// round size to next Pow2
|
|
287
|
+
width = nextPowerOfTwo(this.metrics.width);
|
|
288
|
+
height = nextPowerOfTwo(this.metrics.height);
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
// resize the cache canvas if necessary
|
|
293
|
+
if (this.canvasTexture.width < width || this.canvasTexture.height < height) {
|
|
294
|
+
this.canvasTexture.resize(width, height);
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
this.canvasTexture.clear();
|
|
298
|
+
this._drawFont(this.canvasTexture.context, this._text, this.pos.x - this.metrics.x, this.pos.y - this.metrics.y);
|
|
299
|
+
|
|
300
|
+
this.isDirty = true;
|
|
301
|
+
|
|
302
|
+
return this;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
/**
|
|
306
|
+
* measure the given text size in pixels
|
|
307
|
+
* @param {CanvasRenderer|WebGLRenderer} renderer - reference to the active renderer
|
|
308
|
+
* @param {string} [text] - the text to be measured
|
|
309
|
+
* @returns {TextMetrics} a TextMetrics object defining the dimensions of the given piece of text
|
|
310
|
+
*/
|
|
311
|
+
measureText(renderer, text = this._text) {
|
|
312
|
+
return this.metrics.measureText(text, this.canvasTexture.context);
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
|
|
316
|
+
/**
|
|
317
|
+
* draw a text at the specified coord
|
|
318
|
+
* @param {CanvasRenderer|WebGLRenderer} renderer - Reference to the destination renderer instance
|
|
319
|
+
* @param {string} [text]
|
|
320
|
+
* @param {number} [x]
|
|
321
|
+
* @param {number} [y]
|
|
322
|
+
*/
|
|
323
|
+
draw(renderer, text, x = this.pos.x, y = this.pos.y) {
|
|
324
|
+
// "hacky patch" for backward compatibilty
|
|
325
|
+
if (typeof this.ancestor === "undefined") {
|
|
326
|
+
|
|
327
|
+
// update position if changed
|
|
328
|
+
if (this.pos.x !== x || this.pos.y !== y) {
|
|
329
|
+
this.pos.x = x;
|
|
330
|
+
this.pos.y = y;
|
|
331
|
+
this.isDirty = true;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
// update text cache
|
|
335
|
+
this.setText(text);
|
|
336
|
+
|
|
337
|
+
// save the previous context
|
|
338
|
+
renderer.save();
|
|
339
|
+
|
|
340
|
+
// apply the defined alpha value
|
|
341
|
+
renderer.setGlobalAlpha(renderer.globalAlpha() * this.getOpacity());
|
|
342
|
+
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
// adjust x,y position based on the bounding box
|
|
346
|
+
x = this.metrics.x;
|
|
347
|
+
y = this.metrics.y;
|
|
348
|
+
|
|
349
|
+
// clamp to pixel grid if required
|
|
350
|
+
if (renderer.settings.subPixel === false) {
|
|
351
|
+
x = ~~x;
|
|
352
|
+
y = ~~y;
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
// draw the text
|
|
356
|
+
renderer.drawImage(this.canvasTexture.canvas, x, y);
|
|
357
|
+
|
|
358
|
+
// for backward compatibilty
|
|
359
|
+
if (typeof this.ancestor === "undefined") {
|
|
360
|
+
// restore previous context
|
|
361
|
+
renderer.restore();
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
/**
|
|
366
|
+
* draw a stroke text at the specified coord, as defined by the `lineWidth` and `fillStroke` properties.
|
|
367
|
+
* @deprecated since 15.0.0
|
|
368
|
+
* @param {CanvasRenderer|WebGLRenderer} renderer - Reference to the destination renderer instance
|
|
369
|
+
* @param {string} text
|
|
370
|
+
* @param {number} x
|
|
371
|
+
* @param {number} y
|
|
372
|
+
*/
|
|
373
|
+
drawStroke(renderer, text, x, y) {
|
|
374
|
+
this.draw(renderer, text, x, y);
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
/**
|
|
378
|
+
* @ignore
|
|
379
|
+
*/
|
|
380
|
+
_drawFont(context, text, x, y) {
|
|
381
|
+
setContextStyle(context, this);
|
|
382
|
+
|
|
383
|
+
for (let i = 0; i < text.length; i++) {
|
|
384
|
+
const string = text[i].trimEnd();
|
|
385
|
+
// draw the string
|
|
386
|
+
if (this.fillStyle.alpha > 0) {
|
|
387
|
+
context.fillText(string, x, y);
|
|
388
|
+
}
|
|
389
|
+
// stroke the text
|
|
390
|
+
if (this.lineWidth > 0 && this.strokeStyle.alpha > 0) {
|
|
391
|
+
context.strokeText(string, x, y);
|
|
392
|
+
}
|
|
393
|
+
// add leading space
|
|
394
|
+
y += this.metrics.lineHeight();
|
|
395
|
+
}
|
|
396
|
+
return this.metrics;
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
/**
|
|
400
|
+
* Destroy function
|
|
401
|
+
* @ignore
|
|
402
|
+
*/
|
|
403
|
+
destroy() {
|
|
404
|
+
if (typeof renderer.gl !== "undefined") {
|
|
405
|
+
// make sure the right compositor is active
|
|
406
|
+
renderer.setCompositor("quad");
|
|
407
|
+
renderer.currentCompositor.deleteTexture2D(renderer.currentCompositor.getTexture2D(this.glTextureUnit));
|
|
408
|
+
this.glTextureUnit = undefined;
|
|
409
|
+
}
|
|
410
|
+
renderer.cache.delete(this.canvasTexture.canvas);
|
|
411
|
+
pool.push(this.canvasTexture);
|
|
412
|
+
this.canvasTexture = undefined;
|
|
413
|
+
pool.push(this.fillStyle);
|
|
414
|
+
pool.push(this.strokeStyle);
|
|
415
|
+
this.fillStyle = this.strokeStyle = undefined;
|
|
416
|
+
this.metrics = undefined;
|
|
417
|
+
this._text.length = 0;
|
|
418
|
+
super.destroy();
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
export { Text as default };
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* melonJS Game Engine - v15.4.0
|
|
3
|
+
* http://www.melonjs.org
|
|
4
|
+
* melonjs is licensed under the MIT License.
|
|
5
|
+
* http://www.opensource.org/licenses/mit-license
|
|
6
|
+
* @copyright (C) 2011 - 2023 Olivier Biot (AltByte Pte Ltd)
|
|
7
|
+
*/
|
|
8
|
+
import Bounds from '../../physics/bounds.js';
|
|
9
|
+
import Text from './text.js';
|
|
10
|
+
import setContextStyle from './textstyle.js';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @classdesc
|
|
14
|
+
* a Text Metrics object that contains helper for text manipulation
|
|
15
|
+
* @augments Bounds
|
|
16
|
+
*/
|
|
17
|
+
class TextMetrics extends Bounds {
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* @param {Text|BitmapText} ancestor - the parent object that contains this TextMetrics object
|
|
21
|
+
*/
|
|
22
|
+
constructor(ancestor) {
|
|
23
|
+
|
|
24
|
+
// parent constructor
|
|
25
|
+
super();
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* a reference to the parent object that contains this TextMetrics object
|
|
29
|
+
* @public
|
|
30
|
+
* @type {Renderable}
|
|
31
|
+
* @default undefined
|
|
32
|
+
*/
|
|
33
|
+
this.ancestor = ancestor;
|
|
34
|
+
|
|
35
|
+
this.setMinMax(0, 0, 0, 0);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Returns the height of a segment of inline text in CSS pixels.
|
|
40
|
+
* @returns {number} the height of a segment of inline text in CSS pixels.
|
|
41
|
+
*/
|
|
42
|
+
lineHeight() {
|
|
43
|
+
if (this.ancestor instanceof Text) {
|
|
44
|
+
return this.ancestor.fontSize * this.ancestor.lineHeight;
|
|
45
|
+
} else { // it's a BitmapText
|
|
46
|
+
return this.ancestor.fontData.capHeight * this.ancestor.lineHeight * this.ancestor.fontScale.y;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Returns the width of the given segment of inline text in CSS pixels.
|
|
52
|
+
* @param {string} text - the text to be measured
|
|
53
|
+
* @param {CanvasRenderingContext2D} [context] - reference to an active 2d context for canvas rendering
|
|
54
|
+
* @returns {number} the width of the given segment of inline text in CSS pixels.
|
|
55
|
+
*/
|
|
56
|
+
lineWidth(text, context) {
|
|
57
|
+
if (this.ancestor instanceof Text) {
|
|
58
|
+
return context.measureText(text).width;
|
|
59
|
+
} else { // it's a BitmapText
|
|
60
|
+
let characters = text.split("");
|
|
61
|
+
let width = 0;
|
|
62
|
+
let lastGlyph = null;
|
|
63
|
+
for (let i = 0; i < characters.length; i++) {
|
|
64
|
+
let ch = characters[i].charCodeAt(0);
|
|
65
|
+
let glyph = this.ancestor.fontData.glyphs[ch];
|
|
66
|
+
if (typeof glyph !== "undefined") {
|
|
67
|
+
let kerning = (lastGlyph && lastGlyph.kerning) ? lastGlyph.getKerning(ch) : 0;
|
|
68
|
+
width += (glyph.xadvance + kerning) * this.ancestor.fontScale.x;
|
|
69
|
+
lastGlyph = glyph;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return width;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* measure the given text size in CSS pixels
|
|
78
|
+
* @param {string} text - the text to be measured
|
|
79
|
+
* @param {CanvasRenderingContext2D} [context] - reference to an active 2d context for canvas rendering
|
|
80
|
+
* @returns {TextMetrics} this
|
|
81
|
+
*/
|
|
82
|
+
measureText(text, context) {
|
|
83
|
+
let strings;
|
|
84
|
+
|
|
85
|
+
if (!Array.isArray(text)) {
|
|
86
|
+
strings = ("" + text).split("\n");
|
|
87
|
+
} else {
|
|
88
|
+
strings = text;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (typeof context !== "undefined") {
|
|
92
|
+
// save the previous context
|
|
93
|
+
context.save();
|
|
94
|
+
|
|
95
|
+
// apply the style font
|
|
96
|
+
setContextStyle(context, this.ancestor);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// compute the bounding box size
|
|
100
|
+
this.width = this.height = 0;
|
|
101
|
+
|
|
102
|
+
for (let i = 0; i < strings.length; i++) {
|
|
103
|
+
this.width = Math.max(this.lineWidth(strings[i].trimEnd(), context), this.width);
|
|
104
|
+
this.height += this.lineHeight();
|
|
105
|
+
}
|
|
106
|
+
this.width = Math.ceil(this.width);
|
|
107
|
+
this.height = Math.ceil(this.height);
|
|
108
|
+
|
|
109
|
+
// compute the bounding box position
|
|
110
|
+
this.x = Math.floor((this.ancestor.textAlign === "right" ? this.ancestor.pos.x - this.width : (
|
|
111
|
+
this.ancestor.textAlign === "center" ? this.ancestor.pos.x - (this.width / 2) : this.ancestor.pos.x
|
|
112
|
+
)));
|
|
113
|
+
this.y = Math.floor((this.ancestor.textBaseline.search(/^(top|hanging)$/) === 0) ? this.ancestor.pos.y : (
|
|
114
|
+
this.ancestor.textBaseline === "middle" ? this.ancestor.pos.y - (this.lineHeight() / 2) : this.ancestor.pos.y - this.lineHeight()
|
|
115
|
+
));
|
|
116
|
+
|
|
117
|
+
if (typeof context !== "undefined") {
|
|
118
|
+
// restore the context
|
|
119
|
+
context.restore();
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
return this;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* wrap the given text based on the given width
|
|
127
|
+
* @param {string|string[]} text - the text to be wrapped
|
|
128
|
+
* @param {number} width - maximum width of one segment of text in css pixel
|
|
129
|
+
* @param {CanvasRenderingContext2D} [context] - reference to an active 2d context for canvas rendering
|
|
130
|
+
* @returns {string[]} an array of string representing wrapped text
|
|
131
|
+
*/
|
|
132
|
+
wordWrap(text, width, context) {
|
|
133
|
+
let words;
|
|
134
|
+
let currentLine = "";
|
|
135
|
+
let output = [];
|
|
136
|
+
|
|
137
|
+
if (Array.isArray(text)) {
|
|
138
|
+
// join into a single string
|
|
139
|
+
text = text.join(" ");
|
|
140
|
+
}
|
|
141
|
+
// word splitting to be improved as it replaces \n by space if present
|
|
142
|
+
words = text.replace(/[\r\n]+/g, " ").split(" ");
|
|
143
|
+
|
|
144
|
+
if (typeof context !== "undefined") {
|
|
145
|
+
// save the previous context
|
|
146
|
+
context.save();
|
|
147
|
+
|
|
148
|
+
// apply the style font
|
|
149
|
+
setContextStyle(context, this.ancestor);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
for (let i = 0; i < words.length; i++) {
|
|
153
|
+
let word = words[i];
|
|
154
|
+
let lineWidth = this.lineWidth(currentLine + word + " ", context);
|
|
155
|
+
if (lineWidth < width) {
|
|
156
|
+
// add the word to the current line
|
|
157
|
+
currentLine += word + " ";
|
|
158
|
+
} else {
|
|
159
|
+
output.push(currentLine + "\n");
|
|
160
|
+
currentLine = word + " ";
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
// last line
|
|
164
|
+
output.push(currentLine);
|
|
165
|
+
|
|
166
|
+
if (typeof context !== "undefined") {
|
|
167
|
+
// restore the context
|
|
168
|
+
context.restore();
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
return output;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
export { TextMetrics as default };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* melonJS Game Engine - v15.4.0
|
|
3
|
+
* http://www.melonjs.org
|
|
4
|
+
* melonjs is licensed under the MIT License.
|
|
5
|
+
* http://www.opensource.org/licenses/mit-license
|
|
6
|
+
* @copyright (C) 2011 - 2023 Olivier Biot (AltByte Pte Ltd)
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* apply the current text style to the given context
|
|
10
|
+
* @ignore
|
|
11
|
+
*/
|
|
12
|
+
function setContextStyle(context, style) {
|
|
13
|
+
context.font = style.font;
|
|
14
|
+
context.fillStyle = style.fillStyle.toRGBA();
|
|
15
|
+
context.strokeStyle = style.strokeStyle.toRGBA();
|
|
16
|
+
context.lineWidth = style.lineWidth;
|
|
17
|
+
context.textAlign = style.textAlign;
|
|
18
|
+
context.textBaseline = style.textBaseline;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export { setContextStyle as default };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* melonJS Game Engine - v15.
|
|
2
|
+
* melonJS Game Engine - v15.4.0
|
|
3
3
|
* http://www.melonjs.org
|
|
4
4
|
* melonjs is licensed under the MIT License.
|
|
5
5
|
* http://www.opensource.org/licenses/mit-license
|
|
@@ -16,7 +16,7 @@ import pool from '../system/pooling.js';
|
|
|
16
16
|
* trigger an event when colliding with another object
|
|
17
17
|
* @augments Renderable
|
|
18
18
|
*/
|
|
19
|
-
|
|
19
|
+
class Trigger extends Renderable {
|
|
20
20
|
/**
|
|
21
21
|
* @param {number} x - the x coordinates of the trigger area
|
|
22
22
|
* @param {number} y - the y coordinates of the trigger area
|
|
@@ -92,14 +92,14 @@ import pool from '../system/pooling.js';
|
|
|
92
92
|
/**
|
|
93
93
|
* @ignore
|
|
94
94
|
*/
|
|
95
|
-
|
|
95
|
+
getTriggerSettings() {
|
|
96
96
|
let world = this.ancestor.getRootAncestor();
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
97
|
+
// Lookup for the container instance
|
|
98
|
+
if (typeof(this.triggerSettings.container) === "string") {
|
|
99
|
+
this.triggerSettings.container = world.getChildByName(this.triggerSettings.container)[0];
|
|
100
|
+
}
|
|
101
|
+
return this.triggerSettings;
|
|
102
|
+
}
|
|
103
103
|
|
|
104
104
|
/**
|
|
105
105
|
* @ignore
|
|
@@ -128,7 +128,7 @@ import pool from '../system/pooling.js';
|
|
|
128
128
|
if (!this.fading) {
|
|
129
129
|
this.fading = true;
|
|
130
130
|
world.app.viewport.fadeIn(this.fade, this.duration,
|
|
131
|
-
|
|
131
|
+
() => this.onFadeComplete());
|
|
132
132
|
}
|
|
133
133
|
} else {
|
|
134
134
|
level.load(this.gotolevel, triggerSettings);
|