@moku-labs/game 0.15.162 → 0.15.163
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/dist/app/page.d.mts +1 -1
- package/dist/app/system.d.mts +2 -2
- package/dist/app.d.mts +2 -2
- package/dist/app.mjs +1 -1
- package/dist/{commands-Gi8RMNnU.d.mts → commands-CAvCuLaL.d.mts} +2 -2
- package/dist/control.d.mts +1 -1
- package/dist/{index-CbMDaUan.d.mts → index-oS9wiCoO.d.mts} +11 -11
- package/dist/index.d.mts +3 -3
- package/dist/index.mjs +1 -1
- package/dist/inspect.d.mts +2 -2
- package/dist/jsx-dev-runtime.d.mts +1 -1
- package/dist/jsx-runtime.d.mts +1 -1
- package/dist/{runtime-CkJJvWKb.d.mts → runtime-Bb5sNTGb.d.mts} +1 -1
- package/dist/{src-mZkN8URR.mjs → src-DBhsppmi.mjs} +902 -261
- package/dist/testing.d.mts +2 -2
- package/dist/testing.mjs +1 -1
- package/dist/{types-CPiWOiSc.d.mts → types-C4d1Ptfc.d.mts} +1881 -39
- package/dist/{types-DkQbqqw0.d.mts → types-SUCTOeQZ.d.mts} +3 -3
- package/dist/types-dSup2_q9.d.mts +1841 -0
- package/dist/{visual-nAxiy1aK.d.mts → visual-BZrQT1r1.d.mts} +2 -3
- package/dist/visual.d.mts +1 -1
- package/package.json +3 -3
- package/dist/types-D8D2ZtEi.d.mts +0 -3632
|
@@ -1,3632 +0,0 @@
|
|
|
1
|
-
import { A as FilterSlotInputs, Ar as Api$3, M as SyncApi, Q as Api$4, Qn as AnchorTarget, Un as TypeTag, Ur as Events$3, Vr as Api$6, Wn as Descriptor, Wr as Json, ar as NumericFields, at as PixiSprite, b as Events$4, bi as Require, br as Entity, bt as FilterCache, cr as ReducedMotion, dr as TrackSegment, gr as ComponentHandle, hr as AnyComponentValue, ir as MotionHandle, it as PixiModule, j as FilterSlotQuad, k as FilterSlot, mn as Api$2, nt as PixiFilter, oi as Events$5, ot as PixiTexture, pr as AnyComponent, rt as PixiGpuProgram, s as Events$1, st as PixiUniformGroup, t as Api$5, tr as Ease, ui as Api$1, ur as TrackOptions, vr as ComponentType, vt as Point, yi as Events$2 } from "./types-DTkhpupa.mjs";
|
|
2
|
-
import { R as InputApi, T as TextApi, U as I18nApi, c as UiNode, i as Finding, l as LayoutState, n as ElementChange, o as JsxState, r as ElementMotion, tt as StylesState } from "./types-CPiWOiSc.mjs";
|
|
3
|
-
import { Log } from "@moku-labs/common/browser";
|
|
4
|
-
import { PluginCtx } from "@moku-labs/core";
|
|
5
|
-
|
|
6
|
-
//#region src/plugins/debug/types.d.ts
|
|
7
|
-
declare namespace types_d_exports$4 {
|
|
8
|
-
export { Api, OverlayApi, OverlayMode };
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* @file debug plugin — type definitions: the overlay call.
|
|
12
|
-
*/
|
|
13
|
-
/**
|
|
14
|
-
* The two visible modes of the editor's overlay: the small pill or the full card.
|
|
15
|
-
*/
|
|
16
|
-
type OverlayMode = "pill" | "card";
|
|
17
|
-
/**
|
|
18
|
-
* The editor's overlay, from the game: open it, close it, toggle it, ask whether it shows. Every call is a no-op that
|
|
19
|
-
* answers `false` on a page without the agent (a release build, a test): no import of the editor, no guard needed.
|
|
20
|
-
*/
|
|
21
|
-
type OverlayApi = {
|
|
22
|
-
/**
|
|
23
|
-
* Shows the overlay: the card, or the pill with `{ mode: "pill" }`.
|
|
24
|
-
*
|
|
25
|
-
* @param options - How the overlay shows.
|
|
26
|
-
* @param options.mode - `"card"` (the default) or `"pill"`.
|
|
27
|
-
* @returns True when an overlay took the call; false on a page without the agent.
|
|
28
|
-
* @example
|
|
29
|
-
* ```ts
|
|
30
|
-
* // A game's own "?" button of its settings sheet opens the overlay of a debug build.
|
|
31
|
-
* app.debug.overlay.open(); // true on `moku-game build --debug`; false on the store build
|
|
32
|
-
* app.debug.overlay.open({ mode: "pill" }); // true: the small pill
|
|
33
|
-
* ```
|
|
34
|
-
*/
|
|
35
|
-
open(options?: {
|
|
36
|
-
mode?: OverlayMode;
|
|
37
|
-
}): boolean;
|
|
38
|
-
/**
|
|
39
|
-
* Hides the overlay.
|
|
40
|
-
*
|
|
41
|
-
* @returns True when an overlay took the call; false without the agent.
|
|
42
|
-
* @example
|
|
43
|
-
* ```ts
|
|
44
|
-
* app.debug.overlay.close(); // true; app.debug.overlay.isOpen() is false after it
|
|
45
|
-
* ```
|
|
46
|
-
*/
|
|
47
|
-
close(): boolean;
|
|
48
|
-
/**
|
|
49
|
-
* Switches between hidden and the last visible mode.
|
|
50
|
-
*
|
|
51
|
-
* @returns True when an overlay took the call; false without the agent.
|
|
52
|
-
* @example
|
|
53
|
-
* ```ts
|
|
54
|
-
* // A game binds a three-finger tap of its own to the overlay.
|
|
55
|
-
* app.debug.overlay.toggle(); // true: shown (the card, or the pill if the pill was the last mode)
|
|
56
|
-
* ```
|
|
57
|
-
*/
|
|
58
|
-
toggle(): boolean;
|
|
59
|
-
/**
|
|
60
|
-
* Tells whether the overlay shows, as the pill or the card.
|
|
61
|
-
*
|
|
62
|
-
* @returns True while it shows; false when hidden and without the agent.
|
|
63
|
-
* @example
|
|
64
|
-
* ```ts
|
|
65
|
-
* app.debug.overlay.open({ mode: "pill" });
|
|
66
|
-
* app.debug.overlay.isOpen(); // true
|
|
67
|
-
* ```
|
|
68
|
-
*/
|
|
69
|
-
isOpen(): boolean;
|
|
70
|
-
};
|
|
71
|
-
/**
|
|
72
|
-
* The `debug` plugin's API: the overlay call.
|
|
73
|
-
*/
|
|
74
|
-
type Api = {
|
|
75
|
-
/**
|
|
76
|
-
* The editor's overlay. Usable anywhere the app is; a no-op without the agent. The ui tag `DebugTrigger` is one
|
|
77
|
-
* helper on top of it.
|
|
78
|
-
*
|
|
79
|
-
* @example
|
|
80
|
-
* ```ts
|
|
81
|
-
* // ui's DebugTrigger, after five taps:
|
|
82
|
-
* ctx.require(debugPlugin).overlay.open(); // true on a debug build
|
|
83
|
-
* ```
|
|
84
|
-
*/
|
|
85
|
-
overlay: OverlayApi;
|
|
86
|
-
};
|
|
87
|
-
//#endregion
|
|
88
|
-
//#region src/plugins/anim/tween/types.d.ts
|
|
89
|
-
/**
|
|
90
|
-
* One running track: the numeric fields of one component of one entity moving from the values
|
|
91
|
-
* read at the end of the delay to the exact target, straight or through keyframe segments. A
|
|
92
|
-
* track with repeats walks again from its first segment each time a run ends.
|
|
93
|
-
*/
|
|
94
|
-
type Track = {
|
|
95
|
-
readonly id: number;
|
|
96
|
-
readonly entity: Entity;
|
|
97
|
-
readonly component: AnyComponent;
|
|
98
|
-
/**
|
|
99
|
-
* The target fields. Retarget deletes the fields a newer absolute track took over. A frame reads
|
|
100
|
-
* the slots (`names`, `targets`, `live`) instead.
|
|
101
|
-
*/
|
|
102
|
-
to: Record<string, number>;
|
|
103
|
-
/**
|
|
104
|
-
* The key of the owner, bases and offsets tables per field, built once when the track starts.
|
|
105
|
-
* It keeps a field `to` lost, which nothing reads again.
|
|
106
|
-
*/
|
|
107
|
-
readonly keys: Readonly<Record<string, string>>;
|
|
108
|
-
readonly ms: number;
|
|
109
|
-
readonly ease: Ease;
|
|
110
|
-
readonly delayMs: number;
|
|
111
|
-
/**
|
|
112
|
-
* `[0]`: the milliseconds the track has run, its delay included; `[1]`: the normalised time of
|
|
113
|
-
* the write that runs. Cells and not fields, so a frame writes them in place: a double stored in
|
|
114
|
-
* an object field is a new heap number.
|
|
115
|
-
*/
|
|
116
|
-
readonly clock: Float64Array; /** True once the start values are read, when the delay ends, never earlier. */
|
|
117
|
-
begun: boolean; /** The target fields in slot order: every field `to` held when the track started. */
|
|
118
|
-
readonly names: readonly string[]; /** The key of each slot: the strings of `keys`, by slot. */
|
|
119
|
-
readonly slotKeys: readonly string[]; /** The target of each slot. */
|
|
120
|
-
readonly targets: Float64Array; /** The start value of each slot, read when the delay ends. */
|
|
121
|
-
readonly starts: Float64Array; /** `1` while the track drives the slot, `0` once a newer absolute track took its field. */
|
|
122
|
-
readonly live: Uint8Array; /** `1` for a slot the frame that runs moved: a write of only some fields reads it. */
|
|
123
|
-
readonly moved: Uint8Array;
|
|
124
|
-
/**
|
|
125
|
-
* Per slot, the numbers of the write that runs: first what the slot contributes, then what the
|
|
126
|
-
* field reads, the base plus every offset. Kept here so no number crosses a call boxed.
|
|
127
|
-
*/
|
|
128
|
-
readonly values: Float64Array; /** `1` for a slot that is a colour field (`isColorField`): it mixes per channel and rounds (F219). */
|
|
129
|
-
readonly colors: Uint8Array;
|
|
130
|
-
/**
|
|
131
|
-
* Per slot, the value this track last left in the field or found there, `NaN` while unknown: at
|
|
132
|
-
* the start and while another writer holds the field. A frame whose value moved off it writes
|
|
133
|
-
* without reading the field back.
|
|
134
|
-
*/
|
|
135
|
-
readonly seen: Float64Array;
|
|
136
|
-
readonly muted: () => ReadonlySet<string>;
|
|
137
|
-
readonly additive: boolean; /** True for a track a timeline step advances by hand; the frame step leaves it alone. */
|
|
138
|
-
readonly driven: boolean; /** The frame step the track was born in. That step does not advance it a second time. */
|
|
139
|
-
readonly bornFrame: number;
|
|
140
|
-
ended: boolean;
|
|
141
|
-
/**
|
|
142
|
-
* The keyframe segments the track walks over `ms`, or `undefined` for a straight track. A
|
|
143
|
-
* segment without an ease runs on the track's `ease`.
|
|
144
|
-
*/
|
|
145
|
-
readonly segments: readonly TrackSegment[] | undefined;
|
|
146
|
-
/**
|
|
147
|
-
* The runs still to go after the one that plays: `0` for a track that runs once, `Infinity`
|
|
148
|
-
* for a loop (`repeat: "forever"`), which never ends by itself.
|
|
149
|
-
*/
|
|
150
|
-
repeatsLeft: number;
|
|
151
|
-
/**
|
|
152
|
-
* True while a loop stands on its first key and has written it: the hold writes once, and the
|
|
153
|
-
* walk clears it, so the next hold writes the first key again.
|
|
154
|
-
*/
|
|
155
|
-
held: boolean;
|
|
156
|
-
/**
|
|
157
|
-
* The fields an additive track skipped at its last write because another writer owned them.
|
|
158
|
-
* When such a field is given back, the track adds to the value it finds there and not to the
|
|
159
|
-
* base it kept. Empty for a track that owns its fields.
|
|
160
|
-
*/
|
|
161
|
-
masked: Set<string>; /** Started with `reduced: "keep"`: reduced motion neither shortens nor holds it. */
|
|
162
|
-
readonly keep: boolean;
|
|
163
|
-
/**
|
|
164
|
-
* What the track writes that could show its view again, handed to `renderer.sync.loopsHeld` by an endless track
|
|
165
|
-
* (spec 26 R1.7.4): `"alpha"`, `"place"` (where the view is or how large), `"both"`, or `undefined` for a write
|
|
166
|
-
* that cannot (a tint, a fill colour). Computed once when the track is made.
|
|
167
|
-
*/
|
|
168
|
-
readonly reveals: "alpha" | "place" | "both" | undefined;
|
|
169
|
-
/**
|
|
170
|
-
* The patch the track writes when a frame moves every field, one per track with every field of
|
|
171
|
-
* `to` in it: a frame fills it in place instead of building one. Rebuilt when the track loses a
|
|
172
|
-
* field.
|
|
173
|
-
*/
|
|
174
|
-
patch: Record<string, unknown>;
|
|
175
|
-
/**
|
|
176
|
-
* The patch of a frame that moves only some fields (another writer holds one, or one stands
|
|
177
|
-
* still): exactly the fields `partialMoved` flags, filled in place by the next frame that moves
|
|
178
|
-
* the same ones and built again when they change, so a field the track lost, which never moves
|
|
179
|
-
* again, is never in it. `undefined` until the first such frame.
|
|
180
|
-
*/
|
|
181
|
-
partial: Record<string, unknown> | undefined; /** The `moved` flags `partial` was built for, by slot. */
|
|
182
|
-
readonly partialMoved: Uint8Array;
|
|
183
|
-
};
|
|
184
|
-
/**
|
|
185
|
-
* A motion handle that can also be advanced by hand: what the timeline cursor needs, so a track
|
|
186
|
-
* born inside a frame step still consumes the remainder of that step's delta.
|
|
187
|
-
*/
|
|
188
|
-
type StepMotion = MotionHandle & {
|
|
189
|
-
/**
|
|
190
|
-
* Advances the track by one delta.
|
|
191
|
-
*
|
|
192
|
-
* @param deltaMs - Milliseconds of game time to consume.
|
|
193
|
-
* @returns The milliseconds left over past the end of the track.
|
|
194
|
-
*/
|
|
195
|
-
advance(deltaMs: number): number;
|
|
196
|
-
};
|
|
197
|
-
//#endregion
|
|
198
|
-
//#region src/plugins/anim/timeline/steps.d.ts
|
|
199
|
-
/**
|
|
200
|
-
* Every haptic tick `haptic(kind)` takes, in one frozen list: the three impacts, the selection
|
|
201
|
-
* tick and the three notifications. `platform` checks a kind against it before it plays one.
|
|
202
|
-
*
|
|
203
|
-
* @example
|
|
204
|
-
* ```ts
|
|
205
|
-
* HAPTIC_KINDS.includes("light"); // true
|
|
206
|
-
* ```
|
|
207
|
-
*/
|
|
208
|
-
declare const HAPTIC_KINDS: readonly ["light", "medium", "heavy", "selection", "success", "warning", "error"];
|
|
209
|
-
/**
|
|
210
|
-
* Runs the steps one after another. The remainder past a step's end reaches the next step in the
|
|
211
|
-
* same frame, so the tree takes exactly the sum of its durations. A step that never ends (a
|
|
212
|
-
* `tween` with `repeat: "forever"`, or a `parallel`, `sequence` or `use` that holds one) may only
|
|
213
|
-
* come last: the steps after it would never play.
|
|
214
|
-
*
|
|
215
|
-
* @param steps - The steps, in order.
|
|
216
|
-
* @returns The sequence step.
|
|
217
|
-
* @throws {Error} When a step that never ends has another step after it.
|
|
218
|
-
* @example
|
|
219
|
-
* ```ts
|
|
220
|
-
* sequence(wait(100), mark("done"));
|
|
221
|
-
* // { kind: "sequence", steps: [{ kind: "wait", ms: 100 }, { kind: "mark", name: "done" }] }
|
|
222
|
-
* ```
|
|
223
|
-
*/
|
|
224
|
-
declare function sequence(...steps: readonly Step[]): Step;
|
|
225
|
-
/**
|
|
226
|
-
* Runs every step at once and ends with the longest one.
|
|
227
|
-
*
|
|
228
|
-
* @param steps - The steps.
|
|
229
|
-
* @returns The parallel step.
|
|
230
|
-
* @example
|
|
231
|
-
* ```ts
|
|
232
|
-
* parallel(wait(100), wait(300)); // ends after 300 ms
|
|
233
|
-
* ```
|
|
234
|
-
*/
|
|
235
|
-
declare function parallel(...steps: readonly Step[]): Step;
|
|
236
|
-
/**
|
|
237
|
-
* Builds one step per item and starts each one `staggerMs` later than the one before. The build
|
|
238
|
-
* function runs here, so no function survives in the data.
|
|
239
|
-
*
|
|
240
|
-
* @param items - What to build a step for.
|
|
241
|
-
* @param staggerMs - Delay between two neighbouring items, in game milliseconds.
|
|
242
|
-
* @param build - Builds the step of one item.
|
|
243
|
-
* @returns The parallel of delayed sequences.
|
|
244
|
-
* @example
|
|
245
|
-
* ```ts
|
|
246
|
-
* stagger(["a", "b"], 60, item => mark(item));
|
|
247
|
-
* // parallel(sequence(wait(0), mark("a")), sequence(wait(60), mark("b")))
|
|
248
|
-
* ```
|
|
249
|
-
*/
|
|
250
|
-
declare function stagger<Item>(items: readonly Item[], staggerMs: number, build: (item: Item, index: number) => Step): Step;
|
|
251
|
-
/**
|
|
252
|
-
* Holds still for a while.
|
|
253
|
-
*
|
|
254
|
-
* @param durationMs - How long to wait, in game milliseconds.
|
|
255
|
-
* @returns The wait step.
|
|
256
|
-
* @example
|
|
257
|
-
* ```ts
|
|
258
|
-
* wait(120); // { kind: "wait", ms: 120 }
|
|
259
|
-
* ```
|
|
260
|
-
*/
|
|
261
|
-
declare function wait(durationMs: number): Step;
|
|
262
|
-
/**
|
|
263
|
-
* Names a point in the choreography. Reaching it emits `anim:mark`, calls the `onMark` listeners
|
|
264
|
-
* and appends the name to `marks()`. It is the only way out of a timeline.
|
|
265
|
-
*
|
|
266
|
-
* @param name - Name of the mark.
|
|
267
|
-
* @returns The mark step.
|
|
268
|
-
* @example
|
|
269
|
-
* ```ts
|
|
270
|
-
* mark("landed"); // { kind: "mark", name: "landed" }
|
|
271
|
-
* ```
|
|
272
|
-
*/
|
|
273
|
-
declare function mark(name: string): Step;
|
|
274
|
-
/**
|
|
275
|
-
* Moves the numeric fields of one component of one target to an exact target value. The component
|
|
276
|
-
* is any handle `world.ecs` takes, so the kit's `Sprite` and `NineSlice` of `defineGame` pass as
|
|
277
|
-
* they are.
|
|
278
|
-
*
|
|
279
|
-
* By default the fields are local: they are written into the target's own `Transform`. With
|
|
280
|
-
* `space: "root"` the `x`, `y`, `rotation` and `scale` of a `Transform` are a root pose, the space
|
|
281
|
-
* `at()` answers in, and are turned into the space of the target's `Parent` when the track starts.
|
|
282
|
-
* That aims a hosted view at another element: an order's board item inside the scaled board slot
|
|
283
|
-
* flies onto the order card with `{ x: at(card).x, y: at(card).y, scale: at(card).scale }` in the
|
|
284
|
-
* root space, covers the card at the card's size, and its `Transform` stays slot-local. A field
|
|
285
|
-
* the step does not name stays where it is, so under a turned parent name `x` and `y` together. A
|
|
286
|
-
* target without a parent, and a component other than `Transform`, move as in the local space. An
|
|
287
|
-
* additive walk names offsets, so it stays in the local space.
|
|
288
|
-
*
|
|
289
|
-
* @param target - The projection key or the entity to animate.
|
|
290
|
-
* @param component - The component to animate.
|
|
291
|
-
* @param to - The numeric target fields.
|
|
292
|
-
* @param options - Duration, easing, delay, the additive flag and the space of the fields.
|
|
293
|
-
* @param options.ms - Duration in game milliseconds.
|
|
294
|
-
* @param options.ease - Easing curve; `"out"` when omitted.
|
|
295
|
-
* @param options.delayMs - How long the track waits before it reads its start values.
|
|
296
|
-
* @param options.additive - `true` adds an offset instead of owning the fields.
|
|
297
|
-
* @param options.space - `"root"` reads the `Transform` fields as a root pose; `"local"` when
|
|
298
|
-
* omitted.
|
|
299
|
-
* @param options.reduced - `"keep"` plays the track at its length under reduced motion, a fade
|
|
300
|
-
* for one; `"cut"` (the default) lands it at once, and a `"forever"` track does not play.
|
|
301
|
-
* @param options.segments - Keyframe segments `{ at, ease?, to }` walked one after another over
|
|
302
|
-
* `ms` on one clock; a field a segment does not name holds, `to` is where the last one ends. An
|
|
303
|
-
* additive walk names offsets. The same as `TweenOptions` of `ViewHandle.tween`.
|
|
304
|
-
* @param options.repeat - How many more times the walk runs, or `"forever"`: the step never ends
|
|
305
|
-
* by itself, so it comes last in a `sequence`.
|
|
306
|
-
* @returns The tween step; `segments` and `repeat` are in it only when given.
|
|
307
|
-
* @throws {Error} When the segments are empty, an `at` is outside 0..1 or out of order, the last
|
|
308
|
-
* segment ends before 1, an additive walk names the root space, or the repeat is not a whole
|
|
309
|
-
* number of 0 or more.
|
|
310
|
-
* @example
|
|
311
|
-
* ```ts
|
|
312
|
-
* // A ready chest (entity 1048576) hops 14 up and back every 2.4 s, as offsets over its pose.
|
|
313
|
-
* const chestBounce = defineAnimation("board.chestBounce", { slots: { chest: type<Target>() },
|
|
314
|
-
* build: ({ chest }) => tween(chest, Transform, { y: 0, scale: 0 }, { ms: 2400, additive: true,
|
|
315
|
-
* repeat: "forever", segments: [{ at: 0.08, ease: "out", to: { y: -14, scale: 0.06 } },
|
|
316
|
-
* { at: 0.22, ease: "in", to: { y: 0, scale: 0 } }, { at: 1, to: { y: 0, scale: 0 } }] }) });
|
|
317
|
-
* const bounce = res(AnimPlayer).play(chestBounce, { chest: 1_048_576 });
|
|
318
|
-
* // 192 ms later the chest stands 14 higher, its scale 0.06 larger; it bounces until cancelled
|
|
319
|
-
* bounce.cancel(); // it stands on its own pose again
|
|
320
|
-
* ```
|
|
321
|
-
*/
|
|
322
|
-
declare function tween<Value extends object>(target: Target, component: ComponentHandle<Value>, to: Partial<NumericFields<Value>>, options: {
|
|
323
|
-
ms: number;
|
|
324
|
-
ease?: Ease;
|
|
325
|
-
delayMs?: number;
|
|
326
|
-
additive?: boolean;
|
|
327
|
-
space?: "local" | "root";
|
|
328
|
-
reduced?: ReducedMotion;
|
|
329
|
-
segments?: readonly {
|
|
330
|
-
at: number;
|
|
331
|
-
ease?: Ease;
|
|
332
|
-
to: Partial<NumericFields<Value>>;
|
|
333
|
-
}[];
|
|
334
|
-
repeat?: number | "forever";
|
|
335
|
-
}): Step;
|
|
336
|
-
/**
|
|
337
|
-
* Writes a component patch at once. Any field may be written, not only the numeric ones. The
|
|
338
|
-
* component is any handle `world.ecs` takes, the kit's `Sprite` and `NineSlice` included.
|
|
339
|
-
*
|
|
340
|
-
* @param target - The projection key or the entity to write.
|
|
341
|
-
* @param component - The component to write.
|
|
342
|
-
* @param patch - The fields to overwrite.
|
|
343
|
-
* @returns The set step.
|
|
344
|
-
* @example
|
|
345
|
-
* ```ts
|
|
346
|
-
* set({ projection: "hud", key: "coins" }, Sprite, { texture: "hud.coin-gold" });
|
|
347
|
-
* // { kind: "set", patch: { texture: "hud.coin-gold" }, ... }
|
|
348
|
-
* ```
|
|
349
|
-
*/
|
|
350
|
-
declare function set<Value extends object>(target: Target, component: ComponentHandle<Value>, patch: Partial<Value>): Step;
|
|
351
|
-
/**
|
|
352
|
-
* Plays a frame sprite: one texture key of the list per frame of `fps`, written into `Sprite`.
|
|
353
|
-
*
|
|
354
|
-
* @param target - The projection key or the entity to animate.
|
|
355
|
-
* @param options - The keys, the frame rate and whether the list repeats.
|
|
356
|
-
* @param options.keys - The texture keys, in play order.
|
|
357
|
-
* @param options.fps - Frames per second of the list.
|
|
358
|
-
* @param options.loop - `true` repeats the list until the step is finished.
|
|
359
|
-
* @returns The frames step.
|
|
360
|
-
* @example
|
|
361
|
-
* ```ts
|
|
362
|
-
* frames({ projection: "board", key: "c3" }, { keys: ["fx.pop-1", "fx.pop-2"], fps: 12 });
|
|
363
|
-
* // { kind: "frames", keys: ["fx.pop-1", "fx.pop-2"], fps: 12, loop: false, ... }
|
|
364
|
-
* ```
|
|
365
|
-
*/
|
|
366
|
-
declare function frames(target: Target, options: {
|
|
367
|
-
keys: readonly string[];
|
|
368
|
-
fps: number;
|
|
369
|
-
loop?: boolean;
|
|
370
|
-
}): Step;
|
|
371
|
-
/**
|
|
372
|
-
* Makes a temporary entity when the step is reached: a flying coin, a toast sign, a sparkle. The
|
|
373
|
-
* entity is owned by `anim`, drawn in `layer` at `order`, and despawned when the timeline ends, is
|
|
374
|
-
* finished or is cancelled. Later steps of the same timeline aim at it with `spawned(id)`.
|
|
375
|
-
*
|
|
376
|
-
* @param id - Name of the entity inside this timeline; one timeline spawns each id once.
|
|
377
|
-
* @param components - The component values the entity starts with, as `world.ecs.spawn` takes.
|
|
378
|
-
* @param options - Where the entity is drawn.
|
|
379
|
-
* @param options.layer - The layer; `"ui"` when omitted.
|
|
380
|
-
* @param options.order - The draw order inside the layer; `0` when omitted.
|
|
381
|
-
* @returns The spawn step.
|
|
382
|
-
* @example
|
|
383
|
-
* ```ts
|
|
384
|
-
* spawn("coin1", [Sprite({ texture: "ui.icon-coin" }), Transform({ x: 540, y: 900 })], { order: 50 });
|
|
385
|
-
* // { kind: "spawn", id: "coin1", components: [...], layer: "ui", order: 50 }
|
|
386
|
-
* ```
|
|
387
|
-
*/
|
|
388
|
-
declare function spawn(id: string, components: readonly AnyComponentValue[], options?: {
|
|
389
|
-
layer?: string;
|
|
390
|
-
order?: number;
|
|
391
|
-
}): Step;
|
|
392
|
-
/**
|
|
393
|
-
* Aims a later step at the entity a `spawn` step of the same timeline made. Before that step is
|
|
394
|
-
* reached nothing answers the id, so a step aimed at it ends silently.
|
|
395
|
-
*
|
|
396
|
-
* @param id - The id the `spawn` step was given.
|
|
397
|
-
* @returns The target.
|
|
398
|
-
* @example
|
|
399
|
-
* ```ts
|
|
400
|
-
* tween(spawned("coin1"), Transform, { x: 40, y: 120 }, { ms: 600, ease: "inCubic" });
|
|
401
|
-
* // { kind: "tween", target: { spawned: "coin1" }, ... }
|
|
402
|
-
* ```
|
|
403
|
-
*/
|
|
404
|
-
declare function spawned(id: string): {
|
|
405
|
-
spawned: string;
|
|
406
|
-
};
|
|
407
|
-
/**
|
|
408
|
-
* A sound. `anim` owns the descriptor because it sits below `audio`; `audio` owns the handler,
|
|
409
|
-
* and a game without `audio` plays nothing and hears no error. A sound with an `id` is named:
|
|
410
|
-
* one sound plays per id, a new one with the same id fades the old one out over `fadeMs`, and
|
|
411
|
-
* `stopSfx(id)` stops it. The payload carries `id` and `fadeMs` only when they are given, so a
|
|
412
|
-
* sound without them stays `{ key, bus }`.
|
|
413
|
-
*
|
|
414
|
-
* @param key - Asset key of the sound.
|
|
415
|
-
* @param options - The bus, the name and the fade.
|
|
416
|
-
* @param options.bus - `"sfx"` when omitted.
|
|
417
|
-
* @param options.id - Name of the sound; one sound per id plays.
|
|
418
|
-
* @param options.fadeMs - Fade of the sound with the same id this one replaces; `audio`'s
|
|
419
|
-
* `sfxFadeMs` when omitted.
|
|
420
|
-
* @returns The descriptor, usable as a timeline step and as `fx(...)` in a node.
|
|
421
|
-
* @example
|
|
422
|
-
* ```ts
|
|
423
|
-
* sfx("board.merge"); // { kind: "sfx", payload: { key: "board.merge", bus: "sfx" }, cosmetic: true }
|
|
424
|
-
* sfx("voice.hello", { id: "voice", fadeMs: 200 });
|
|
425
|
-
* // { kind: "sfx", payload: { key: "voice.hello", bus: "sfx", id: "voice", fadeMs: 200 }, cosmetic: true }
|
|
426
|
-
* ```
|
|
427
|
-
*/
|
|
428
|
-
declare function sfx(key: string, options?: {
|
|
429
|
-
bus?: string;
|
|
430
|
-
id?: string;
|
|
431
|
-
fadeMs?: number;
|
|
432
|
-
}): SfxDescriptor;
|
|
433
|
-
/**
|
|
434
|
-
* Stops the named sound `sfx(key, { id })` started, fading it out over `fadeMs`. `audio` owns the
|
|
435
|
-
* handler; an id nothing plays is silent. It works as `fx.start(stopSfx("voice"))` in a node, as a
|
|
436
|
-
* step a timeline reaches, and as the hint `hint("stopSfx", { id: "voice" })`. A timeline that is
|
|
437
|
-
* finished or cut fires no effect, this one included: a game that must stop the voice then stops
|
|
438
|
-
* it from the node.
|
|
439
|
-
*
|
|
440
|
-
* @param id - The id the sound was played with.
|
|
441
|
-
* @param options - The fade.
|
|
442
|
-
* @param options.fadeMs - Fade-out in ms; `audio`'s `sfxFadeMs` when omitted.
|
|
443
|
-
* @returns The descriptor, usable as a timeline step and as `fx(...)` in a node.
|
|
444
|
-
* @example
|
|
445
|
-
* ```ts
|
|
446
|
-
* stopSfx("voice", { fadeMs: 200 }); // { kind: "stopSfx", payload: { id: "voice", fadeMs: 200 }, cosmetic: true }
|
|
447
|
-
* stopSfx("voice"); // { kind: "stopSfx", payload: { id: "voice" }, cosmetic: true }
|
|
448
|
-
* ```
|
|
449
|
-
*/
|
|
450
|
-
declare function stopSfx(id: string, options?: {
|
|
451
|
-
fadeMs?: number;
|
|
452
|
-
}): StopSfxDescriptor;
|
|
453
|
-
/**
|
|
454
|
-
* A haptic tick. `platform` owns the handler; a device without one stays still.
|
|
455
|
-
*
|
|
456
|
-
* @param kind - Which tick to play, one of `HAPTIC_KINDS`, for example `"light"`.
|
|
457
|
-
* @returns The descriptor, usable as a timeline step and as `fx(...)` in a node.
|
|
458
|
-
* @example
|
|
459
|
-
* ```ts
|
|
460
|
-
* haptic("light"); // { kind: "haptic", payload: { kind: "light" }, cosmetic: true }
|
|
461
|
-
* ```
|
|
462
|
-
*/
|
|
463
|
-
declare function haptic(kind: HapticKind): HapticDescriptor;
|
|
464
|
-
/**
|
|
465
|
-
* Reserved for Spine and the other external players. It throws until one arrives, so nobody
|
|
466
|
-
* builds a choreography on a door that is not open yet.
|
|
467
|
-
*
|
|
468
|
-
* @param _player - The player that would run the clip.
|
|
469
|
-
* @param _clip - Name of the clip.
|
|
470
|
-
* @throws {Error} Always.
|
|
471
|
-
* @example
|
|
472
|
-
* ```ts
|
|
473
|
-
* external(spine, "idle"); // throws: External players arrive with Spine.
|
|
474
|
-
* ```
|
|
475
|
-
*/
|
|
476
|
-
declare function external(_player: ExternalPlayer, _clip: string): never;
|
|
477
|
-
/**
|
|
478
|
-
* Nests one animation inside another. The nested tree is built here, so its marks are reported
|
|
479
|
-
* under the nested id and no function survives in the data. Pass the outer `tools` when the
|
|
480
|
-
* nested `build` reads `at` or `reducedMotion`.
|
|
481
|
-
*
|
|
482
|
-
* @param animation - The animation to nest.
|
|
483
|
-
* @param slots - One target, or a list of targets, per slot of the nested animation.
|
|
484
|
-
* @param tools - The build tools of the outer animation, which carry `at` and `reducedMotion`; without
|
|
485
|
-
* them `at` is the identity pose and `reducedMotion` is absent (false).
|
|
486
|
-
* @returns The use step.
|
|
487
|
-
* @example
|
|
488
|
-
* ```ts
|
|
489
|
-
* use(popCard, { card: { projection: "hud", key: "order" } });
|
|
490
|
-
* // { kind: "use", id: "hud.popCard", step: { kind: "sequence", ... } }
|
|
491
|
-
* ```
|
|
492
|
-
*/
|
|
493
|
-
declare function use<Tags extends SlotTags>(animation: AnimationDefinition<Tags>, slots: SlotValues<Tags>, tools?: BuildTools): Step;
|
|
494
|
-
/**
|
|
495
|
-
* The effect descriptor a node awaits to play a choreography. The payload names the animation,
|
|
496
|
-
* so the handler resolves the definition from the registry the features filled.
|
|
497
|
-
*
|
|
498
|
-
* @param animation - The animation to play.
|
|
499
|
-
* @param slots - One target, or a list of targets, per slot.
|
|
500
|
-
* @returns The descriptor, cosmetic, so a failing build never breaks the node.
|
|
501
|
-
* @example
|
|
502
|
-
* ```ts
|
|
503
|
-
* play(coinsFly, { from: { projection: "hud", key: "purse" } });
|
|
504
|
-
* // { kind: "play", payload: { animation: "hud.coinsFly", slots: { from: { ... } } }, cosmetic: true }
|
|
505
|
-
* ```
|
|
506
|
-
*/
|
|
507
|
-
declare function play<Tags extends SlotTags>(animation: AnimationDefinition<Tags>, slots: SlotValues<Tags>): PlayDescriptor;
|
|
508
|
-
/**
|
|
509
|
-
* Declares one animation: an id, the slots it takes and the pure function that builds its step
|
|
510
|
-
* tree. `build` runs once per play, so the same animation may play twice at once.
|
|
511
|
-
*
|
|
512
|
-
* @param id - Animation id, unique across the features of a game.
|
|
513
|
-
* @param spec - The slots and the build function.
|
|
514
|
-
* @returns The animation as frozen plain data.
|
|
515
|
-
* @example
|
|
516
|
-
* ```ts
|
|
517
|
-
* const coinsFly = defineAnimation("hud.coinsFly", {
|
|
518
|
-
* slots: { from: type<Target>() },
|
|
519
|
-
* build: ({ from }) => tween(from, Transform, { scale: 0.4 }, { ms: 600 })
|
|
520
|
-
* });
|
|
521
|
-
* coinsFly.id; // "hud.coinsFly"
|
|
522
|
-
* ```
|
|
523
|
-
*/
|
|
524
|
-
declare function defineAnimation<Tags extends SlotTags>(id: string, spec: AnimationSpec<Tags>): AnimationDefinition<Tags>;
|
|
525
|
-
//#endregion
|
|
526
|
-
//#region src/plugins/anim/timeline/types.d.ts
|
|
527
|
-
/**
|
|
528
|
-
* The value of the component a step names, with its shape erased: the value type of
|
|
529
|
-
* `AnyComponent`. A step is built against the real component, so `set(target, Sprite, patch)`
|
|
530
|
-
* checks the patch; the step tree and the runtime then carry the component erased, which lets one
|
|
531
|
-
* choreography mix components.
|
|
532
|
-
*
|
|
533
|
-
* @example
|
|
534
|
-
* ```ts
|
|
535
|
-
* const patch: ErasedFields = { texture: "hud.coin-gold" };
|
|
536
|
-
* ```
|
|
537
|
-
*/
|
|
538
|
-
type ErasedFields = AnyComponent extends ComponentType<infer Value> ? Value : never;
|
|
539
|
-
/**
|
|
540
|
-
* A sound, owned by `anim` and handled by `audio`. It is a `flow` descriptor and a timeline step
|
|
541
|
-
* at once: `fx(sfx("board.merge"))` in a node, or `sfx("board.merge")` inside a `sequence`. A
|
|
542
|
-
* sound with an `id` is named: a second one with the same id fades the first out over `fadeMs`,
|
|
543
|
-
* and `stopSfx(id)` stops it. The payload carries `id` and `fadeMs` only when they were given.
|
|
544
|
-
*
|
|
545
|
-
* @example
|
|
546
|
-
* ```ts
|
|
547
|
-
* const descriptor: SfxDescriptor = {
|
|
548
|
-
* kind: "sfx", payload: { key: "voice.hello", bus: "sfx", id: "voice", fadeMs: 200 }, cosmetic: true
|
|
549
|
-
* };
|
|
550
|
-
* ```
|
|
551
|
-
*/
|
|
552
|
-
type SfxDescriptor = {
|
|
553
|
-
readonly kind: "sfx";
|
|
554
|
-
readonly payload: {
|
|
555
|
-
readonly key: string;
|
|
556
|
-
readonly bus: string; /** Name of the sound: one sound per id plays, and `stopSfx(id)` stops it. */
|
|
557
|
-
readonly id?: string; /** Fade of the sound with the same id this one replaces; `audio`'s `sfxFadeMs` when absent. */
|
|
558
|
-
readonly fadeMs?: number;
|
|
559
|
-
};
|
|
560
|
-
readonly cosmetic: true; /** Never set: `await fx(sfx(...))` resolves nothing. */
|
|
561
|
-
readonly $result?: () => void;
|
|
562
|
-
};
|
|
563
|
-
/**
|
|
564
|
-
* Stops the named sound an `sfx(key, { id })` started, owned by `anim` and handled by `audio`.
|
|
565
|
-
* Like `sfx` it is a descriptor and a timeline step at once; an id nothing plays is silent.
|
|
566
|
-
*
|
|
567
|
-
* @example
|
|
568
|
-
* ```ts
|
|
569
|
-
* const descriptor: StopSfxDescriptor = {
|
|
570
|
-
* kind: "stopSfx", payload: { id: "voice", fadeMs: 200 }, cosmetic: true
|
|
571
|
-
* };
|
|
572
|
-
* ```
|
|
573
|
-
*/
|
|
574
|
-
type StopSfxDescriptor = {
|
|
575
|
-
readonly kind: "stopSfx";
|
|
576
|
-
readonly payload: {
|
|
577
|
-
readonly id: string; /** Fade-out of the sound; `audio`'s `sfxFadeMs` when absent. */
|
|
578
|
-
readonly fadeMs?: number;
|
|
579
|
-
};
|
|
580
|
-
readonly cosmetic: true; /** Never set: `await fx(stopSfx(...))` resolves nothing. */
|
|
581
|
-
readonly $result?: () => void;
|
|
582
|
-
};
|
|
583
|
-
/**
|
|
584
|
-
* One haptic tick a device can play: the impact, selection and notification families of Tauri.
|
|
585
|
-
* `HAPTIC_KINDS` lists the same seven at runtime.
|
|
586
|
-
*
|
|
587
|
-
* @example
|
|
588
|
-
* ```ts
|
|
589
|
-
* const kind: HapticKind = "success";
|
|
590
|
-
* ```
|
|
591
|
-
*/
|
|
592
|
-
type HapticKind = (typeof HAPTIC_KINDS)[number];
|
|
593
|
-
/**
|
|
594
|
-
* A haptic tick, owned by `anim` and handled by `platform`. Like `sfx` it is a descriptor and a
|
|
595
|
-
* timeline step at once.
|
|
596
|
-
*
|
|
597
|
-
* @example
|
|
598
|
-
* ```ts
|
|
599
|
-
* const descriptor: HapticDescriptor = {
|
|
600
|
-
* kind: "haptic", payload: { kind: "light" }, cosmetic: true
|
|
601
|
-
* };
|
|
602
|
-
* ```
|
|
603
|
-
*/
|
|
604
|
-
type HapticDescriptor = {
|
|
605
|
-
readonly kind: "haptic";
|
|
606
|
-
readonly payload: {
|
|
607
|
-
readonly kind: HapticKind;
|
|
608
|
-
};
|
|
609
|
-
readonly cosmetic: true; /** Never set: `await fx(haptic(...))` resolves nothing. */
|
|
610
|
-
readonly $result?: () => void;
|
|
611
|
-
};
|
|
612
|
-
/**
|
|
613
|
-
* The three descriptors `anim` owns. As a step, the descriptor is dispatched through
|
|
614
|
-
* `flow.fx.dispatch` when the step is reached; a kind nobody handles is silent.
|
|
615
|
-
*
|
|
616
|
-
* @example
|
|
617
|
-
* ```ts
|
|
618
|
-
* const step: FxStep = { kind: "haptic", payload: { kind: "light" }, cosmetic: true };
|
|
619
|
-
* ```
|
|
620
|
-
*/
|
|
621
|
-
type FxStep = SfxDescriptor | StopSfxDescriptor | HapticDescriptor;
|
|
622
|
-
/**
|
|
623
|
-
* The descriptor `play(animation, slots)` builds. The payload names the animation, so the
|
|
624
|
-
* handler resolves the definition from the registry instead of carrying a function.
|
|
625
|
-
*
|
|
626
|
-
* @example
|
|
627
|
-
* ```ts
|
|
628
|
-
* const descriptor: PlayDescriptor = {
|
|
629
|
-
* kind: "play",
|
|
630
|
-
* payload: { animation: "hud.coinsFly", slots: { from: { projection: "hud", key: "coins" } } },
|
|
631
|
-
* cosmetic: true
|
|
632
|
-
* };
|
|
633
|
-
* ```
|
|
634
|
-
*/
|
|
635
|
-
type PlayDescriptor = {
|
|
636
|
-
readonly kind: "play";
|
|
637
|
-
readonly payload: {
|
|
638
|
-
readonly animation: string;
|
|
639
|
-
readonly slots: Json;
|
|
640
|
-
};
|
|
641
|
-
readonly cosmetic: true; /** Never set: `await fx(play(...))` resolves nothing. */
|
|
642
|
-
readonly $result?: () => void;
|
|
643
|
-
};
|
|
644
|
-
/**
|
|
645
|
-
* One step of a choreography: plain frozen data with no callback inside, so a step tree can be
|
|
646
|
-
* read, logged and compared. A `spawn` step carries the component values of a temporary entity,
|
|
647
|
-
* made when the step is reached and despawned when the timeline ends.
|
|
648
|
-
*
|
|
649
|
-
* @example
|
|
650
|
-
* ```ts
|
|
651
|
-
* const step: Step = { kind: "wait", ms: 120 };
|
|
652
|
-
* ```
|
|
653
|
-
*/
|
|
654
|
-
type Step = {
|
|
655
|
-
readonly kind: "sequence";
|
|
656
|
-
readonly steps: readonly Step[];
|
|
657
|
-
} | {
|
|
658
|
-
readonly kind: "parallel";
|
|
659
|
-
readonly steps: readonly Step[];
|
|
660
|
-
} | {
|
|
661
|
-
readonly kind: "wait";
|
|
662
|
-
readonly ms: number;
|
|
663
|
-
} | {
|
|
664
|
-
readonly kind: "mark";
|
|
665
|
-
readonly name: string;
|
|
666
|
-
} | {
|
|
667
|
-
readonly kind: "tween";
|
|
668
|
-
readonly target: Target;
|
|
669
|
-
readonly component: AnyComponent;
|
|
670
|
-
readonly to: Readonly<Record<string, number>>;
|
|
671
|
-
readonly ms: number;
|
|
672
|
-
readonly ease: Ease;
|
|
673
|
-
readonly delayMs: number;
|
|
674
|
-
readonly additive: boolean; /** `"root"`: the `Transform` fields are a root pose, turned local when the track starts. */
|
|
675
|
-
readonly space: "local" | "root"; /** `"keep"`: reduced motion plays the track as written; `"cut"` lands it at once. */
|
|
676
|
-
readonly reduced: ReducedMotion;
|
|
677
|
-
/**
|
|
678
|
-
* The keyframe segments the track walks over `ms`, frozen; only on a step built with them.
|
|
679
|
-
* In the root space each segment's target is turned local when the track starts, like `to`.
|
|
680
|
-
*/
|
|
681
|
-
readonly segments?: readonly TrackSegment[];
|
|
682
|
-
/**
|
|
683
|
-
* The runs after the first one, or `"forever"` for a step that never ends by itself; only on
|
|
684
|
-
* a step built with it.
|
|
685
|
-
*/
|
|
686
|
-
readonly repeat?: number | "forever";
|
|
687
|
-
} | {
|
|
688
|
-
readonly kind: "set";
|
|
689
|
-
readonly target: Target;
|
|
690
|
-
readonly component: AnyComponent;
|
|
691
|
-
readonly patch: Readonly<ErasedFields>;
|
|
692
|
-
} | {
|
|
693
|
-
readonly kind: "frames";
|
|
694
|
-
readonly target: Target;
|
|
695
|
-
readonly keys: readonly string[];
|
|
696
|
-
readonly fps: number;
|
|
697
|
-
readonly loop: boolean;
|
|
698
|
-
} | {
|
|
699
|
-
readonly kind: "spawn";
|
|
700
|
-
readonly id: string;
|
|
701
|
-
readonly components: readonly AnyComponentValue[];
|
|
702
|
-
readonly layer: string;
|
|
703
|
-
readonly order: number;
|
|
704
|
-
} | FxStep | {
|
|
705
|
-
readonly kind: "use";
|
|
706
|
-
readonly id: string;
|
|
707
|
-
readonly step: Step;
|
|
708
|
-
};
|
|
709
|
-
/**
|
|
710
|
-
* Reserved for Spine and the other external players: `external` throws, and this is the shape it
|
|
711
|
-
* would take. Exported as a type only.
|
|
712
|
-
*
|
|
713
|
-
* @example
|
|
714
|
-
* ```ts
|
|
715
|
-
* const player: ExternalPlayer = { name: "spine", play: () => undefined };
|
|
716
|
-
* ```
|
|
717
|
-
*/
|
|
718
|
-
type ExternalPlayer = {
|
|
719
|
-
readonly name: string;
|
|
720
|
-
play(clip: string): unknown;
|
|
721
|
-
};
|
|
722
|
-
/**
|
|
723
|
-
* Where one step of a running timeline stands. One mutable record per step of the tree, built
|
|
724
|
-
* when the timeline starts.
|
|
725
|
-
*/
|
|
726
|
-
type Cursor = {
|
|
727
|
-
readonly step: Step;
|
|
728
|
-
readonly children: readonly Cursor[]; /** Position in a `sequence`, and the last written key of a `frames` step. */
|
|
729
|
-
index: number;
|
|
730
|
-
/**
|
|
731
|
-
* `[0]`: the consumed milliseconds of a `wait` or a `frames` step. A cell and not a field, so a
|
|
732
|
-
* frame writes it in place: a double stored in an object field is a new heap number.
|
|
733
|
-
*/
|
|
734
|
-
readonly clock: Float64Array;
|
|
735
|
-
motion: StepMotion | undefined;
|
|
736
|
-
started: boolean;
|
|
737
|
-
ended: boolean; /** The entity a running `frames` step holds against its `Frames` loop, until the step ends. */
|
|
738
|
-
held: Entity | undefined;
|
|
739
|
-
};
|
|
740
|
-
/**
|
|
741
|
-
* What the cursor reaches the rest of the engine through. Injected, so `timeline` never imports
|
|
742
|
-
* the run-time code of `tween` or of another plugin.
|
|
743
|
-
*/
|
|
744
|
-
type TimelineRuntime = {
|
|
745
|
-
/**
|
|
746
|
-
* Resolves a target to an entity.
|
|
747
|
-
*
|
|
748
|
-
* @param target - The projection key, the entity or the spawned id a step names.
|
|
749
|
-
* @param spawned - The spawn table of the timeline that asks; a spawned id resolves only there.
|
|
750
|
-
* @returns The entity, or `undefined` when no live view, element or spawned entity holds it.
|
|
751
|
-
*/
|
|
752
|
-
entityOf(target: Target, spawned?: ReadonlyMap<string, Entity>): Entity | undefined;
|
|
753
|
-
/**
|
|
754
|
-
* Spawns a temporary entity owned by `anim`. The timeline that spawned it despawns it when it
|
|
755
|
-
* ends, whichever way it ends.
|
|
756
|
-
*
|
|
757
|
-
* @param components - The component values the entity starts with, `Layer` and `Order` included.
|
|
758
|
-
* @returns The new entity.
|
|
759
|
-
*/
|
|
760
|
-
spawn(components: readonly AnyComponentValue[]): Entity;
|
|
761
|
-
/**
|
|
762
|
-
* Reads a component of an entity, which is also the liveness check of a step.
|
|
763
|
-
*
|
|
764
|
-
* @param entity - The entity to read.
|
|
765
|
-
* @param component - The component to read.
|
|
766
|
-
* @returns The stored value, or `undefined`.
|
|
767
|
-
*/
|
|
768
|
-
read(entity: Entity, component: AnyComponent): Readonly<ErasedFields> | undefined;
|
|
769
|
-
/**
|
|
770
|
-
* Writes a patch through `ecs.set`, so `changed()` sees it.
|
|
771
|
-
*
|
|
772
|
-
* @param entity - The entity to write.
|
|
773
|
-
* @param component - The component to write.
|
|
774
|
-
* @param patch - The fields to overwrite.
|
|
775
|
-
*/
|
|
776
|
-
write(entity: Entity, component: AnyComponent, patch: Partial<ErasedFields>): void;
|
|
777
|
-
/**
|
|
778
|
-
* Turns the root-space target of a `tween` step into the local target under the entity's
|
|
779
|
-
* parent, through `localPoseOf` of `renderer`.
|
|
780
|
-
*
|
|
781
|
-
* @param entity - The entity the step moves.
|
|
782
|
-
* @param component - The component the step drives; only `Transform` is converted.
|
|
783
|
-
* @param to - The numeric target fields, in root space.
|
|
784
|
-
* @returns The target fields in the space of the entity's parent.
|
|
785
|
-
*/
|
|
786
|
-
toLocal(entity: Entity, component: AnyComponent, to: Readonly<Record<string, number>>): Record<string, number>;
|
|
787
|
-
/**
|
|
788
|
-
* Starts one track on the tween core.
|
|
789
|
-
*
|
|
790
|
-
* @param entity - The entity to animate.
|
|
791
|
-
* @param component - The component to animate.
|
|
792
|
-
* @param to - The numeric target fields.
|
|
793
|
-
* @param options - Duration, easing, delay and the additive flag.
|
|
794
|
-
* @returns The motion of the track, advanceable by hand.
|
|
795
|
-
*/
|
|
796
|
-
start(entity: Entity, component: AnyComponent, to: Record<string, number>, options: TrackOptions): StepMotion;
|
|
797
|
-
/**
|
|
798
|
-
* Hands a descriptor step to `flow.fx.dispatch`.
|
|
799
|
-
*
|
|
800
|
-
* @param descriptor - The `sfx` or `haptic` step that was reached.
|
|
801
|
-
*/
|
|
802
|
-
dispatch(descriptor: FxStep): void;
|
|
803
|
-
/**
|
|
804
|
-
* Reports a mark: the event, the `onMark` listeners and the timeline's own list.
|
|
805
|
-
*
|
|
806
|
-
* @param animation - Id of the animation the mark belongs to.
|
|
807
|
-
* @param name - Name of the mark.
|
|
808
|
-
*/
|
|
809
|
-
mark(animation: string, name: string): void;
|
|
810
|
-
/**
|
|
811
|
-
* Lifts the idle frame rate, because something started to move.
|
|
812
|
-
*/
|
|
813
|
-
wake(): void;
|
|
814
|
-
/**
|
|
815
|
-
* Claims the sprite of an entity for a running `frames` step: the `Frames` loop of the entity
|
|
816
|
-
* writes nothing while any claim is open.
|
|
817
|
-
*
|
|
818
|
-
* @param entity - The entity the step writes.
|
|
819
|
-
*/
|
|
820
|
-
holdFrames(entity: Entity): void;
|
|
821
|
-
/**
|
|
822
|
-
* Gives one claim back. At the last one the `Frames` loop writes its current key again on its
|
|
823
|
-
* next step, so the sprite does not stay on the step's last key.
|
|
824
|
-
*
|
|
825
|
-
* @param entity - The entity the step wrote.
|
|
826
|
-
*/
|
|
827
|
-
releaseFrames(entity: Entity): void;
|
|
828
|
-
};
|
|
829
|
-
/**
|
|
830
|
-
* What the cursor functions carry down the tree: the runtime, the animation id marks are
|
|
831
|
-
* reported under, the list of marks reached so far, the entities the timeline spawned, by id, and
|
|
832
|
-
* the entities its key targets named when it started.
|
|
833
|
-
*/
|
|
834
|
-
type CursorCtx = {
|
|
835
|
-
/** The runtime of the frame step that walks the tree now. */rt: TimelineRuntime; /** Swapped for the nested id while a `use` step walks its tree, and set back after. */
|
|
836
|
-
animation: string;
|
|
837
|
-
readonly marks: string[];
|
|
838
|
-
readonly spawned: Map<string, Entity>; /** The entities the key targets named when the timeline started, by target object. */
|
|
839
|
-
readonly targets: ReadonlyMap<Target, Entity>;
|
|
840
|
-
};
|
|
841
|
-
/**
|
|
842
|
-
* One running timeline: its cursor, the marks it reached, the entities it counts on, the entities
|
|
843
|
-
* its key targets named at its start, the entities it spawned and despawns at its end, and the
|
|
844
|
-
* resolver of its `done` promise.
|
|
845
|
-
*/
|
|
846
|
-
type RunningTimeline = {
|
|
847
|
-
readonly id: number;
|
|
848
|
-
readonly animation: string; /** The slot values exactly as `play` received them, by reference: `timelines()` shows them. */
|
|
849
|
-
readonly slots: SlotRecord; /** The frame count of anim (`State.frame`) when the timeline started. */
|
|
850
|
-
readonly startFrame: number;
|
|
851
|
-
readonly cursor: Cursor;
|
|
852
|
-
readonly marks: string[];
|
|
853
|
-
readonly entities: readonly Entity[]; /** The entities its `{ projection, key }` targets named when it started, by target object. */
|
|
854
|
-
readonly targets: ReadonlyMap<Target, Entity>; /** The entities its `spawn` steps made, by spawn id. Despawned when the timeline ends. */
|
|
855
|
-
readonly spawned: Map<string, Entity>;
|
|
856
|
-
readonly resolve: () => void;
|
|
857
|
-
ended: boolean; /** The one cursor context of the timeline, made at its start and reused by every frame. */
|
|
858
|
-
readonly cctx: CursorCtx;
|
|
859
|
-
};
|
|
860
|
-
/**
|
|
861
|
-
* One slot of the ring of ended timelines. The sixteen records are made once with the state and
|
|
862
|
-
* written in place at every end, so an end allocates no record. Private: the API answers
|
|
863
|
-
* `EndedTimelineInfo` copies.
|
|
864
|
-
*/
|
|
865
|
-
type EndedRecord = {
|
|
866
|
-
timeline: number;
|
|
867
|
-
animation: string;
|
|
868
|
-
startFrame: number;
|
|
869
|
-
endFrame: number;
|
|
870
|
-
reason: TimelineEndReason;
|
|
871
|
-
};
|
|
872
|
-
declare namespace types_d_exports$3 {
|
|
873
|
-
export { AnimApi, AnimCtx, AnimPlayerValue, AnimationDefinition, AnimationSpec, AnyAnimationDefinition, BuildTools, Config$3 as Config, Cursor, Deps$3 as Deps, EndedTimelineInfo, ErasedFields, Events, ExternalPlayer, FrameLoop, FramesValue, FxStep, HapticDescriptor, HapticKind, KernelSlice$3 as KernelSlice, MarkListener, MotionKeyframe, PlayDescriptor, PlayHandle, Pose, RunningTimeline, RunningTimelineInfo, SfxDescriptor, SlotRecord, SlotTags, SlotValue, SlotValues, State$3 as State, Step, StepMotion, StopSfxDescriptor, Target, TimelineEndReason, TimelineRuntime, TimelinesSnapshot, Track };
|
|
874
|
-
}
|
|
875
|
-
/**
|
|
876
|
-
* What a step and a slot are pointed at: the projection key of a live view or of an element a
|
|
877
|
-
* plugin above registered with `registerKey`, an entity, or the id of an entity a `spawn` step of
|
|
878
|
-
* the same timeline made (`spawned(id)`). A node passes keys, never entities.
|
|
879
|
-
*
|
|
880
|
-
* @example
|
|
881
|
-
* ```ts
|
|
882
|
-
* const counter: Target = { projection: "hud", key: "coins" };
|
|
883
|
-
* const flyingCoin: Target = spawned("coin1"); // { spawned: "coin1" }
|
|
884
|
-
* ```
|
|
885
|
-
*/
|
|
886
|
-
type Target = {
|
|
887
|
-
projection: string;
|
|
888
|
-
key: string;
|
|
889
|
-
} | Entity | {
|
|
890
|
-
spawned: string;
|
|
891
|
-
};
|
|
892
|
-
/**
|
|
893
|
-
* The pose `at(target)` answers with: where the target rests in root (reference) space, its rest
|
|
894
|
-
* `Transform` composed through the `Parent` chain, or the identity pose when nothing is there. The per-axis factors
|
|
895
|
-
* of the target (`scaleX`, `scaleY`) are not carried: `at()` answers the uniform `scale` only.
|
|
896
|
-
*
|
|
897
|
-
* @example
|
|
898
|
-
* ```ts
|
|
899
|
-
* const pose: Pose = { x: 540, y: 960, rotation: 0, scale: 1 };
|
|
900
|
-
* ```
|
|
901
|
-
*/
|
|
902
|
-
type Pose = {
|
|
903
|
-
x: number;
|
|
904
|
-
y: number;
|
|
905
|
-
rotation: number;
|
|
906
|
-
scale: number;
|
|
907
|
-
};
|
|
908
|
-
/**
|
|
909
|
-
* The slot declaration of an animation: one type tag per slot, each carrying one target or a
|
|
910
|
-
* list of targets.
|
|
911
|
-
*
|
|
912
|
-
* @example
|
|
913
|
-
* ```ts
|
|
914
|
-
* const slots: SlotTags = { items: type<Target[]>(), card: type<Target>() };
|
|
915
|
-
* ```
|
|
916
|
-
*/
|
|
917
|
-
type SlotTags = Readonly<Record<string, TypeTag<Target> | TypeTag<Target[]>>>;
|
|
918
|
-
/**
|
|
919
|
-
* The targets `play` and `use` take, read off the slot tags of the animation.
|
|
920
|
-
*
|
|
921
|
-
* @example
|
|
922
|
-
* ```ts
|
|
923
|
-
* type Slots = SlotValues<{ card: TypeTag<Target> }>; // { card: Target }
|
|
924
|
-
* ```
|
|
925
|
-
*/
|
|
926
|
-
type SlotValues<Tags extends SlotTags> = { [Name in keyof Tags]: SlotValue<Tags[Name]> };
|
|
927
|
-
/**
|
|
928
|
-
* What one slot tag stands for: a list of targets when the tag declared one, a single target
|
|
929
|
-
* otherwise. Distributive on purpose, so the erased `SlotTags` widens to both.
|
|
930
|
-
*
|
|
931
|
-
* @example
|
|
932
|
-
* ```ts
|
|
933
|
-
* type One = SlotValue<TypeTag<Target>>; // Target
|
|
934
|
-
* ```
|
|
935
|
-
*/
|
|
936
|
-
type SlotValue<Tag> = Tag extends TypeTag<Target[]> ? Target[] : Target;
|
|
937
|
-
/**
|
|
938
|
-
* The slots of a running animation with their tags erased, as `build` and the `play` handler
|
|
939
|
-
* read them.
|
|
940
|
-
*
|
|
941
|
-
* @example
|
|
942
|
-
* ```ts
|
|
943
|
-
* const slots: SlotRecord = { card: { projection: "hud", key: "order" } };
|
|
944
|
-
* ```
|
|
945
|
-
*/
|
|
946
|
-
type SlotRecord = SlotValues<SlotTags>;
|
|
947
|
-
/**
|
|
948
|
-
* What `build` is handed next to the slots: `at` reads where a target rests at play time, in root
|
|
949
|
-
* space (its rest `Transform` composed through the `Parent` chain, every pivot applied), so a
|
|
950
|
-
* choreography can fly one element to where another one rests, even inside a scaled slot. A view
|
|
951
|
-
* that has a `Parent` itself is aimed at that pose with a `tween` in `space: "root"`.
|
|
952
|
-
*
|
|
953
|
-
* `reducedMotion` is the live reduced-motion switch (`setReducedMotion`) read once, when the play
|
|
954
|
-
* starts, so `build` can choose a designed variant: fades in place, waits, marks, every track
|
|
955
|
-
* `reduced: "keep"`. The engine never guesses: a tween of that variant that is not marked `keep`
|
|
956
|
-
* is still cut. A switch while the timeline runs does not rebuild it. An absent `reducedMotion` reads as
|
|
957
|
-
* `false`, so a hand-written `{ at }` passes; a nested `use` sees it only when the outer tools are
|
|
958
|
-
* passed on.
|
|
959
|
-
*
|
|
960
|
-
* @example
|
|
961
|
-
* ```ts
|
|
962
|
-
* const giftFade = defineAnimation("puzzles.giftFade", {
|
|
963
|
-
* slots: { hero: type<Target>() },
|
|
964
|
-
* build: ({ hero }, { reducedMotion }) =>
|
|
965
|
-
* reducedMotion
|
|
966
|
-
* ? tween(hero, Shape, { alpha: 0 }, { ms: 200, reduced: "keep" })
|
|
967
|
-
* : tween(hero, Transform, { y: -300 }, { ms: 600 })
|
|
968
|
-
* });
|
|
969
|
-
* app.anim.setReducedMotion(true);
|
|
970
|
-
* app.anim.play(giftFade, { hero }); // build got reducedMotion: true: the hero fades in place over 200 ms
|
|
971
|
-
* ```
|
|
972
|
-
*/
|
|
973
|
-
type BuildTools = {
|
|
974
|
-
at(target: Target): Pose; /** Whether reduced motion was on when this play started. Absent reads as `false`. */
|
|
975
|
-
readonly reducedMotion?: boolean;
|
|
976
|
-
};
|
|
977
|
-
/**
|
|
978
|
-
* One animation: an id, the slots it takes and the pure function that builds its step tree. The
|
|
979
|
-
* same definition may play twice at once, because `build` runs per play.
|
|
980
|
-
*
|
|
981
|
-
* @example
|
|
982
|
-
* ```ts
|
|
983
|
-
* const coinsFly: AnimationDefinition<{ from: TypeTag<Target> }> = defineAnimation("hud.coinsFly", {
|
|
984
|
-
* slots: { from: type<Target>() },
|
|
985
|
-
* build: ({ from }) => tween(from, Transform, { scale: 0.4 }, { ms: 600 })
|
|
986
|
-
* });
|
|
987
|
-
* coinsFly.id; // "hud.coinsFly"
|
|
988
|
-
* ```
|
|
989
|
-
*/
|
|
990
|
-
type AnimationDefinition<Tags extends SlotTags = SlotTags> = {
|
|
991
|
-
readonly id: string;
|
|
992
|
-
readonly slots: Tags;
|
|
993
|
-
build(slots: SlotValues<Tags>, tools: BuildTools): Step;
|
|
994
|
-
};
|
|
995
|
-
/**
|
|
996
|
-
* What `defineAnimation` is given: the slots the animation takes and the pure function that
|
|
997
|
-
* builds its step tree.
|
|
998
|
-
*
|
|
999
|
-
* @example
|
|
1000
|
-
* ```ts
|
|
1001
|
-
* const spec: AnimationSpec<{ card: TypeTag<Target> }> = {
|
|
1002
|
-
* slots: { card: type<Target>() },
|
|
1003
|
-
* build: ({ card }) => tween(card, Transform, { scale: 1.2 }, { ms: 120 })
|
|
1004
|
-
* };
|
|
1005
|
-
* ```
|
|
1006
|
-
*/
|
|
1007
|
-
type AnimationSpec<Tags extends SlotTags> = {
|
|
1008
|
-
readonly slots: Tags;
|
|
1009
|
-
build(slots: SlotValues<Tags>, tools: BuildTools): Step;
|
|
1010
|
-
};
|
|
1011
|
-
/**
|
|
1012
|
-
* An animation with its slot tags erased, as the registry stores it.
|
|
1013
|
-
*
|
|
1014
|
-
* @example
|
|
1015
|
-
* ```ts
|
|
1016
|
-
* const stored: AnyAnimationDefinition = { id: "hud.coinsFly", slots: {}, build: () => wait(0) };
|
|
1017
|
-
* ```
|
|
1018
|
-
*/
|
|
1019
|
-
type AnyAnimationDefinition = AnimationDefinition<SlotTags>;
|
|
1020
|
-
/**
|
|
1021
|
-
* What `play` hands back: the motion contract over the whole step tree, the promise of its end
|
|
1022
|
-
* and the marks it reached so far.
|
|
1023
|
-
*
|
|
1024
|
-
* @example
|
|
1025
|
-
* ```ts
|
|
1026
|
-
* const deliverOrder = defineAnimation("orders.deliver", { slots: { card: type<Target>() },
|
|
1027
|
-
* build: ({ card }) => sequence(tween(card, Transform, { x: 100 }, { ms: 100 }), mark("done")) });
|
|
1028
|
-
* const handle: PlayHandle = app.anim.play(deliverOrder, { card: { projection: "board.items", key: "a" } });
|
|
1029
|
-
* handle.marks(); // []: nothing reached yet
|
|
1030
|
-
* ```
|
|
1031
|
-
*/
|
|
1032
|
-
type PlayHandle = MotionHandle & {
|
|
1033
|
-
readonly done: Promise<void>;
|
|
1034
|
-
marks(): readonly string[];
|
|
1035
|
-
};
|
|
1036
|
-
/**
|
|
1037
|
-
* A listener of `onMark`: the animation id and the name of the mark that was reached.
|
|
1038
|
-
*
|
|
1039
|
-
* @example
|
|
1040
|
-
* ```ts
|
|
1041
|
-
* const reached: string[] = [];
|
|
1042
|
-
* const listener: MarkListener = (_animation, mark) => reached.push(mark);
|
|
1043
|
-
* ```
|
|
1044
|
-
*/
|
|
1045
|
-
type MarkListener = (animation: string, mark: string) => void;
|
|
1046
|
-
/**
|
|
1047
|
-
* anim plugin events.
|
|
1048
|
-
*
|
|
1049
|
-
* @example
|
|
1050
|
-
* ```ts
|
|
1051
|
-
* // A feature plugin logs every mark a choreography reaches.
|
|
1052
|
-
* createPlugin("rewardLog", {
|
|
1053
|
-
* depends: [animPlugin],
|
|
1054
|
-
* hooks: ctx => ({ "anim:mark": ({ mark }) => ctx.log.info("mark", { mark }) })
|
|
1055
|
-
* }); // a reached mark("done") step logs { mark: "done" }
|
|
1056
|
-
* ```
|
|
1057
|
-
*/
|
|
1058
|
-
type Events = {
|
|
1059
|
-
/** A `mark` step was reached, or jumped by `finish()`. */"anim:mark": {
|
|
1060
|
-
animation: string;
|
|
1061
|
-
mark: string;
|
|
1062
|
-
}; /** A timeline started: it is in `timelines()` and `play` has not returned yet. */
|
|
1063
|
-
"anim:started": {
|
|
1064
|
-
animation: string;
|
|
1065
|
-
timeline: number;
|
|
1066
|
-
}; /** A timeline was cancelled with `handle.cancel()`. `anim:finished` does not follow. */
|
|
1067
|
-
"anim:cancelled": {
|
|
1068
|
-
animation: string;
|
|
1069
|
-
timeline: number;
|
|
1070
|
-
};
|
|
1071
|
-
/**
|
|
1072
|
-
* A timeline ended or was finished, with `reason: "ended"` when its tree ran through and
|
|
1073
|
-
* `"finished"` for `finish()`, `finishAll()` and the abort of the node that played it. Not
|
|
1074
|
-
* emitted on `cancel()`.
|
|
1075
|
-
*/
|
|
1076
|
-
"anim:finished": {
|
|
1077
|
-
animation: string;
|
|
1078
|
-
timeline: number;
|
|
1079
|
-
reason: "ended" | "finished";
|
|
1080
|
-
};
|
|
1081
|
-
};
|
|
1082
|
-
/**
|
|
1083
|
-
* Why a timeline ended: it ran through its tree, it was finished early, or it was cancelled.
|
|
1084
|
-
*
|
|
1085
|
-
* @example
|
|
1086
|
-
* ```ts
|
|
1087
|
-
* // A timeline that played to its last step, then one a node's abort finished early.
|
|
1088
|
-
* const ran: TimelineEndReason = "ended";
|
|
1089
|
-
* const aborted: TimelineEndReason = "finished";
|
|
1090
|
-
* ```
|
|
1091
|
-
*/
|
|
1092
|
-
type TimelineEndReason = "ended" | "finished" | "cancelled";
|
|
1093
|
-
/**
|
|
1094
|
-
* One running timeline as `timelines()` reports it.
|
|
1095
|
-
*
|
|
1096
|
-
* @example
|
|
1097
|
-
* ```ts
|
|
1098
|
-
* // The delivery of order card "a", one frame in, with nothing reached yet.
|
|
1099
|
-
* const info: RunningTimelineInfo = {
|
|
1100
|
-
* timeline: 4, animation: "orders.deliver", startFrame: 0,
|
|
1101
|
-
* slots: { card: { projection: "board.items", key: "a" } }, entities: [1_048_576], marks: []
|
|
1102
|
-
* };
|
|
1103
|
-
* ```
|
|
1104
|
-
*/
|
|
1105
|
-
type RunningTimelineInfo = {
|
|
1106
|
-
/** The timeline number: the one `anim:started` and `anim:finished` carry. Ids are shared with tracks. */readonly timeline: number; /** The animation id. */
|
|
1107
|
-
readonly animation: string; /** The anim frame count when it started. */
|
|
1108
|
-
readonly startFrame: number; /** The targets as `play` received them: the very object, not a copy. Do not mutate it. */
|
|
1109
|
-
readonly slots: SlotRecord; /** The entities its targets resolved to at the start, each counted in `Animation`. A copy. */
|
|
1110
|
-
readonly entities: readonly Entity[]; /** The marks reached so far. A copy. */
|
|
1111
|
-
readonly marks: readonly string[];
|
|
1112
|
-
};
|
|
1113
|
-
/**
|
|
1114
|
-
* One ended timeline of the ring `timelines()` keeps.
|
|
1115
|
-
*
|
|
1116
|
-
* @example
|
|
1117
|
-
* ```ts
|
|
1118
|
-
* const info: EndedTimelineInfo = {
|
|
1119
|
-
* timeline: 4, animation: "orders.deliver", startFrame: 0, endFrame: 2, reason: "ended"
|
|
1120
|
-
* };
|
|
1121
|
-
* ```
|
|
1122
|
-
*/
|
|
1123
|
-
type EndedTimelineInfo = {
|
|
1124
|
-
/** The timeline number it ran under. */readonly timeline: number; /** The animation id. */
|
|
1125
|
-
readonly animation: string; /** The anim frame count when it started. */
|
|
1126
|
-
readonly startFrame: number; /** The anim frame count when it ended. */
|
|
1127
|
-
readonly endFrame: number; /** How it ended. */
|
|
1128
|
-
readonly reason: TimelineEndReason;
|
|
1129
|
-
};
|
|
1130
|
-
/**
|
|
1131
|
-
* What `timelines()` and the `game.timelines` source answer: the timelines that run now, in start
|
|
1132
|
-
* order, and the last sixteen that ended, oldest first.
|
|
1133
|
-
*
|
|
1134
|
-
* @example
|
|
1135
|
-
* ```ts
|
|
1136
|
-
* const idle: TimelinesSnapshot = { running: [], ended: [] };
|
|
1137
|
-
* ```
|
|
1138
|
-
*/
|
|
1139
|
-
type TimelinesSnapshot = {
|
|
1140
|
-
/** The running timelines, in start order. */readonly running: readonly RunningTimelineInfo[]; /** The last ended timelines, oldest first, at most 16. */
|
|
1141
|
-
readonly ended: readonly EndedTimelineInfo[];
|
|
1142
|
-
};
|
|
1143
|
-
/**
|
|
1144
|
-
* One key of a keyframe track in `defineMotion`: where on the track it sits (`at`, 0..1 of
|
|
1145
|
-
* `transition.ms`), the curve of the segment that ends on it (default `"inOut"`) and the pose.
|
|
1146
|
-
* `dx` and `dy` are offsets from the rest pose in reference units; `rotation` (radians), `scale`,
|
|
1147
|
-
* `scaleX`, `scaleY` and `alpha` are absolute. `scaleX` and `scaleY` stretch one axis on top of `scale`; a view
|
|
1148
|
-
* that sets neither rests at 1. A field the key leaves out holds the previous key's value.
|
|
1149
|
-
*
|
|
1150
|
-
* An enter walk starts on the first key and ends on the rest pose at `at: 1`; an exit walk starts
|
|
1151
|
-
* where the view is and ends on the last key, the pose the element leaves in.
|
|
1152
|
-
*
|
|
1153
|
-
* In a loop (`loop: { track }`) every Transform field is an offset added to the rest pose: `dx`, `dy`, `rotation`,
|
|
1154
|
-
* `scale`, `scaleX` and `scaleY` (`scale: 0.05` grows a scale-1 view to 1.05, `scaleX: 0.05` widens it alone). `alpha`
|
|
1155
|
-
* stays absolute. The loop stands on its first key until that key's `at`, and its last key repeats its first one.
|
|
1156
|
-
*
|
|
1157
|
-
* @example
|
|
1158
|
-
* ```ts
|
|
1159
|
-
* // A popup board at 42 % of its swing: 14 u below its rest, tilted 5°, slightly larger.
|
|
1160
|
-
* const key: MotionKeyframe = { at: 0.42, ease: "out", Transform: { dy: 14, rotation: 0.087, scale: 1.04 } };
|
|
1161
|
-
* // A ribbon at 65 % of its unfurl: 8 % wider than its rest, as tall as it rests.
|
|
1162
|
-
* const unfurl: MotionKeyframe = { at: 0.65, Transform: { scaleX: 1.08 } };
|
|
1163
|
-
* ```
|
|
1164
|
-
*/
|
|
1165
|
-
type MotionKeyframe = {
|
|
1166
|
-
readonly at: number;
|
|
1167
|
-
readonly ease?: Ease;
|
|
1168
|
-
readonly Transform?: {
|
|
1169
|
-
readonly dx?: number;
|
|
1170
|
-
readonly dy?: number;
|
|
1171
|
-
readonly rotation?: number;
|
|
1172
|
-
readonly scale?: number;
|
|
1173
|
-
readonly scaleX?: number;
|
|
1174
|
-
readonly scaleY?: number;
|
|
1175
|
-
};
|
|
1176
|
-
readonly Shape?: {
|
|
1177
|
-
readonly alpha?: number;
|
|
1178
|
-
};
|
|
1179
|
-
readonly Sprite?: {
|
|
1180
|
-
readonly alpha?: number;
|
|
1181
|
-
};
|
|
1182
|
-
readonly NineSlice?: {
|
|
1183
|
-
readonly alpha?: number;
|
|
1184
|
-
};
|
|
1185
|
-
};
|
|
1186
|
-
/**
|
|
1187
|
-
* The value of the `Frames` component: a frame loop that lives as long as its entity. `keys` and
|
|
1188
|
-
* `fps` mean what they mean on the `frames` step; `loop: false` stops on the last key and
|
|
1189
|
-
* `playing: false` holds the key on the screen. A new `keys` array restarts at key 0, the same
|
|
1190
|
-
* array keeps its phase.
|
|
1191
|
-
*
|
|
1192
|
-
* @example
|
|
1193
|
-
* ```ts
|
|
1194
|
-
* const spin: FramesValue = { keys: ["items.coin-0", "items.coin-1"], fps: 12, loop: true, playing: true };
|
|
1195
|
-
* ```
|
|
1196
|
-
*/
|
|
1197
|
-
type FramesValue = {
|
|
1198
|
-
keys: readonly string[];
|
|
1199
|
-
fps: number;
|
|
1200
|
-
loop: boolean;
|
|
1201
|
-
playing: boolean;
|
|
1202
|
-
};
|
|
1203
|
-
/**
|
|
1204
|
-
* Where the `Frames` loop of one entity stands. `keys` is the array last seen, for the restart
|
|
1205
|
-
* check; `index` is the key the clock last landed on, `-1` before the first one; `written` is
|
|
1206
|
-
* false while that key still has to reach the sprite.
|
|
1207
|
-
*/
|
|
1208
|
-
type FrameLoop = {
|
|
1209
|
-
keys: readonly string[];
|
|
1210
|
-
elapsed: number;
|
|
1211
|
-
index: number;
|
|
1212
|
-
written: boolean;
|
|
1213
|
-
};
|
|
1214
|
-
/**
|
|
1215
|
-
* anim plugin config. The timings live in the steps and in `defineMotion`, not here: a
|
|
1216
|
-
* choreography that reads its duration from a config cannot be read as text.
|
|
1217
|
-
*
|
|
1218
|
-
* @example
|
|
1219
|
-
* ```ts
|
|
1220
|
-
* createApp({ plugins: [...screen], pluginConfigs: { anim: { maxTracks: 500, reducedMotion: true } } });
|
|
1221
|
-
* ```
|
|
1222
|
-
*/
|
|
1223
|
-
type Config$3 = {
|
|
1224
|
-
/** Dev guard: one warning each time the running track count rises past this number. */maxTracks: number;
|
|
1225
|
-
/**
|
|
1226
|
-
* Start value of reduced motion: every track but a loop takes 0 ms and every loop stands on
|
|
1227
|
-
* its first key. `app.anim.setReducedMotion(on)` switches it while the game runs.
|
|
1228
|
-
*/
|
|
1229
|
-
reducedMotion: boolean;
|
|
1230
|
-
};
|
|
1231
|
-
/**
|
|
1232
|
-
* anim plugin state: the one track table, the field bookkeeping of the retarget policy and the
|
|
1233
|
-
* offsets accumulator, the running timelines and the animation registry.
|
|
1234
|
-
*/
|
|
1235
|
-
type State$3 = {
|
|
1236
|
-
/** The one track table. Insertion order is advance order. */tracks: Map<number, Track>;
|
|
1237
|
-
/**
|
|
1238
|
-
* The tracks of the table in start order, as a dense list the frame step walks by index. An ended
|
|
1239
|
-
* track stays in it until the next frame step drops it.
|
|
1240
|
-
*/
|
|
1241
|
-
trackList: Track[]; /** Ids of tracks and timelines. */
|
|
1242
|
-
nextId: number; /** `"<entity>:<component>:<field>"` to the id of the absolute track that drives the field. */
|
|
1243
|
-
owner: Map<string, number>;
|
|
1244
|
-
/**
|
|
1245
|
-
* Per field key, the delta each additive track contributes, in a one-number cell per track that
|
|
1246
|
-
* a frame writes in place.
|
|
1247
|
-
*/
|
|
1248
|
-
offsets: Map<string, Map<number, Float64Array>>;
|
|
1249
|
-
/**
|
|
1250
|
-
* Per field key, the value the offsets are added to, in a one-number cell a frame writes in
|
|
1251
|
-
* place. Dropped when no track drives the field.
|
|
1252
|
-
*/
|
|
1253
|
-
bases: Map<string, Float64Array>;
|
|
1254
|
-
/**
|
|
1255
|
-
* Per entity, its running additive tracks. `offsetsOf` of the driver reads it, so the cost of
|
|
1256
|
-
* one answer is the loops of that entity and not every track of the game.
|
|
1257
|
-
*/
|
|
1258
|
-
additive: Map<Entity, Set<Track>>; /** The running timelines, by id. */
|
|
1259
|
-
timelines: Map<number, RunningTimeline>;
|
|
1260
|
-
/**
|
|
1261
|
-
* The timelines in start order, as a dense list the frame step walks by index. An ended timeline
|
|
1262
|
-
* stays in it until the next frame step drops it.
|
|
1263
|
-
*/
|
|
1264
|
-
timelineList: RunningTimeline[];
|
|
1265
|
-
/**
|
|
1266
|
-
* The ring of the last 16 ended timelines. Its 16 records are made with the state and written
|
|
1267
|
-
* in place at every end, never replaced.
|
|
1268
|
-
*/
|
|
1269
|
-
ended: EndedRecord[]; /** The ring slot the next end writes, 0..15. */
|
|
1270
|
-
endedNext: number; /** How many slots of the ring hold a real record, 0..16. */
|
|
1271
|
-
endedCount: number; /** The `animations` of every feature, read in `onStart`. */
|
|
1272
|
-
registry: Map<string, AnyAnimationDefinition>; /** `onMark` subscribers, in subscription order. */
|
|
1273
|
-
markListeners: Set<MarkListener>; /** Counter of the frame steps. A track born in the running step is not advanced by it. */
|
|
1274
|
-
frame: number; /** True while the track count is over `maxTracks`, so the warning is one per crossing. */
|
|
1275
|
-
overMaxTracks: boolean; /** The animations already warned for a looping `frames` step that blocks the rest of a `sequence` (dev). */
|
|
1276
|
-
warnedLoops: Set<string>; /** The live reduced-motion switch. The frozen `Config.reducedMotion` only seeds it. */
|
|
1277
|
-
reducedMotion: boolean; /** Remover of `world.projection.setDriver`. */
|
|
1278
|
-
removeDriver: (() => void) | undefined; /** Remover of `time.onFrame("animate")`. */
|
|
1279
|
-
offFrame: (() => void) | undefined; /** Remover of `flow.fx.handle("play")`. */
|
|
1280
|
-
offPlay: (() => void) | undefined; /** Bound in `onInit`, so the teardown context can end everything with the state alone. */
|
|
1281
|
-
finishAll: (() => void) | undefined; /** One loop per entity that carries `Frames`, kept by the two world hooks. */
|
|
1282
|
-
frameLoops: Map<Entity, FrameLoop>; /** How many running `frames` steps write this entity now. Its loop writes nothing above 0. */
|
|
1283
|
-
framesHeld: Map<Entity, number>;
|
|
1284
|
-
/**
|
|
1285
|
-
* Per entity that carries `Frames`, the remover of its `world.projection.mute` on
|
|
1286
|
-
* `Sprite.texture`: the loop owns that field, so a projection never corrects it back.
|
|
1287
|
-
*/
|
|
1288
|
-
frameMutes: Map<Entity, () => void>; /** Removers of the `onAdded` and `onRemoved` hooks on `Frames`. */
|
|
1289
|
-
offFrames: Array<() => void>;
|
|
1290
|
-
/**
|
|
1291
|
-
* The renderer's `sync.loopsHeld`, bound in `onStart`: an endless loop of an entity it answers true for writes
|
|
1292
|
-
* nothing while its clock runs on (spec 22 O9), told what the loop reveals (spec 26 R1.7). `undefined` before the
|
|
1293
|
-
* start and after the stop: nothing is held.
|
|
1294
|
-
*/
|
|
1295
|
-
loopsHeld: SyncApi["loopsHeld"] | undefined;
|
|
1296
|
-
};
|
|
1297
|
-
/**
|
|
1298
|
-
* anim plugin API, `app.anim`: play a choreography, end everything, count what runs and listen
|
|
1299
|
-
* to the marks. A choreography may spawn temporary entities; they live exactly as long as its
|
|
1300
|
-
* timeline.
|
|
1301
|
-
*
|
|
1302
|
-
* @example
|
|
1303
|
-
* ```ts
|
|
1304
|
-
* // A choreography runs in game time: two frames of 50 ms play the 100 ms slide of a card.
|
|
1305
|
-
* const deliverOrder = defineAnimation("orders.deliver", { slots: { card: type<Target>() },
|
|
1306
|
-
* build: ({ card }) => sequence(tween(card, Transform, { x: 100 }, { ms: 100 }), mark("done")) });
|
|
1307
|
-
* app.anim.play(deliverOrder, { card: { projection: "board.items", key: "a" } });
|
|
1308
|
-
* app.time.step(50); // app.anim.active() is 1: the card slides
|
|
1309
|
-
* app.time.step(50); // app.anim.active() is 0: the card rests at x 100
|
|
1310
|
-
* ```
|
|
1311
|
-
*/
|
|
1312
|
-
type AnimApi = {
|
|
1313
|
-
/**
|
|
1314
|
-
* Builds the step tree of an animation with the given targets and starts it. The tree runs
|
|
1315
|
-
* from the next frame step on, in game time, so `time.setScale` and a pause apply to it. `at`
|
|
1316
|
-
* inside `build` answers where a target rests in root space, even inside a scaled slot. A
|
|
1317
|
-
* `tween` with `space: "root"` lands a hosted view on such a pose: a board item inside the board
|
|
1318
|
-
* slot flies onto an order card of the HUD.
|
|
1319
|
-
*
|
|
1320
|
-
* @param animation - What `defineAnimation` returned.
|
|
1321
|
-
* @param slots - One target, or a list of targets, per declared slot.
|
|
1322
|
-
* @returns The handle of the running timeline.
|
|
1323
|
-
* @throws {Error} When the tree spawns one id twice.
|
|
1324
|
-
* @example
|
|
1325
|
-
* ```ts
|
|
1326
|
-
* // The player delivers order card "a": it slides to x 100 in 100 ms, then reaches "done".
|
|
1327
|
-
* const deliverOrder = defineAnimation("orders.deliver", { slots: { card: type<Target>() },
|
|
1328
|
-
* build: ({ card }) => sequence(tween(card, Transform, { x: 100 }, { ms: 100 }), mark("done")) });
|
|
1329
|
-
* const handle = app.anim.play(deliverOrder, { card: { projection: "board.items", key: "a" } });
|
|
1330
|
-
* app.time.step(100);
|
|
1331
|
-
* handle.marks(); // ["done"], and handle.done resolves
|
|
1332
|
-
* ```
|
|
1333
|
-
*/
|
|
1334
|
-
play<Tags extends SlotTags>(animation: AnimationDefinition<Tags>, slots: SlotValues<Tags>): PlayHandle;
|
|
1335
|
-
/**
|
|
1336
|
-
* Ends every track and every timeline now: each writes its exact target, the marks of a
|
|
1337
|
-
* running timeline are jumped in tree order, every entity a timeline spawned is despawned and
|
|
1338
|
-
* every pending `done` resolves.
|
|
1339
|
-
*
|
|
1340
|
-
* @example
|
|
1341
|
-
* ```ts
|
|
1342
|
-
* // A /control tool skips the delivery mid-flight: the card lands on x 100 at once.
|
|
1343
|
-
* const deliverOrder = defineAnimation("orders.deliver", { slots: { card: type<Target>() },
|
|
1344
|
-
* build: ({ card }) => sequence(tween(card, Transform, { x: 100 }, { ms: 100 }), mark("done")) });
|
|
1345
|
-
* app.anim.play(deliverOrder, { card: { projection: "board.items", key: "a" } });
|
|
1346
|
-
* app.time.step(50);
|
|
1347
|
-
* app.anim.finishAll(); // app.anim.active() is 0
|
|
1348
|
-
* ```
|
|
1349
|
-
*/
|
|
1350
|
-
finishAll(): void;
|
|
1351
|
-
/**
|
|
1352
|
-
* How many tracks are in the table, the delayed ones and the running loops included. A loop
|
|
1353
|
-
* never ends by itself, so a screen at rest counts one track per loop lane it shows. A `Frames`
|
|
1354
|
-
* component is not a track: a spinning coin counts nothing.
|
|
1355
|
-
*
|
|
1356
|
-
* @returns The number of running tracks.
|
|
1357
|
-
* @example
|
|
1358
|
-
* ```ts
|
|
1359
|
-
* // The assertion every motion test ends with: the screen came to rest.
|
|
1360
|
-
* const deliverOrder = defineAnimation("orders.deliver", { slots: { card: type<Target>() },
|
|
1361
|
-
* build: ({ card }) => sequence(tween(card, Transform, { x: 100 }, { ms: 100 }), mark("done")) });
|
|
1362
|
-
* app.anim.play(deliverOrder, { card: { projection: "board.items", key: "a" } });
|
|
1363
|
-
* app.time.step(100);
|
|
1364
|
-
* app.anim.active(); // 0
|
|
1365
|
-
* ```
|
|
1366
|
-
*/
|
|
1367
|
-
active(): number;
|
|
1368
|
-
/**
|
|
1369
|
-
* What plays now and what ended last: every running timeline with the targets it was played
|
|
1370
|
-
* with, and the last 16 that ended with the reason of each end. Every call builds new plain
|
|
1371
|
-
* objects and copies `entities` and `marks`; `slots` is the very object `play` received, so do
|
|
1372
|
-
* not mutate it. A reader pays for the copies, the frame step does not. Stopping the app empties
|
|
1373
|
-
* the ring.
|
|
1374
|
-
*
|
|
1375
|
-
* @returns The running timelines in start order and the ended ones, oldest first.
|
|
1376
|
-
* @example
|
|
1377
|
-
* ```ts
|
|
1378
|
-
* // A test asks what the delivery did, one frame in and at its end.
|
|
1379
|
-
* const deliverOrder = defineAnimation("orders.deliver", { slots: { card: type<Target>() },
|
|
1380
|
-
* build: ({ card }) => sequence(tween(card, Transform, { x: 100 }, { ms: 100 }), mark("done")) });
|
|
1381
|
-
* app.anim.play(deliverOrder, { card: { projection: "board.items", key: "a" } });
|
|
1382
|
-
* app.time.step(50);
|
|
1383
|
-
* app.anim.timelines().running[0]?.animation; // "orders.deliver"
|
|
1384
|
-
* app.time.step(50);
|
|
1385
|
-
* app.anim.timelines().running; // []
|
|
1386
|
-
* app.anim.timelines().ended[0]?.reason; // "ended"
|
|
1387
|
-
* ```
|
|
1388
|
-
*/
|
|
1389
|
-
timelines(): TimelinesSnapshot;
|
|
1390
|
-
/**
|
|
1391
|
-
* Whether reduced motion is on. It starts at `Config.reducedMotion` and `setReducedMotion`
|
|
1392
|
-
* switches it.
|
|
1393
|
-
*
|
|
1394
|
-
* @returns True while every new track takes 0 ms and every loop stands on its first key.
|
|
1395
|
-
* @example
|
|
1396
|
-
* ```ts
|
|
1397
|
-
* // A settings popup shows the switch as the player left it.
|
|
1398
|
-
* app.anim.reducedMotion(); // false: the start value of Config.reducedMotion
|
|
1399
|
-
* ```
|
|
1400
|
-
*/
|
|
1401
|
-
reducedMotion(): boolean;
|
|
1402
|
-
/**
|
|
1403
|
-
* Switches reduced motion. While it is on, every track started from then on takes 0 ms: enter
|
|
1404
|
-
* and exit, state changes, change and settle motions, drag returns and timeline tweens land on
|
|
1405
|
-
* their target at the next frame, and their marks and sounds still fire. Every loop stands on
|
|
1406
|
-
* its first key, a running one at once. Tracks already running keep their length. A `Frames`
|
|
1407
|
-
* loop stops on the frame it shows and walks on from that frame when the switch goes off.
|
|
1408
|
-
*
|
|
1409
|
-
* @param on - True for less motion, false for the full motion.
|
|
1410
|
-
* @example
|
|
1411
|
-
* ```ts
|
|
1412
|
-
* // The player turns on "Less motion" in the settings popup.
|
|
1413
|
-
* app.anim.setReducedMotion(true);
|
|
1414
|
-
* app.anim.reducedMotion(); // true: a popup opened now stands in its rest pose next frame
|
|
1415
|
-
* ```
|
|
1416
|
-
*/
|
|
1417
|
-
setReducedMotion(on: boolean): void;
|
|
1418
|
-
/**
|
|
1419
|
-
* Registers a listener called for every mark a timeline reaches, next to the `anim:mark`
|
|
1420
|
-
* event. A listener that throws is logged and the listeners after it still run.
|
|
1421
|
-
*
|
|
1422
|
-
* @param fn - Called with the animation id and the mark name.
|
|
1423
|
-
* @returns The remover; calling it twice is a no-op.
|
|
1424
|
-
* @example
|
|
1425
|
-
* ```ts
|
|
1426
|
-
* // A test waits for the "done" mark instead of counting frames.
|
|
1427
|
-
* const ping = defineAnimation("fx.ping", { slots: {}, build: () => sequence(wait(100), mark("done")) });
|
|
1428
|
-
* const reached: string[] = [];
|
|
1429
|
-
* app.anim.onMark((animation, name) => reached.push(`${animation}:${name}`));
|
|
1430
|
-
* app.anim.play(ping, {});
|
|
1431
|
-
* app.time.step(100); // reached: ["fx.ping:done"]
|
|
1432
|
-
* ```
|
|
1433
|
-
*/
|
|
1434
|
-
onMark(fn: MarkListener): () => void;
|
|
1435
|
-
/**
|
|
1436
|
-
* Swaps a registered animation for a new definition of the same id. The dev hot swap of `ui`
|
|
1437
|
-
* calls it when a saved `animations.ts` exports one. The next `play` effect of a node builds
|
|
1438
|
-
* the new definition; a timeline that runs now keeps the tree it was built with.
|
|
1439
|
-
*
|
|
1440
|
-
* @param definition - The new definition; its id names the animation it replaces.
|
|
1441
|
-
* @throws {Error} When no feature registered an animation with that id.
|
|
1442
|
-
* @example
|
|
1443
|
-
* ```ts
|
|
1444
|
-
* // The ui hot swap: a save of `board/animations.ts` brings a bigger merge burst.
|
|
1445
|
-
* const mergeBurst = defineAnimation("board.mergeBurst", { slots: { cell: type<Target>() },
|
|
1446
|
-
* build: ({ cell }) => tween(cell, Transform, { scale: 1.4 }, { ms: 300 }) });
|
|
1447
|
-
* ctx.require(animPlugin).replace(mergeBurst);
|
|
1448
|
-
* // A node then runs fx(play(mergeBurst, { cell: { projection: "board.items", key: "i3" } })):
|
|
1449
|
-
* // the play effect builds the new tree, and item i3 grows to scale 1.4 in 300 ms.
|
|
1450
|
-
* ```
|
|
1451
|
-
*/
|
|
1452
|
-
replace(definition: AnyAnimationDefinition): void;
|
|
1453
|
-
};
|
|
1454
|
-
/**
|
|
1455
|
-
* What a system may do with anim, read with `res(AnimPlayer)`: play. A system that needs more
|
|
1456
|
-
* than play is a plugin. Play on a change, never on every frame: keep the handle in a resource, or
|
|
1457
|
-
* take away the tag that asked for the play.
|
|
1458
|
-
*
|
|
1459
|
-
* @example
|
|
1460
|
-
* ```ts
|
|
1461
|
-
* // A fresh item pops once: the system plays, then takes the Fresh tag away.
|
|
1462
|
-
* const popIn = system({ name: "popIn", phase: "input", query: [Fresh], run: (items, { world, res }) => {
|
|
1463
|
-
* for (const [entity] of items) {
|
|
1464
|
-
* res(AnimPlayer).play(pop, { thing: entity });
|
|
1465
|
-
* world.untag(entity, Fresh);
|
|
1466
|
-
* }
|
|
1467
|
-
* } });
|
|
1468
|
-
* ```
|
|
1469
|
-
*/
|
|
1470
|
-
type AnimPlayerValue = {
|
|
1471
|
-
/**
|
|
1472
|
-
* Plays an animation from a system, the way `app.anim.play` does. The registered animation of
|
|
1473
|
-
* `animation.id` wins when a feature brought one, so a hot swap reaches the system. Played from
|
|
1474
|
-
* phase `input`, the tree moves in `animate` of the same frame; from a later phase it moves
|
|
1475
|
-
* from the next frame.
|
|
1476
|
-
*
|
|
1477
|
-
* @param animation - What `defineAnimation` returned.
|
|
1478
|
-
* @param slots - One target, or a list of targets, per declared slot.
|
|
1479
|
-
* @returns The handle: `cancel()`, `finish()`, `active()`, `done`, `marks()`.
|
|
1480
|
-
* @throws {Error} Before `anim` started: `[game] AnimPlayer is not ready: anim has not started.`
|
|
1481
|
-
* @example
|
|
1482
|
-
* ```ts
|
|
1483
|
-
* const lift = defineAnimation("look.hover", { slots: { thing: type<Target>() },
|
|
1484
|
-
* build: ({ thing }) => tween(thing, Transform, { scale: 1.1 }, { ms: 100 }) });
|
|
1485
|
-
* // Inside a system of phase "input": entity 1048576 is the item under the pointer.
|
|
1486
|
-
* const handle = res(AnimPlayer).play(lift, { thing: 1_048_576 });
|
|
1487
|
-
* handle.active(); // true until the lift lands 100 ms later, then false
|
|
1488
|
-
* ```
|
|
1489
|
-
*/
|
|
1490
|
-
play<Tags extends SlotTags>(animation: AnimationDefinition<Tags>, slots: SlotValues<Tags>): PlayHandle;
|
|
1491
|
-
};
|
|
1492
|
-
/**
|
|
1493
|
-
* Resolved dependency APIs. `renderer` is not among them: `anim` writes its `Sprite` and reads
|
|
1494
|
-
* its `Transform` through the component objects, which are plain data, composes the root pose
|
|
1495
|
-
* of `at` with the pure `rootPoseOf` of `renderer/sync/pose.ts`, and turns the target of a
|
|
1496
|
-
* `tween` in `space: "root"` local with the pure `localPoseOf` of the same module.
|
|
1497
|
-
*/
|
|
1498
|
-
type Deps$3 = {
|
|
1499
|
-
time: Api$1;
|
|
1500
|
-
flow: Api$2;
|
|
1501
|
-
world: Api$3;
|
|
1502
|
-
};
|
|
1503
|
-
/**
|
|
1504
|
-
* What the kernel context offers before the deps are attached.
|
|
1505
|
-
*
|
|
1506
|
-
* `index.ts` writes `events` with an annotated `register` (core spec `14-EVENT-REGISTRATION.md`
|
|
1507
|
-
* row 8), so the own events reach the context the kernel hands the factories and `emit` is the
|
|
1508
|
-
* kernel's own, anim-typed one. No member of the context is cast.
|
|
1509
|
-
*/
|
|
1510
|
-
type KernelSlice$3 = PluginCtx<Config$3, State$3, Events> & {
|
|
1511
|
-
readonly global: object;
|
|
1512
|
-
readonly log: Log.LogApi;
|
|
1513
|
-
readonly require: Require;
|
|
1514
|
-
};
|
|
1515
|
-
/**
|
|
1516
|
-
* Domain context of the anim plugin: the kernel slice and the three resolved dependencies.
|
|
1517
|
-
*/
|
|
1518
|
-
type AnimCtx = KernelSlice$3 & {
|
|
1519
|
-
readonly deps: Deps$3;
|
|
1520
|
-
};
|
|
1521
|
-
//#endregion
|
|
1522
|
-
//#region src/plugins/effects/filters/types.d.ts
|
|
1523
|
-
/**
|
|
1524
|
-
* One uniform of a custom filter, as declared: a number is an `f32` (`float` in GLSL), `{ color }`
|
|
1525
|
-
* a `0xrrggbb` hex sent as a `vec3<f32>` (`vec3`), a tuple of 2 to 4 numbers a `vecN<f32>`
|
|
1526
|
-
* (`vecN`).
|
|
1527
|
-
*
|
|
1528
|
-
* @example
|
|
1529
|
-
* ```ts
|
|
1530
|
-
* const uniforms: Record<string, UniformDeclaration> = { amount: 0.5, color: { color: 0xffd700 }, offset: [2, 2] };
|
|
1531
|
-
* ```
|
|
1532
|
-
*/
|
|
1533
|
-
type UniformDeclaration = number | {
|
|
1534
|
-
readonly color: number;
|
|
1535
|
-
} | readonly [number, number] | readonly [number, number, number] | readonly [number, number, number, number];
|
|
1536
|
-
/**
|
|
1537
|
-
* The component field a uniform declaration becomes: a number for a number and for a colour, a
|
|
1538
|
-
* list of numbers for a tuple.
|
|
1539
|
-
*
|
|
1540
|
-
* @example
|
|
1541
|
-
* ```ts
|
|
1542
|
-
* type Amount = UniformValue<0.5>; // number
|
|
1543
|
-
* ```
|
|
1544
|
-
*/
|
|
1545
|
-
type UniformValue<Declaration> = Declaration extends number ? number : Declaration extends {
|
|
1546
|
-
readonly color: number;
|
|
1547
|
-
} ? number : readonly number[];
|
|
1548
|
-
/**
|
|
1549
|
-
* The value of a filter component made by `defineFilter`: one field per uniform, then `enabled`
|
|
1550
|
-
* and `order`.
|
|
1551
|
-
*
|
|
1552
|
-
* @example
|
|
1553
|
-
* ```ts
|
|
1554
|
-
* type TintValue = FilterValueOf<{ amount: number; color: { color: number } }>;
|
|
1555
|
-
* // { amount: number; color: number; enabled: boolean; order: number }
|
|
1556
|
-
* ```
|
|
1557
|
-
*/
|
|
1558
|
-
type FilterValueOf<Uniforms extends Record<string, UniformDeclaration>> = { -readonly [Name in keyof Uniforms]: UniformValue<Uniforms[Name]> } & {
|
|
1559
|
-
enabled: boolean;
|
|
1560
|
-
order: number;
|
|
1561
|
-
};
|
|
1562
|
-
/**
|
|
1563
|
-
* A rectangle in the filtered entity's own units — the space its box, its hit box and its children's positions are in
|
|
1564
|
-
* (reference units for a view at the root without scale): x, y, width, height.
|
|
1565
|
-
*
|
|
1566
|
-
* @example
|
|
1567
|
-
* ```ts
|
|
1568
|
-
* // A lens disc of reach 88 around (195, 189): the 176 × 176 box it can draw in.
|
|
1569
|
-
* const area: FilterArea = [107, 101, 176, 176];
|
|
1570
|
-
* ```
|
|
1571
|
-
*/
|
|
1572
|
-
type FilterArea = readonly [x: number, y: number, width: number, height: number];
|
|
1573
|
-
/**
|
|
1574
|
-
* What `defineFilter` takes besides the id. Both bodies are required, so the filter draws on
|
|
1575
|
-
* WebGPU and on the WebGL fallback: `wgsl` is the WGSL fragment body only, the engine prepends the
|
|
1576
|
-
* vertex stage, the input bindings and the `FilterUniforms` struct; `glsl` is its GLSL ES 3.0 twin
|
|
1577
|
-
* over the same uniform names, the engine prepends the version, the inputs, `finalColor` and one
|
|
1578
|
-
* `uniform` per declared uniform.
|
|
1579
|
-
*
|
|
1580
|
-
* @example
|
|
1581
|
-
* ```ts
|
|
1582
|
-
* // A Memory Missing's frost on the layer of its panels: the body reads a blurred copy of the scene drawn under them.
|
|
1583
|
-
* const Frost = defineFilter("Frost", {
|
|
1584
|
-
* wgsl: FROST_WGSL,
|
|
1585
|
-
* glsl: FROST_GLSL,
|
|
1586
|
-
* uniforms: { view: [0, 0, 1], rectA: [0, 0, 0, 0], strength: 16, vivid: 1.2 },
|
|
1587
|
-
* backdrop: true,
|
|
1588
|
-
* inputs: { blur: { from: "back", stages: [FrostBox4, FrostHalf, FrostGauss], chain: frostChain } },
|
|
1589
|
-
* area: value => [value.rectA[0] ?? 0, value.rectA[1] ?? 0, value.rectA[2] ?? 0, value.rectA[3] ?? 0],
|
|
1590
|
-
* fallback: FrostVeil
|
|
1591
|
-
* });
|
|
1592
|
-
* [Frost.filter.backdrop, Frost.filter.cache, Frost.filter.inputs[0]?.from]; // [true, "screen", "back"]
|
|
1593
|
-
* ```
|
|
1594
|
-
*/
|
|
1595
|
-
type FilterSpec<Uniforms extends Record<string, UniformDeclaration>> = {
|
|
1596
|
-
/** The WGSL fragment body: `fn mainFragment` and its helpers, without the engine's header. */readonly wgsl: string;
|
|
1597
|
-
/**
|
|
1598
|
-
* The GLSL ES 3.0 fragment body: `void main()`, which sets `finalColor`, and its helpers, without
|
|
1599
|
-
* the engine's header. It reads each uniform under its bare name: `amount`, not `fu.amount`.
|
|
1600
|
-
*/
|
|
1601
|
-
readonly glsl: string; /** The uniforms in struct order. Default `{}`. */
|
|
1602
|
-
readonly uniforms?: Uniforms; /** Render passes one apply of the filter costs, an integer of at least 1. Default `1`. */
|
|
1603
|
-
readonly passes?: number; /** Pixels around the view's bounds, or the name of a number uniform whose live value they are. Default `0`. */
|
|
1604
|
-
readonly padding?: number | string;
|
|
1605
|
-
/**
|
|
1606
|
-
* Second textures the body reads, by name: `blur` declares `sampleBlur(uv)` in the WGSL and the GLSL, with the
|
|
1607
|
-
* texture, its sampler and two uniforms the engine fills. Leave `passes` out: the engine counts them. Default none.
|
|
1608
|
-
*/
|
|
1609
|
-
readonly inputs?: Readonly<Record<string, FilterInput<FilterValueOf<Uniforms>>>>;
|
|
1610
|
-
/**
|
|
1611
|
-
* What draws instead when the filter is broken (its shader or a stage does not compile on the device, its apply
|
|
1612
|
-
* throws, its chain fails): another filter over a subset of its uniforms, with the same value. Default none: a broken
|
|
1613
|
-
* filter leaves its view unfiltered.
|
|
1614
|
-
*/
|
|
1615
|
-
readonly fallback?: FilterStage;
|
|
1616
|
-
/**
|
|
1617
|
-
* What the renderer may do with a view this filter draws on, while nothing it depends on changes: `"local"` (the
|
|
1618
|
-
* default) keeps it as a picture, also while the view moves; `"placed"` keeps it with its canvas origin, for a body
|
|
1619
|
-
* that reads where it is drawn through `canvasPixel(uv)` (a body that calls the helper is placed by itself); set
|
|
1620
|
-
* `false` for a body whose look depends on where the view is drawn in a way the engine cannot see (a time read from
|
|
1621
|
-
* a texture, a hash of the screen position): no output of it is kept. On WebGPU the view's subtree picture is kept
|
|
1622
|
-
* and the body runs on its quad in every frame, the canvas place in `uOutputFrame.xy`; on WebGL, or when it does not
|
|
1623
|
-
* fit the quad, it is drawn live in every frame. A body that reads `uGlobalFrame`, `@builtin(position)`,
|
|
1624
|
-
* `gl_FragCoord`, `uOutputTexture` or the origin of `uOutputFrame` and declares nothing is treated as `false`, and a
|
|
1625
|
-
* dev build warns once: declare `cache: false`.
|
|
1626
|
-
*/
|
|
1627
|
-
readonly cache?: "local" | "placed" | false;
|
|
1628
|
-
/**
|
|
1629
|
-
* The rectangle outside of which this filter draws nothing, in the filtered entity's own units, from the component's
|
|
1630
|
-
* value; `undefined` for "the view's bounds" (the default). Outside it Pixi draws nothing of the view at all — neither
|
|
1631
|
-
* the filter nor the view's own content — so declare it only for a filter whose output is transparent there. A view
|
|
1632
|
-
* with several enabled filters gets the union; a view with an enabled filter that declares no area gets none. Called
|
|
1633
|
-
* only when the value changed.
|
|
1634
|
-
*/
|
|
1635
|
-
readonly area?: (value: Readonly<FilterValueOf<Uniforms>>) => FilterArea | undefined;
|
|
1636
|
-
/**
|
|
1637
|
-
* The texels per CSS px the view and its filters are drawn at under this filter, from 0 to 4; `0` (the default) for
|
|
1638
|
-
* the resolution of the canvas. Pixi draws all the filters of a view at the smallest resolution among them, so a
|
|
1639
|
-
* resolution below the canvas's lowers the others on the same view too. A stage of an input ignores it: its step's
|
|
1640
|
-
* `scale` sizes it.
|
|
1641
|
-
*/
|
|
1642
|
-
readonly resolution?: number;
|
|
1643
|
-
/**
|
|
1644
|
-
* `true` for a filter that reads what was drawn under its view, inside its box (the view's bounds, or its `area`):
|
|
1645
|
-
* Pixi copies that part of the canvas before the view draws, the body reads it through `sampleBack(uv)`, and an input
|
|
1646
|
-
* may start from it (`from: "back"`). Its output is laid over the canvas like the view's own pixels: where the body
|
|
1647
|
-
* answers transparent the canvas stays as it is. A backdrop is drawn live in every frame, never kept (`cache` may only
|
|
1648
|
-
* be left out or `false`), has no padding, and is no stage; its fallback may be one. On WebGL the renderer then draws
|
|
1649
|
-
* every frame into Pixi's back buffer. Default `false`.
|
|
1650
|
-
*/
|
|
1651
|
-
readonly backdrop?: boolean;
|
|
1652
|
-
};
|
|
1653
|
-
/**
|
|
1654
|
-
* How one uniform travels to the GPU: its name, its WGSL type and the form it was declared in.
|
|
1655
|
-
*
|
|
1656
|
-
* @example
|
|
1657
|
-
* ```ts
|
|
1658
|
-
* const spec: UniformSpec = { name: "color", type: "vec3<f32>", form: "color", size: 3 };
|
|
1659
|
-
* ```
|
|
1660
|
-
*/
|
|
1661
|
-
type UniformSpec = {
|
|
1662
|
-
readonly name: string;
|
|
1663
|
-
readonly type: "f32" | "vec2<f32>" | "vec3<f32>" | "vec4<f32>";
|
|
1664
|
-
readonly form: "number" | "color" | "vector";
|
|
1665
|
-
readonly size: number;
|
|
1666
|
-
};
|
|
1667
|
-
/**
|
|
1668
|
-
* The filter a component made by `defineFilter` carries: the assembled WGSL in `source`, the
|
|
1669
|
-
* assembled GLSL in `glsl`, the uniforms in struct order, the passes one apply costs, the
|
|
1670
|
-
* padding, the second textures the body reads and the filter drawn in its place when it is broken.
|
|
1671
|
-
*
|
|
1672
|
-
* @example
|
|
1673
|
-
* ```ts
|
|
1674
|
-
* Tint.filter.source.includes("fn mainFragment"); // true: the WGSL, drawn on WebGPU
|
|
1675
|
-
* Tint.filter.glsl.startsWith("#version 300 es"); // true: the GLSL, drawn on WebGL
|
|
1676
|
-
* Tint.filter.uniforms.map(uniform => uniform.name); // ["amount", "color"]
|
|
1677
|
-
* Tint.filter.inputs.length; // 0: it reads no second texture
|
|
1678
|
-
* Tint.filter.cache; // "local": a still view under it is drawn from a picture
|
|
1679
|
-
* ```
|
|
1680
|
-
*/
|
|
1681
|
-
type FilterDefinition = {
|
|
1682
|
-
readonly id: string; /** The assembled WGSL: the engine's header, the uniform struct, the input bindings, the body. */
|
|
1683
|
-
readonly source: string; /** The assembled GLSL ES 3.0: the engine's header, one `uniform` per uniform, the inputs, the body. */
|
|
1684
|
-
readonly glsl: string;
|
|
1685
|
-
/**
|
|
1686
|
-
* The quad program: the same body on a mesh, in the pass that draws the canvas (renderer README, "Kept pictures").
|
|
1687
|
-
* A definition with inputs has one too: each input starts from the view's own input, and the mesh binds its held
|
|
1688
|
-
* chain result (`Bloom` rides it while its `strength` moves). `undefined` for a backdrop, an input from `"back"`, or
|
|
1689
|
-
* a body the rewrite does not fit.
|
|
1690
|
-
*/
|
|
1691
|
-
readonly quadSource: string | undefined;
|
|
1692
|
-
readonly uniforms: readonly UniformSpec[];
|
|
1693
|
-
readonly passes: number;
|
|
1694
|
-
readonly padding: number | string; /** The second textures the body reads, in declaration order; empty for a filter with none. */
|
|
1695
|
-
readonly inputs: readonly FilterInputDefinition[]; /** What draws in its place when it is broken: another definition over a subset of its uniforms. */
|
|
1696
|
-
readonly fallback: FilterDefinition | undefined; /** What the kept-picture cache may do with it: the worst of its declaration, its body and its stages' bodies. */
|
|
1697
|
-
readonly cache: FilterCache;
|
|
1698
|
-
/**
|
|
1699
|
-
* The engine's `keptOrigin` uniform (`vec2<f32>`) of a body that calls `canvasPixel(uv)`, kept out of `uniforms`;
|
|
1700
|
-
* `undefined` for any other body.
|
|
1701
|
-
*/
|
|
1702
|
-
readonly origin: UniformSpec | undefined; /** The rectangle outside of which the filter draws nothing, from the value; present only when the spec gave one. */
|
|
1703
|
-
readonly area?: (value: Readonly<FilterFields>) => FilterArea | undefined; /** The texels per CSS px it draws at; 0 for the resolution of the canvas. */
|
|
1704
|
-
readonly resolution: number; /** True for a filter that reads what was drawn under its view: Pixi's `blendRequired`, and `sampleBack` in its body. */
|
|
1705
|
-
readonly backdrop: boolean;
|
|
1706
|
-
};
|
|
1707
|
-
/**
|
|
1708
|
-
* A filter a chain may draw: any component `defineFilter` made. Listed in an input's `stages` and named by its steps.
|
|
1709
|
-
* A built-in Pixi-core kind (`Blur`, `ColorMatrix`, …) has no `filter` and cannot be a stage.
|
|
1710
|
-
*
|
|
1711
|
-
* @example
|
|
1712
|
-
* ```ts
|
|
1713
|
-
* const FrostGauss = defineFilter("FrostGauss", { wgsl: gaussWgsl, glsl: gaussGlsl, uniforms: { dir: [0, 0], sigma: 0 } });
|
|
1714
|
-
* const stages: readonly FilterStage[] = [FrostBox4, FrostHalf, FrostGauss];
|
|
1715
|
-
* stages.map(stage => stage.filter.id); // ["FrostBox4", "FrostHalf", "FrostGauss"]
|
|
1716
|
-
* ```
|
|
1717
|
-
*/
|
|
1718
|
-
type FilterStage = {
|
|
1719
|
-
readonly componentName: string;
|
|
1720
|
-
readonly defaults: object;
|
|
1721
|
-
readonly filter: FilterDefinition;
|
|
1722
|
-
};
|
|
1723
|
-
/**
|
|
1724
|
-
* One step of a chain: the stage that draws, the share of the input's resolution it draws at, and the stage uniforms
|
|
1725
|
-
* of this step. A uniform the step leaves out takes the stage's default. A colour is a `0xrrggbb` number.
|
|
1726
|
-
*
|
|
1727
|
-
* @example
|
|
1728
|
-
* ```ts
|
|
1729
|
-
* // A Gaussian along x at an eighth of the resolution of the view's input.
|
|
1730
|
-
* const step: FilterStep = { stage: FrostGauss, scale: 1 / 8, uniforms: { dir: [1, 0], sigma: 4.66 } };
|
|
1731
|
-
* ```
|
|
1732
|
-
*/
|
|
1733
|
-
type FilterStep = {
|
|
1734
|
-
readonly stage: FilterStage; /** Above 0 and at most 1: the target of this step has `scale` × the resolution of the view's input. */
|
|
1735
|
-
readonly scale: number;
|
|
1736
|
-
readonly uniforms?: Readonly<Record<string, number | readonly number[]>>;
|
|
1737
|
-
};
|
|
1738
|
-
/**
|
|
1739
|
-
* What a chain is told besides the value: the real pixels per CSS pixel of the texture the view is drawn into (the
|
|
1740
|
-
* canvas resolution for a view at the top, less under a filter of lower resolution).
|
|
1741
|
-
*
|
|
1742
|
-
* @example
|
|
1743
|
-
* ```ts
|
|
1744
|
-
* // The owner's phone at maxResolution 3: 16 units of blur are 37 real pixels, an eighth is enough.
|
|
1745
|
-
* frostChain({ ...Frost().value, strength: 16, view: [0, 0, 384 / 390] }, { resolution: 2.8125 }).map(step => step.scale);
|
|
1746
|
-
* // [0.25, 0.125, 0.125, 0.125]
|
|
1747
|
-
* ```
|
|
1748
|
-
*/
|
|
1749
|
-
type FilterChainContext = {
|
|
1750
|
-
readonly resolution: number;
|
|
1751
|
-
};
|
|
1752
|
-
/**
|
|
1753
|
-
* A second texture the body of a filter reads, named by its key in `inputs`: `blur` gives the body
|
|
1754
|
-
* `sampleBlur(uv)`. `chain` returns the steps that draw it from the view's own input, each from the one before;
|
|
1755
|
-
* the body reads the last one. `stages` lists every filter the chain may name: they are checked on the device and
|
|
1756
|
-
* warmed up before the first draw, and a step naming another one is refused. The chain runs again only when a uniform
|
|
1757
|
-
* of the value or the resolution changed, never per frame; it may return `[]`, and the body then reads the view's own
|
|
1758
|
-
* input.
|
|
1759
|
-
*
|
|
1760
|
-
* @example
|
|
1761
|
-
* ```ts
|
|
1762
|
-
* const input: FilterInput<{ strength: number; enabled: boolean; order: number }> = {
|
|
1763
|
-
* stages: [FrostHalf, FrostGauss],
|
|
1764
|
-
* chain: (value, { resolution }) => [
|
|
1765
|
-
* { stage: FrostHalf, scale: 1 / 2 },
|
|
1766
|
-
* { stage: FrostGauss, scale: 1 / 2, uniforms: { dir: [1, 0], sigma: (value.strength * resolution) / 2 } },
|
|
1767
|
-
* { stage: FrostGauss, scale: 1 / 2, uniforms: { dir: [0, 1], sigma: (value.strength * resolution) / 2 } }
|
|
1768
|
-
* ]
|
|
1769
|
-
* };
|
|
1770
|
-
* ```
|
|
1771
|
-
*/
|
|
1772
|
-
type FilterInput<Value> = {
|
|
1773
|
-
/**
|
|
1774
|
-
* Where the first step reads: `"input"` (the default), the view's own input; `"back"`, what was drawn under the
|
|
1775
|
-
* view inside its box, for a backdrop filter only. A chain from back runs at the resolution of the surface under the
|
|
1776
|
-
* view, which `context.resolution` then holds.
|
|
1777
|
-
*/
|
|
1778
|
-
readonly from?: "input" | "back";
|
|
1779
|
-
readonly stages: readonly FilterStage[];
|
|
1780
|
-
/**
|
|
1781
|
-
* The steps of the second texture for this value and resolution. Pure: no state, no randomness; the context object
|
|
1782
|
-
* is the engine's and valid during the call only. The engine reads the steps during the call and copies the uniform
|
|
1783
|
-
* values it needs, so a chain may answer the same array on every call, its uniform objects written in place (what
|
|
1784
|
-
* `Bloom` does, so a tween allocates nothing in the chain).
|
|
1785
|
-
*
|
|
1786
|
-
* @param value - The stored value of the filter component.
|
|
1787
|
-
* @param context - The resolution of the texture the view is drawn into.
|
|
1788
|
-
* @returns The steps in draw order, at most 16.
|
|
1789
|
-
* @example
|
|
1790
|
-
* ```ts
|
|
1791
|
-
* // A quarter is enough at one real pixel per CSS pixel: the box, then the Gaussian along x and along y.
|
|
1792
|
-
* Frost.filter.inputs[0]?.chain({ ...Frost().value, strength: 16, view: [0, 0, 1] }, { resolution: 1 }).length; // 3
|
|
1793
|
-
* ```
|
|
1794
|
-
*/
|
|
1795
|
-
chain(value: Readonly<Value>, context: FilterChainContext): readonly FilterStep[];
|
|
1796
|
-
};
|
|
1797
|
-
/**
|
|
1798
|
-
* An input as `defineFilter` stored it: the names the engine declared for it in both shader languages, its two
|
|
1799
|
-
* uniforms, its stages and its chain.
|
|
1800
|
-
*
|
|
1801
|
-
* @example
|
|
1802
|
-
* ```ts
|
|
1803
|
-
* const [blur] = Frost.filter.inputs;
|
|
1804
|
-
* [blur?.texture, blur?.sampler, blur?.scale.name, blur?.clamp.name, blur?.sample, blur?.from];
|
|
1805
|
-
* // ["blurTexture", "blurSampler", "blurScale", "blurClamp", "sampleBlur", "back"]
|
|
1806
|
-
* ```
|
|
1807
|
-
*/
|
|
1808
|
-
type FilterInputDefinition = {
|
|
1809
|
-
readonly name: string; /** Where its first step reads: the view's own input, or what was drawn under the view. */
|
|
1810
|
-
readonly from: "input" | "back";
|
|
1811
|
-
readonly texture: string;
|
|
1812
|
-
readonly sampler: string;
|
|
1813
|
-
readonly scale: UniformSpec;
|
|
1814
|
-
readonly clamp: UniformSpec;
|
|
1815
|
-
readonly sample: string;
|
|
1816
|
-
readonly stages: readonly FilterStage[];
|
|
1817
|
-
readonly chain: FilterInput<FilterFields>["chain"];
|
|
1818
|
-
};
|
|
1819
|
-
/**
|
|
1820
|
-
* A filter component type: the `component()` of its id, with the filter definition attached. Its
|
|
1821
|
-
* numeric fields are tweenable like any component.
|
|
1822
|
-
*
|
|
1823
|
-
* @example
|
|
1824
|
-
* ```ts
|
|
1825
|
-
* const Tint: FilterComponent<{ amount: number; enabled: boolean; order: number }> =
|
|
1826
|
-
* defineFilter("fx.tint", { wgsl: tintWgsl, glsl: tintGlsl, uniforms: { amount: 0 } });
|
|
1827
|
-
* Tint.componentName; // "fx.tint"
|
|
1828
|
-
* ```
|
|
1829
|
-
*/
|
|
1830
|
-
type FilterComponent<Value extends object> = ComponentType<Value> & {
|
|
1831
|
-
readonly filter: FilterDefinition;
|
|
1832
|
-
};
|
|
1833
|
-
/**
|
|
1834
|
-
* One field of a stored filter value: a number, a switch, an asset key or a vector.
|
|
1835
|
-
*
|
|
1836
|
-
* @example
|
|
1837
|
-
* ```ts
|
|
1838
|
-
* const field: FilterField = 0.5;
|
|
1839
|
-
* ```
|
|
1840
|
-
*/
|
|
1841
|
-
type FilterField = number | boolean | string | readonly number[];
|
|
1842
|
-
/**
|
|
1843
|
-
* The stored value of any filter component, with the kind erased: the filter sync reads every
|
|
1844
|
-
* kind through it.
|
|
1845
|
-
*/
|
|
1846
|
-
type FilterFields = {
|
|
1847
|
-
readonly enabled: boolean;
|
|
1848
|
-
readonly order: number;
|
|
1849
|
-
readonly [field: string]: FilterField;
|
|
1850
|
-
};
|
|
1851
|
-
/**
|
|
1852
|
-
* `Glow`: a soft halo of `color` around the opaque pixels of the view.
|
|
1853
|
-
*
|
|
1854
|
-
* @example
|
|
1855
|
-
* ```ts
|
|
1856
|
-
* const value: GlowValue = { strength: 2, distance: 10, color: 0xffffff, alpha: 1, enabled: true, order: 0 };
|
|
1857
|
-
* ```
|
|
1858
|
-
*/
|
|
1859
|
-
type GlowValue = {
|
|
1860
|
-
strength: number;
|
|
1861
|
-
distance: number;
|
|
1862
|
-
color: number;
|
|
1863
|
-
alpha: number;
|
|
1864
|
-
enabled: boolean;
|
|
1865
|
-
order: number;
|
|
1866
|
-
};
|
|
1867
|
-
/**
|
|
1868
|
-
* `Outline`: a ring of `thickness` pixels in `color` around the opaque pixels of the view.
|
|
1869
|
-
*
|
|
1870
|
-
* @example
|
|
1871
|
-
* ```ts
|
|
1872
|
-
* const value: OutlineValue = { thickness: 2, color: 0x000000, alpha: 1, enabled: true, order: 0 };
|
|
1873
|
-
* ```
|
|
1874
|
-
*/
|
|
1875
|
-
type OutlineValue = {
|
|
1876
|
-
thickness: number;
|
|
1877
|
-
color: number;
|
|
1878
|
-
alpha: number;
|
|
1879
|
-
enabled: boolean;
|
|
1880
|
-
order: number;
|
|
1881
|
-
};
|
|
1882
|
-
/**
|
|
1883
|
-
* `Blur`: Pixi's blur. `quality: 0` means `config.blur.quality`; `resolution: 0` means
|
|
1884
|
-
* `config.blur.phoneResolution` on a phone, otherwise 1.
|
|
1885
|
-
*
|
|
1886
|
-
* @example
|
|
1887
|
-
* ```ts
|
|
1888
|
-
* const value: BlurValue = { strength: 8, quality: 0, resolution: 0, repeatEdgePixels: true, enabled: true, order: 0 };
|
|
1889
|
-
* ```
|
|
1890
|
-
*/
|
|
1891
|
-
type BlurValue = {
|
|
1892
|
-
strength: number;
|
|
1893
|
-
quality: number;
|
|
1894
|
-
resolution: number;
|
|
1895
|
-
repeatEdgePixels: boolean;
|
|
1896
|
-
enabled: boolean;
|
|
1897
|
-
order: number;
|
|
1898
|
-
};
|
|
1899
|
-
/**
|
|
1900
|
-
* `ColorMatrix`: brightness, saturation, contrast, hue and grayscale composed in that order.
|
|
1901
|
-
* Every default is the identity.
|
|
1902
|
-
*
|
|
1903
|
-
* @example
|
|
1904
|
-
* ```ts
|
|
1905
|
-
* const value: ColorMatrixValue = { brightness: 1, saturation: 0, contrast: 0, hue: 0, grayscale: 1, enabled: true, order: 0 };
|
|
1906
|
-
* ```
|
|
1907
|
-
*/
|
|
1908
|
-
type ColorMatrixValue = {
|
|
1909
|
-
brightness: number;
|
|
1910
|
-
saturation: number;
|
|
1911
|
-
contrast: number;
|
|
1912
|
-
hue: number;
|
|
1913
|
-
grayscale: number;
|
|
1914
|
-
enabled: boolean;
|
|
1915
|
-
order: number;
|
|
1916
|
-
};
|
|
1917
|
-
/**
|
|
1918
|
-
* `Noise`: Pixi's noise with its seed always given, so two runs draw the same grain.
|
|
1919
|
-
*
|
|
1920
|
-
* @example
|
|
1921
|
-
* ```ts
|
|
1922
|
-
* const value: NoiseValue = { amount: 0.5, seed: 7, enabled: true, order: 0 };
|
|
1923
|
-
* ```
|
|
1924
|
-
*/
|
|
1925
|
-
type NoiseValue = {
|
|
1926
|
-
amount: number;
|
|
1927
|
-
seed: number;
|
|
1928
|
-
enabled: boolean;
|
|
1929
|
-
order: number;
|
|
1930
|
-
};
|
|
1931
|
-
/**
|
|
1932
|
-
* `Displacement`: Pixi's displacement over the texture of an asset key.
|
|
1933
|
-
*
|
|
1934
|
-
* @example
|
|
1935
|
-
* ```ts
|
|
1936
|
-
* const value: DisplacementValue = { map: "fx.ripple", scaleX: 20, scaleY: 20, enabled: true, order: 0 };
|
|
1937
|
-
* ```
|
|
1938
|
-
*/
|
|
1939
|
-
type DisplacementValue = {
|
|
1940
|
-
map: string;
|
|
1941
|
-
scaleX: number;
|
|
1942
|
-
scaleY: number;
|
|
1943
|
-
enabled: boolean;
|
|
1944
|
-
order: number;
|
|
1945
|
-
};
|
|
1946
|
-
/**
|
|
1947
|
-
* `Alpha`: Pixi's alpha over the whole subtree, as one layer. `resolution` is the texels per CSS px the subtree is drawn
|
|
1948
|
-
* at, at most 4, `0` for the resolution of the canvas; Pixi draws all the filters of a view at the smallest resolution
|
|
1949
|
-
* among them, so `Alpha({ resolution: 0.5 })` beside a `Glow` draws the glow at 0.5 too. At `alpha: 1` and
|
|
1950
|
-
* `resolution: 0` the filter would copy the subtree unchanged through a pass of its own: it is switched off, at once
|
|
1951
|
-
* when it is built so, otherwise after 8 frames at rest there (a keyframe that touches 1 switches nothing), and the
|
|
1952
|
-
* subtree draws as if the Alpha were not there.
|
|
1953
|
-
*
|
|
1954
|
-
* @example
|
|
1955
|
-
* ```ts
|
|
1956
|
-
* // The fog of a memory screen, opaque, drawn at half a texel per CSS px through the Alpha's one pass.
|
|
1957
|
-
* const value: AlphaValue = { alpha: 1, resolution: 0.5, enabled: true, order: 0 };
|
|
1958
|
-
* ```
|
|
1959
|
-
*/
|
|
1960
|
-
type AlphaValue = {
|
|
1961
|
-
alpha: number;
|
|
1962
|
-
resolution: number;
|
|
1963
|
-
enabled: boolean;
|
|
1964
|
-
order: number;
|
|
1965
|
-
};
|
|
1966
|
-
/**
|
|
1967
|
-
* The five built-in kinds drawn by a Pixi core filter.
|
|
1968
|
-
*
|
|
1969
|
-
* @example
|
|
1970
|
-
* ```ts
|
|
1971
|
-
* const kind: CoreKind = "blur";
|
|
1972
|
-
* ```
|
|
1973
|
-
*/
|
|
1974
|
-
type CoreKind = "blur" | "colorMatrix" | "noise" | "displacement" | "alpha";
|
|
1975
|
-
/**
|
|
1976
|
-
* Where a filter kind comes from: our or a game's shaders (`"wgsl"`, with the GLSL twin beside
|
|
1977
|
-
* it), or a Pixi core filter.
|
|
1978
|
-
*/
|
|
1979
|
-
type KindSource = {
|
|
1980
|
-
readonly source: "wgsl";
|
|
1981
|
-
readonly definition: FilterDefinition;
|
|
1982
|
-
} | {
|
|
1983
|
-
readonly source: "core";
|
|
1984
|
-
readonly core: CoreKind;
|
|
1985
|
-
};
|
|
1986
|
-
/**
|
|
1987
|
-
* A filter kind before it is registered: its id, its component and its source.
|
|
1988
|
-
*/
|
|
1989
|
-
type KindEntry = KindSource & {
|
|
1990
|
-
readonly id: string;
|
|
1991
|
-
readonly component: ComponentHandle<FilterFields>;
|
|
1992
|
-
};
|
|
1993
|
-
/**
|
|
1994
|
-
* One registered filter kind. `index` is the registration order: the built-ins first, then the
|
|
1995
|
-
* filters of every feature in feature order.
|
|
1996
|
-
*/
|
|
1997
|
-
type FilterKind = KindEntry & {
|
|
1998
|
-
readonly index: number;
|
|
1999
|
-
};
|
|
2000
|
-
/**
|
|
2001
|
-
* The values of the uniform group of one of our filter instances: a number per `f32`, a vector
|
|
2002
|
-
* per colour and tuple. Written where they differ from the stored value.
|
|
2003
|
-
*/
|
|
2004
|
-
type UniformValues = Record<string, number | Float32Array>;
|
|
2005
|
-
/**
|
|
2006
|
-
* The uniform group of one of our filter instances, as the instance writes it.
|
|
2007
|
-
*/
|
|
2008
|
-
type FilterUniforms = PixiUniformGroup & {
|
|
2009
|
-
readonly uniforms: UniformValues;
|
|
2010
|
-
};
|
|
2011
|
-
/**
|
|
2012
|
-
* The Pixi object of one kind on one view, with the passes one apply of it costs now: what the
|
|
2013
|
-
* builders of `instance.ts` make before the instance gets its sort keys. A Pixi-core kind keeps
|
|
2014
|
-
* the fields its setters were last given, `applied`, so an equal value calls no setter.
|
|
2015
|
-
*/
|
|
2016
|
-
type FilterBody = {
|
|
2017
|
-
readonly kind: "wgsl";
|
|
2018
|
-
readonly filter: PixiFilter;
|
|
2019
|
-
readonly group: FilterUniforms | undefined;
|
|
2020
|
-
readonly definition: FilterDefinition;
|
|
2021
|
-
passes: number; /** The chains and their places; `undefined` for a definition without inputs. Set once, by `createFilter`. */
|
|
2022
|
-
inputs: InputsState | undefined; /** The dev mark drawn after the fallback by a stand-in (E5.4); `undefined` otherwise. */
|
|
2023
|
-
readonly mark: OursBody | undefined; /** The definition's last area answer, filled in place; `some: false` for `undefined` (B4). */
|
|
2024
|
-
readonly area: AreaBox; /** The value changed since the area was last asked: the next sync asks the definition again. */
|
|
2025
|
-
areaStale: boolean; /** What the slot hands over for the quad, made once: the renderer compares it by identity. */
|
|
2026
|
-
quad: FilterSlotQuad | undefined;
|
|
2027
|
-
} | {
|
|
2028
|
-
readonly kind: "blur";
|
|
2029
|
-
readonly filter: InstanceType<PixiModule["BlurFilter"]>; /** The fields the setters were last given; compared before a write. */
|
|
2030
|
-
readonly applied: Record<string, FilterField>; /** The keys of `applied`, listed once: a compare walks them by index, with no `Object.keys` per frame. */
|
|
2031
|
-
readonly fields: readonly string[];
|
|
2032
|
-
passes: number;
|
|
2033
|
-
} | {
|
|
2034
|
-
readonly kind: "colorMatrix";
|
|
2035
|
-
readonly filter: InstanceType<PixiModule["ColorMatrixFilter"]>; /** The fields the setters were last given; compared before a write. */
|
|
2036
|
-
readonly applied: Record<string, FilterField>; /** The keys of `applied`, listed once: a compare walks them by index, with no `Object.keys` per frame. */
|
|
2037
|
-
readonly fields: readonly string[];
|
|
2038
|
-
passes: number;
|
|
2039
|
-
} | {
|
|
2040
|
-
readonly kind: "noise";
|
|
2041
|
-
readonly filter: InstanceType<PixiModule["NoiseFilter"]>; /** The fields the setters were last given; compared before a write. */
|
|
2042
|
-
readonly applied: Record<string, FilterField>; /** The keys of `applied`, listed once: a compare walks them by index, with no `Object.keys` per frame. */
|
|
2043
|
-
readonly fields: readonly string[];
|
|
2044
|
-
passes: number;
|
|
2045
|
-
} | {
|
|
2046
|
-
readonly kind: "displacement";
|
|
2047
|
-
readonly filter: InstanceType<PixiModule["DisplacementFilter"]>;
|
|
2048
|
-
readonly sprite: PixiSprite; /** The fields the setters were last given; compared before a write. */
|
|
2049
|
-
readonly applied: Record<string, FilterField>; /** The keys of `applied`, listed once: a compare walks them by index, with no `Object.keys` per frame. */
|
|
2050
|
-
readonly fields: readonly string[]; /** The asset key the map sprite shows now. */
|
|
2051
|
-
map: string;
|
|
2052
|
-
passes: number;
|
|
2053
|
-
} | {
|
|
2054
|
-
readonly kind: "alpha";
|
|
2055
|
-
readonly filter: InstanceType<PixiModule["AlphaFilter"]>; /** The fields the setters were last given; compared before a write. */
|
|
2056
|
-
readonly applied: Record<string, FilterField>; /** The keys of `applied`, listed once: a compare walks them by index, with no `Object.keys` per frame. */
|
|
2057
|
-
readonly fields: readonly string[];
|
|
2058
|
-
passes: number;
|
|
2059
|
-
/**
|
|
2060
|
-
* Syncs in a row its value drew the view unchanged (at 1, at the canvas's resolution) while its filter was on;
|
|
2061
|
-
* the filter is switched off at `CALM_AFTER` and the count starts over.
|
|
2062
|
-
*/
|
|
2063
|
-
calm: number;
|
|
2064
|
-
};
|
|
2065
|
-
/**
|
|
2066
|
-
* A probe of the warm-up (spec 27 F4): the Pixi filter handed to `renderer.sync.filters.warm`, the quad of a kind whose
|
|
2067
|
-
* body can run on one, and its teardown.
|
|
2068
|
-
*/
|
|
2069
|
-
type WarmProbe = {
|
|
2070
|
-
readonly filter: PixiFilter;
|
|
2071
|
-
readonly quad: FilterSlotQuad | undefined;
|
|
2072
|
-
destroy(): void;
|
|
2073
|
-
};
|
|
2074
|
-
/**
|
|
2075
|
-
* A filter area as the filter sync keeps it, written in place: the four numbers, and whether there is one.
|
|
2076
|
-
*/
|
|
2077
|
-
type AreaBox = {
|
|
2078
|
-
x: number;
|
|
2079
|
-
y: number;
|
|
2080
|
-
width: number;
|
|
2081
|
-
height: number;
|
|
2082
|
-
some: boolean;
|
|
2083
|
-
};
|
|
2084
|
-
/**
|
|
2085
|
-
* The instance of one kind on one view: its Pixi object, and what it sorts by on the view, the
|
|
2086
|
-
* `order` of its component (written every frame) and the `index` of its kind. The instance is
|
|
2087
|
-
* the object the builder made, never a copy: a closure made while building (the apply guard)
|
|
2088
|
-
* reads and writes the same fields the filter sync does.
|
|
2089
|
-
*/
|
|
2090
|
-
type FilterInstance = FilterBody & {
|
|
2091
|
-
order: number;
|
|
2092
|
-
readonly index: number; /** True once the instance broke (its apply threw, its chain failed): it stays broken until it is retired. */
|
|
2093
|
-
broken: boolean; /** The value the filter sync handed over last: the chain and a stand-in are built from it. */
|
|
2094
|
-
value: Readonly<FilterFields>; /** The kind this instance draws for; a stand-in carries the id of the kind it stands in for. */
|
|
2095
|
-
readonly kindId: string; /** True for an instance that draws in place of a broken kind or instance (E5). */
|
|
2096
|
-
readonly standIn: boolean; /** A stand-in built while this broken instance was drawing; the next sync puts it in its place. */
|
|
2097
|
-
replacement: FilterInstance | undefined;
|
|
2098
|
-
/**
|
|
2099
|
-
* The entity of the view it draws on, set when the filter sync takes it in; 0 for a warm-up probe. A break inside a
|
|
2100
|
-
* render tells the renderer about this view (`renderer.invalidate`) before it switches the filter off.
|
|
2101
|
-
*/
|
|
2102
|
-
entity: Entity;
|
|
2103
|
-
};
|
|
2104
|
-
/**
|
|
2105
|
-
* One of our bodies: a `Filter` over the assembled programs, the kind of every place of a chain and of a mark.
|
|
2106
|
-
*/
|
|
2107
|
-
type OursBody = Extract<FilterBody, {
|
|
2108
|
-
kind: "wgsl";
|
|
2109
|
-
}>;
|
|
2110
|
-
/** One place of a chain: the Pixi filter that draws the stage there, and the share of the resolution it draws at. */
|
|
2111
|
-
type Place = {
|
|
2112
|
-
readonly definition: FilterDefinition;
|
|
2113
|
-
readonly body: OursBody;
|
|
2114
|
-
scale: number;
|
|
2115
|
-
};
|
|
2116
|
-
/**
|
|
2117
|
-
* The chains of one instance of a filter with inputs: what draws each second texture, and the seam spec 23 keeps
|
|
2118
|
-
* pictures through.
|
|
2119
|
-
*/
|
|
2120
|
-
type InputsState = {
|
|
2121
|
-
/** A uniform of the value changed since the last evaluation (set by `writeFilter`). */stale: boolean; /** The resolution of the view's input at the last evaluation. */
|
|
2122
|
-
resolution: number; /** The resolution of what was drawn under the view at the last evaluation; the input's for a filter that reads none. */
|
|
2123
|
-
backResolution: number; /** An input starts from the view's own input: a new resolution of the input runs the chains again. */
|
|
2124
|
-
readonly fromInput: boolean; /** An input starts from what was drawn under the view: a new resolution of the back runs the chains again. */
|
|
2125
|
-
readonly fromBack: boolean; /** Changes whenever what the stages draw changes; 1 after the first evaluation. */
|
|
2126
|
-
version: number; /** The object `chain` receives, reused: its `resolution` is written before each call. */
|
|
2127
|
-
readonly context: {
|
|
2128
|
-
resolution: number;
|
|
2129
|
-
}; /** Per input, its places in draw order (each with the scale of its step). */
|
|
2130
|
-
readonly places: Place[][]; /** Bodies of places that left the chain, destroyed by the next sync. */
|
|
2131
|
-
readonly retired: OursBody[]; /** Pooled textures taken by the running apply; emptied in its `finally`. One array, reused. */
|
|
2132
|
-
readonly taken: PixiTexture[]; /** The options object handed to `TexturePool.getOptimalTexture`, reused. */
|
|
2133
|
-
readonly request: {
|
|
2134
|
-
width: number;
|
|
2135
|
-
height: number;
|
|
2136
|
-
resolution: number;
|
|
2137
|
-
}; /** Results lent by spec 23: while set, the apply draws the main body only, over them. */
|
|
2138
|
-
held: readonly PixiTexture[] | undefined; /** The slot seam, a frozen object replaced when a place is built or dropped. */
|
|
2139
|
-
slot: FilterSlotInputs;
|
|
2140
|
-
};
|
|
2141
|
-
/**
|
|
2142
|
-
* Where the shader check of every definition a kind can draw stands, in every build: one run per start of the
|
|
2143
|
-
* plugin.
|
|
2144
|
-
*/
|
|
2145
|
-
type CheckState = {
|
|
2146
|
-
/** Bumped by `stopEffects`: an answer of an earlier run is ignored. */run: number; /** The checks were started on the running backend. */
|
|
2147
|
-
started: boolean; /** Where each definition stands. */
|
|
2148
|
-
status: WeakMap<FilterDefinition, "pending" | "ok" | "broken">; /** The definitions whose quad text compiled clean on this run's device: only they hand a quad over. */
|
|
2149
|
-
quads: WeakSet<FilterDefinition>; /** The program of each of them, built at the first ask: `GpuProgram.from` keys the whole source on every call. */
|
|
2150
|
-
programs: WeakMap<FilterDefinition, PixiGpuProgram>; /** Definitions still pending. */
|
|
2151
|
-
waiting: number; /** Definitions started, for the `effects:checks` line. */
|
|
2152
|
-
checked: number; /** Definitions that failed, for the `effects:checks` line. */
|
|
2153
|
-
failed: number; /** GLSL compiles in flight under `KHR_parallel_shader_compile`. */
|
|
2154
|
-
gl: Array<{
|
|
2155
|
-
definition: FilterDefinition;
|
|
2156
|
-
shader: WebGLShader;
|
|
2157
|
-
}>; /** `performance.now()` when the checks started, for the `effects:checks` line. */
|
|
2158
|
-
startedAt: number; /** Resolves when `started` and `waiting === 0`. */
|
|
2159
|
-
settled: Promise<void>; /** Resolves `settled`. */
|
|
2160
|
-
resolve: () => void;
|
|
2161
|
-
};
|
|
2162
|
-
/**
|
|
2163
|
-
* What the filter sync keeps for one entity: the kinds it carries, one instance per kind, the
|
|
2164
|
-
* instances waiting to be destroyed after the next assignment, the slots last handed to
|
|
2165
|
-
* `renderer.sync.filters.set`, the run in which each core kind's component last changed, the
|
|
2166
|
-
* instances of this frame in their sorted order (one array, reused every frame), the one
|
|
2167
|
-
* `renderer.invalidate` call a visible filter write of the frame makes, and whether the next run
|
|
2168
|
-
* syncs it.
|
|
2169
|
-
*/
|
|
2170
|
-
type FilteredView = {
|
|
2171
|
-
/** The entity the record is kept for. */readonly entity: Entity;
|
|
2172
|
-
readonly kinds: Set<string>;
|
|
2173
|
-
readonly instances: Map<string, FilterInstance>;
|
|
2174
|
-
readonly retired: FilterInstance[];
|
|
2175
|
-
assigned: readonly FilterSlot[];
|
|
2176
|
-
/**
|
|
2177
|
-
* Per kind `index`, the run of the filter sync in which its component was last seen changed; read only for a
|
|
2178
|
-
* Pixi-core kind, which is written only in such a run. A number per kind, so marking allocates nothing.
|
|
2179
|
-
*/
|
|
2180
|
-
readonly marks: number[];
|
|
2181
|
-
readonly placed: FilterInstance[]; /** True once `renderer.invalidate` was called for this view in the current frame. */
|
|
2182
|
-
signalled: boolean; /** Calls `renderer.invalidate(entity)` once per frame for this view, before the write; made once with the record. */
|
|
2183
|
-
readonly signal: () => void; /** The area last handed to `renderer.sync.filters.area`, written in place (B4). */
|
|
2184
|
-
readonly areaSent: AreaBox; /** The `enabled` switches of the placed instances when the area was last judged, one bit each in placed order. */
|
|
2185
|
-
areaMask: number;
|
|
2186
|
-
/**
|
|
2187
|
-
* The next run of the filter sync brings the view up to date: a filter component of it changed, came or left, its
|
|
2188
|
-
* map was retired, a kind of it still waits for its instance, or a chain left places to destroy.
|
|
2189
|
-
*/
|
|
2190
|
-
dirty: boolean; /** Forgotten: out of `State.views`; the next run drops it from `State.viewList`. */
|
|
2191
|
-
gone: boolean;
|
|
2192
|
-
};
|
|
2193
|
-
/**
|
|
2194
|
-
* Where the filter sync stands between two runs. It syncs only the views marked dirty, and judges the full-screen
|
|
2195
|
-
* budget only when something it depends on moved.
|
|
2196
|
-
*/
|
|
2197
|
-
type FilterSyncState = {
|
|
2198
|
-
/** The current run, counted from 1: a core kind's change mark holds the run it was made in. */round: number;
|
|
2199
|
-
/**
|
|
2200
|
-
* Every view syncs at the next run: a debug switch turned a kind off or on, or a filter broke or ran its chains at a
|
|
2201
|
-
* new resolution inside a render, where the view it belongs to is not known.
|
|
2202
|
-
*/
|
|
2203
|
-
all: boolean; /** A view was marked dirty or forgotten since the last walk: the next run walks the dense list, otherwise it skips it. */
|
|
2204
|
-
pending: boolean; /** The viewport width the full-screen budget was last judged at; -1 before the first judgement. */
|
|
2205
|
-
width: number; /** The viewport height the full-screen budget was last judged at; -1 before the first judgement. */
|
|
2206
|
-
height: number;
|
|
2207
|
-
};
|
|
2208
|
-
//#endregion
|
|
2209
|
-
//#region src/plugins/effects/particles/types.d.ts
|
|
2210
|
-
/**
|
|
2211
|
-
* An inclusive `[min, max]` range; every particle draws its own value from it.
|
|
2212
|
-
*
|
|
2213
|
-
* @example
|
|
2214
|
-
* ```ts
|
|
2215
|
-
* const lifeMs: Range = [500, 900];
|
|
2216
|
-
* ```
|
|
2217
|
-
*/
|
|
2218
|
-
type Range = readonly [min: number, max: number];
|
|
2219
|
-
/**
|
|
2220
|
-
* A value over the life of a particle, linear from its birth (`from`) to its death (`to`).
|
|
2221
|
-
*
|
|
2222
|
-
* @example
|
|
2223
|
-
* ```ts
|
|
2224
|
-
* const shrink: Curve = { from: 1, to: 0.2 };
|
|
2225
|
-
* ```
|
|
2226
|
-
*/
|
|
2227
|
-
type Curve = {
|
|
2228
|
-
readonly from: number;
|
|
2229
|
-
readonly to: number;
|
|
2230
|
-
};
|
|
2231
|
-
/**
|
|
2232
|
-
* Where a particle is born, around the origin of its emitter, in reference units. `circle` is
|
|
2233
|
-
* uniform over the disc, `ring` uniform between `radius − width / 2` and `radius + width / 2`,
|
|
2234
|
-
* `rect` uniform over the centred box.
|
|
2235
|
-
*
|
|
2236
|
-
* @example
|
|
2237
|
-
* ```ts
|
|
2238
|
-
* const burstRing: Shape = { kind: "ring", radius: 48, width: 16 };
|
|
2239
|
-
* ```
|
|
2240
|
-
*/
|
|
2241
|
-
type Shape = {
|
|
2242
|
-
readonly kind: "point";
|
|
2243
|
-
} | {
|
|
2244
|
-
readonly kind: "circle";
|
|
2245
|
-
readonly radius: number;
|
|
2246
|
-
} | {
|
|
2247
|
-
readonly kind: "rect";
|
|
2248
|
-
readonly w: number;
|
|
2249
|
-
readonly h: number;
|
|
2250
|
-
} | {
|
|
2251
|
-
readonly kind: "ring";
|
|
2252
|
-
readonly radius: number;
|
|
2253
|
-
readonly width: number;
|
|
2254
|
-
};
|
|
2255
|
-
/**
|
|
2256
|
-
* A particle effect as data, what `defineEmitter` takes. Every field is optional except
|
|
2257
|
-
* `textures` and exactly one of `burst` and `rate`. Speeds are reference units per second, angles
|
|
2258
|
-
* degrees with 0 to the right and 90 down, spins radians per second.
|
|
2259
|
-
*
|
|
2260
|
-
* @example
|
|
2261
|
-
* ```ts
|
|
2262
|
-
* const stars: EmitterConfig = {
|
|
2263
|
-
* textures: ["fx.star", "fx.sparkle"], burst: 40, lifeMs: [500, 900], speed: [300, 700],
|
|
2264
|
-
* gravity: 900, drag: 0.2, shape: { kind: "circle", radius: 24 }, alpha: { from: 1, to: 0 }
|
|
2265
|
-
* };
|
|
2266
|
-
* ```
|
|
2267
|
-
*/
|
|
2268
|
-
type EmitterConfig = {
|
|
2269
|
-
/** 1 to 16 asset keys of one atlas page; a particle picks one at random. */readonly textures: readonly string[]; /** Particles emitted once, when the component appears or its `effect` changes. */
|
|
2270
|
-
readonly burst?: number; /** Particles per second while `active` is true and the entity lives. */
|
|
2271
|
-
readonly rate?: number; /** Life of a particle in milliseconds. Default `[600, 1000]`. */
|
|
2272
|
-
readonly lifeMs?: Range; /** Start speed in reference units per second. Default `[0, 0]`. */
|
|
2273
|
-
readonly speed?: Range; /** Start direction in degrees, 0 right, 90 down. Default `[0, 360]`. */
|
|
2274
|
-
readonly angle?: Range; /** Downward acceleration in reference units per second². Default `0`. */
|
|
2275
|
-
readonly gravity?: number; /** Velocity lost per second, 0..1: `v *= (1 − drag) ^ seconds`. Default `0`. */
|
|
2276
|
-
readonly drag?: number; /** Spin in radians per second. Default `[0, 0]`. */
|
|
2277
|
-
readonly spin?: Range; /** Where particles are born around the origin. Default `{ kind: "point" }`. */
|
|
2278
|
-
readonly shape?: Shape; /** Scale over life. Default `{ from: 1, to: 1 }`. */
|
|
2279
|
-
readonly scale?: Curve; /** Alpha over life, 0..1. Default `{ from: 1, to: 1 }`. */
|
|
2280
|
-
readonly alpha?: Curve; /** Tint over life, `0xrrggbb`, linear per channel. Default white to white. */
|
|
2281
|
-
readonly tint?: Curve; /** `"world"`: particles outlive the entity. `"local"`: they move and die with it. Default `"world"`. */
|
|
2282
|
-
readonly space?: "world" | "local"; /** Milliseconds simulated before the first frame, for streams, 0..5000. Default `0`. */
|
|
2283
|
-
readonly prewarmMs?: number; /** Hard ceiling of live particles of one instance, 1..5000. Default `256`. */
|
|
2284
|
-
readonly maxParticles?: number; /** Blend mode of the particle container. Default `"normal"`. */
|
|
2285
|
-
readonly blend?: "normal" | "add";
|
|
2286
|
-
};
|
|
2287
|
-
/**
|
|
2288
|
-
* An `EmitterConfig` with every default filled in. `burst` and `rate` stay as given: exactly one
|
|
2289
|
-
* of them is present.
|
|
2290
|
-
*
|
|
2291
|
-
* @example
|
|
2292
|
-
* ```ts
|
|
2293
|
-
* defineEmitter("fx.steam", { textures: ["fx.puff"], rate: 12 }).config.lifeMs; // [600, 1000]
|
|
2294
|
-
* ```
|
|
2295
|
-
*/
|
|
2296
|
-
type ResolvedEmitterConfig = Required<Omit<EmitterConfig, "burst" | "rate">> & Pick<EmitterConfig, "burst" | "rate">;
|
|
2297
|
-
/**
|
|
2298
|
-
* A particle effect as `defineEmitter` returns it: frozen, registered through the `emitters` key
|
|
2299
|
-
* of a feature and started by an `Emitter` component that names its id.
|
|
2300
|
-
*
|
|
2301
|
-
* @example
|
|
2302
|
-
* ```ts
|
|
2303
|
-
* const steam: EmitterDefinition = defineEmitter("fx.steam", { textures: ["fx.puff"], rate: 12 });
|
|
2304
|
-
* steam.config.rate; // 12
|
|
2305
|
-
* ```
|
|
2306
|
-
*/
|
|
2307
|
-
type EmitterDefinition = {
|
|
2308
|
-
readonly id: string;
|
|
2309
|
-
readonly config: ResolvedEmitterConfig;
|
|
2310
|
-
};
|
|
2311
|
-
/**
|
|
2312
|
-
* The value of the `Emitter` component: which effect runs on the entity and whether a stream
|
|
2313
|
-
* emits. `""` draws nothing.
|
|
2314
|
-
*
|
|
2315
|
-
* @example
|
|
2316
|
-
* ```ts
|
|
2317
|
-
* const value: EmitterValue = { effect: "fx.steam", active: true };
|
|
2318
|
-
* ```
|
|
2319
|
-
*/
|
|
2320
|
-
type EmitterValue = {
|
|
2321
|
-
effect: string;
|
|
2322
|
-
active: boolean;
|
|
2323
|
-
};
|
|
2324
|
-
/**
|
|
2325
|
-
* The cosmetic random source of one instance: xorshift32 over its own seed, never `Math.random`
|
|
2326
|
-
* and never the model's rng.
|
|
2327
|
-
*/
|
|
2328
|
-
type Rng = {
|
|
2329
|
-
/** The next number in `[0, 1)`. */next(): number; /** An integer in `[0, count)`. */
|
|
2330
|
-
int(count: number): number; /** A number in `[min, max]`. */
|
|
2331
|
-
between(min: number, max: number): number;
|
|
2332
|
-
};
|
|
2333
|
-
/**
|
|
2334
|
-
* A Pixi particle container: what one emitter instance draws in.
|
|
2335
|
-
*/
|
|
2336
|
-
type PixiParticleContainer = InstanceType<PixiModule["ParticleContainer"]>;
|
|
2337
|
-
/**
|
|
2338
|
-
* One particle of a container, as the container keeps it.
|
|
2339
|
-
*/
|
|
2340
|
-
type PixiParticle = PixiParticleContainer["particleChildren"][number];
|
|
2341
|
-
/**
|
|
2342
|
-
* What one effect id bakes to on first use: the 64-entry curve tables, the reach rectangle's half
|
|
2343
|
-
* side and the resolved textures. Dropped when a bundle with one of its textures leaves.
|
|
2344
|
-
*/
|
|
2345
|
-
type BakedEmitter = {
|
|
2346
|
-
readonly id: string;
|
|
2347
|
-
readonly config: ResolvedEmitterConfig; /** Scale per 1/64 of the life. */
|
|
2348
|
-
readonly scaleTable: Float32Array; /** Alpha per 1/64 of the life, 0..1. */
|
|
2349
|
-
readonly alphaTable: Float32Array; /** Tint per 1/64 of the life, packed as Pixi's `0xbbggrr`. */
|
|
2350
|
-
readonly tintTable: Uint32Array;
|
|
2351
|
-
/**
|
|
2352
|
-
* The colour a particle is drawn with per 1/64 of the life, packed as Pixi's `0xaabbggrr`: the tint under the alpha
|
|
2353
|
-
* byte. Read straight from the table every frame: a number above the small integers handed back by a call is boxed.
|
|
2354
|
-
*/
|
|
2355
|
-
readonly colorTable: Uint32Array; /** Half side of the box no particle leaves, in reference units. */
|
|
2356
|
-
readonly reach: number;
|
|
2357
|
-
readonly textures: readonly PixiTexture[]; /** The texture source of the first texture: every texture of the effect samples it. */
|
|
2358
|
-
readonly source: PixiTexture["source"] | undefined; /** The largest side of the textures, in pixels. */
|
|
2359
|
-
readonly maxSide: number;
|
|
2360
|
-
};
|
|
2361
|
-
/**
|
|
2362
|
-
* The per-particle numbers a Pixi particle has no field for, one entry per live particle, in the
|
|
2363
|
-
* order of `particleChildren`.
|
|
2364
|
-
*/
|
|
2365
|
-
type BornFields = {
|
|
2366
|
-
readonly age: Float32Array;
|
|
2367
|
-
readonly life: Float32Array;
|
|
2368
|
-
readonly vx: Float32Array;
|
|
2369
|
-
readonly vy: Float32Array;
|
|
2370
|
-
readonly spin: Float32Array;
|
|
2371
|
-
readonly variant: Float32Array;
|
|
2372
|
-
};
|
|
2373
|
-
/**
|
|
2374
|
-
* One running effect: its container, the plugin-owned entity that carries it, the particle pool
|
|
2375
|
-
* and the numbers the step needs.
|
|
2376
|
-
*/
|
|
2377
|
-
type EmitterInstance = {
|
|
2378
|
-
readonly id: string;
|
|
2379
|
-
readonly baked: BakedEmitter; /** The entity whose `Emitter` started it. */
|
|
2380
|
-
readonly host: Entity; /** The plugin-owned entity whose `Display` is the container. */
|
|
2381
|
-
readonly entity: Entity;
|
|
2382
|
-
readonly container: PixiParticleContainer; /** Retired particles, reused before a new one is made. */
|
|
2383
|
-
readonly pool: PixiParticle[];
|
|
2384
|
-
readonly born: BornFields; /** Fraction of a particle owed to the next frame of a stream. */
|
|
2385
|
-
carry: number;
|
|
2386
|
-
readonly rng: Rng; /** The point the container was placed at, in root space (world space only). */
|
|
2387
|
-
readonly origin: Readonly<Point>;
|
|
2388
|
-
readonly space: "world" | "local"; /** Pixi's particle class, from the module the renderer loaded. */
|
|
2389
|
-
readonly particleClass: PixiModule["Particle"];
|
|
2390
|
-
};
|
|
2391
|
-
//#endregion
|
|
2392
|
-
//#region src/plugins/effects/set/types.d.ts
|
|
2393
|
-
/**
|
|
2394
|
-
* @file effects/set — the values of the members of the engine's effect set: one field per uniform, then `enabled` and
|
|
2395
|
-
* `order`, which every filter component carries. A number field is tweenable; a colour is a `0xrrggbb` number, set,
|
|
2396
|
-
* not tweened.
|
|
2397
|
-
*/
|
|
2398
|
-
/**
|
|
2399
|
-
* `Flash`: the view washed with `color` by `amount`, 0 none, 1 all of it.
|
|
2400
|
-
*
|
|
2401
|
-
* @example
|
|
2402
|
-
* ```ts
|
|
2403
|
-
* const value: FlashValue = { amount: 1, color: 0xffd700, enabled: true, order: 0 };
|
|
2404
|
-
* ```
|
|
2405
|
-
*/
|
|
2406
|
-
type FlashValue = {
|
|
2407
|
-
amount: number;
|
|
2408
|
-
color: number;
|
|
2409
|
-
enabled: boolean;
|
|
2410
|
-
order: number;
|
|
2411
|
-
};
|
|
2412
|
-
/**
|
|
2413
|
-
* `Grade`: contrast, brightness and saturation of the view, each 1 for none (0..2), then a multiply by `tint`.
|
|
2414
|
-
*
|
|
2415
|
-
* @example
|
|
2416
|
-
* ```ts
|
|
2417
|
-
* const value: GradeValue = { brightness: 1, contrast: 1, saturation: 0, tint: 0xffffff, enabled: true, order: 0 };
|
|
2418
|
-
* ```
|
|
2419
|
-
*/
|
|
2420
|
-
type GradeValue = {
|
|
2421
|
-
brightness: number;
|
|
2422
|
-
contrast: number;
|
|
2423
|
-
saturation: number;
|
|
2424
|
-
tint: number;
|
|
2425
|
-
enabled: boolean;
|
|
2426
|
-
order: number;
|
|
2427
|
-
};
|
|
2428
|
-
/**
|
|
2429
|
-
* `Vignette`: the view darkened, or coloured, outside a disc around `x`, `y` (0..1 of the view) of `radius`, over a soft
|
|
2430
|
-
* edge `soft` wide, by `amount`.
|
|
2431
|
-
*
|
|
2432
|
-
* @example
|
|
2433
|
-
* ```ts
|
|
2434
|
-
* const value: VignetteValue = { x: 0.5, y: 0.5, radius: 0.3, soft: 0.4, color: 0x000000, amount: 1, enabled: true, order: 0 };
|
|
2435
|
-
* ```
|
|
2436
|
-
*/
|
|
2437
|
-
type VignetteValue = {
|
|
2438
|
-
x: number;
|
|
2439
|
-
y: number;
|
|
2440
|
-
radius: number;
|
|
2441
|
-
soft: number;
|
|
2442
|
-
color: number;
|
|
2443
|
-
amount: number;
|
|
2444
|
-
enabled: boolean;
|
|
2445
|
-
order: number;
|
|
2446
|
-
};
|
|
2447
|
-
/**
|
|
2448
|
-
* `RevealLine`: the view shown up to a straight line that sweeps across it, `progress` 0 none of it, 1 all of it, the
|
|
2449
|
-
* line at `angle` (radians, in the view's own 0..1 frame), its edge `soft` wide.
|
|
2450
|
-
*
|
|
2451
|
-
* @example
|
|
2452
|
-
* ```ts
|
|
2453
|
-
* const value: RevealLineValue = { progress: 0.5, angle: Math.PI / 4, soft: 0.1, enabled: true, order: 0 };
|
|
2454
|
-
* ```
|
|
2455
|
-
*/
|
|
2456
|
-
type RevealLineValue = {
|
|
2457
|
-
progress: number;
|
|
2458
|
-
angle: number;
|
|
2459
|
-
soft: number;
|
|
2460
|
-
enabled: boolean;
|
|
2461
|
-
order: number;
|
|
2462
|
-
};
|
|
2463
|
-
/**
|
|
2464
|
-
* `RevealRound`: the view shown inside a disc around `x`, `y` (0..1 of the view) of `radius`, its edge `soft` wide and
|
|
2465
|
-
* wavy by `wobble`.
|
|
2466
|
-
*
|
|
2467
|
-
* @example
|
|
2468
|
-
* ```ts
|
|
2469
|
-
* const value: RevealRoundValue = { x: 0.5, y: 0.5, radius: 1.2, soft: 0.05, wobble: 0.04, enabled: true, order: 0 };
|
|
2470
|
-
* ```
|
|
2471
|
-
*/
|
|
2472
|
-
type RevealRoundValue = {
|
|
2473
|
-
x: number;
|
|
2474
|
-
y: number;
|
|
2475
|
-
radius: number;
|
|
2476
|
-
soft: number;
|
|
2477
|
-
wobble: number;
|
|
2478
|
-
enabled: boolean;
|
|
2479
|
-
order: number;
|
|
2480
|
-
};
|
|
2481
|
-
/**
|
|
2482
|
-
* `Dissolve`: the view eaten by a noise of `scale` cells across, `progress` 0 none of it, 1 all of it, the rim `edge`
|
|
2483
|
-
* wide in `edgeColor`.
|
|
2484
|
-
*
|
|
2485
|
-
* @example
|
|
2486
|
-
* ```ts
|
|
2487
|
-
* const value: DissolveValue = { progress: 0.5, scale: 8, edge: 0.08, edgeColor: 0xffffff, enabled: true, order: 0 };
|
|
2488
|
-
* ```
|
|
2489
|
-
*/
|
|
2490
|
-
type DissolveValue = {
|
|
2491
|
-
progress: number;
|
|
2492
|
-
scale: number;
|
|
2493
|
-
edge: number;
|
|
2494
|
-
edgeColor: number;
|
|
2495
|
-
enabled: boolean;
|
|
2496
|
-
order: number;
|
|
2497
|
-
};
|
|
2498
|
-
/**
|
|
2499
|
-
* `Shine`: a band of light `width` wide at `position` of its sweep (-0.5..1.5), across the view at `angle`, by
|
|
2500
|
-
* `strength`.
|
|
2501
|
-
*
|
|
2502
|
-
* @example
|
|
2503
|
-
* ```ts
|
|
2504
|
-
* const value: ShineValue = { position: 0.5, width: 0.2, angle: 0.6, strength: 0.6, enabled: true, order: 0 };
|
|
2505
|
-
* ```
|
|
2506
|
-
*/
|
|
2507
|
-
type ShineValue = {
|
|
2508
|
-
position: number;
|
|
2509
|
-
width: number;
|
|
2510
|
-
angle: number;
|
|
2511
|
-
strength: number;
|
|
2512
|
-
enabled: boolean;
|
|
2513
|
-
order: number;
|
|
2514
|
-
};
|
|
2515
|
-
/**
|
|
2516
|
-
* `Aura`: a halo of `color` by `strength` (0..2) around the shape of the view, `spread` CSS px wide, which is also the
|
|
2517
|
-
* view's padding.
|
|
2518
|
-
*
|
|
2519
|
-
* @example
|
|
2520
|
-
* ```ts
|
|
2521
|
-
* const value: AuraValue = { color: 0xffd700, strength: 1, spread: 12, enabled: true, order: 0 };
|
|
2522
|
-
* ```
|
|
2523
|
-
*/
|
|
2524
|
-
type AuraValue = {
|
|
2525
|
-
color: number;
|
|
2526
|
-
strength: number;
|
|
2527
|
-
spread: number;
|
|
2528
|
-
enabled: boolean;
|
|
2529
|
-
order: number;
|
|
2530
|
-
};
|
|
2531
|
-
/**
|
|
2532
|
-
* `Fold`: the view turned by `angle` (radians) about its vertical axis (`axis: 0`) or its horizontal one (`axis: 1`),
|
|
2533
|
-
* leaning by `perspective` (0..1), its back darkened by `shade` (0..1).
|
|
2534
|
-
*
|
|
2535
|
-
* @example
|
|
2536
|
-
* ```ts
|
|
2537
|
-
* const value: FoldValue = { angle: Math.PI / 2, axis: 1, perspective: 0.5, shade: 0.4, enabled: true, order: 0 };
|
|
2538
|
-
* ```
|
|
2539
|
-
*/
|
|
2540
|
-
type FoldValue = {
|
|
2541
|
-
angle: number;
|
|
2542
|
-
axis: number;
|
|
2543
|
-
perspective: number;
|
|
2544
|
-
shade: number;
|
|
2545
|
-
enabled: boolean;
|
|
2546
|
-
order: number;
|
|
2547
|
-
};
|
|
2548
|
-
/**
|
|
2549
|
-
* `Bloom`: light around the bright parts of the view: what is above `threshold` (0..1) of its light, blurred `radius`
|
|
2550
|
-
* CSS px wide and added back by `strength` (0..2).
|
|
2551
|
-
*
|
|
2552
|
-
* @example
|
|
2553
|
-
* ```ts
|
|
2554
|
-
* const value: BloomValue = { strength: 0.6, threshold: 0.7, radius: 16, enabled: true, order: 0 };
|
|
2555
|
-
* ```
|
|
2556
|
-
*/
|
|
2557
|
-
type BloomValue = {
|
|
2558
|
-
strength: number;
|
|
2559
|
-
threshold: number;
|
|
2560
|
-
radius: number;
|
|
2561
|
-
enabled: boolean;
|
|
2562
|
-
order: number;
|
|
2563
|
-
};
|
|
2564
|
-
/**
|
|
2565
|
-
* `Pixelate`: the view drawn in square blocks `size` CSS px wide, from its top-left; 1 or less draws it as it is.
|
|
2566
|
-
*
|
|
2567
|
-
* @example
|
|
2568
|
-
* ```ts
|
|
2569
|
-
* const value: PixelateValue = { size: 8, enabled: true, order: 0 };
|
|
2570
|
-
* ```
|
|
2571
|
-
*/
|
|
2572
|
-
type PixelateValue = {
|
|
2573
|
-
size: number;
|
|
2574
|
-
enabled: boolean;
|
|
2575
|
-
order: number;
|
|
2576
|
-
};
|
|
2577
|
-
/**
|
|
2578
|
-
* `GradientMap`: the view's light mapped from `dark` through `middle` to `light`, mixed in by `amount` (0..1).
|
|
2579
|
-
*
|
|
2580
|
-
* @example
|
|
2581
|
-
* ```ts
|
|
2582
|
-
* const value: GradientMapValue = { dark: 0x2b1a0e, middle: 0x9c6b3c, light: 0xf5e6c8, amount: 1, enabled: true, order: 0 };
|
|
2583
|
-
* ```
|
|
2584
|
-
*/
|
|
2585
|
-
type GradientMapValue = {
|
|
2586
|
-
dark: number;
|
|
2587
|
-
middle: number;
|
|
2588
|
-
light: number;
|
|
2589
|
-
amount: number;
|
|
2590
|
-
enabled: boolean;
|
|
2591
|
-
order: number;
|
|
2592
|
-
};
|
|
2593
|
-
/**
|
|
2594
|
-
* `Wave`: the view swaying by `amplitude` CSS px, one wave every `wavelength` CSS px, shifted by `phase` (radians);
|
|
2595
|
-
* at `angle` 0 its rows sway left and right, at `π / 2` its columns up and down.
|
|
2596
|
-
*
|
|
2597
|
-
* @example
|
|
2598
|
-
* ```ts
|
|
2599
|
-
* const value: WaveValue = { amplitude: 4, wavelength: 48, phase: Math.PI, angle: 0, enabled: true, order: 0 };
|
|
2600
|
-
* ```
|
|
2601
|
-
*/
|
|
2602
|
-
type WaveValue = {
|
|
2603
|
-
amplitude: number;
|
|
2604
|
-
wavelength: number;
|
|
2605
|
-
phase: number;
|
|
2606
|
-
angle: number;
|
|
2607
|
-
enabled: boolean;
|
|
2608
|
-
order: number;
|
|
2609
|
-
};
|
|
2610
|
-
/**
|
|
2611
|
-
* `Mirror`: the view flipped top to bottom (`axis: 1`) or left to right (`axis: 0`), at `alpha` (0..1), fading out to
|
|
2612
|
-
* nothing at `fade` of its size from the mirror line; `fade: 0` keeps it whole.
|
|
2613
|
-
*
|
|
2614
|
-
* @example
|
|
2615
|
-
* ```ts
|
|
2616
|
-
* const value: MirrorValue = { axis: 1, alpha: 0.4, fade: 0.5, enabled: true, order: 0 };
|
|
2617
|
-
* ```
|
|
2618
|
-
*/
|
|
2619
|
-
type MirrorValue = {
|
|
2620
|
-
axis: number;
|
|
2621
|
-
alpha: number;
|
|
2622
|
-
fade: number;
|
|
2623
|
-
enabled: boolean;
|
|
2624
|
-
order: number;
|
|
2625
|
-
};
|
|
2626
|
-
/**
|
|
2627
|
-
* `Shadow`: a shadow of `color` at `alpha` (0..1) under the view, moved by `x`, `y` CSS px and `soft` CSS px wide;
|
|
2628
|
-
* `|x| + soft` and `|y| + soft` are held within the padding of 8.
|
|
2629
|
-
*
|
|
2630
|
-
* @example
|
|
2631
|
-
* ```ts
|
|
2632
|
-
* const value: ShadowValue = { x: 0, y: 4, soft: 4, color: 0x000000, alpha: 0.5, enabled: true, order: 0 };
|
|
2633
|
-
* ```
|
|
2634
|
-
*/
|
|
2635
|
-
type ShadowValue = {
|
|
2636
|
-
x: number;
|
|
2637
|
-
y: number;
|
|
2638
|
-
soft: number;
|
|
2639
|
-
color: number;
|
|
2640
|
-
alpha: number;
|
|
2641
|
-
enabled: boolean;
|
|
2642
|
-
order: number;
|
|
2643
|
-
};
|
|
2644
|
-
declare namespace types_d_exports$2 {
|
|
2645
|
-
export { AlphaValue, AssetsReplaced$1 as AssetsReplaced, AuraValue, BloomValue, BlurValue, BundleUnloaded$1 as BundleUnloaded, ColorMatrixValue, Config$2 as Config, CoreKind, Curve, Deps$2 as Deps, DisplacementValue, DissolveValue, EffectsApi, EffectsCtx, EffectsDiagnostics, EffectsStats, EmitterConfig, EmitterDefinition, EmitterValue, FilterArea, FilterCache, FilterChainContext, FilterComponent, FilterDefinition, FilterInput, FilterInputDefinition, FilterSpec, FilterStage, FilterStep, FilterValueOf, FlashValue, FoldValue, GlowValue, GradeValue, GradientMapValue, HotSwap, KernelSlice$2 as KernelSlice, MirrorValue, NoiseValue, OutlineValue, PixelateValue, Range, ResolvedEmitterConfig, RevealLineValue, RevealRoundValue, ShadowValue, Shape, ShineValue, State$2 as State, UniformDeclaration, UniformSpec, UniformValue, VignetteValue, WaveValue };
|
|
2646
|
-
}
|
|
2647
|
-
/**
|
|
2648
|
-
* effects plugin config. `maxParticles` here is the global warning line; the `maxParticles` of an
|
|
2649
|
-
* emitter config caps one instance.
|
|
2650
|
-
*
|
|
2651
|
-
* @example
|
|
2652
|
-
* ```ts
|
|
2653
|
-
* createApp({
|
|
2654
|
-
* plugins: [...screen, effectsPlugin],
|
|
2655
|
-
* pluginConfigs: { effects: { maxPasses: 16, phone: false } }
|
|
2656
|
-
* });
|
|
2657
|
-
* ```
|
|
2658
|
-
*/
|
|
2659
|
-
type Config$2 = {
|
|
2660
|
-
/** Live particles over all instances above which one dev warning fires per crossing. */maxParticles: number; /** Render passes per frame above which one dev warning fires once they stay over it 60 frames in a row. */
|
|
2661
|
-
maxPasses: number; /** Whether this device is a phone. `"auto"`: a coarse pointer and a short side of at most 820 CSS px, read once in `onStart`. */
|
|
2662
|
-
phone: boolean | "auto";
|
|
2663
|
-
/**
|
|
2664
|
-
* What a `Blur` with `quality: 0` and `resolution: 0` resolves to. Shallow merge: a game that
|
|
2665
|
-
* sets `blur` gives both fields.
|
|
2666
|
-
*/
|
|
2667
|
-
blur: {
|
|
2668
|
-
quality: number;
|
|
2669
|
-
phoneResolution: number;
|
|
2670
|
-
};
|
|
2671
|
-
};
|
|
2672
|
-
/**
|
|
2673
|
-
* effects plugin state: the particle half, the filter half, and what both share.
|
|
2674
|
-
*/
|
|
2675
|
-
type State$2 = {
|
|
2676
|
-
/** Resolved in `onStart`. */phone: boolean; /** The `emitters` of every feature, read in `onStart`. */
|
|
2677
|
-
emitters: Map<string, EmitterDefinition>; /** Per effect id, built on first use. */
|
|
2678
|
-
baked: Map<string, BakedEmitter>; /** Host entity to its running instance. */
|
|
2679
|
-
instances: Map<Entity, EmitterInstance>; /** World-space instances whose host left, stepped until empty. */
|
|
2680
|
-
orphans: Set<EmitterInstance>; /** Ordinal of the next instance: the cosmetic seed. */
|
|
2681
|
-
seedCounter: number; /** Live particles after the last step. */
|
|
2682
|
-
particles: number; /** Filter kinds whose shader or one of whose stages failed the check on the running backend, in every build. */
|
|
2683
|
-
broken: Set<string>; /** Filter kinds whose main definition and every stage answered ok: a kind's status is a set lookup once settled. */
|
|
2684
|
-
ready: Set<string>; /** The filter kinds, built-ins first, then the filters of every feature. */
|
|
2685
|
-
kinds: Map<string, FilterKind>; /** The shader check of every definition a kind can draw, in every build. */
|
|
2686
|
-
checks: CheckState; /** Entity to the filters the sync keeps for it. */
|
|
2687
|
-
views: Map<Entity, FilteredView>;
|
|
2688
|
-
/**
|
|
2689
|
-
* The records of `views` in the order they were first seen: the dense list the filter sync walks by index. A
|
|
2690
|
-
* forgotten record stays, `gone`, until the next run drops it.
|
|
2691
|
-
*/
|
|
2692
|
-
viewList: FilteredView[]; /** The filter kinds in registration order, one per `index`: the change sets the filter sync reads, by index. */
|
|
2693
|
-
kindList: FilterKind[]; /** Where the filter sync stands between two runs. */
|
|
2694
|
-
filterSync: FilterSyncState; /** Keys of the one-shot warnings: `"emitter:fx.x"`, `"texture:board.cell"`, `"atlas:fx.x"`. */
|
|
2695
|
-
warned: Set<string>;
|
|
2696
|
-
/**
|
|
2697
|
-
* Whether each budget warning is in force, so a crossing warns once; for the passes, the frames in a row over the
|
|
2698
|
-
* budget, so only a steady crossing warns.
|
|
2699
|
-
*/
|
|
2700
|
-
over: {
|
|
2701
|
-
particles: boolean;
|
|
2702
|
-
passes: number;
|
|
2703
|
-
fullScreen: boolean;
|
|
2704
|
-
}; /** The teardown closure, the two systems and the world hooks. */
|
|
2705
|
-
removers: Array<() => void>;
|
|
2706
|
-
/**
|
|
2707
|
-
* The switches of a debug build: the kind ids in registration order (frozen, filled in `onStart`), the kinds
|
|
2708
|
-
* turned off, and those as a frozen list in the order of `kinds`.
|
|
2709
|
-
*/
|
|
2710
|
-
diagnostics: {
|
|
2711
|
-
kinds: readonly string[];
|
|
2712
|
-
off: Set<string>;
|
|
2713
|
-
offList: readonly string[];
|
|
2714
|
-
};
|
|
2715
|
-
/**
|
|
2716
|
-
* The warm-up hand-over (spec 27 F4): started at the first frame with a ready host, the Pixi-core kinds noted then,
|
|
2717
|
-
* and the probes handed to `renderer.sync.filters.warm`, kept until the app stops.
|
|
2718
|
-
*/
|
|
2719
|
-
warm: {
|
|
2720
|
-
started: boolean;
|
|
2721
|
-
core: string[];
|
|
2722
|
-
probes: WarmProbe[];
|
|
2723
|
-
};
|
|
2724
|
-
};
|
|
2725
|
-
/**
|
|
2726
|
-
* What `app.effects.stats()` answers: live particles, running emitter instances, filter instances
|
|
2727
|
-
* on views, and the render passes of the frame as the renderer counts them.
|
|
2728
|
-
*
|
|
2729
|
-
* @example
|
|
2730
|
-
* ```ts
|
|
2731
|
-
* const stats: EffectsStats = { particles: 120, emitters: 3, filters: 25, renderPasses: 49 };
|
|
2732
|
-
* ```
|
|
2733
|
-
*/
|
|
2734
|
-
type EffectsStats = {
|
|
2735
|
-
/** Live particles over every instance and orphan after the last step. */particles: number; /** Running instances plus the orphans still flying. */
|
|
2736
|
-
emitters: number; /** Filter instances over every view; the stages of a filter's inputs are counted in `renderPasses`, not here. */
|
|
2737
|
-
filters: number; /** `renderer.sync.renderPasses()`, read at call time. */
|
|
2738
|
-
renderPasses: number;
|
|
2739
|
-
};
|
|
2740
|
-
/**
|
|
2741
|
-
* effects plugin API, `app.effects`. Everything a game does with effects is data on entities;
|
|
2742
|
-
* the API only counts.
|
|
2743
|
-
*
|
|
2744
|
-
* @example
|
|
2745
|
-
* ```ts
|
|
2746
|
-
* // A test waits for a merge burst to land before it compares the board.
|
|
2747
|
-
* while (app.effects.stats().particles > 0) app.time.step(16);
|
|
2748
|
-
* app.effects.stats().particles; // 0
|
|
2749
|
-
* ```
|
|
2750
|
-
*/
|
|
2751
|
-
type EffectsApi = {
|
|
2752
|
-
/**
|
|
2753
|
-
* Counts what runs now. `renderPasses` is the renderer's own number, read at call time; the
|
|
2754
|
-
* others are the plugin's. Headless every number is 0.
|
|
2755
|
-
*
|
|
2756
|
-
* @returns A fresh object: live particles, emitter instances with orphans, filter instances
|
|
2757
|
-
* and render passes.
|
|
2758
|
-
* @example
|
|
2759
|
-
* ```ts
|
|
2760
|
-
* // After the board rests: one steam stream, 24 enabled glows on 24 views, one disabled blur.
|
|
2761
|
-
* app.effects.stats();
|
|
2762
|
-
* // { particles: 18, emitters: 1, filters: 25, renderPasses: 49 }: 1 + 24 × (1 + 1), the disabled blur costs 0
|
|
2763
|
-
* ```
|
|
2764
|
-
*/
|
|
2765
|
-
stats(): EffectsStats;
|
|
2766
|
-
/**
|
|
2767
|
-
* Switches of a debug build: filter kinds turned off by hand, to measure what a kind costs on the device. Acts on
|
|
2768
|
-
* a page with the agent flag (a debug build, the dev page); elsewhere `disable` and `enable` change nothing. An off
|
|
2769
|
-
* kind keeps its instances: `stats().filters` still counts them, `renderPasses` drops.
|
|
2770
|
-
*
|
|
2771
|
-
* @example
|
|
2772
|
-
* ```ts
|
|
2773
|
-
* // A game's overlay toggle "Glow": the frame without any glow, then with it again.
|
|
2774
|
-
* app.effects.diagnostics.disable("effects.glow"); // true
|
|
2775
|
-
* app.effects.diagnostics.enable("effects.glow"); // true
|
|
2776
|
-
* ```
|
|
2777
|
-
*/
|
|
2778
|
-
diagnostics: EffectsDiagnostics;
|
|
2779
|
-
};
|
|
2780
|
-
/**
|
|
2781
|
-
* Switches of a debug build: filter kinds turned off by hand, to measure what a kind costs on the device. Acts on
|
|
2782
|
-
* a page with the agent flag (a debug build, the dev page); elsewhere `disable` and `enable` change nothing.
|
|
2783
|
-
*
|
|
2784
|
-
* @example
|
|
2785
|
-
* ```ts
|
|
2786
|
-
* // A game's overlay toggle "Glow" (H4.4): the frame without any glow, then with it again.
|
|
2787
|
-
* app.effects.diagnostics.disable("effects.glow"); // true
|
|
2788
|
-
* app.effects.diagnostics.enable("effects.glow"); // true
|
|
2789
|
-
* ```
|
|
2790
|
-
*/
|
|
2791
|
-
type EffectsDiagnostics = {
|
|
2792
|
-
/**
|
|
2793
|
-
* The filter kinds this app knows, in registration order: the seven built-ins, then the `filters` of every
|
|
2794
|
-
* feature. The same frozen array on every call; empty before start. Every build.
|
|
2795
|
-
*
|
|
2796
|
-
* @returns The kind ids.
|
|
2797
|
-
* @example
|
|
2798
|
-
* ```ts
|
|
2799
|
-
* // A game with the frost filter of its casefile feature, after start.
|
|
2800
|
-
* app.effects.diagnostics.kinds();
|
|
2801
|
-
* // ["effects.glow", "effects.outline", "effects.blur", "effects.colorMatrix", "effects.noise",
|
|
2802
|
-
* // "effects.displacement", "effects.alpha", "casefile.frost"]
|
|
2803
|
-
* ```
|
|
2804
|
-
*/
|
|
2805
|
-
kinds(): readonly string[];
|
|
2806
|
-
/**
|
|
2807
|
-
* Turns a filter kind off: from the next frame no view draws it (no apply, no render pass), while its instances
|
|
2808
|
-
* stay and are still written, so `enable` shows the current look at once. Agent pages only.
|
|
2809
|
-
*
|
|
2810
|
-
* @param kind - A kind id of `kinds()`.
|
|
2811
|
-
* @returns True when the kind is known and now off; false for an unknown kind, and on a page without the agent
|
|
2812
|
-
* flag, where nothing changes.
|
|
2813
|
-
* @example
|
|
2814
|
-
* ```ts
|
|
2815
|
-
* // The owner measures the board without the glow of its four cards (one glow pass each).
|
|
2816
|
-
* app.effects.diagnostics.disable("effects.glow"); // true
|
|
2817
|
-
* app.time.step(16);
|
|
2818
|
-
* app.effects.stats().renderPasses; // 9, down from 13
|
|
2819
|
-
* app.effects.diagnostics.disable("fx.nope"); // false, and one warning effects:diagnostics-unknown
|
|
2820
|
-
* ```
|
|
2821
|
-
*/
|
|
2822
|
-
disable(kind: string): boolean;
|
|
2823
|
-
/**
|
|
2824
|
-
* Turns a filter kind on again: from the next frame its views draw it with their current values.
|
|
2825
|
-
*
|
|
2826
|
-
* @param kind - A kind id of `kinds()`.
|
|
2827
|
-
* @returns True when the kind is known and now on; false for an unknown kind and without the agent flag.
|
|
2828
|
-
* @example
|
|
2829
|
-
* ```ts
|
|
2830
|
-
* app.effects.diagnostics.enable("effects.glow"); // true
|
|
2831
|
-
* app.time.step(16);
|
|
2832
|
-
* app.effects.stats().renderPasses; // 13
|
|
2833
|
-
* ```
|
|
2834
|
-
*/
|
|
2835
|
-
enable(kind: string): boolean;
|
|
2836
|
-
/**
|
|
2837
|
-
* The kinds turned off now, in registration order. The same frozen array until the next change; empty without
|
|
2838
|
-
* the agent flag.
|
|
2839
|
-
*
|
|
2840
|
-
* @returns The kind ids.
|
|
2841
|
-
* @example
|
|
2842
|
-
* ```ts
|
|
2843
|
-
* app.effects.diagnostics.disable("casefile.frost");
|
|
2844
|
-
* app.effects.diagnostics.disable("effects.glow");
|
|
2845
|
-
* app.effects.diagnostics.disabled(); // ["effects.glow", "casefile.frost"]
|
|
2846
|
-
* ```
|
|
2847
|
-
*/
|
|
2848
|
-
disabled(): readonly string[];
|
|
2849
|
-
};
|
|
2850
|
-
/**
|
|
2851
|
-
* Resolved dependency APIs.
|
|
2852
|
-
*/
|
|
2853
|
-
type Deps$2 = {
|
|
2854
|
-
flow: Api$2;
|
|
2855
|
-
world: Api$3;
|
|
2856
|
-
renderer: Api$4;
|
|
2857
|
-
assets: Api$5;
|
|
2858
|
-
anim: AnimApi;
|
|
2859
|
-
};
|
|
2860
|
-
/**
|
|
2861
|
-
* What the kernel context offers before the deps are attached. `effects` owns no event, so
|
|
2862
|
-
* `emit` is the kernel's and never called here.
|
|
2863
|
-
*/
|
|
2864
|
-
type KernelSlice$2 = PluginCtx<Config$2, State$2> & {
|
|
2865
|
-
readonly global: object;
|
|
2866
|
-
readonly log: Log.LogApi;
|
|
2867
|
-
readonly require: Require;
|
|
2868
|
-
};
|
|
2869
|
-
/**
|
|
2870
|
-
* Domain context shared by both modules: the kernel slice plus the resolved deps.
|
|
2871
|
-
*/
|
|
2872
|
-
type EffectsCtx = KernelSlice$2 & {
|
|
2873
|
-
readonly deps: Deps$2;
|
|
2874
|
-
};
|
|
2875
|
-
/**
|
|
2876
|
-
* Payload of the `assets:bundle-unloaded` hook: `keys` names every texture that is gone.
|
|
2877
|
-
*/
|
|
2878
|
-
type BundleUnloaded$1 = Events$1["assets:bundle-unloaded"];
|
|
2879
|
-
/**
|
|
2880
|
-
* Payload of the `assets:replaced` hook: `keys` names every asset a dev hot swap gave new bytes.
|
|
2881
|
-
*/
|
|
2882
|
-
type AssetsReplaced$1 = Events$1["assets:replaced"];
|
|
2883
|
-
/**
|
|
2884
|
-
* Payload of the global `ui:hot-swap` hook: the saved file and its new exports.
|
|
2885
|
-
*/
|
|
2886
|
-
type HotSwap = Events$2["ui:hot-swap"];
|
|
2887
|
-
declare namespace types_d_exports$1 {
|
|
2888
|
-
export { AssetsReplaced, AudioApi, AudioContextLike, AudioCtx, AudioSessionLike, AudioSessionType, BundleUnloaded, Bus, BusState, Config$1 as Config, Deps$1 as Deps, KernelSlice$1 as KernelSlice, LifecycleChanged, ModelCommitted, MusicDescriptor, MusicMode, MusicOptions, MusicRequest, MusicSwitch, MusicTrack, NamedSound, RetiringTrack, SceneChanged, SfxRequest, SoundEntry, State$1 as State, StreamTrack, Volumes, VolumesFor };
|
|
2889
|
-
}
|
|
2890
|
-
/**
|
|
2891
|
-
* The three volume buses. `master` carries the whole game, `music` the scene track, `sfx` every
|
|
2892
|
-
* sound a node or a timeline fires.
|
|
2893
|
-
*
|
|
2894
|
-
* @example
|
|
2895
|
-
* ```ts
|
|
2896
|
-
* const bus: Bus = "music";
|
|
2897
|
-
* ```
|
|
2898
|
-
*/
|
|
2899
|
-
type Bus = "master" | "music" | "sfx";
|
|
2900
|
-
/**
|
|
2901
|
-
* The part of `AudioContext` the plugin uses. A test passes its own through `config.context`, so
|
|
2902
|
-
* nothing in the unit tests touches a sound card. `state` adds Safari's `"interrupted"`, which a
|
|
2903
|
-
* phone call or the lock screen puts a context into.
|
|
2904
|
-
*
|
|
2905
|
-
* @example
|
|
2906
|
-
* ```ts
|
|
2907
|
-
* // A dev tool builds the engine's context itself and hands it to the plugin.
|
|
2908
|
-
* const context: AudioContextLike = new AudioContext();
|
|
2909
|
-
* createApp({ plugins: [...screen, audioPlugin], pluginConfigs: { audio: { context: () => context } } });
|
|
2910
|
-
* ```
|
|
2911
|
-
*/
|
|
2912
|
-
type AudioContextLike = Pick<AudioContext, "destination" | "currentTime" | "createGain" | "createBufferSource" | "decodeAudioData" | "createMediaElementSource" | "resume" | "close"> & {
|
|
2913
|
-
readonly state: AudioContext["state"] | "interrupted";
|
|
2914
|
-
};
|
|
2915
|
-
/**
|
|
2916
|
-
* What `music` accepts besides the key. An absent `fadeMs` means `config.musicFadeMs` at play time.
|
|
2917
|
-
*
|
|
2918
|
-
* @example
|
|
2919
|
-
* ```ts
|
|
2920
|
-
* const options: MusicOptions = { fadeMs: 200 };
|
|
2921
|
-
* ```
|
|
2922
|
-
*/
|
|
2923
|
-
type MusicOptions = {
|
|
2924
|
-
fadeMs?: number;
|
|
2925
|
-
};
|
|
2926
|
-
/**
|
|
2927
|
-
* `music` bound to the audio asset keys of one game. `defineGame` returns it through `audioFor`;
|
|
2928
|
-
* the loose export accepts any string. The descriptor resolves nothing.
|
|
2929
|
-
*
|
|
2930
|
-
* @example
|
|
2931
|
-
* ```ts
|
|
2932
|
-
* const gameMusic: MusicDescriptor<"board.theme"> = music;
|
|
2933
|
-
* ```
|
|
2934
|
-
*/
|
|
2935
|
-
type MusicDescriptor<Asset extends string> = (key: Asset | null, options?: MusicOptions) => Descriptor<void>;
|
|
2936
|
-
/**
|
|
2937
|
-
* Reads the player's volume choice out of the committed player state. Every bus it names is
|
|
2938
|
-
* applied; the ones it leaves out keep the value they had.
|
|
2939
|
-
*
|
|
2940
|
-
* @example
|
|
2941
|
-
* ```ts
|
|
2942
|
-
* const volumes: Volumes = player => (player as { settings: { audio: { music: number } } }).settings.audio;
|
|
2943
|
-
* ```
|
|
2944
|
-
*/
|
|
2945
|
-
type Volumes = (player: Json) => Partial<Record<Bus, number>>;
|
|
2946
|
-
/**
|
|
2947
|
-
* `Volumes`, written against the player type of one game: `defineGame` hands it as `volumes`, so
|
|
2948
|
-
* the callback reads the game's player with no cast. The same function at run time.
|
|
2949
|
-
*
|
|
2950
|
-
* @example
|
|
2951
|
-
* ```ts
|
|
2952
|
-
* // index.ts of a game: `volumes` comes from the kit, so `player` is the game's Player.
|
|
2953
|
-
* pluginConfigs: { audio: { volumes: volumes(player => ({ music: player.settings.music })) } }
|
|
2954
|
-
* ```
|
|
2955
|
-
*/
|
|
2956
|
-
type VolumesFor<Player> = (read: (player: Player) => Partial<Record<Bus, number>>) => Volumes;
|
|
2957
|
-
/**
|
|
2958
|
-
* How a music track is played. `"decode"`: one AudioBuffer per track, gapless, about 58 MB per
|
|
2959
|
-
* 150 s at 48 kHz. `"stream"`: an `<audio>` element on a `blob:` URL of the bytes `assets` holds,
|
|
2960
|
-
* about 12 MB, and a gap at every loop: 5 to 49 ms in Chromium, about 0.4 s in WebKit. A tight
|
|
2961
|
-
* loop keeps `"decode"`; a long track that tolerates a seam takes `"stream"`.
|
|
2962
|
-
*
|
|
2963
|
-
* @example
|
|
2964
|
-
* ```ts
|
|
2965
|
-
* const mode: MusicMode = "stream";
|
|
2966
|
-
* ```
|
|
2967
|
-
*/
|
|
2968
|
-
type MusicMode = "decode" | "stream";
|
|
2969
|
-
/**
|
|
2970
|
-
* What the page asks iOS for. `"ambient"`: mixes with other apps, the silent switch mutes it.
|
|
2971
|
-
* `"playback"`: stops other apps, plays through the switch. `"auto"`: WebKit picks.
|
|
2972
|
-
*
|
|
2973
|
-
* @example
|
|
2974
|
-
* ```ts
|
|
2975
|
-
* const session: AudioSessionType = "playback";
|
|
2976
|
-
* ```
|
|
2977
|
-
*/
|
|
2978
|
-
type AudioSessionType = "ambient" | "playback" | "auto";
|
|
2979
|
-
/**
|
|
2980
|
-
* The part of `navigator.audioSession` the plugin writes. `lib.dom` has no type for it, and only
|
|
2981
|
-
* WebKit has the object at all.
|
|
2982
|
-
*
|
|
2983
|
-
* @example
|
|
2984
|
-
* ```ts
|
|
2985
|
-
* // What Safari answers before the plugin started: no override.
|
|
2986
|
-
* const session: AudioSessionLike = { type: "auto" };
|
|
2987
|
-
* ```
|
|
2988
|
-
*/
|
|
2989
|
-
type AudioSessionLike = {
|
|
2990
|
-
type: string;
|
|
2991
|
-
};
|
|
2992
|
-
/**
|
|
2993
|
-
* One music track played by an element at `music: "stream"`: the element, its source node in the
|
|
2994
|
-
* graph, the track gain every level goes through, and the `blob:` URL the element reads.
|
|
2995
|
-
*
|
|
2996
|
-
* @example
|
|
2997
|
-
* ```ts
|
|
2998
|
-
* // `state.music.stream` once "board.theme" plays at `music: "stream"`.
|
|
2999
|
-
* const { element, url }: StreamTrack = track;
|
|
3000
|
-
* element.loop; // true
|
|
3001
|
-
* url.startsWith("blob:"); // true
|
|
3002
|
-
* ```
|
|
3003
|
-
*/
|
|
3004
|
-
type StreamTrack = {
|
|
3005
|
-
element: HTMLAudioElement;
|
|
3006
|
-
node: MediaElementAudioSourceNode;
|
|
3007
|
-
gain: GainNode;
|
|
3008
|
-
url: string;
|
|
3009
|
-
};
|
|
3010
|
-
/**
|
|
3011
|
-
* A streamed track that fades out. Its timer frees the element when the fade ends: an element has
|
|
3012
|
-
* no `stop(when)` on the context clock.
|
|
3013
|
-
*
|
|
3014
|
-
* @example
|
|
3015
|
-
* ```ts
|
|
3016
|
-
* // A switch at `musicFadeMs: 600` keeps the old track here for 600 ms.
|
|
3017
|
-
* const entry: RetiringTrack = { stream: oldTrack, timer: setTimeout(free, 600) };
|
|
3018
|
-
* ```
|
|
3019
|
-
*/
|
|
3020
|
-
type RetiringTrack = {
|
|
3021
|
-
stream: StreamTrack;
|
|
3022
|
-
timer: ReturnType<typeof setTimeout>;
|
|
3023
|
-
};
|
|
3024
|
-
/**
|
|
3025
|
-
* audio plugin config.
|
|
3026
|
-
*
|
|
3027
|
-
* @example
|
|
3028
|
-
* ```ts
|
|
3029
|
-
* // `volumes` comes from the game's `defineGame` kit, so `player` is the game's Player.
|
|
3030
|
-
* createApp({
|
|
3031
|
-
* plugins: [...screen, audioPlugin],
|
|
3032
|
-
* pluginConfigs: {
|
|
3033
|
-
* audio: { musicFadeMs: 400, music: "stream", session: "playback", volumes: volumes(player => player.settings.audio) }
|
|
3034
|
-
* }
|
|
3035
|
-
* });
|
|
3036
|
-
* ```
|
|
3037
|
-
*/
|
|
3038
|
-
type Config$1 = {
|
|
3039
|
-
/** Start gain of each bus, 0..1. Overridden per commit when `volumes` is set. */buses: {
|
|
3040
|
-
master: number;
|
|
3041
|
-
music: number;
|
|
3042
|
-
sfx: number;
|
|
3043
|
-
}; /** Cross-fade of a music switch, in real milliseconds of the context clock. */
|
|
3044
|
-
musicFadeMs: number;
|
|
3045
|
-
/**
|
|
3046
|
-
* Fade of a named sound, an `sfx` with `id`, in real milliseconds of the context clock: when a
|
|
3047
|
-
* new sound with its id replaces it and names no `fadeMs`, or a stop names none.
|
|
3048
|
-
*/
|
|
3049
|
-
sfxFadeMs: number; /** Reads the player's choice from the committed player. `undefined`: the buses stay at `buses`. */
|
|
3050
|
-
volumes: Volumes | undefined;
|
|
3051
|
-
/**
|
|
3052
|
-
* Context factory, the test seam. `undefined`: `new AudioContext()` when the global exists, otherwise headless.
|
|
3053
|
-
* On iOS the plugin calls it again after a return from the background, so each call returns a new context.
|
|
3054
|
-
*/
|
|
3055
|
-
context: (() => AudioContextLike) | undefined; /** How many started sounds `journal()` keeps, newest last. `0` turns the journal off. */
|
|
3056
|
-
journal: number; /** How music plays. `"stream"` needs MP3 or AAC: WebM Opus is silent through a media element in WebKit (bug 276813). Sounds always decode. */
|
|
3057
|
-
music: MusicMode; /** Set on `navigator.audioSession.type` in `onStart`, before the context exists. No-op where the API is missing (every Chromium, Firefox). */
|
|
3058
|
-
session: AudioSessionType;
|
|
3059
|
-
};
|
|
3060
|
-
/**
|
|
3061
|
-
* One sound that started: a play of an `sfx` or a music track that began. `at` is the elapsed
|
|
3062
|
-
* game time in milliseconds, `app.time.snapshot().elapsed` at the start. `id` is there only for
|
|
3063
|
-
* an `sfx` started with one.
|
|
3064
|
-
*
|
|
3065
|
-
* @example
|
|
3066
|
-
* ```ts
|
|
3067
|
-
* const entry: SoundEntry = { key: "ui.click", bus: "sfx", kind: "sfx", at: 1600 };
|
|
3068
|
-
* const line: SoundEntry = { key: "story.line1", bus: "sfx", kind: "sfx", id: "voice", at: 2400 };
|
|
3069
|
-
* ```
|
|
3070
|
-
*/
|
|
3071
|
-
type SoundEntry = {
|
|
3072
|
-
readonly key: string;
|
|
3073
|
-
readonly bus: Bus;
|
|
3074
|
-
readonly kind: "sfx" | "music";
|
|
3075
|
-
readonly id?: string;
|
|
3076
|
-
readonly at: number;
|
|
3077
|
-
};
|
|
3078
|
-
/**
|
|
3079
|
-
* What the plugin keeps for one bus: its gain node while a context exists, the volume a game or
|
|
3080
|
-
* the player chose, and whether it is muted.
|
|
3081
|
-
*
|
|
3082
|
-
* @example
|
|
3083
|
-
* ```ts
|
|
3084
|
-
* const entry: BusState = { gain: undefined, volume: 0.6, muted: false };
|
|
3085
|
-
* ```
|
|
3086
|
-
*/
|
|
3087
|
-
type BusState = {
|
|
3088
|
-
gain: GainNode | undefined;
|
|
3089
|
-
volume: number;
|
|
3090
|
-
muted: boolean;
|
|
3091
|
-
};
|
|
3092
|
-
/**
|
|
3093
|
-
* The music that is playing, or the key remembered until the context is unlocked.
|
|
3094
|
-
* `source` plays a decoded track, `stream` a streamed one; they are never both set. Both
|
|
3095
|
-
* `undefined`: the key is only remembered (a locked context, or a refused `play()`).
|
|
3096
|
-
*
|
|
3097
|
-
* @example
|
|
3098
|
-
* ```ts
|
|
3099
|
-
* const track: MusicTrack = { key: "board.theme", gain: undefined, source: undefined, stream: undefined };
|
|
3100
|
-
* ```
|
|
3101
|
-
*/
|
|
3102
|
-
type MusicTrack = {
|
|
3103
|
-
key: string;
|
|
3104
|
-
gain: GainNode | undefined;
|
|
3105
|
-
source: AudioBufferSourceNode | undefined;
|
|
3106
|
-
stream: StreamTrack | undefined;
|
|
3107
|
-
};
|
|
3108
|
-
/**
|
|
3109
|
-
* A music switch that waits for its buffer to decode. Its identity is the token: a later request
|
|
3110
|
-
* replaces it, and the replaced switch neither starts nor fades anything when its buffer arrives.
|
|
3111
|
-
*
|
|
3112
|
-
* @example
|
|
3113
|
-
* ```ts
|
|
3114
|
-
* const waiting: MusicSwitch = { key: "ui.theme" };
|
|
3115
|
-
* ```
|
|
3116
|
-
*/
|
|
3117
|
-
type MusicSwitch = {
|
|
3118
|
-
key: string;
|
|
3119
|
-
};
|
|
3120
|
-
/**
|
|
3121
|
-
* The sound that plays, or still decodes, under one id. The entry object is the token, as a
|
|
3122
|
-
* `MusicSwitch` is: a sound whose entry is no longer the one `named` holds when its buffer arrives
|
|
3123
|
-
* starts nothing. `gain` and `source` stay `undefined` until the sound started.
|
|
3124
|
-
*/
|
|
3125
|
-
type NamedSound = {
|
|
3126
|
-
gain: GainNode | undefined;
|
|
3127
|
-
source: AudioBufferSourceNode | undefined;
|
|
3128
|
-
};
|
|
3129
|
-
/**
|
|
3130
|
-
* audio plugin state.
|
|
3131
|
-
*/
|
|
3132
|
-
type State$1 = {
|
|
3133
|
-
/** `undefined` means headless: no graph, no sound, every member still keeps its value. */context: AudioContextLike | undefined;
|
|
3134
|
-
buses: Record<Bus, BusState>; /** A lifecycle push is in force: every bus is held at zero. */
|
|
3135
|
-
paused: boolean;
|
|
3136
|
-
unlocked: boolean; /** A gesture called `resume()` and it has not settled yet. The start attempt never sets it. */
|
|
3137
|
-
resuming: boolean;
|
|
3138
|
-
/**
|
|
3139
|
-
* Sounds fired while `resuming`: one per id, under `"#" + id`, and one per key for a sound
|
|
3140
|
-
* without an id. Played when the context runs, dropped when it does not.
|
|
3141
|
-
*/
|
|
3142
|
-
pendingSfx: Map<string, SfxRequest>; /** The sound that plays, or decodes, under each id; an entry leaves when its sound ends or stops. */
|
|
3143
|
-
named: Map<string, NamedSound>; /** Per key, evicted per key on `assets:bundle-unloaded` and `assets:replaced`, and when a music track stops being the one that plays. */
|
|
3144
|
-
decoded: Map<string, Promise<AudioBuffer>>; /** Asset keys that already got their one warning. */
|
|
3145
|
-
warned: Set<string>; /** `config.volumes` threw once and was reported; it is not reported again this run. */
|
|
3146
|
-
warnedVolumes: boolean;
|
|
3147
|
-
music: MusicTrack | undefined; /** The latest switch still decoding; `undefined` once it started or a later request replaced it. */
|
|
3148
|
-
musicPending: MusicSwitch | undefined; /** Removes the two window listeners of the unlock. */
|
|
3149
|
-
unlock: (() => void) | undefined; /** Cancels the renewal that waits after a return from the background: its timer and its two listeners. */
|
|
3150
|
-
renewal: (() => void) | undefined; /** The token of the renewal that runs; a stop or a newer renewal replaces it, and the old one makes nothing. */
|
|
3151
|
-
renewing: object | undefined; /** The removers of the three fx handlers. */
|
|
3152
|
-
removers: Array<() => void>; /** The `navigator.audioSession` that took `config.session`; `stop` writes `"auto"` back to it. */
|
|
3153
|
-
session: AudioSessionLike | undefined; /** Streamed tracks that fade out, each freed by its timer. */
|
|
3154
|
-
retiring: Set<RetiringTrack>;
|
|
3155
|
-
/**
|
|
3156
|
-
* The sounds that started, oldest first, at most `config.journal` of them. Frozen: a write
|
|
3157
|
-
* replaces the whole list, so `journal()` hands it out without a copy.
|
|
3158
|
-
*/
|
|
3159
|
-
journal: readonly SoundEntry[];
|
|
3160
|
-
};
|
|
3161
|
-
/**
|
|
3162
|
-
* audio plugin API, `app.audio`. Three buses, the unlock flag, the journal and the stop of a named
|
|
3163
|
-
* sound: what a game changes about sound it commits to the player state, which this plugin applies
|
|
3164
|
-
* on the next commit.
|
|
3165
|
-
*
|
|
3166
|
-
* @example
|
|
3167
|
-
* ```ts
|
|
3168
|
-
* // A dev overlay pulls the music down and reads the value back.
|
|
3169
|
-
* app.audio.setVolume("music", 0.2);
|
|
3170
|
-
* app.audio.volume("music"); // 0.2
|
|
3171
|
-
* ```
|
|
3172
|
-
*/
|
|
3173
|
-
type AudioApi = {
|
|
3174
|
-
/**
|
|
3175
|
-
* Sets the volume of one bus and schedules the new gain at once. The value is clamped to 0..1
|
|
3176
|
-
* and `NaN` becomes 0. Nothing is persisted: a game stores the choice in the player state and
|
|
3177
|
-
* lets `config.volumes` apply it, so the next commit overwrites what this call set.
|
|
3178
|
-
*
|
|
3179
|
-
* @param bus - The bus to change.
|
|
3180
|
-
* @param value - The new volume, 0..1.
|
|
3181
|
-
* @throws {Error} When the bus does not exist.
|
|
3182
|
-
* @example
|
|
3183
|
-
* ```ts
|
|
3184
|
-
* // A test turns the music off before it walks the graph, so nothing rings.
|
|
3185
|
-
* app.audio.setVolume("music", 0);
|
|
3186
|
-
* app.audio.volume("music"); // 0
|
|
3187
|
-
* ```
|
|
3188
|
-
*/
|
|
3189
|
-
setVolume(bus: Bus, value: number): void;
|
|
3190
|
-
/**
|
|
3191
|
-
* The stored volume of a bus, never the live gain: a muted or paused bus still answers the
|
|
3192
|
-
* value the player chose.
|
|
3193
|
-
*
|
|
3194
|
-
* @param bus - The bus to read.
|
|
3195
|
-
* @returns The stored volume, 0..1.
|
|
3196
|
-
* @throws {Error} When the bus does not exist.
|
|
3197
|
-
* @example
|
|
3198
|
-
* ```ts
|
|
3199
|
-
* // The settings screen draws the slider of the sfx bus at its stored place.
|
|
3200
|
-
* app.audio.mute("sfx", true);
|
|
3201
|
-
* app.audio.volume("sfx"); // 1: muting does not move the slider
|
|
3202
|
-
* ```
|
|
3203
|
-
*/
|
|
3204
|
-
volume(bus: Bus): number;
|
|
3205
|
-
/**
|
|
3206
|
-
* Mutes or unmutes one bus. The flag is independent of the pause: a bus muted here stays muted
|
|
3207
|
-
* when the game comes back from the background.
|
|
3208
|
-
*
|
|
3209
|
-
* @param bus - The bus to change.
|
|
3210
|
-
* @param on - `true` mutes it, `false` lets it play again.
|
|
3211
|
-
* @throws {Error} When the bus does not exist.
|
|
3212
|
-
* @example
|
|
3213
|
-
* ```ts
|
|
3214
|
-
* // A dev overlay silences the whole game while a profiler trace runs.
|
|
3215
|
-
* app.audio.mute("master", true);
|
|
3216
|
-
* app.audio.volume("master"); // 1, and nothing is heard
|
|
3217
|
-
* ```
|
|
3218
|
-
*/
|
|
3219
|
-
mute(bus: Bus, on: boolean): void;
|
|
3220
|
-
/**
|
|
3221
|
-
* Tells whether one bus is muted: the stored flag `mute` wrote. A pause does not change it, and
|
|
3222
|
-
* a headless run answers it too.
|
|
3223
|
-
*
|
|
3224
|
-
* @param bus - The bus to read.
|
|
3225
|
-
* @returns True while the bus is muted.
|
|
3226
|
-
* @throws {Error} When the bus does not exist.
|
|
3227
|
-
* @example
|
|
3228
|
-
* ```ts
|
|
3229
|
-
* // The settings screen draws the Sound switch off after the player muted the game.
|
|
3230
|
-
* app.audio.mute("master", true);
|
|
3231
|
-
* app.audio.muted("master"); // true
|
|
3232
|
-
* ```
|
|
3233
|
-
*/
|
|
3234
|
-
muted(bus: Bus): boolean;
|
|
3235
|
-
/**
|
|
3236
|
-
* Tells whether the audio context runs. A shell that lets audio play with no gesture, such as a
|
|
3237
|
-
* native webview with the requirement switched off, makes it true at start: at once when the
|
|
3238
|
-
* context is created running, otherwise when the `resume()` of `onStart` fulfils. A browser
|
|
3239
|
-
* that wants a gesture keeps it false until the first touch or click on the page resumed the
|
|
3240
|
-
* context and it runs; on iOS that resume may stay pending until iOS gives the sound back. It is
|
|
3241
|
-
* false for the whole of a headless run, and for the moment an iOS renewal closes the old context.
|
|
3242
|
-
*
|
|
3243
|
-
* @returns True once the context is running.
|
|
3244
|
-
* @example
|
|
3245
|
-
* ```ts
|
|
3246
|
-
* // A "tap for sound" hint stays on screen only while the shell holds the sound back.
|
|
3247
|
-
* await app.start();
|
|
3248
|
-
* app.audio.unlocked(); // true where the context was created running, false in a browser tab
|
|
3249
|
-
* // The player touches the page of that tab.
|
|
3250
|
-
* app.audio.unlocked(); // true
|
|
3251
|
-
* ```
|
|
3252
|
-
*/
|
|
3253
|
-
unlocked(): boolean;
|
|
3254
|
-
/**
|
|
3255
|
-
* The sounds that started, oldest first: every play of an `sfx` and every music track that
|
|
3256
|
-
* began, at most `config.journal` of them. A sound dropped before the unlock, a missing file
|
|
3257
|
-
* and a music switch to the track that already plays are not in it. Empty while
|
|
3258
|
-
* `config.journal` is 0, the default, and after the app stopped.
|
|
3259
|
-
*
|
|
3260
|
-
* No copy and no live view: the list and its entries are never written. Every new sound replaces the plugin's list
|
|
3261
|
-
* with a new frozen one, so a list read earlier keeps what it held, and a caller cannot change the journal through it.
|
|
3262
|
-
*
|
|
3263
|
-
* @returns The journal, frozen; a later sound replaces the list and leaves this one as it was.
|
|
3264
|
-
* @example
|
|
3265
|
-
* ```ts
|
|
3266
|
-
* // A test composed with `pluginConfigs.audio = { journal: 200 }` taps "deliver" after the
|
|
3267
|
-
* // first touch and checks the chime was heard.
|
|
3268
|
-
* app.audio.journal();
|
|
3269
|
-
* // [{ key: "board.theme", bus: "music", kind: "music", at: 0 },
|
|
3270
|
-
* // { key: "orders.complete", bus: "sfx", kind: "sfx", at: 1600 }]
|
|
3271
|
-
* ```
|
|
3272
|
-
*/
|
|
3273
|
-
journal(): readonly SoundEntry[];
|
|
3274
|
-
/**
|
|
3275
|
-
* Fades out and ends the sound that plays under one id, an `sfx` started with `{ id }`. The
|
|
3276
|
-
* same stop as the effect kind `stopSfx`: a sound with that id still decoding never starts, one
|
|
3277
|
-
* waiting for the unlock is dropped, and an id nothing plays under changes nothing. Headless it
|
|
3278
|
-
* does nothing.
|
|
3279
|
-
*
|
|
3280
|
-
* @param id - The id the sound was started with, `"voice"` for `sfx(key, { id: "voice" })`.
|
|
3281
|
-
* @param options - How the sound ends.
|
|
3282
|
-
* @param options.fadeMs - Length of the fade in real milliseconds; `config.sfxFadeMs` when absent, `0` cuts it at once.
|
|
3283
|
-
* @example
|
|
3284
|
-
* ```ts
|
|
3285
|
-
* // A test composed with `journal: 200` cuts the narrator's line before it checks the next screen.
|
|
3286
|
-
* app.audio.journal().at(-1); // { key: "story.line1", bus: "sfx", kind: "sfx", id: "voice", at: 0 }
|
|
3287
|
-
* app.audio.stop("voice", { fadeMs: 0 }); // the line ends now and stays in the journal
|
|
3288
|
-
* ```
|
|
3289
|
-
*/
|
|
3290
|
-
stop(id: string, options?: {
|
|
3291
|
-
fadeMs?: number;
|
|
3292
|
-
}): void;
|
|
3293
|
-
};
|
|
3294
|
-
/**
|
|
3295
|
-
* Resolved dependency APIs.
|
|
3296
|
-
*/
|
|
3297
|
-
type Deps$1 = {
|
|
3298
|
-
flow: Api$2;
|
|
3299
|
-
assets: Api$5;
|
|
3300
|
-
model: Api$6;
|
|
3301
|
-
time: Api$1;
|
|
3302
|
-
};
|
|
3303
|
-
/**
|
|
3304
|
-
* What the kernel context offers before the deps are attached.
|
|
3305
|
-
*
|
|
3306
|
-
* `audio` owns no event, so `emit` is the kernel's and never called here.
|
|
3307
|
-
*/
|
|
3308
|
-
type KernelSlice$1 = PluginCtx<Config$1, State$1> & {
|
|
3309
|
-
readonly global: object;
|
|
3310
|
-
readonly log: Log.LogApi;
|
|
3311
|
-
readonly require: Require;
|
|
3312
|
-
};
|
|
3313
|
-
/**
|
|
3314
|
-
* Domain context shared by the files of the plugin: the kernel slice plus the resolved deps.
|
|
3315
|
-
*/
|
|
3316
|
-
type AudioCtx = KernelSlice$1 & {
|
|
3317
|
-
readonly deps: Deps$1;
|
|
3318
|
-
};
|
|
3319
|
-
/**
|
|
3320
|
-
* Payload of the `model:committed` hook: the source of every volume a game sets.
|
|
3321
|
-
*/
|
|
3322
|
-
type ModelCommitted = Events$3["model:committed"];
|
|
3323
|
-
/**
|
|
3324
|
-
* Payload of the `scenes:changed` hook: `music` is the track the next scene declared.
|
|
3325
|
-
*/
|
|
3326
|
-
type SceneChanged = Events$4["scenes:changed"];
|
|
3327
|
-
/**
|
|
3328
|
-
* Payload of the `lifecycle:changed` hook: the pause that holds every bus at zero.
|
|
3329
|
-
*/
|
|
3330
|
-
type LifecycleChanged = Events$5["lifecycle:changed"];
|
|
3331
|
-
/**
|
|
3332
|
-
* Payload of the `assets:bundle-unloaded` hook: `keys` names every decoded sound that is gone.
|
|
3333
|
-
*/
|
|
3334
|
-
type BundleUnloaded = Events$1["assets:bundle-unloaded"];
|
|
3335
|
-
/**
|
|
3336
|
-
* Payload of the `assets:replaced` hook: `keys` names every asset a dev hot swap gave new bytes.
|
|
3337
|
-
*/
|
|
3338
|
-
type AssetsReplaced = Events$1["assets:replaced"];
|
|
3339
|
-
/**
|
|
3340
|
-
* What one play of a sound asks for: the key, the bus the sound goes to, the id it plays under
|
|
3341
|
-
* (`undefined`: none), and the fade in milliseconds of the sound with that id it replaces.
|
|
3342
|
-
*/
|
|
3343
|
-
type SfxRequest = {
|
|
3344
|
-
key: string;
|
|
3345
|
-
bus: string;
|
|
3346
|
-
id: string | undefined;
|
|
3347
|
-
fadeMs: number;
|
|
3348
|
-
};
|
|
3349
|
-
/**
|
|
3350
|
-
* What one music switch asks for: the key, or `null` to fade the current track out.
|
|
3351
|
-
*/
|
|
3352
|
-
type MusicRequest = {
|
|
3353
|
-
key: string | null;
|
|
3354
|
-
fadeMs: number;
|
|
3355
|
-
};
|
|
3356
|
-
declare namespace types_d_exports {
|
|
3357
|
-
export { AnchorTarget, Config, Deps, ElementChange, ElementMotion, Finding, FocusRing, KernelSlice, State, TextInputLook, UiApi, UiCtx, UiNode };
|
|
3358
|
-
}
|
|
3359
|
-
/**
|
|
3360
|
-
* The look of the keyboard focus ring: a dashed ring with a solid halo under it, drawn around the
|
|
3361
|
-
* focused control. Colours are `0xRRGGBB`, lengths reference units.
|
|
3362
|
-
*
|
|
3363
|
-
* @example
|
|
3364
|
-
* ```ts
|
|
3365
|
-
* // A dashed ink ring with a cream halo, 9 u outside the control.
|
|
3366
|
-
* const ring: FocusRing = {
|
|
3367
|
-
* stroke: 0x3a2212, strokeWidth: 4, dash: 10, offset: 9, halo: 0xfff3d6, haloWidth: 12
|
|
3368
|
-
* };
|
|
3369
|
-
* ```
|
|
3370
|
-
*/
|
|
3371
|
-
type FocusRing = {
|
|
3372
|
-
/** The colour of the dashed ring. */stroke: number; /** The stroke width of the dashed ring. */
|
|
3373
|
-
strokeWidth: number; /** The dash length of the ring, with gaps of half a dash; 0 draws it solid. */
|
|
3374
|
-
dash: number; /** How far outside the control's rect the ring runs, on every side. */
|
|
3375
|
-
offset: number; /** The colour of the solid halo drawn under the ring. */
|
|
3376
|
-
halo: number; /** The stroke width of the halo, centred on the same path as the ring. */
|
|
3377
|
-
haloWidth: number;
|
|
3378
|
-
};
|
|
3379
|
-
/**
|
|
3380
|
-
* The look of a text field while it is edited: the caret, the selection box and the IME
|
|
3381
|
-
* underline. Colours are `0xRRGGBB`, lengths reference units, `keyboardMargin` CSS px. The caret
|
|
3382
|
-
* does not blink.
|
|
3383
|
-
*
|
|
3384
|
-
* @example
|
|
3385
|
-
* ```ts
|
|
3386
|
-
* // A thick ink caret, a pale blue selection, the field 16 px above the keyboard.
|
|
3387
|
-
* const look: TextInputLook = {
|
|
3388
|
-
* caretWidth: 3, caret: 0x3a2212, selection: 0x3390ff, selectionAlpha: 0.35,
|
|
3389
|
-
* composingUnderline: 3, keyboardMargin: 16
|
|
3390
|
-
* };
|
|
3391
|
-
* ```
|
|
3392
|
-
*/
|
|
3393
|
-
type TextInputLook = {
|
|
3394
|
-
/** The width of the caret. */caretWidth: number; /** The colour of the caret and of the underline under an IME composing range. */
|
|
3395
|
-
caret: number; /** The colour of the selection box. */
|
|
3396
|
-
selection: number; /** The alpha of the selection box. */
|
|
3397
|
-
selectionAlpha: number; /** The height of the underline under an IME composing range. */
|
|
3398
|
-
composingUnderline: number; /** How far above the keyboard the bottom of the edited field is lifted, in CSS px. */
|
|
3399
|
-
keyboardMargin: number;
|
|
3400
|
-
};
|
|
3401
|
-
/**
|
|
3402
|
-
* ui plugin config.
|
|
3403
|
-
*
|
|
3404
|
-
* @example
|
|
3405
|
-
* ```ts
|
|
3406
|
-
* createApp({ pluginConfigs: { ui: { tapTargetPt: 48, breakpoints: { tall: 2, wide: 1.5 } } } });
|
|
3407
|
-
* // A game with a white focus ring on a dark board.
|
|
3408
|
-
* createApp({
|
|
3409
|
-
* pluginConfigs: {
|
|
3410
|
-
* ui: {
|
|
3411
|
-
* focusRing: {
|
|
3412
|
-
* stroke: 0xffffff, strokeWidth: 4, dash: 10, offset: 9, halo: 0x000000, haloWidth: 12
|
|
3413
|
-
* }
|
|
3414
|
-
* }
|
|
3415
|
-
* }
|
|
3416
|
-
* });
|
|
3417
|
-
* // A game whose text fields have an ink caret.
|
|
3418
|
-
* createApp({
|
|
3419
|
-
* pluginConfigs: {
|
|
3420
|
-
* ui: {
|
|
3421
|
-
* textInput: {
|
|
3422
|
-
* caretWidth: 3, caret: 0x3a2212, selection: 0x3390ff, selectionAlpha: 0.35,
|
|
3423
|
-
* composingUnderline: 3, keyboardMargin: 16
|
|
3424
|
-
* }
|
|
3425
|
-
* }
|
|
3426
|
-
* }
|
|
3427
|
-
* });
|
|
3428
|
-
* ```
|
|
3429
|
-
*/
|
|
3430
|
-
type Config = {
|
|
3431
|
-
/** Smallest tap target `lint()` accepts, in CSS px (points). */tapTargetPt: number; /** `when` flags: `tall` when height / width is at least `tall`, `wide` the other way round. */
|
|
3432
|
-
breakpoints: {
|
|
3433
|
-
tall: number;
|
|
3434
|
-
wide: number;
|
|
3435
|
-
};
|
|
3436
|
-
/**
|
|
3437
|
-
* The ring drawn around the control the keyboard focused. Shallow merge: a game that sets
|
|
3438
|
-
* `focusRing` gives all six fields.
|
|
3439
|
-
*/
|
|
3440
|
-
focusRing: FocusRing;
|
|
3441
|
-
/**
|
|
3442
|
-
* The caret, the selection and the IME underline of a text field. Shallow merge: a game that
|
|
3443
|
-
* sets `textInput` gives all six fields.
|
|
3444
|
-
*/
|
|
3445
|
-
textInput: TextInputLook;
|
|
3446
|
-
};
|
|
3447
|
-
/**
|
|
3448
|
-
* ui plugin state: one branch per module.
|
|
3449
|
-
*/
|
|
3450
|
-
type State = {
|
|
3451
|
-
jsx: JsxState;
|
|
3452
|
-
styles: StylesState;
|
|
3453
|
-
layout: LayoutState;
|
|
3454
|
-
};
|
|
3455
|
-
/**
|
|
3456
|
-
* Resolved dependency APIs. `anim` is here for the dev hot swap, which replaces animations; the
|
|
3457
|
-
* motions of `ui` reach `anim` through the tween driver behind every `ViewHandle`.
|
|
3458
|
-
*/
|
|
3459
|
-
type Deps = {
|
|
3460
|
-
anim: AnimApi;
|
|
3461
|
-
debug: Api;
|
|
3462
|
-
time: Api$1;
|
|
3463
|
-
flow: Api$2;
|
|
3464
|
-
world: Api$3;
|
|
3465
|
-
renderer: Api$4;
|
|
3466
|
-
input: InputApi;
|
|
3467
|
-
i18n: I18nApi;
|
|
3468
|
-
text: TextApi;
|
|
3469
|
-
};
|
|
3470
|
-
/**
|
|
3471
|
-
* What the kernel context offers before the deps are attached.
|
|
3472
|
-
*
|
|
3473
|
-
* `ui` owns no event of its own; `emit` sends the global `ui:hot-swap` of the dev hot swap.
|
|
3474
|
-
*/
|
|
3475
|
-
type KernelSlice = PluginCtx<Config, State, Events$2> & {
|
|
3476
|
-
readonly global: object;
|
|
3477
|
-
readonly log: Log.LogApi;
|
|
3478
|
-
readonly require: Require;
|
|
3479
|
-
};
|
|
3480
|
-
/**
|
|
3481
|
-
* Domain context shared by the three modules: the kernel slice plus the resolved deps.
|
|
3482
|
-
*/
|
|
3483
|
-
type UiCtx = KernelSlice & {
|
|
3484
|
-
readonly deps: Deps;
|
|
3485
|
-
};
|
|
3486
|
-
/**
|
|
3487
|
-
* ui plugin API, `app.ui`. The screen is one more projection, so three members read it the way a
|
|
3488
|
-
* test reads the board: a snapshot, a key lookup and a list of findings; the fourth types into a
|
|
3489
|
-
* text field, the fifth scrolls a `scroll`, the sixth measures where a view or an element is drawn.
|
|
3490
|
-
*
|
|
3491
|
-
* @example
|
|
3492
|
-
* ```ts
|
|
3493
|
-
* // A headless scenario taps the claim button of the reward popup.
|
|
3494
|
-
* app.ui.tree().type; // "row", the root element of the HUD
|
|
3495
|
-
* app.input.tap(app.ui.find("claim") ?? 0);
|
|
3496
|
-
* app.ui.lint(); // []
|
|
3497
|
-
* ```
|
|
3498
|
-
*/
|
|
3499
|
-
type UiApi = {
|
|
3500
|
-
/**
|
|
3501
|
-
* The live screen as plain data: every root in layer order, every element in child order, with
|
|
3502
|
-
* its rect in root coordinates, its resolved style and its seven state flags. A rect is natural:
|
|
3503
|
-
* under a `fit: "contain"` element it is the rect before that scale, and the fitted element
|
|
3504
|
-
* adds `fitScale`. A windowed scroll adds `window`, and its content lists the live rows only.
|
|
3505
|
-
* Works headless.
|
|
3506
|
-
*
|
|
3507
|
-
* @returns The root node; several roots come back under one `screen` node.
|
|
3508
|
-
* @example
|
|
3509
|
-
* ```ts
|
|
3510
|
-
* // On an iPhone SE the 970 u board is drawn smaller to fit the slot between the bars.
|
|
3511
|
-
* const screen = app.ui.tree();
|
|
3512
|
-
* screen.children.map(child => child.key); // ["fitTop", "slot", "fitBottom"]
|
|
3513
|
-
* const board = screen.children[1]?.children[0];
|
|
3514
|
-
* board?.rect.w; // 970, the natural width
|
|
3515
|
-
* board?.fitScale; // 0.805, the 781 u the slot leaves over 970 u
|
|
3516
|
-
* ```
|
|
3517
|
-
*/
|
|
3518
|
-
tree(): UiNode;
|
|
3519
|
-
/**
|
|
3520
|
-
* The entity of a keyed element, so a test can tap it and `anim` can aim at it. Popup roots
|
|
3521
|
-
* come first, then the projection roots in layer order.
|
|
3522
|
-
*
|
|
3523
|
-
* @param key - The `key` prop of the element.
|
|
3524
|
-
* @returns The entity, or `undefined` for an unknown or exiting element.
|
|
3525
|
-
* @example
|
|
3526
|
-
* ```ts
|
|
3527
|
-
* // A headless scenario answers the gate through the button of the popup.
|
|
3528
|
-
* app.input.tap(app.ui.find("claim") ?? 0); // true
|
|
3529
|
-
* app.ui.find("nothing"); // undefined
|
|
3530
|
-
* ```
|
|
3531
|
-
*/
|
|
3532
|
-
find(key: string): Entity | undefined;
|
|
3533
|
-
/**
|
|
3534
|
-
* Reads the live screen against the six rules: a tap target under `tapTargetPt` at the size
|
|
3535
|
-
* it is drawn (a `fit: "contain"` on it or above it shrinks it), a text that does not fit its
|
|
3536
|
-
* box in some registered locale, an absolute element with no `reason`, a clipping element
|
|
3537
|
-
* (`scroll`, `overflow: "hidden"`) whose style names a nine-slice it never draws, a style that
|
|
3538
|
-
* is `hollow` with no nine-slice to hollow, and a root element whose style sets a `zIndex` it
|
|
3539
|
-
* ignores. Never throws; empty when nothing is mounted.
|
|
3540
|
-
*
|
|
3541
|
-
* @returns One finding per rule and element.
|
|
3542
|
-
* @example
|
|
3543
|
-
* ```ts
|
|
3544
|
-
* // A game test keeps the board honest on an iPhone SE: a 140 u cell in the 0.8 slot.
|
|
3545
|
-
* app.ui.lint(); // [{ rule: "tap-target", key: "cell", detail: "39 x 39 pt" }]
|
|
3546
|
-
* // A list styled with a nine-slice: the clip keeps it from drawing.
|
|
3547
|
-
* app.ui.lint(); // [{ rule: "nine-slice-clipped", key: "orders", detail: "scroll" }]
|
|
3548
|
-
* // A frame made hollow before its nine-slice was named: there is no rim to draw.
|
|
3549
|
-
* app.ui.lint(); // [{ rule: "hollow-without-nine-slice", key: "memFrost", detail: "stack" }]
|
|
3550
|
-
* // A screen root that asks to be drawn over the others: the layer decides that.
|
|
3551
|
-
* app.ui.lint(); // [{ rule: "z-index-on-root", key: "board", detail: "zIndex 2" }]
|
|
3552
|
-
* ```
|
|
3553
|
-
*/
|
|
3554
|
-
lint(): readonly Finding[];
|
|
3555
|
-
/**
|
|
3556
|
-
* Types into a text field the way a player does, for a headless test or an agent: the field
|
|
3557
|
-
* becomes the one being edited, `value` cut to its `maxLength` is written into it, and the
|
|
3558
|
-
* local field it names is written, so the component re-renders on the next frame. Nothing
|
|
3559
|
-
* reaches the gate: Enter submits.
|
|
3560
|
-
*
|
|
3561
|
-
* @param key - The `key` prop of the `input` element.
|
|
3562
|
-
* @param value - The text to type.
|
|
3563
|
-
* @returns True when the field took the text; false with one warning when no live `input` has
|
|
3564
|
-
* the key.
|
|
3565
|
-
* @example
|
|
3566
|
-
* ```ts
|
|
3567
|
-
* // A headless test renames the player through the Rename popup.
|
|
3568
|
-
* app.ui.fill("nameField", "Alex"); // true
|
|
3569
|
-
* app.time.step(16);
|
|
3570
|
-
* app.input.pressKey("Enter"); // true: the gate took { intent: "save", payload: { name: "Alex" } }
|
|
3571
|
-
* app.ui.fill("nothing", "Alex"); // false, with the warning "ui:fill-without-input"
|
|
3572
|
-
* ```
|
|
3573
|
-
*/
|
|
3574
|
-
fill(key: string, value: string): boolean;
|
|
3575
|
-
/**
|
|
3576
|
-
* Scrolls a `scroll` element to an offset from its start, at once: the offset is kept inside 0
|
|
3577
|
-
* to `max`, a fling or a glide stops, and `ScrollState` reads the new offset with
|
|
3578
|
-
* `moving: false`. A finger that holds the scroll goes on from there. Works headless, for a
|
|
3579
|
-
* test, an agent or a visual test (the `game.scroll` command, the step `{ scroll: { key, to } }`).
|
|
3580
|
-
*
|
|
3581
|
-
* @param key - The `key` prop of the `scroll` element.
|
|
3582
|
-
* @param to - How far from the start, in reference units. `NaN` leaves the scroll where it is.
|
|
3583
|
-
* @returns True when a live scroll took it. False in two cases, each with one warning `{ key }`:
|
|
3584
|
-
* `ui:scroll-without-scroll` when no live `scroll` has the key, and `ui:scroll-before-solve`
|
|
3585
|
-
* when the `scroll` came in this frame and its first solve has not placed it yet: call it
|
|
3586
|
-
* again after the frame.
|
|
3587
|
-
* @example
|
|
3588
|
-
* ```ts
|
|
3589
|
-
* // A test shows the order strip on its events: the strip is 306 u over a 696 u track.
|
|
3590
|
-
* app.ui.scroll("strip", 0); // true
|
|
3591
|
-
* app.world.ecs.get(app.ui.find("strip") ?? 0, ScrollState); // { offset: 0, max: 390, moving: false }
|
|
3592
|
-
* app.ui.scroll("strip", 999); // true: it stands on the end, offset 390
|
|
3593
|
-
* app.ui.scroll("nothing", 0); // false, with the warning "ui:scroll-without-scroll"
|
|
3594
|
-
* ```
|
|
3595
|
-
*/
|
|
3596
|
-
scroll(key: string, to: number): boolean;
|
|
3597
|
-
/**
|
|
3598
|
-
* Where a target is drawn, in screen reference units: the rect an `<anchor>` sits on. A ui
|
|
3599
|
-
* element's layout box, a nine-slice's panel, a shape's rectangle or a sprite's box, through its
|
|
3600
|
-
* root pose, so a fit, a slot, a scroll's offset and the motion of an ancestor move it; the
|
|
3601
|
-
* rotation is left out. A list gives the bounding rect of its shown targets. A target of no area
|
|
3602
|
-
* (an empty element, a width or a height of 0) answers its point, `{ x, y, w: 0, h: 0 }`. Not
|
|
3603
|
-
* shown: the key names no entity, or one leaving, built aside or drawn at alpha 0 (an image laid
|
|
3604
|
-
* out at no size is drawn at alpha 0), or a world sprite of no width or height, which the
|
|
3605
|
-
* renderer draws at its texture's size. Works in every build and headless; every call answers a
|
|
3606
|
-
* new object.
|
|
3607
|
-
*
|
|
3608
|
-
* @param target - A view or an element by projection and key, or a list of them.
|
|
3609
|
-
* @returns The rect, or `undefined` when no target is shown.
|
|
3610
|
-
* @example
|
|
3611
|
-
* ```ts
|
|
3612
|
-
* // The tutorial puts its hint beside the first seat of the board's order strip.
|
|
3613
|
-
* app.ui.rectOf({ projection: "board.strip", key: "seat0" }); // { x: 40, y: 1500, w: 116, h: 120 }
|
|
3614
|
-
* // The seat and the cell of the board fitted to 0.5: the rect around both.
|
|
3615
|
-
* app.ui.rectOf([
|
|
3616
|
-
* { projection: "board.strip", key: "seat0" },
|
|
3617
|
-
* { projection: "board.strip", key: "cell" }
|
|
3618
|
-
* ]); // { x: 40, y: 250, w: 680, h: 1370 }
|
|
3619
|
-
* app.ui.rectOf({ projection: "board.strip", key: "nowhere" }); // undefined
|
|
3620
|
-
* // An empty element of no area, the spot a card lands on: its point.
|
|
3621
|
-
* app.ui.rectOf({ projection: "point.board", key: "dot" }); // { x: 300, y: 400, w: 0, h: 0 }
|
|
3622
|
-
* ```
|
|
3623
|
-
*/
|
|
3624
|
-
rectOf(target: AnchorTarget | readonly AnchorTarget[]): Readonly<{
|
|
3625
|
-
x: number;
|
|
3626
|
-
y: number;
|
|
3627
|
-
w: number;
|
|
3628
|
-
h: number;
|
|
3629
|
-
}> | undefined;
|
|
3630
|
-
};
|
|
3631
|
-
//#endregion
|
|
3632
|
-
export { MotionKeyframe as $, ShadowValue as A, DisplacementValue as B, FoldValue as C, use as Ct, PixelateValue as D, MirrorValue as E, types_d_exports$4 as Et, EmitterDefinition as F, GlowValue as G, FilterComponent as H, EmitterValue as I, UniformDeclaration as J, NoiseValue as K, AlphaValue as L, VignetteValue as M, WaveValue as N, RevealLineValue as O, EmitterConfig as P, FramesValue as Q, BlurValue as R, FlashValue as S, tween as St, GradientMapValue as T, OverlayApi as Tt, FilterSpec as U, FilterArea as V, FilterValueOf as W, AnimPlayerValue as X, AnimApi as Y, Config$3 as Z, State$2 as _, sfx as _t, AudioApi as a, SfxDescriptor as at, BloomValue as b, stagger as bt, MusicDescriptor as c, defineAnimation as ct, State$1 as d, haptic as dt, State$3 as et, VolumesFor as f, mark as ft, EffectsStats as g, set as gt, EffectsApi as h, sequence as ht, types_d_exports as i, HapticKind as it, ShineValue as j, RevealRoundValue as k, MusicOptions as l, external as lt, Config$2 as m, play as mt, State as n, TimelinesSnapshot as nt, AudioContextLike as o, Step as ot, types_d_exports$1 as p, parallel as pt, OutlineValue as q, UiApi as r, types_d_exports$3 as rt, Config$1 as s, HAPTIC_KINDS as st, Config as t, Target as tt, SoundEntry as u, frames as ut, types_d_exports$2 as v, spawn as vt, GradeValue as w, wait as wt, DissolveValue as x, stopSfx as xt, AuraValue as y, spawned as yt, ColorMatrixValue as z };
|