@typeonce/ritmo-browser 0.10.0 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +83 -0
- package/README.md +6 -1
- package/dist/Controls.d.ts +495 -0
- package/dist/Controls.d.ts.map +1 -0
- package/dist/Controls.js +343 -0
- package/dist/Controls.js.map +1 -0
- package/dist/Gamepad.d.ts +375 -0
- package/dist/Gamepad.d.ts.map +1 -0
- package/dist/Gamepad.js +452 -0
- package/dist/Gamepad.js.map +1 -0
- package/dist/InputCapture.d.ts +46 -16
- package/dist/InputCapture.d.ts.map +1 -1
- package/dist/InputCapture.js +1 -1
- package/dist/InputCapture.js.map +1 -1
- package/dist/Keyboard.d.ts +184 -21
- package/dist/Keyboard.d.ts.map +1 -1
- package/dist/Keyboard.js +257 -91
- package/dist/Keyboard.js.map +1 -1
- package/dist/Pointer.d.ts +231 -62
- package/dist/Pointer.d.ts.map +1 -1
- package/dist/Pointer.js +205 -145
- package/dist/Pointer.js.map +1 -1
- package/dist/Touch.d.ts +73 -27
- package/dist/Touch.d.ts.map +1 -1
- package/dist/Touch.js +25 -30
- package/dist/Touch.js.map +1 -1
- package/dist/index.d.ts +10 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -1
- package/dist/index.js.map +1 -1
- package/dist/internal/buttons.d.ts +52 -0
- package/dist/internal/buttons.d.ts.map +1 -0
- package/dist/internal/buttons.js +211 -0
- package/dist/internal/buttons.js.map +1 -0
- package/dist/internal/introspect.d.ts +14 -0
- package/dist/internal/introspect.d.ts.map +1 -0
- package/dist/internal/introspect.js +19 -0
- package/dist/internal/introspect.js.map +1 -0
- package/dist/internal/used.d.ts +8 -0
- package/dist/internal/used.d.ts.map +1 -0
- package/dist/internal/used.js +14 -0
- package/dist/internal/used.js.map +1 -0
- package/dist/internal/vectors.d.ts +24 -0
- package/dist/internal/vectors.d.ts.map +1 -0
- package/dist/internal/vectors.js +22 -0
- package/dist/internal/vectors.js.map +1 -0
- package/package.json +4 -3
- package/src/Controls.ts +799 -0
- package/src/Gamepad.ts +747 -0
- package/src/InputCapture.ts +43 -24
- package/src/Keyboard.ts +395 -68
- package/src/Pointer.ts +392 -164
- package/src/Touch.ts +111 -54
- package/src/index.ts +10 -1
- package/src/internal/buttons.ts +222 -0
- package/src/internal/introspect.ts +23 -0
- package/src/internal/used.ts +14 -0
- package/src/internal/vectors.ts +36 -0
|
@@ -0,0 +1,375 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Gamepad input as caller-named actions, plus the sticks and triggers.
|
|
3
|
+
*
|
|
4
|
+
* Games bind actions to buttons once and read one snapshot per update, as
|
|
5
|
+
* with `Keyboard`. The module owns the plumbing every game rewrites: polling
|
|
6
|
+
* (the Gamepad API has no button events), press/release edges, a radial dead
|
|
7
|
+
* zone on the sticks, following the pad that was used last when several are
|
|
8
|
+
* connected, and releasing everything held when a pad disconnects. It does
|
|
9
|
+
* not know about the ECS; `InputCapture.system(...)` copies snapshots from a
|
|
10
|
+
* service into a resource.
|
|
11
|
+
*
|
|
12
|
+
* Buttons are named by their place in the browser's standard mapping
|
|
13
|
+
* (`"south"` is A on Xbox, Cross on PlayStation, B on Nintendo), so bindings
|
|
14
|
+
* stay the same on every pad. A pad whose `mapping` is not `"standard"` is
|
|
15
|
+
* read by the same indices, which may not match its labels: let players
|
|
16
|
+
* remap (`rebind`). The snapshot also reports every `button` by name,
|
|
17
|
+
* whatever the bindings, for fixed menu navigation and for a settings screen
|
|
18
|
+
* that waits for the button to bind; `parseRebinding(...)` validates
|
|
19
|
+
* bindings saved as JSON.
|
|
20
|
+
*
|
|
21
|
+
* The Gamepad API has no button events, so the pads are read on every
|
|
22
|
+
* animation frame and on every `snapshot()`; a tap that starts and ends
|
|
23
|
+
* between two updates still counts. Browsers expose a pad only after
|
|
24
|
+
* a button is pressed on it, and only in a secure context (HTTPS or
|
|
25
|
+
* localhost); elsewhere, or when a permission policy blocks the API, the
|
|
26
|
+
* live actions read no pad and report `connected: false`.
|
|
27
|
+
*
|
|
28
|
+
* `actions(...)` is one player on whichever pad is used. For local
|
|
29
|
+
* multiplayer, `pads(host, bindings, max)` reads every pad on its own for
|
|
30
|
+
* `Controls.players(...).pool(...)` (`scriptedPads(...)` in tests).
|
|
31
|
+
*
|
|
32
|
+
* @module Gamepad
|
|
33
|
+
* @docGroup browser
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```ts
|
|
37
|
+
* const pad = Gamepad.actions(window, {
|
|
38
|
+
* move: Gamepad.vector({ stick: "left", up: ["dpadUp"], down: ["dpadDown"], left: ["dpadLeft"], right: ["dpadRight"] }),
|
|
39
|
+
* attack: ["west"],
|
|
40
|
+
* pause: ["start"]
|
|
41
|
+
* })
|
|
42
|
+
*
|
|
43
|
+
* // Once per update:
|
|
44
|
+
* const snapshot = pad.snapshot()
|
|
45
|
+
* move(snapshot.vectors.move) // the stick's tilt, or the d-pad's direction
|
|
46
|
+
* if (snapshot.actions.attack.pressed) attack()
|
|
47
|
+
*
|
|
48
|
+
* // In a settings screen, rebinding keeps the action names:
|
|
49
|
+
* pad.rebind({ move: Gamepad.vector({ stick: "right" }), attack: ["north"], pause: ["start"] })
|
|
50
|
+
* ```
|
|
51
|
+
*
|
|
52
|
+
* For tests, replays, and headless runs, `scripted(...)` plays a timeline of
|
|
53
|
+
* button presses, releases, and stick moves instead of polling a host, and
|
|
54
|
+
* `recording(...)` wraps live actions to capture the timeline a session
|
|
55
|
+
* produced. `parseTimeline(...)` validates a timeline loaded from JSON.
|
|
56
|
+
*/
|
|
57
|
+
import type * as System from "@typeonce/ritmo/System";
|
|
58
|
+
import * as Result from "@typeonce/ritmo/Result";
|
|
59
|
+
import type * as BrowserTickSource from "./BrowserTickSource.ts";
|
|
60
|
+
import type { ActionState } from "./Keyboard.ts";
|
|
61
|
+
import * as ButtonsInternal from "./internal/buttons.ts";
|
|
62
|
+
/**
|
|
63
|
+
* The buttons of the browser's standard mapping, in index order: face
|
|
64
|
+
* buttons by compass position, bumpers and triggers, the two small center
|
|
65
|
+
* buttons, the stick clicks, the d-pad, and the home button.
|
|
66
|
+
*/
|
|
67
|
+
export declare const buttonNames: readonly ["south", "east", "west", "north", "leftBumper", "rightBumper", "leftTrigger", "rightTrigger", "select", "start", "leftStick", "rightStick", "dpadUp", "dpadDown", "dpadLeft", "dpadRight", "home"];
|
|
68
|
+
/** One button of the standard mapping, see {@link buttonNames}. */
|
|
69
|
+
export type Button = (typeof buttonNames)[number];
|
|
70
|
+
/** The buttons of one action: at least one. */
|
|
71
|
+
export type Buttons = readonly [Button, ...Array<Button>];
|
|
72
|
+
/** The two sticks a vector action can read. */
|
|
73
|
+
export type StickName = "left" | "right";
|
|
74
|
+
/**
|
|
75
|
+
* A vector action (movement) on the pad, built with {@link vector}: a
|
|
76
|
+
* stick, buttons for the four directions (the d-pad), or both.
|
|
77
|
+
*/
|
|
78
|
+
export interface VectorBinding {
|
|
79
|
+
readonly _tag: "Vector";
|
|
80
|
+
readonly stick?: StickName;
|
|
81
|
+
readonly up?: Buttons;
|
|
82
|
+
readonly down?: Buttons;
|
|
83
|
+
readonly left?: Buttons;
|
|
84
|
+
readonly right?: Buttons;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Action name to the buttons that trigger it (at least one), or to a
|
|
88
|
+
* {@link vector} binding for a direction such as movement.
|
|
89
|
+
*/
|
|
90
|
+
export type Bindings = Readonly<Record<string, Buttons | VectorBinding>>;
|
|
91
|
+
/** The bound button actions: the names bound to buttons. */
|
|
92
|
+
export type ButtonNames<B> = {
|
|
93
|
+
[K in keyof B]: B[K] extends VectorBinding ? never : K;
|
|
94
|
+
}[keyof B] & string;
|
|
95
|
+
/** The bound vector actions: the names bound with {@link vector}. */
|
|
96
|
+
export type VectorNames<B> = {
|
|
97
|
+
[K in keyof B]: B[K] extends VectorBinding ? K : never;
|
|
98
|
+
}[keyof B] & string;
|
|
99
|
+
/**
|
|
100
|
+
* Binds a vector action to a stick, to buttons for its four directions, or
|
|
101
|
+
* to both. The snapshot's `vectors` reports the longer of the two: the
|
|
102
|
+
* stick keeps its tilt (after the dead zone), and the buttons give length 1
|
|
103
|
+
* (a diagonal is not faster).
|
|
104
|
+
*
|
|
105
|
+
* @example
|
|
106
|
+
* ```ts
|
|
107
|
+
* const bindings = {
|
|
108
|
+
* move: Gamepad.vector({ stick: "left", up: ["dpadUp"], down: ["dpadDown"], left: ["dpadLeft"], right: ["dpadRight"] }),
|
|
109
|
+
* jump: ["south"]
|
|
110
|
+
* } as const
|
|
111
|
+
* ```
|
|
112
|
+
*/
|
|
113
|
+
export declare const vector: (binding: {
|
|
114
|
+
readonly stick: StickName;
|
|
115
|
+
} | {
|
|
116
|
+
readonly stick?: StickName;
|
|
117
|
+
readonly up: Buttons;
|
|
118
|
+
readonly down: Buttons;
|
|
119
|
+
readonly left: Buttons;
|
|
120
|
+
readonly right: Buttons;
|
|
121
|
+
}) => VectorBinding;
|
|
122
|
+
/**
|
|
123
|
+
* New buttons for the same actions, for {@link Actions.rebind}: buttons for
|
|
124
|
+
* a button action, a {@link vector} for a vector action. Load saved ones
|
|
125
|
+
* with {@link parseRebinding}.
|
|
126
|
+
*/
|
|
127
|
+
export type Rebinding<B extends Bindings> = {
|
|
128
|
+
readonly [Action in keyof B]: B[Action] extends VectorBinding ? VectorBinding : Buttons;
|
|
129
|
+
};
|
|
130
|
+
/** One button's reading, the subset of the browser's `GamepadButton` the module reads. */
|
|
131
|
+
export interface ButtonReading {
|
|
132
|
+
readonly pressed: boolean;
|
|
133
|
+
readonly value: number;
|
|
134
|
+
}
|
|
135
|
+
/** One pad's reading, the subset of the browser's `Gamepad` the module reads. */
|
|
136
|
+
export interface PadReading {
|
|
137
|
+
readonly id: string;
|
|
138
|
+
readonly index: number;
|
|
139
|
+
readonly connected: boolean;
|
|
140
|
+
readonly mapping: string;
|
|
141
|
+
readonly buttons: ReadonlyArray<ButtonReading>;
|
|
142
|
+
readonly axes: ReadonlyArray<number>;
|
|
143
|
+
}
|
|
144
|
+
/** Where pads are read from, the subset of the browser's `navigator` the module reads. */
|
|
145
|
+
export interface GamepadNavigator {
|
|
146
|
+
getGamepads(): ReadonlyArray<PadReading | null>;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* What live actions need from the window: the pads, and animation frames to
|
|
150
|
+
* read them on, since the Gamepad API has no button events.
|
|
151
|
+
*/
|
|
152
|
+
export interface GamepadHost extends BrowserTickSource.Host {
|
|
153
|
+
readonly navigator: GamepadNavigator;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* A direction and strength, length at most 1, `y` growing down as on
|
|
157
|
+
* screen: a stick's tilt (dead zone removed, zero at rest, 1 at full tilt)
|
|
158
|
+
* or a vector action's direction.
|
|
159
|
+
*/
|
|
160
|
+
export interface Vector {
|
|
161
|
+
readonly x: number;
|
|
162
|
+
readonly y: number;
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* The followed pad's state, with the same core as the other devices'
|
|
166
|
+
* snapshots (`actions`, `vectors`, and `used`) so `Controls` can merge it.
|
|
167
|
+
* With no pad everything is idle and `connected` is `false`.
|
|
168
|
+
*/
|
|
169
|
+
export interface Snapshot<B extends Bindings> {
|
|
170
|
+
/** Every bound button action's state. */
|
|
171
|
+
readonly actions: {
|
|
172
|
+
readonly [Action in ButtonNames<B>]: ActionState;
|
|
173
|
+
};
|
|
174
|
+
/** Each vector action's direction, length at most 1, `y` growing down. */
|
|
175
|
+
readonly vectors: {
|
|
176
|
+
readonly [Action in VectorNames<B>]: Vector;
|
|
177
|
+
};
|
|
178
|
+
/** Every button's state by name, whatever the bindings. */
|
|
179
|
+
readonly buttons: {
|
|
180
|
+
readonly [Name in Button]: ActionState;
|
|
181
|
+
};
|
|
182
|
+
/** The left stick's tilt, whatever the bindings. */
|
|
183
|
+
readonly left: Vector;
|
|
184
|
+
/** The right stick's tilt, whatever the bindings. */
|
|
185
|
+
readonly right: Vector;
|
|
186
|
+
/** How far the left trigger is pulled, 0 to 1. */
|
|
187
|
+
readonly leftTrigger: number;
|
|
188
|
+
/** How far the right trigger is pulled, 0 to 1. */
|
|
189
|
+
readonly rightTrigger: number;
|
|
190
|
+
/**
|
|
191
|
+
* Some button was pressed in this window or is held, or a stick is past
|
|
192
|
+
* the dead zone: the player is using the pad.
|
|
193
|
+
*/
|
|
194
|
+
readonly used: boolean;
|
|
195
|
+
/** Whether a pad is being followed. */
|
|
196
|
+
readonly connected: boolean;
|
|
197
|
+
/** The followed pad's `id` (it names the maker, for button labels), or `null`. */
|
|
198
|
+
readonly id: string | null;
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Rejects actions a rebinding names that the bindings do not have, so
|
|
202
|
+
* {@link Actions.rebind} takes exactly the actions it was made with.
|
|
203
|
+
*/
|
|
204
|
+
export type OnlyActionsOf<R, B extends Bindings> = {
|
|
205
|
+
readonly [Name in Exclude<keyof R, keyof B>]: `${Name & string} is not an action of these bindings`;
|
|
206
|
+
};
|
|
207
|
+
/**
|
|
208
|
+
* A pad bound to actions, built with {@link actions} (live), {@link scripted},
|
|
209
|
+
* or {@link recording}. Capture it with `InputCapture.system(...)`, or merge
|
|
210
|
+
* it with `Controls`.
|
|
211
|
+
*/
|
|
212
|
+
export interface Actions<B extends Bindings> extends System.Consumes<"snapshot"> {
|
|
213
|
+
/** Returns the input state and starts a new press/release window. */
|
|
214
|
+
snapshot(): Snapshot<B>;
|
|
215
|
+
/**
|
|
216
|
+
* Binds the same actions to new buttons, from the next snapshot, for a
|
|
217
|
+
* settings screen where players remap controls (capture the button to bind
|
|
218
|
+
* from the snapshot's `buttons`). An action held only through buttons it
|
|
219
|
+
* lost reports `released`. A button held across the rebind holds a newly
|
|
220
|
+
* bound action only once it is pressed again, so an action never turns
|
|
221
|
+
* held without a press. It takes exactly the actions the source was made
|
|
222
|
+
* with.
|
|
223
|
+
*/
|
|
224
|
+
rebind<const R extends Rebinding<B>>(bindings: R & OnlyActionsOf<R, B>): void;
|
|
225
|
+
/** Stops reading pads and cancels the animation frame. */
|
|
226
|
+
dispose(): void;
|
|
227
|
+
}
|
|
228
|
+
/** Options for {@link actions} and {@link pads}. */
|
|
229
|
+
export interface ActionsOptions {
|
|
230
|
+
/** Fraction of a stick's tilt that reads as zero. Defaults to 0.15. */
|
|
231
|
+
readonly deadZone?: number;
|
|
232
|
+
/** How far a trigger is pulled before it counts as held. Defaults to 0.5. */
|
|
233
|
+
readonly triggerThreshold?: number;
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* A snapshot with nothing held and no pad, for initializing an input
|
|
237
|
+
* resource before the first capture.
|
|
238
|
+
*/
|
|
239
|
+
export declare const idle: <const B extends Bindings>(bindings: B) => Snapshot<B>;
|
|
240
|
+
/**
|
|
241
|
+
* Starts reading pads from `host`, usually `window`, on every animation
|
|
242
|
+
* frame until `dispose()`. With several pads connected it follows the one
|
|
243
|
+
* used last; switching pads, or the followed pad disconnecting, releases
|
|
244
|
+
* everything it held. Use {@link pads} to give each pad its own player.
|
|
245
|
+
*/
|
|
246
|
+
export declare const actions: <const B extends Bindings>(host: GamepadHost, bindings: B, options?: ActionsOptions) => Actions<B>;
|
|
247
|
+
/**
|
|
248
|
+
* Every pad connected to the browser, each one on its own: what
|
|
249
|
+
* `Controls.players(...).pool(...)` hands to the player who joins with it.
|
|
250
|
+
* Use {@link actions} for one player, which follows whichever pad is used.
|
|
251
|
+
*/
|
|
252
|
+
export interface Pads<B extends Bindings> extends System.Consumes<"snapshot"> {
|
|
253
|
+
readonly _tag: "Pads";
|
|
254
|
+
/** The most pads read at once: their places in the list run from 0 to `max - 1`. */
|
|
255
|
+
readonly max: number;
|
|
256
|
+
/**
|
|
257
|
+
* One snapshot per pad seen so far, in the order they appeared, and
|
|
258
|
+
* starts a new press/release window on each. An unplugged pad stays in
|
|
259
|
+
* the list with `connected: false` and its last `id`, so a player keeps
|
|
260
|
+
* it until it comes back.
|
|
261
|
+
*/
|
|
262
|
+
snapshot(): ReadonlyArray<Snapshot<B>>;
|
|
263
|
+
/** Binds the same actions to new buttons on every pad, as {@link Actions.rebind}. */
|
|
264
|
+
rebind<const R extends Rebinding<B>>(bindings: R & OnlyActionsOf<R, B>): void;
|
|
265
|
+
/** Stops reading pads and cancels the animation frame. */
|
|
266
|
+
dispose(): void;
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* Starts reading every pad on `host`, usually `window`, up to `max` of
|
|
270
|
+
* them, each with its own presses and sticks; pads beyond `max` are
|
|
271
|
+
* ignored. A pad keeps its place in the list while unplugged; one that comes
|
|
272
|
+
* back at the same browser index continues it, and a different pad at that
|
|
273
|
+
* index takes the place over with nothing held.
|
|
274
|
+
*/
|
|
275
|
+
export declare const pads: <const B extends Bindings>(host: GamepadHost, bindings: B, max: number, options?: ActionsOptions) => Pads<B>;
|
|
276
|
+
/**
|
|
277
|
+
* Pads driven by timelines instead of a host, one timeline per pad (as
|
|
278
|
+
* {@link scripted}), each with the id `scripted <n>` (from `scripted 1`)
|
|
279
|
+
* and `max` the number of timelines: for tests of games where every player
|
|
280
|
+
* has a pad.
|
|
281
|
+
*/
|
|
282
|
+
export declare const scriptedPads: <const B extends Bindings>(bindings: B, timelines: ReadonlyArray<Timeline>) => Pads<B>;
|
|
283
|
+
/**
|
|
284
|
+
* Input changes applied just before one snapshot: the buttons, then the
|
|
285
|
+
* sticks and triggers, which keep their value until set again, then
|
|
286
|
+
* `connected`. `frame` is the snapshot's index, counting from 0 at the first
|
|
287
|
+
* `snapshot()` call. A button in both `press` and `release` changed twice
|
|
288
|
+
* within the frame: a tap shorter than a frame when it was up, a release and
|
|
289
|
+
* a new press when it was held.
|
|
290
|
+
*/
|
|
291
|
+
export interface TimelineEntry {
|
|
292
|
+
readonly frame: number;
|
|
293
|
+
/**
|
|
294
|
+
* Connects or disconnects the pad from this frame on. The first entry
|
|
295
|
+
* connects it unless it says otherwise. A disconnect releases every held
|
|
296
|
+
* button and zeroes the sticks and triggers, as with a live pad.
|
|
297
|
+
*/
|
|
298
|
+
readonly connected?: boolean;
|
|
299
|
+
readonly press?: ReadonlyArray<Button>;
|
|
300
|
+
readonly release?: ReadonlyArray<Button>;
|
|
301
|
+
readonly left?: Vector;
|
|
302
|
+
readonly right?: Vector;
|
|
303
|
+
readonly leftTrigger?: number;
|
|
304
|
+
readonly rightTrigger?: number;
|
|
305
|
+
}
|
|
306
|
+
/**
|
|
307
|
+
* Input changes by snapshot index. Plain data, so it round-trips through
|
|
308
|
+
* JSON; load it back with `parseTimeline`. It names buttons, not actions, so
|
|
309
|
+
* a replay follows the bindings as live play does.
|
|
310
|
+
*/
|
|
311
|
+
export type Timeline = ReadonlyArray<TimelineEntry>;
|
|
312
|
+
/** Actions driven by a timeline instead of a host. */
|
|
313
|
+
export interface Scripted<B extends Bindings> extends Actions<B> {
|
|
314
|
+
/** Number of snapshots taken so far, which is the next frame index. */
|
|
315
|
+
readonly frames: () => number;
|
|
316
|
+
}
|
|
317
|
+
/**
|
|
318
|
+
* Plays `timeline`: before the snapshot at index `frame`, every entry for
|
|
319
|
+
* that frame is applied. A pad counts as connected (with the id
|
|
320
|
+
* `"scripted"`) from the first entry on, until an entry says
|
|
321
|
+
* `connected: false`; `scripted(bindings, [])` is a pad that never connects.
|
|
322
|
+
* Buttons stay held from their press until their release; pressing a held
|
|
323
|
+
* button is not a new press.
|
|
324
|
+
*/
|
|
325
|
+
export declare const scripted: <const B extends Bindings>(bindings: B, timeline: Timeline) => Scripted<B>;
|
|
326
|
+
/** Live actions that also record the timeline they produce. */
|
|
327
|
+
export interface Recording<B extends Bindings> extends Actions<B> {
|
|
328
|
+
/** The recorded timeline; `scripted(bindings, timeline)` replays it exactly. */
|
|
329
|
+
readonly timeline: () => Timeline;
|
|
330
|
+
}
|
|
331
|
+
/**
|
|
332
|
+
* Wraps `actions` and records, for every snapshot, the buttons pressed and
|
|
333
|
+
* released since the previous one and the sticks and triggers that moved.
|
|
334
|
+
*/
|
|
335
|
+
export declare const recording: <B extends Bindings>(actions: Actions<B>) => Recording<B>;
|
|
336
|
+
/**
|
|
337
|
+
* Why loaded data is not a timeline. `path` points at the offending value,
|
|
338
|
+
* for example `[3].press[0]`.
|
|
339
|
+
*/
|
|
340
|
+
export interface InvalidTimeline {
|
|
341
|
+
readonly _tag: "InvalidTimeline";
|
|
342
|
+
readonly path: string;
|
|
343
|
+
readonly message: string;
|
|
344
|
+
}
|
|
345
|
+
/** Whether `name` is a button of the standard mapping, for validating stored bindings. */
|
|
346
|
+
export declare const isButton: (name: unknown) => name is Button;
|
|
347
|
+
/**
|
|
348
|
+
* Validates untrusted data, such as a parsed JSON file, as a timeline: an
|
|
349
|
+
* array of entries with a non-negative integer `frame`, optional
|
|
350
|
+
* `press`/`release` arrays of button names, optional `left`/`right` vectors
|
|
351
|
+
* of length at most 1, optional triggers from 0 to 1, and an optional
|
|
352
|
+
* boolean `connected`.
|
|
353
|
+
*/
|
|
354
|
+
export declare const parseTimeline: (data: unknown) => Result.Result<Timeline, InvalidTimeline>;
|
|
355
|
+
/**
|
|
356
|
+
* Why loaded data is not a rebinding for the bindings. `path` points at the
|
|
357
|
+
* offending value, for example `attack[1]`.
|
|
358
|
+
*/
|
|
359
|
+
export type InvalidRebinding = ButtonsInternal.InvalidRebinding;
|
|
360
|
+
/**
|
|
361
|
+
* Validates untrusted data, such as saved settings parsed from JSON, as new
|
|
362
|
+
* buttons for `bindings`: an object with exactly the same action names, each
|
|
363
|
+
* mapped to a non-empty array of button names (for a vector action, an
|
|
364
|
+
* object with an optional `stick` and buttons for all four directions or
|
|
365
|
+
* none, as `Gamepad.vector` saves). Pass the result to
|
|
366
|
+
* {@link Actions.rebind}; on failure, keep the defaults.
|
|
367
|
+
*
|
|
368
|
+
* @example
|
|
369
|
+
* ```ts
|
|
370
|
+
* const saved = Gamepad.parseRebinding(bindings, JSON.parse(stored))
|
|
371
|
+
* if (saved.ok) pad.rebind(saved.value)
|
|
372
|
+
* ```
|
|
373
|
+
*/
|
|
374
|
+
export declare const parseRebinding: <const B extends Bindings>(bindings: B, data: unknown) => Result.Result<Rebinding<B>, InvalidRebinding>;
|
|
375
|
+
//# sourceMappingURL=Gamepad.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Gamepad.d.ts","sourceRoot":"","sources":["../src/Gamepad.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuDG;AACH,OAAO,KAAK,KAAK,MAAM,MAAM,wBAAwB,CAAA;AACrD,OAAO,KAAK,MAAM,MAAM,wBAAwB,CAAA;AAEhD,OAAO,KAAK,KAAK,iBAAiB,MAAM,wBAAwB,CAAA;AAChE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAChD,OAAO,KAAK,eAAe,MAAM,uBAAuB,CAAA;AAKxD;;;;GAIG;AACH,eAAO,MAAM,WAAW,YACtB,OAAO,EACP,MAAM,EACN,MAAM,EACN,OAAO,EACP,YAAY,EACZ,aAAa,EACb,aAAa,EACb,cAAc,EACd,QAAQ,EACR,OAAO,EACP,WAAW,EACX,YAAY,EACZ,QAAQ,EACR,UAAU,EACV,UAAU,EACV,WAAW,EACX,MAAM,CACE,CAAA;AAEV,mEAAmE;AACnE,MAAM,MAAM,MAAM,GAAG,CAAC,OAAO,WAAW,CAAC,CAAC,MAAM,CAAC,CAAA;AAEjD,+CAA+C;AAC/C,MAAM,MAAM,OAAO,GAAG,SAAS,CAAC,MAAM,EAAE,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,CAAA;AAEzD,+CAA+C;AAC/C,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG,OAAO,CAAA;AAExC;;;GAGG;AACH,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAA;IACvB,QAAQ,CAAC,KAAK,CAAC,EAAE,SAAS,CAAA;IAC1B,QAAQ,CAAC,EAAE,CAAC,EAA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