melonjs 20.12.0 → 20.13.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 +2 -1
- package/build/camera/camera2d.d.ts +2 -0
- package/build/camera/camera2d.d.ts.map +1 -1
- package/build/camera/effects/fade_effect.d.ts.map +1 -1
- package/build/geometries/ellipse.d.ts +3 -0
- package/build/geometries/ellipse.d.ts.map +1 -1
- package/build/geometries/line.d.ts.map +1 -1
- package/build/geometries/polygon.d.ts +2 -1
- package/build/geometries/polygon.d.ts.map +1 -1
- package/build/index.d.ts +13 -2
- package/build/index.d.ts.map +1 -1
- package/build/index.js +5409 -1500
- package/build/index.js.map +4 -4
- package/build/input/gamepad.d.ts.map +1 -1
- package/build/input/pointerevent.d.ts.map +1 -1
- package/build/level/tiled/TMXLayer.d.ts +48 -14
- package/build/level/tiled/TMXLayer.d.ts.map +1 -1
- package/build/level/tiled/TMXTileMap.d.ts +1 -1
- package/build/level/tiled/TMXTileMap.d.ts.map +1 -1
- package/build/level/tiled/TMXTileset.d.ts.map +1 -1
- package/build/level/tiled/TMXUtils.d.ts.map +1 -1
- package/build/level/tiled/renderer/TMXHexagonalRenderer.d.ts.map +1 -1
- package/build/level/tiled/renderer/TMXIsometricRenderer.d.ts.map +1 -1
- package/build/level/tiled/renderer/TMXObliqueRenderer.d.ts.map +1 -1
- package/build/level/tiled/renderer/TMXOrthogonalRenderer.d.ts.map +1 -1
- package/build/level/tiled/renderer/TMXRenderer.d.ts +1 -1
- package/build/level/tiled/renderer/TMXRenderer.d.ts.map +1 -1
- package/build/level/tiled/renderer/TMXStaggeredRenderer.d.ts.map +1 -1
- package/build/loader/loader.d.ts +55 -11
- package/build/loader/loader.d.ts.map +1 -1
- package/build/math/color.d.ts.map +1 -1
- package/build/math/math.d.ts +6 -1
- package/build/math/math.d.ts.map +1 -1
- package/build/math/observableVector2d.d.ts +6 -6
- package/build/math/observableVector2d.d.ts.map +1 -1
- package/build/math/observableVector3d.d.ts +8 -8
- package/build/math/observableVector3d.d.ts.map +1 -1
- package/build/particles/emitter.d.ts +15 -3
- package/build/particles/emitter.d.ts.map +1 -1
- package/build/particles/particle.d.ts +6 -0
- package/build/particles/particle.d.ts.map +1 -1
- package/build/particles/settings.d.ts +22 -5
- package/build/particles/settings.d.ts.map +1 -1
- package/build/physics/builtin/body.d.ts +14 -4
- package/build/physics/builtin/body.d.ts.map +1 -1
- package/build/physics/builtin/raycast.d.ts.map +1 -1
- package/build/physics/world.d.ts.map +1 -1
- package/build/renderable/container.d.ts +40 -6
- package/build/renderable/container.d.ts.map +1 -1
- package/build/renderable/frameAnimation.d.ts.map +1 -1
- package/build/renderable/renderable.d.ts.map +1 -1
- package/build/renderable/sprite.d.ts +4 -2
- package/build/renderable/sprite.d.ts.map +1 -1
- package/build/renderable/text/bitmaptext.d.ts +12 -3
- package/build/renderable/text/bitmaptext.d.ts.map +1 -1
- package/build/renderable/text/text.d.ts +147 -4
- package/build/renderable/text/text.d.ts.map +1 -1
- package/build/renderable/text/textmetrics.d.ts +10 -2
- package/build/renderable/text/textmetrics.d.ts.map +1 -1
- package/build/renderable/text/textstyle.d.ts.map +1 -1
- package/build/renderable/ui/panelpaint.d.ts +5 -1
- package/build/renderable/ui/panelpaint.d.ts.map +1 -1
- package/build/renderable/ui/progressbar.d.ts +267 -95
- package/build/renderable/ui/progressbar.d.ts.map +1 -1
- package/build/renderable/ui/uibaseelement.d.ts +436 -50
- package/build/renderable/ui/uibaseelement.d.ts.map +1 -1
- package/build/renderable/ui/uicheckbox.d.ts +383 -0
- package/build/renderable/ui/uicheckbox.d.ts.map +1 -0
- package/build/renderable/ui/uifocus.d.ts +6 -0
- package/build/renderable/ui/uifocus.d.ts.map +1 -0
- package/build/renderable/ui/uilabel.d.ts +31 -0
- package/build/renderable/ui/uilabel.d.ts.map +1 -0
- package/build/renderable/ui/uipanel.d.ts +589 -116
- package/build/renderable/ui/uipanel.d.ts.map +1 -1
- package/build/renderable/ui/uiskin.d.ts +25 -0
- package/build/renderable/ui/uiskin.d.ts.map +1 -0
- package/build/renderable/ui/uislider.d.ts +518 -0
- package/build/renderable/ui/uislider.d.ts.map +1 -0
- package/build/renderable/ui/uispriteelement.d.ts +161 -85
- package/build/renderable/ui/uispriteelement.d.ts.map +1 -1
- package/build/renderable/ui/uitextbutton.d.ts +369 -63
- package/build/renderable/ui/uitextbutton.d.ts.map +1 -1
- package/build/state/stage.d.ts.map +1 -1
- package/build/system/pool.d.ts.map +1 -1
- package/build/system/save.d.ts +2 -1
- package/build/system/save.d.ts.map +1 -1
- package/build/tweens/tween.d.ts +5 -2
- package/build/tweens/tween.d.ts.map +1 -1
- package/build/utils/fetchdata.d.ts.map +1 -1
- package/build/video/canvas/canvas_renderer.d.ts +0 -5
- package/build/video/canvas/canvas_renderer.d.ts.map +1 -1
- package/build/video/renderer.d.ts +20 -4
- package/build/video/renderer.d.ts.map +1 -1
- package/build/video/renderstate.d.ts +26 -3
- package/build/video/renderstate.d.ts.map +1 -1
- package/build/video/utils/tessellation.d.ts +11 -0
- package/build/video/utils/tessellation.d.ts.map +1 -1
- package/build/video/webgl/webgl_renderer.d.ts +3 -6
- package/build/video/webgl/webgl_renderer.d.ts.map +1 -1
- package/build/video/webgpu/batchers/primitive_batcher.d.ts.map +1 -1
- package/build/video/webgpu/webgpu_renderer.d.ts +3 -6
- package/build/video/webgpu/webgpu_renderer.d.ts.map +1 -1
- package/package.json +1 -1
- package/skills/melonjs/SKILL.md +3 -3
- package/skills/melonjs-audio/SKILL.md +7 -5
- package/skills/melonjs-camera-and-drawing/SKILL.md +41 -1
- package/skills/melonjs-effects-and-shaders/SKILL.md +1 -0
- package/skills/melonjs-events/SKILL.md +3 -1
- package/skills/melonjs-getting-started/SKILL.md +1 -2
- package/skills/melonjs-input/SKILL.md +38 -2
- package/skills/melonjs-loading-assets/SKILL.md +53 -12
- package/skills/melonjs-math/SKILL.md +14 -3
- package/skills/melonjs-particles-and-trails/SKILL.md +72 -8
- package/skills/melonjs-physics/SKILL.md +53 -4
- package/skills/melonjs-plugins/SKILL.md +7 -2
- package/skills/melonjs-renderables/SKILL.md +7 -0
- package/skills/melonjs-scenes-and-state/SKILL.md +15 -0
- package/skills/melonjs-sprites-and-animation/SKILL.md +14 -0
- package/skills/melonjs-tilemaps/SKILL.md +96 -2
- package/skills/melonjs-ui-and-text/SKILL.md +560 -23
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"text.d.ts","sourceRoot":"","sources":["../../../src/renderable/text/text.js"],"names":[],"mappings":"AAiDA
|
|
1
|
+
{"version":3,"file":"text.d.ts","sourceRoot":"","sources":["../../../src/renderable/text/text.js"],"names":[],"mappings":"AAiDA;;;;;;;;;;;;;;;;GAgBG;AACH;IACC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA8GG;IACH,eA9GW,MAAM,KACN,MAAM,YAEd;QAAyB,IAAI,EAArB,MAAM;QACkB,IAAI,EAA5B,MAAM,GAAC,MAAM;QACoB,SAAS;QACvB,eAAe;QACV,WAAW;QACjB,SAAS;QACQ,QAAQ;QACzB,UAAU;QACD,UAAU;QACnB,SAAS;QACT,YAAY;QACZ,UAAU;QACmB,WAAW;eAAvC,MAAM;eAAG,MAAM;;QAChB,aAAa;QACZ,IAAI;QACJ,MAAM;QACI,IAAI;KACzC,EA2PF;IA7JA;;;;OAIG;IACH,WAHU,KAAK,CAGwB;IAEvC;;;;OAIG;IACH,aAHU,KAAK,CAG0B;IAEzC;;;;OAIG;IACH,WAHU,MAAM,CAGE;IAElB;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA4BG;IACH,UAfU,OAAO,GAAC,OAAO,GAAC,OAAO,CAeV;IAEvB;;;;;;;;;;;;;;;;;OAiBG;IACH,YARU,MAAM,CAQI;IAEpB;;;;;;;;;;;;;;;;;;;;;;;;;;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
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
|
|
1
2
|
export default TextMetrics;
|
|
2
3
|
/**
|
|
3
4
|
* a Text Metrics object that contains helper for text manipulation
|
|
@@ -36,12 +37,19 @@ declare class TextMetrics extends Bounds {
|
|
|
36
37
|
glyphMaxBottom: number | undefined;
|
|
37
38
|
inkPadTop: number | undefined;
|
|
38
39
|
inkPadBottom: number | undefined;
|
|
40
|
+
inkPadLeft: number | undefined;
|
|
41
|
+
inkPadRight: number | undefined;
|
|
39
42
|
/**
|
|
40
|
-
* wrap the given text based on the given width
|
|
43
|
+
* wrap the given text based on the given width.
|
|
44
|
+
*
|
|
45
|
+
* Each `\n`-separated line (each entry, for an array) is wrapped on its
|
|
46
|
+
* own, so wrapping only ever adds line breaks: the explicit ones are kept,
|
|
47
|
+
* blank lines included. A line breaks between words, never inside one: a
|
|
48
|
+
* word wider than `width` is put on a line of its own and overflows it.
|
|
41
49
|
* @param {string|string[]} text - the text to be wrapped
|
|
42
50
|
* @param {number} width - maximum width of one segment of text in css pixel
|
|
43
51
|
* @param {CanvasRenderingContext2D} [context] - reference to an active 2d context for canvas rendering
|
|
44
|
-
* @returns {string[]} an array of string representing wrapped text
|
|
52
|
+
* @returns {string[]} an array of string representing wrapped text, one entry per line
|
|
45
53
|
*/
|
|
46
54
|
wordWrap(text: string | string[], width: number, context?: CanvasRenderingContext2D): string[];
|
|
47
55
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"textmetrics.d.ts","sourceRoot":"","sources":["../../../src/renderable/text/textmetrics.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"textmetrics.d.ts","sourceRoot":"","sources":["../../../src/renderable/text/textmetrics.js"],"names":[],"mappings":"AA+BA;;;;;;;GAOG;AACH,gCALW,MAAM,GAAC,MAAM,GAAC,MAAM,EAAE,GAAC,IAAI,GACzB,MAAM,EAAE,CAWpB;AAED;;;;;;;;GAQG;AACH,6BANW,MAAM,EAAE,KACR,MAAM,EAAE,GACN,OAAO,CAcnB;;AAaD;;GAEG;AACH;IACC;;OAEG;IACH,sBAFW,IAAI,GAAC,UAAU,EAczB;IARA;;;;OAIG;IACH,UAHU,UAAU,CAGI;IAKzB;;;OAGG;IACH,cAFa,MAAM,CAalB;IAED;;;;;OAKG;IACH,gBAJW,MAAM,YACN,wBAAwB,GACtB,MAAM,CA4BlB;IAED;;;;;OAKG;IACH,kBAJW,MAAM,YACN,wBAAwB,GACtB,WAAW,CAuJvB;IArHA,iCAAqB;IACrB,mCAAuB;IAyCvB,8BAAkB;IAClB,iCAAqB;IACrB,+BAAmB;IACnB,gCAAoB;IA0ErB;;;;;;;;;;;;;;;;;;;;;OAqBG;IACH,gBAJa,WAAW,CAcvB;IAED;;;;;;;;;;;OAWG;IACH,cAJa,MAAM,CAclB;IAED;;;;;;;;;;;OAWG;IACH,eALW,MAAM,GAAC,MAAM,EAAE,SACf,MAAM,YACN,wBAAwB,GACtB,MAAM,EAAE,CA8CpB;CACD;uBAxasB,yBAAyB;4BAOrB,kBAAkB;iBAN5B,WAAW;4BAKD,iBAAiB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"textstyle.d.ts","sourceRoot":"","sources":["../../../src/renderable/text/textstyle.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"textstyle.d.ts","sourceRoot":"","sources":["../../../src/renderable/text/textstyle.js"],"names":[],"mappings":"AAwFA;;;;;;;;;;;;GAYG;AACH,mCALW,MAAM,GACJ,MAAM,CAclB;AAED;;;;;;;;GAQG;AACH,iDAPW,wBAAwB,SACxB,MAAM,GACJ,MAAM,GAAC,cAAc,CAgBjC"}
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { Color } from "../../math/color.ts";
|
|
2
2
|
import type { Gradient } from "../../video/gradient.js";
|
|
3
|
-
/**
|
|
3
|
+
/**
|
|
4
|
+
* A colour a widget is painted with: a CSS string, a {@link Color} (kept
|
|
5
|
+
* and read every frame, so changing it animates the widget), or a gradient.
|
|
6
|
+
* @category UI
|
|
7
|
+
*/
|
|
4
8
|
export type Paint = Color | string | Gradient;
|
|
5
9
|
//# sourceMappingURL=panelpaint.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"panelpaint.d.ts","sourceRoot":"","sources":["../../../src/renderable/ui/panelpaint.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,EAAa,MAAM,qBAAqB,CAAC;AACvD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AAGxD
|
|
1
|
+
{"version":3,"file":"panelpaint.d.ts","sourceRoot":"","sources":["../../../src/renderable/ui/panelpaint.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,EAAa,MAAM,qBAAqB,CAAC;AACvD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AAGxD;;;;GAIG;AACH,MAAM,MAAM,KAAK,GAAG,KAAK,GAAG,MAAM,GAAG,QAAQ,CAAC"}
|
|
@@ -10,147 +10,298 @@ import type { Paint } from "./panelpaint.ts";
|
|
|
10
10
|
* the event module; this gets the same set without widening that surface.
|
|
11
11
|
*/
|
|
12
12
|
type EventName = Parameters<typeof on>[0];
|
|
13
|
-
/**
|
|
13
|
+
/**
|
|
14
|
+
* Which edge a {@link ProgressBar}'s fill grows from: `"left-to-right"`
|
|
15
|
+
* and `"right-to-left"` for a horizontal bar, `"top-to-bottom"` and
|
|
16
|
+
* `"bottom-to-top"` for a vertical one.
|
|
17
|
+
* @category UI
|
|
18
|
+
*/
|
|
14
19
|
export type ProgressBarDirection = "left-to-right" | "right-to-left" | "top-to-bottom" | "bottom-to-top";
|
|
15
20
|
/**
|
|
16
|
-
*
|
|
21
|
+
* The settings a {@link ProgressBar} takes. Only `width` and `height` are
|
|
22
|
+
* required.
|
|
23
|
+
* @category UI
|
|
17
24
|
*/
|
|
18
25
|
export interface ProgressBarSettings {
|
|
19
26
|
/** the bar's full width, in pixels */
|
|
20
27
|
width: number;
|
|
21
28
|
/** the bar's full height, in pixels */
|
|
22
29
|
height: number;
|
|
23
|
-
/**
|
|
30
|
+
/**
|
|
31
|
+
* the value that shows as empty
|
|
32
|
+
* @default 0
|
|
33
|
+
*/
|
|
24
34
|
min?: number;
|
|
25
|
-
/**
|
|
35
|
+
/**
|
|
36
|
+
* the value that shows as full; given below `min`, the two are swapped
|
|
37
|
+
* @default 1
|
|
38
|
+
*/
|
|
26
39
|
max?: number;
|
|
27
|
-
/**
|
|
40
|
+
/**
|
|
41
|
+
* the starting value, clamped between `min` and `max`; `min` if not given
|
|
42
|
+
*/
|
|
28
43
|
value?: number;
|
|
29
|
-
/**
|
|
44
|
+
/**
|
|
45
|
+
* which edge the fill grows from; see {@link ProgressBarDirection}
|
|
46
|
+
* @default "left-to-right"
|
|
47
|
+
*/
|
|
30
48
|
direction?: ProgressBarDirection;
|
|
31
|
-
/**
|
|
49
|
+
/**
|
|
50
|
+
* the colour behind the fill; `null` leaves it hollow, showing whatever
|
|
51
|
+
* is behind the bar
|
|
52
|
+
* @default null
|
|
53
|
+
*/
|
|
32
54
|
trackColor?: Paint | null;
|
|
33
55
|
/**
|
|
34
|
-
* the fill
|
|
35
|
-
* one you passed
|
|
56
|
+
* The colour of the fill. A {@link Color} is read again every frame, so
|
|
57
|
+
* changing the one you passed changes the bar.
|
|
58
|
+
* @default "#ffffff"
|
|
36
59
|
*/
|
|
37
60
|
fillColor?: Paint;
|
|
38
|
-
/**
|
|
61
|
+
/**
|
|
62
|
+
* the colour of the border drawn around the bar; `null` for none
|
|
63
|
+
* @default null
|
|
64
|
+
*/
|
|
39
65
|
borderColor?: Paint | null;
|
|
40
|
-
/**
|
|
66
|
+
/**
|
|
67
|
+
* the border's thickness, in pixels, drawn inside the bar's edge
|
|
68
|
+
* @default 1
|
|
69
|
+
*/
|
|
41
70
|
borderWidth?: number;
|
|
42
|
-
/**
|
|
71
|
+
/**
|
|
72
|
+
* the gap between the track's edge and the fill on each side, in pixels
|
|
73
|
+
* @default 0
|
|
74
|
+
*/
|
|
43
75
|
padding?: number;
|
|
44
|
-
/**
|
|
76
|
+
/**
|
|
77
|
+
* the corner radius, in pixels; `0` is square. The fill's corners are
|
|
78
|
+
* reduced by `padding`, so they stay parallel to the track's.
|
|
79
|
+
* @default 0
|
|
80
|
+
*/
|
|
45
81
|
radius?: number;
|
|
46
|
-
/**
|
|
47
|
-
|
|
48
|
-
|
|
82
|
+
/**
|
|
83
|
+
* The colour of a drop shadow under the bar; `null` for none. Its alpha
|
|
84
|
+
* sets how dark the shadow is, e.g. `"#00000066"`.
|
|
85
|
+
* @default null
|
|
86
|
+
*/
|
|
87
|
+
shadowColor?: Paint | null;
|
|
88
|
+
/**
|
|
89
|
+
* how far right the shadow falls, in pixels; negative goes left
|
|
90
|
+
* @default 0
|
|
91
|
+
*/
|
|
92
|
+
shadowOffsetX?: number;
|
|
93
|
+
/**
|
|
94
|
+
* how far down the shadow falls, in pixels; negative goes up
|
|
95
|
+
* @default 4
|
|
96
|
+
*/
|
|
97
|
+
shadowOffsetY?: number;
|
|
98
|
+
/**
|
|
99
|
+
* how far the shadow's soft edge spreads, in pixels; `0` is a sharp edge
|
|
100
|
+
* @default 8
|
|
101
|
+
*/
|
|
102
|
+
shadowBlur?: number;
|
|
103
|
+
/**
|
|
104
|
+
* Called each time the value changes, with the new value, the same as a
|
|
105
|
+
* `0..1` fraction of the way from `min` to `max`, and the bar. Not called
|
|
106
|
+
* when the value is set to what it already is.
|
|
107
|
+
*/
|
|
108
|
+
onChange?: (value: number, ratio: number, bar: ProgressBar) => void;
|
|
109
|
+
/**
|
|
110
|
+
* draw a text label centred over the bar
|
|
111
|
+
* @default false
|
|
112
|
+
*/
|
|
49
113
|
showLabel?: boolean;
|
|
50
|
-
/**
|
|
114
|
+
/**
|
|
115
|
+
* the label's CSS font family
|
|
116
|
+
* @default "sans-serif"
|
|
117
|
+
*/
|
|
51
118
|
font?: string;
|
|
52
|
-
/**
|
|
119
|
+
/**
|
|
120
|
+
* the label's text height, in pixels; 70% of the bar's height (at least
|
|
121
|
+
* 8), rounded, if not given
|
|
122
|
+
*/
|
|
53
123
|
fontSize?: number;
|
|
54
|
-
/**
|
|
124
|
+
/**
|
|
125
|
+
* the label's colour
|
|
126
|
+
* @default "#ffffff"
|
|
127
|
+
*/
|
|
55
128
|
labelFillStyle?: Paint;
|
|
56
|
-
/**
|
|
129
|
+
/**
|
|
130
|
+
* What the label says, given the value and its `0..1` fraction. The
|
|
131
|
+
* default shows a rounded percentage, such as `"75%"`.
|
|
132
|
+
*/
|
|
57
133
|
labelFormat?: (value: number, ratio: number) => string;
|
|
58
134
|
/**
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
* destroyed, which is the point: a subscription that outlives what it
|
|
63
|
-
* drives is a listener writing into a freed object.
|
|
135
|
+
* An event to take the value from, instead of setting it by hand: each
|
|
136
|
+
* time the event fires, its first argument becomes the value. The bar
|
|
137
|
+
* stops listening when it is destroyed.
|
|
64
138
|
*/
|
|
65
139
|
bindEvent?: EventName;
|
|
66
140
|
}
|
|
67
141
|
/**
|
|
68
|
-
* A bar that shows one value between
|
|
142
|
+
* A bar that shows one value between a minimum and a maximum: a health
|
|
143
|
+
* bar, a shield or stamina gauge, a cooldown, a loading bar. Set
|
|
144
|
+
* {@link ProgressBar#value} and it redraws. The engine's own loading screen
|
|
145
|
+
* uses one.
|
|
146
|
+
*
|
|
147
|
+
* It draws its track, fill, border and optional label itself, as one
|
|
148
|
+
* renderable, so there is nothing to keep in step.
|
|
69
149
|
*
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
*
|
|
150
|
+
* ## Look
|
|
151
|
+
* `trackColor` is behind the fill (`null` for a hollow frame), `fillColor`
|
|
152
|
+
* is the fill, `borderColor` and `borderWidth` draw an outline, `padding`
|
|
153
|
+
* insets the fill, and `radius` rounds the corners. `direction` sets which
|
|
154
|
+
* edge the fill grows from, horizontal or vertical.
|
|
73
155
|
*
|
|
74
|
-
*
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
*
|
|
78
|
-
*
|
|
156
|
+
* ## Value
|
|
157
|
+
* `min` and `max` set the range (`0` to `1` by default). A value outside it
|
|
158
|
+
* is clamped. {@link ProgressBar#ratio} gives the value as a `0..1`
|
|
159
|
+
* fraction. `onChange(value, ratio, bar)` is called whenever the value
|
|
160
|
+
* changes, and `bindEvent` takes the value from an event.
|
|
79
161
|
*
|
|
80
|
-
* ##
|
|
162
|
+
* ## Label
|
|
163
|
+
* `showLabel` draws text over the bar, a percentage by default; `labelFormat`
|
|
164
|
+
* changes what it says, and `font`, `fontSize` and `labelFillStyle` how it
|
|
165
|
+
* looks.
|
|
81
166
|
*
|
|
82
|
-
*
|
|
83
|
-
*
|
|
84
|
-
*
|
|
85
|
-
*
|
|
86
|
-
*
|
|
167
|
+
* ## Drop shadow
|
|
168
|
+
* `shadowColor` draws a soft shadow under the bar; its alpha sets how dark
|
|
169
|
+
* it is. `shadowOffsetX` and `shadowOffsetY` move it and `shadowBlur`
|
|
170
|
+
* softens its edge.
|
|
171
|
+
*
|
|
172
|
+
* ## Colour that follows the value
|
|
173
|
+
* `fillColor` is read every frame, not copied, so pass a {@link Color} you
|
|
174
|
+
* keep and change it as the value changes. To make the bar blink, use
|
|
175
|
+
* {@link Renderable#setOpacity}.
|
|
176
|
+
* @category UI
|
|
177
|
+
* @example
|
|
178
|
+
* // a loading bar, fed by the loader
|
|
179
|
+
* import { ProgressBar, event } from "melonjs";
|
|
180
|
+
*
|
|
181
|
+
* const loading = new ProgressBar(0, 300, {
|
|
182
|
+
* width: 800,
|
|
183
|
+
* height: 4,
|
|
184
|
+
* trackColor: "black",
|
|
185
|
+
* fillColor: "#55aa00",
|
|
186
|
+
* bindEvent: event.LOADER_PROGRESS,
|
|
187
|
+
* });
|
|
188
|
+
* app.world.addChild(loading);
|
|
189
|
+
* @example
|
|
190
|
+
* // a health bar with a label, and a range that is not 0 to 1
|
|
191
|
+
* const hp = new ProgressBar(20, 20, {
|
|
192
|
+
* width: 200,
|
|
193
|
+
* height: 24,
|
|
194
|
+
* min: 0,
|
|
195
|
+
* max: 100,
|
|
196
|
+
* value: 100,
|
|
197
|
+
* trackColor: "#3a1010",
|
|
198
|
+
* fillColor: "#c0392b",
|
|
199
|
+
* radius: 6,
|
|
200
|
+
* showLabel: true,
|
|
201
|
+
* labelFormat: (value) => `${Math.round(value)} HP`,
|
|
202
|
+
* });
|
|
203
|
+
* // when the player is hit
|
|
204
|
+
* hp.value -= 15;
|
|
205
|
+
* @example
|
|
206
|
+
* // a colour that follows the value, from red when empty to blue when full
|
|
207
|
+
* import { ProgressBar, Color } from "melonjs";
|
|
87
208
|
*
|
|
88
|
-
* ```js
|
|
89
209
|
* const full = new Color().parseCSS("#7fe0ff");
|
|
90
210
|
* const empty = new Color().parseCSS("#ff2a1e");
|
|
91
|
-
* const mixed =
|
|
92
|
-
*
|
|
93
|
-
*
|
|
94
|
-
*
|
|
95
|
-
*
|
|
211
|
+
* const mixed = full.clone();
|
|
212
|
+
* const shield = new ProgressBar(20, 52, {
|
|
213
|
+
* width: 190,
|
|
214
|
+
* height: 13,
|
|
215
|
+
* value: 1,
|
|
216
|
+
* trackColor: null, // a hollow frame
|
|
96
217
|
* borderColor: "rgba(122, 190, 235, 0.8)",
|
|
97
218
|
* padding: 2,
|
|
98
|
-
*
|
|
219
|
+
* radius: 4,
|
|
220
|
+
* fillColor: mixed, // kept, not copied
|
|
221
|
+
* onChange: (value, ratio) => {
|
|
222
|
+
* mixed.copy(empty).lerp(full, ratio);
|
|
223
|
+
* },
|
|
99
224
|
* });
|
|
100
|
-
*
|
|
101
|
-
* // each frame
|
|
102
|
-
* mixed.copy(empty).lerp(full, hp);
|
|
103
|
-
* shield.value = hp;
|
|
104
|
-
* ```
|
|
105
|
-
*
|
|
106
|
-
* Blinking is the same story: {@link Renderable#setOpacity} already does it,
|
|
107
|
-
* on whatever clock the game is already keeping.
|
|
108
|
-
* @category UI
|
|
109
225
|
* @example
|
|
110
|
-
* // a
|
|
111
|
-
* const
|
|
112
|
-
* width:
|
|
113
|
-
*
|
|
226
|
+
* // a vertical bar that fills from the bottom
|
|
227
|
+
* const power = new ProgressBar(740, 200, {
|
|
228
|
+
* width: 16,
|
|
229
|
+
* height: 120,
|
|
230
|
+
* direction: "bottom-to-top",
|
|
231
|
+
* trackColor: "#222222",
|
|
232
|
+
* fillColor: "#f1c40f",
|
|
233
|
+
* borderColor: "#ffffff",
|
|
234
|
+
* borderWidth: 2,
|
|
235
|
+
* padding: 3,
|
|
114
236
|
* });
|
|
115
|
-
* event.on(event.LOADER_PROGRESS, (progress) => { bar.value = progress; });
|
|
116
237
|
* @example
|
|
117
|
-
* // a
|
|
118
|
-
* const
|
|
119
|
-
* width:
|
|
120
|
-
*
|
|
121
|
-
*
|
|
122
|
-
*
|
|
123
|
-
*
|
|
238
|
+
* // a drop shadow under the bar
|
|
239
|
+
* const xp = new ProgressBar(20, 80, {
|
|
240
|
+
* width: 240,
|
|
241
|
+
* height: 16,
|
|
242
|
+
* trackColor: "#1e1e2e",
|
|
243
|
+
* fillColor: "#9b59b6",
|
|
244
|
+
* radius: 8,
|
|
245
|
+
* shadowColor: "#00000080", // the alpha sets how dark
|
|
246
|
+
* shadowOffsetY: 3,
|
|
247
|
+
* shadowBlur: 6,
|
|
248
|
+
* });
|
|
249
|
+
* @example
|
|
250
|
+
* // react when the bar is emptied
|
|
251
|
+
* const timer = new ProgressBar(20, 110, {
|
|
252
|
+
* width: 200,
|
|
253
|
+
* height: 8,
|
|
254
|
+
* value: 1,
|
|
255
|
+
* fillColor: "#2ecc71",
|
|
256
|
+
* onChange: (value, ratio, bar) => {
|
|
257
|
+
* if (ratio === 0) {
|
|
258
|
+
* bar.setOpacity(0.5);
|
|
259
|
+
* onTimeUp();
|
|
260
|
+
* }
|
|
261
|
+
* },
|
|
124
262
|
* });
|
|
125
263
|
*/
|
|
126
264
|
export default class ProgressBar extends Renderable {
|
|
127
|
-
/** the
|
|
128
|
-
min: number;
|
|
129
|
-
/** the value that reads as full */
|
|
130
|
-
max: number;
|
|
131
|
-
/** which edge the fill grows from */
|
|
265
|
+
/** which edge the fill grows from; see {@link ProgressBarDirection} */
|
|
132
266
|
direction: ProgressBarDirection;
|
|
133
|
-
/** behind the fill; `null` leaves it hollow */
|
|
267
|
+
/** the colour behind the fill; `null` leaves it hollow */
|
|
134
268
|
trackColor: Paint | null;
|
|
135
|
-
/** the fill
|
|
269
|
+
/** the colour of the fill; a {@link Color} here is read every frame */
|
|
136
270
|
fillColor: Paint;
|
|
137
|
-
/**
|
|
271
|
+
/** the colour of the border; `null` for none */
|
|
138
272
|
borderColor: Paint | null;
|
|
139
|
-
/**
|
|
273
|
+
/** the border's thickness, in pixels */
|
|
140
274
|
borderWidth: number;
|
|
141
|
-
/**
|
|
275
|
+
/** the gap between the track's edge and the fill on each side, in pixels */
|
|
142
276
|
padding: number;
|
|
143
|
-
/** corner radius; `0` is square */
|
|
277
|
+
/** the corner radius, in pixels; `0` is square */
|
|
144
278
|
radius: number;
|
|
145
|
-
/**
|
|
146
|
-
|
|
147
|
-
/**
|
|
279
|
+
/** the colour of the drop shadow, its alpha setting how dark; `null` for none */
|
|
280
|
+
shadowColor: Paint | null;
|
|
281
|
+
/** how far right the shadow falls, in pixels */
|
|
282
|
+
shadowOffsetX: number;
|
|
283
|
+
/** how far down the shadow falls, in pixels */
|
|
284
|
+
shadowOffsetY: number;
|
|
285
|
+
/** how far the shadow's soft edge spreads, in pixels */
|
|
286
|
+
shadowBlur: number;
|
|
287
|
+
/**
|
|
288
|
+
* Called each time the value changes, with the new value, its `0..1`
|
|
289
|
+
* fraction from `min` to `max`, and the bar.
|
|
290
|
+
* @example
|
|
291
|
+
* bar.onChange = (value, ratio, bar) => {
|
|
292
|
+
* bar.setOpacity(ratio < 0.25 ? 0.6 : 1);
|
|
293
|
+
* };
|
|
294
|
+
*/
|
|
295
|
+
onChange?: ((value: number, ratio: number, bar: ProgressBar) => void) | undefined;
|
|
296
|
+
/** builds the label's text from the value and its `0..1` fraction */
|
|
148
297
|
labelFormat: (value: number, ratio: number) => string;
|
|
149
|
-
/** the label, when `showLabel` was
|
|
298
|
+
/** the label's text object, when `showLabel` was set */
|
|
150
299
|
label?: Text | undefined;
|
|
151
300
|
/** the event the value is taken from, if any */
|
|
152
301
|
readonly bindEvent?: EventName | undefined;
|
|
153
302
|
private _value;
|
|
303
|
+
private _min;
|
|
304
|
+
private _max;
|
|
154
305
|
/**
|
|
155
306
|
* @param x - position of the bar's left edge
|
|
156
307
|
* @param y - position of its top edge
|
|
@@ -158,22 +309,43 @@ export default class ProgressBar extends Renderable {
|
|
|
158
309
|
*/
|
|
159
310
|
constructor(x: number, y: number, settings: ProgressBarSettings);
|
|
160
311
|
/**
|
|
161
|
-
*
|
|
162
|
-
*
|
|
163
|
-
*
|
|
164
|
-
*
|
|
165
|
-
*
|
|
166
|
-
*
|
|
167
|
-
*
|
|
312
|
+
* The value that shows as empty. Setting it clamps the value into the
|
|
313
|
+
* new range, and a `min` above `max` raises `max` to it, so the bar never
|
|
314
|
+
* draws past its ends. A value moved by the clamp calls `onChange`, as
|
|
315
|
+
* any change of the value does; the label is rewritten either way.
|
|
316
|
+
* @example
|
|
317
|
+
* // a gauge that starts at 50 rather than 0
|
|
318
|
+
* pressure.min = 50;
|
|
319
|
+
*/
|
|
320
|
+
get min(): number;
|
|
321
|
+
set min(v: number);
|
|
322
|
+
/**
|
|
323
|
+
* The value that shows as full. Setting it clamps the value into the
|
|
324
|
+
* new range, and a `max` below `min` lowers `min` to it, so the bar never
|
|
325
|
+
* draws past its ends. A value moved by the clamp calls `onChange`, as
|
|
326
|
+
* any change of the value does; the label is rewritten either way.
|
|
327
|
+
* @example
|
|
328
|
+
* // a debuff lowers the most health the player can have: a full bar
|
|
329
|
+
* // stays full, at the new maximum
|
|
330
|
+
* hp.max = 50;
|
|
331
|
+
*/
|
|
332
|
+
get max(): number;
|
|
333
|
+
set max(v: number);
|
|
334
|
+
/**
|
|
335
|
+
* The current value, between {@link ProgressBar#min} and
|
|
336
|
+
* {@link ProgressBar#max}. Setting it redraws the bar and updates the
|
|
337
|
+
* label. A value outside the range is clamped, and setting the value it
|
|
338
|
+
* already has does nothing, so `onChange` only fires on a real change.
|
|
339
|
+
* @example
|
|
340
|
+
* // a cooldown that refills over 3 seconds
|
|
341
|
+
* cooldown.value = Math.min(1, elapsed / 3000);
|
|
168
342
|
*/
|
|
169
343
|
get value(): number;
|
|
170
344
|
set value(v: number);
|
|
171
345
|
/**
|
|
172
|
-
* The value as a fraction, `0` at `min` and `1` at `max
|
|
173
|
-
*
|
|
174
|
-
*
|
|
175
|
-
* anything else keyed to the same number. Read only; set
|
|
176
|
-
* {@link ProgressBar#value}.
|
|
346
|
+
* The value as a fraction, `0` at `min` and `1` at `max`; how full the
|
|
347
|
+
* bar is drawn. Always within `0..1`, and `0` when `min` equals `max`.
|
|
348
|
+
* Read only: set {@link ProgressBar#value} instead.
|
|
177
349
|
*/
|
|
178
350
|
get ratio(): number;
|
|
179
351
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"progressbar.d.ts","sourceRoot":"","sources":["../../../src/renderable/ui/progressbar.ts"],"names":[],"mappings":"AACA,OAAO,EAAO,EAAE,EAAE,MAAM,uBAAuB,CAAC;AAChD,OAAO,KAAK,QAAQ,MAAM,yBAAyB,CAAC;AACpD,OAAO,UAAU,MAAM,kBAAkB,CAAC;AAC1C,OAAO,IAAI,MAAM,iBAAiB,CAAC;AACnC,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAG7C;;;;;GAKG;AACH,KAAK,SAAS,GAAG,UAAU,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;AAE1C
|
|
1
|
+
{"version":3,"file":"progressbar.d.ts","sourceRoot":"","sources":["../../../src/renderable/ui/progressbar.ts"],"names":[],"mappings":"AACA,OAAO,EAAO,EAA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