@wasm-gaming/rsdkv4-wasm 0.1.4 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +242 -35
- package/dist/rsdkv4/rsdkv4.options.d.ts +355 -16
- package/dist/rsdkv4/rsdkv4.options.d.ts.map +1 -1
- package/dist/rsdkv4/rsdkv4.options.js +170 -31
- package/dist/rsdkv4/rsdkv4.options.js.map +1 -1
- package/dist/rsdkv4/rsdkv4.sdk.d.ts +229 -33
- package/dist/rsdkv4/rsdkv4.sdk.d.ts.map +1 -1
- package/dist/rsdkv4/rsdkv4.sdk.js +1015 -172
- package/dist/rsdkv4/rsdkv4.sdk.js.map +1 -1
- package/package.json +7 -12
- package/src/rsdkv4.options.ts +484 -46
- package/src/rsdkv4.sdk.ts +1282 -192
- package/dist/manifest.json +0 -75
- package/dist/rsdkv4/rsdkv4.js +0 -9268
- package/dist/rsdkv4/rsdkv4.manifest.d.ts +0 -4
- package/dist/rsdkv4/rsdkv4.manifest.d.ts.map +0 -1
- package/dist/rsdkv4/rsdkv4.manifest.js +0 -39
- package/dist/rsdkv4/rsdkv4.manifest.js.map +0 -1
- package/dist/rsdkv4/rsdkv4.wasm +0 -0
- package/src/rsdkv4.manifest.ts +0 -44
package/src/rsdkv4.options.ts
CHANGED
|
@@ -1,64 +1,502 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
1
|
+
/**
|
|
2
|
+
* What this engine's four payloads accept, and the {@link RSDKV4_SPEC} that describes
|
|
3
|
+
* them to a host.
|
|
4
|
+
*
|
|
5
|
+
* ```ts
|
|
6
|
+
* import type { Rsdkv4Config, Rsdkv4Options } from '@wasm-gaming/rsdkv4-wasm/options';
|
|
7
|
+
* ```
|
|
8
|
+
*
|
|
9
|
+
* The contract's own module documents *how* the four payloads behave — they read as
|
|
10
|
+
* descriptors and write as patches, and `live` says whether a key reaches a running
|
|
11
|
+
* engine. This module is only the part that is RSDKv4's: which keys exist, what they
|
|
12
|
+
* mean here, and what the engine does with them.
|
|
13
|
+
*
|
|
14
|
+
* The split between the first two is the whole design:
|
|
15
|
+
*
|
|
16
|
+
* - {@link Rsdkv4Config} is **the engine**. It is serialized into RSDKv4's
|
|
17
|
+
* `settings.ini` and read once, at boot — so none of it is `live`.
|
|
18
|
+
* - {@link Rsdkv4Options} is **the session**: which character, which save slot, which
|
|
19
|
+
* stage. That is what a `restart()` reopens. It also carries the engine's own GAME
|
|
20
|
+
* OPTIONS rows, which *are* `live` — and which are not declared here at all, because
|
|
21
|
+
* they differ between Sonic 1 and Sonic 2 and are only knowable once the pack is
|
|
22
|
+
* loaded.
|
|
23
|
+
*
|
|
24
|
+
* @module
|
|
25
|
+
*/
|
|
15
26
|
|
|
16
|
-
|
|
27
|
+
import type { EnginePayloads, EngineSpec } from '@wasm-gaming/engine-specs';
|
|
28
|
+
|
|
29
|
+
/** Bytes a host can hand over for an asset. */
|
|
30
|
+
export type Rsdkv4AssetData = Uint8Array | ArrayBuffer | ArrayBufferView | string;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* An asset, eagerly or on demand.
|
|
34
|
+
*
|
|
35
|
+
* The thunk form is what the old `dataProvider` / `settingsProvider` config fields
|
|
36
|
+
* were: `assets({ data: () => fetch(url).then((r) => r.arrayBuffer()) })`. See
|
|
37
|
+
* {@link Rsdkv4Assets} for when each one is actually called — they differ, and the
|
|
38
|
+
* difference is tens of megabytes.
|
|
39
|
+
*/
|
|
40
|
+
export type Rsdkv4Asset = Rsdkv4AssetData | (() => Rsdkv4AssetData | Promise<Rsdkv4AssetData>);
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* The engine, as `settings.ini` — read once at boot, which is why nothing here is
|
|
44
|
+
* `live`. Change any of it and the engine has to come back up: `destroy()` and a new
|
|
45
|
+
* factory, not `restart()`.
|
|
46
|
+
*
|
|
47
|
+
* Regenerated on every boot, and that is safe: RSDKv4's `writeSettings()` is inside
|
|
48
|
+
* `#ifndef __EMSCRIPTEN__`, so this build never writes the file back and there is
|
|
49
|
+
* nothing of the player's in it to overwrite. A host that wants its own file hands one
|
|
50
|
+
* over as `assets.settings` instead, and then this payload is ignored.
|
|
51
|
+
*/
|
|
52
|
+
export interface Rsdkv4Config {
|
|
53
|
+
/**
|
|
54
|
+
* VSync the engine's SDL window.
|
|
55
|
+
*
|
|
56
|
+
* @defaultValue `true`
|
|
57
|
+
*/
|
|
58
|
+
vsync?: boolean;
|
|
17
59
|
/**
|
|
18
|
-
* RSDKv4's native in-canvas Dev Menu.
|
|
19
|
-
*
|
|
60
|
+
* RSDKv4's native in-canvas Dev Menu. Off by default: a host that wants a
|
|
61
|
+
* debug/stage-select UI draws it from `play.devMenu`, and leaving this on has
|
|
20
62
|
* historically produced a native menu-like screen at boot.
|
|
63
|
+
*
|
|
64
|
+
* @defaultValue `false`
|
|
21
65
|
*/
|
|
22
66
|
devMenu?: boolean;
|
|
23
|
-
/**
|
|
67
|
+
/**
|
|
68
|
+
* RSDKv4 `EngineDebugMode`. In this build it gates the engine's log output and
|
|
69
|
+
* nothing else — `play.devMenu` and `play.game` are embind bridges the wasm installs
|
|
70
|
+
* unconditionally, so they work either way.
|
|
71
|
+
*
|
|
72
|
+
* @defaultValue `true`
|
|
73
|
+
*/
|
|
24
74
|
engineDebugMode?: boolean;
|
|
25
|
-
/**
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
75
|
+
/**
|
|
76
|
+
* Who draws the save-select / character-select / game-options screens.
|
|
77
|
+
*
|
|
78
|
+
* `'native'` leaves RSDKv4's own in-canvas Start Menu on. `'host'` skips it, for a
|
|
79
|
+
* host that renders those screens itself from `play.game` — otherwise the engine's
|
|
80
|
+
* menu runs underneath the host's.
|
|
81
|
+
*
|
|
82
|
+
* This is the old `skipStartMenu` boolean, the right way up: the inverted name meant
|
|
83
|
+
* `false` had to be read twice to mean "yes, show it".
|
|
84
|
+
*
|
|
85
|
+
* @defaultValue `'native'`
|
|
86
|
+
*/
|
|
87
|
+
startMenu?: 'native' | 'host';
|
|
88
|
+
/**
|
|
89
|
+
* Where to load the Emscripten glue from. Defaults to `./rsdkv4.js` next to the
|
|
90
|
+
* built SDK, which is where `make build` puts it.
|
|
91
|
+
*/
|
|
92
|
+
jsUrl?: string;
|
|
93
|
+
/** Where to load the wasm from. Defaults to `./rsdkv4.wasm` next to the built SDK. */
|
|
94
|
+
wasmUrl?: string;
|
|
33
95
|
}
|
|
34
96
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
97
|
+
/**
|
|
98
|
+
* A stage, as the engine's two-level stage list indexes it.
|
|
99
|
+
*
|
|
100
|
+
* `name` is **read-only**: the descriptors {@link Rsdkv4Options.stage} reports back
|
|
101
|
+
* carry one so a host can paint a stage picker straight from `options()`, but writing
|
|
102
|
+
* it is ignored — `category` and `scene` are what reach the engine.
|
|
103
|
+
*/
|
|
104
|
+
export interface Rsdkv4Stage {
|
|
105
|
+
/** 0-based category, as ordered by `play.devMenu.getStageList()`. */
|
|
106
|
+
category: number;
|
|
107
|
+
/** 0-based scene within the category. */
|
|
108
|
+
scene: number;
|
|
109
|
+
/** `"<Category> · <Scene>"`, filled in by the SDK. Ignored on write. */
|
|
110
|
+
name?: string;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* RSDKv4's fourteen buttons, in the engine's own `InputButtons` order.
|
|
115
|
+
*
|
|
116
|
+
* The order is not cosmetic: it is the bit order of the mask the SDK hands the
|
|
117
|
+
* engine once per tick, so this array is the wire format and not merely a list.
|
|
118
|
+
*
|
|
119
|
+
* Sonic 1 and Sonic 2 read only the four directions, A, B, C and start. The other
|
|
120
|
+
* six exist in the engine and are free for a host to do as it likes with.
|
|
121
|
+
*/
|
|
122
|
+
export const RSDKV4_BUTTONS = [
|
|
123
|
+
'up',
|
|
124
|
+
'down',
|
|
125
|
+
'left',
|
|
126
|
+
'right',
|
|
127
|
+
'a',
|
|
128
|
+
'b',
|
|
129
|
+
'c',
|
|
130
|
+
'x',
|
|
131
|
+
'y',
|
|
132
|
+
'z',
|
|
133
|
+
'l',
|
|
134
|
+
'r',
|
|
135
|
+
'start',
|
|
136
|
+
'select',
|
|
137
|
+
] as const;
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* One button, spelled as {@link RSDKV4_BUTTONS} spells it.
|
|
141
|
+
*
|
|
142
|
+
* Derived from the array rather than declared beside it, so there is one list and
|
|
143
|
+
* not two to drift apart — and so a typo in a `buttons` literal is a compile error
|
|
144
|
+
* rather than a button that silently never fires.
|
|
145
|
+
*/
|
|
146
|
+
export type Rsdkv4Button = (typeof RSDKV4_BUTTONS)[number];
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Every button as a boolean — what a host hands over to {@link Rsdkv4Options.buttons}
|
|
150
|
+
* and keeps writing to for as long as it holds the claim.
|
|
151
|
+
*
|
|
152
|
+
* All fourteen are required. A key that is merely absent reads as `false` on every
|
|
153
|
+
* tick, which is a dead button and no error anywhere; requiring the whole set is what
|
|
154
|
+
* turns that into something the compiler catches.
|
|
155
|
+
*/
|
|
156
|
+
export type Rsdkv4Buttons = Record<Rsdkv4Button, boolean>;
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* What the engine binds each button to by default, for a host that has taken input
|
|
160
|
+
* over and now has to bind them itself.
|
|
161
|
+
*
|
|
162
|
+
* Not engine configuration — nothing here is read by the engine, and writing to it
|
|
163
|
+
* changes nothing. It is a starting table, so a host that claims input can offer the
|
|
164
|
+
* bindings a player already knows instead of inventing its own.
|
|
165
|
+
*/
|
|
166
|
+
export interface Rsdkv4InputDefaults {
|
|
167
|
+
/** `KeyboardEvent.code` values, as `settings.ini`'s `[Keyboard 1]` binds them. */
|
|
168
|
+
keyboard: Record<Rsdkv4Button, string>;
|
|
169
|
+
/**
|
|
170
|
+
* Indices into `Gamepad.buttons` under the browser's **standard mapping**.
|
|
171
|
+
*
|
|
172
|
+
* These are translated, not copied: `settings.ini`'s `[Controller 1]` holds
|
|
173
|
+
* SDL's `SDL_CONTROLLER_BUTTON_*` values, and those are different numbers — SDL's
|
|
174
|
+
* left shoulder is 9, where the browser's is 4. A host polling the Gamepad API
|
|
175
|
+
* wants the browser's, so that is what this carries.
|
|
176
|
+
*
|
|
177
|
+
* `null` where the engine's default has no standard-mapping button: `select` is
|
|
178
|
+
* bound to SDL's GUIDE, which this build's own web-gamepad mapping never wires
|
|
179
|
+
* up, so it is dead on a pad in the engine too. `y` and `z` are the analog
|
|
180
|
+
* triggers (the engine reads them past a deadzone, as ZL/ZR).
|
|
181
|
+
*/
|
|
182
|
+
gamepad: Record<Rsdkv4Button, number | null>;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* The engine's own default bindings. See {@link Rsdkv4InputDefaults}.
|
|
187
|
+
*
|
|
188
|
+
* This replaces the old `RSDKV4_KEYMAP`, which nothing read and which was wrong in
|
|
189
|
+
* three ways for want of ever being checked against the engine: it listed 9 of the
|
|
190
|
+
* 14 buttons, and bound `select` to `ShiftLeft` where the engine's default is `Tab`.
|
|
191
|
+
*/
|
|
192
|
+
export const RSDKV4_INPUT: Rsdkv4InputDefaults = {
|
|
193
|
+
keyboard: {
|
|
194
|
+
up: 'ArrowUp',
|
|
195
|
+
down: 'ArrowDown',
|
|
196
|
+
left: 'ArrowLeft',
|
|
197
|
+
right: 'ArrowRight',
|
|
198
|
+
a: 'KeyZ',
|
|
199
|
+
b: 'KeyX',
|
|
200
|
+
c: 'KeyC',
|
|
201
|
+
x: 'KeyA',
|
|
202
|
+
y: 'KeyS',
|
|
203
|
+
z: 'KeyD',
|
|
204
|
+
l: 'KeyQ',
|
|
205
|
+
r: 'KeyE',
|
|
206
|
+
start: 'Enter',
|
|
207
|
+
select: 'Tab',
|
|
208
|
+
},
|
|
209
|
+
gamepad: {
|
|
210
|
+
up: 12,
|
|
211
|
+
down: 13,
|
|
212
|
+
left: 14,
|
|
213
|
+
right: 15,
|
|
214
|
+
a: 0,
|
|
215
|
+
b: 1,
|
|
216
|
+
c: 2,
|
|
217
|
+
x: 3,
|
|
218
|
+
y: 6,
|
|
219
|
+
z: 7,
|
|
220
|
+
l: 4,
|
|
221
|
+
r: 5,
|
|
222
|
+
start: 9,
|
|
223
|
+
select: null,
|
|
224
|
+
},
|
|
42
225
|
};
|
|
43
226
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
227
|
+
/**
|
|
228
|
+
* The session — what a `restart()` reopens.
|
|
229
|
+
*
|
|
230
|
+
* **Absence is the neutral value.** The old `RSDKV4_UNSET = 255` sentinel is gone:
|
|
231
|
+
* leaving a key out means "boot the way the engine normally would", and there is no
|
|
232
|
+
* longer a number that quietly means something else. (In particular `player: 0` used
|
|
233
|
+
* to be indistinguishable from "unset" in the ini, which is why it was a footgun.)
|
|
234
|
+
*
|
|
235
|
+
* The index signature is not laziness. The engine's GAME OPTIONS rows — spin dash,
|
|
236
|
+
* item-box set, and whatever else the loaded pack declares — are keys neither this
|
|
237
|
+
* package nor the host can know ahead of time. They come back from `options()` as
|
|
238
|
+
* descriptors with their own labels and choices, `live: true`, and are written back
|
|
239
|
+
* the same way. That is what lets a host paint a settings screen without knowing a
|
|
240
|
+
* single key name.
|
|
241
|
+
*/
|
|
242
|
+
export interface Rsdkv4Options {
|
|
243
|
+
/**
|
|
244
|
+
* The character to start a *new* game as, by the name the pack reports — the
|
|
245
|
+
* `enum` of this key's descriptor is exactly `play.game.players()`, so a host paints
|
|
246
|
+
* a character picker from it and writes one of the values straight back. Matched
|
|
247
|
+
* case-insensitively; an unknown name is an error rather than a silent Sonic.
|
|
248
|
+
*
|
|
249
|
+
* Continuing a slot that already has a save ignores this: the save carries its own
|
|
250
|
+
* character.
|
|
251
|
+
*/
|
|
252
|
+
player?: string;
|
|
253
|
+
/**
|
|
254
|
+
* Which of RSDKv4's four save slots (0-3) the session runs on. `null` plays without
|
|
255
|
+
* saving, as the native menu's NO SAVE does.
|
|
256
|
+
*
|
|
257
|
+
* A slot with data continues it; an empty slot starts a new game as {@link player}.
|
|
258
|
+
*/
|
|
259
|
+
slot?: number | null;
|
|
260
|
+
/**
|
|
261
|
+
* Jump straight to a stage, skipping wherever the session would otherwise open.
|
|
262
|
+
*
|
|
263
|
+
* Applied through the engine's own stage loader after boot, not through
|
|
264
|
+
* `settings.ini`'s `Starting*` trio — which is why it works on a `restart()` of a
|
|
265
|
+
* running engine and not only on the first one.
|
|
266
|
+
*/
|
|
267
|
+
stage?: Rsdkv4Stage;
|
|
268
|
+
/**
|
|
269
|
+
* Take input over: hand the engine a live object of fourteen booleans and it stops
|
|
270
|
+
* polling SDL, reading yours instead — touch buttons, rebinding, netplay, a test
|
|
271
|
+
* that drives a stage from a script.
|
|
272
|
+
*
|
|
273
|
+
* ```ts
|
|
274
|
+
* const buttons = { up: false, down: false, ...rest, select: false }; // all 14
|
|
275
|
+
* play.options({ buttons }); // claim
|
|
276
|
+
* play.options({ buttons: null }); // release — the engine polls SDL again
|
|
277
|
+
* ```
|
|
278
|
+
*
|
|
279
|
+
* **Read once per tick, from wherever it lives.** The engine calls in at the top of
|
|
280
|
+
* its input pass and the SDK reads the object at that moment, so a plain object and
|
|
281
|
+
* a reactive store both work and neither one needs the SDK to know which it is.
|
|
282
|
+
* Whatever is `true` when the engine asks is what the engine sees.
|
|
283
|
+
*
|
|
284
|
+
* Three things become the host's the moment it claims:
|
|
285
|
+
*
|
|
286
|
+
* - **Keyup on focus loss.** SDL resets its keyboard when the window loses focus; a
|
|
287
|
+
* host that owns input inherits that job (`blur`, `visibilitychange`) or a held
|
|
288
|
+
* arrow strands the player mid-run.
|
|
289
|
+
* - **The gamepad, entirely.** The engine stops polling it, so a host that wants one
|
|
290
|
+
* polls the Gamepad API itself — deadzones and the D-pad-from-axes fallback
|
|
291
|
+
* included. {@link RSDKV4_INPUT} is the table to start from.
|
|
292
|
+
* - **Releasing.** Absence means "leave the claim as it is"; only `null` releases.
|
|
293
|
+
* A component that claims and then unmounts without releasing leaves the engine
|
|
294
|
+
* pulling at an object nobody writes to any more.
|
|
295
|
+
*
|
|
296
|
+
* Not persistable, and not a settings row: it reads back from `options()` as `null`
|
|
297
|
+
* whether or not a claim is held, so that `JSON.stringify(await play.options())`
|
|
298
|
+
* cannot sweep fourteen transient booleans into a host's saved settings. Ask
|
|
299
|
+
* `play.input.claimed` for the claim state.
|
|
300
|
+
*
|
|
301
|
+
* `play.input.claim(buttons)` and `play.input.release()` are the same thing, named.
|
|
302
|
+
*/
|
|
303
|
+
buttons?: Rsdkv4Buttons | null;
|
|
304
|
+
/**
|
|
305
|
+
* The engine's GAME OPTIONS rows. See the note on the interface: these are declared
|
|
306
|
+
* by the loaded pack, not here.
|
|
307
|
+
*
|
|
308
|
+
* A `boolean` row reads and writes as a boolean, an enum row as one of its choice
|
|
309
|
+
* labels; the raw engine-side number is accepted on write too.
|
|
310
|
+
*/
|
|
311
|
+
[key: string]: unknown;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
/**
|
|
315
|
+
* The two files the engine reads out of its working directory.
|
|
316
|
+
*
|
|
317
|
+
* Neither is `live`: they are read while the engine comes up, so a patch after that
|
|
318
|
+
* lands in the state a *future* engine would boot from.
|
|
319
|
+
*/
|
|
320
|
+
export interface Rsdkv4Assets {
|
|
321
|
+
/**
|
|
322
|
+
* The `Data.rsdk` pack — the whole game, and what decides *which* game: one
|
|
323
|
+
* game-agnostic wasm runs both Sonic 1 and Sonic 2, the pack is the difference.
|
|
324
|
+
*
|
|
325
|
+
* Precedence, and the reason the thunk form exists: bytes handed over here win;
|
|
326
|
+
* otherwise a copy already persisted in this storage namespace is reused; only if
|
|
327
|
+
* there is neither is a thunk called. That is what keeps a host from re-fetching
|
|
328
|
+
* tens of megabytes it already has. With none of the three, `start()` fails.
|
|
329
|
+
*/
|
|
330
|
+
data?: Rsdkv4Asset;
|
|
331
|
+
/**
|
|
332
|
+
* A ready-made `settings.ini`, for a host that would rather write the file itself
|
|
333
|
+
* than describe it through {@link Rsdkv4Config}. Given one, the config payload is
|
|
334
|
+
* not serialized at all.
|
|
335
|
+
*
|
|
336
|
+
* Unlike `data`, a thunk here is called on **every** boot rather than only on a
|
|
337
|
+
* cache miss — the file is a few hundred bytes, and re-reading it is what makes the
|
|
338
|
+
* host's copy authoritative instead of whatever an earlier session left behind.
|
|
339
|
+
*/
|
|
340
|
+
settings?: Rsdkv4Asset;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
/** Where this engine's files live, and whether they outlive the page. */
|
|
344
|
+
export interface Rsdkv4Storage {
|
|
345
|
+
/**
|
|
346
|
+
* Per-game folder for the pack, the settings and the save file, so two games do not
|
|
347
|
+
* overwrite each other. Examples: `"sonic1"`, `"rsdkv4/Sonic2"`.
|
|
348
|
+
*
|
|
349
|
+
* It is a path under the engine's working root *and* the OPFS directory the SDK
|
|
350
|
+
* mirrors save data into, which is what lets a host read `<namespace>/SData.bin`
|
|
351
|
+
* itself. Anything that is not a usable relative path normalises to `"default"` —
|
|
352
|
+
* including the object you get from interpolating a game record by mistake.
|
|
353
|
+
*
|
|
354
|
+
* @defaultValue `"default"`
|
|
355
|
+
*/
|
|
356
|
+
namespace?: string;
|
|
357
|
+
/**
|
|
358
|
+
* What the engine's working directory is backed by.
|
|
359
|
+
*
|
|
360
|
+
* `'opfs'` forces a persistent mount and warns if it cannot have one; `null` means
|
|
361
|
+
* the host wants nothing kept, which switches off the save mirror as well; leaving
|
|
362
|
+
* it out picks OPFS when the page is cross-origin isolated.
|
|
363
|
+
*
|
|
364
|
+
* Worth knowing: on every build without Asyncify/JSPI — today's included — the mount
|
|
365
|
+
* itself cannot be OPFS, so the working dir is in-memory whatever this says. Saves
|
|
366
|
+
* survive anyway, because the SDK mirrors `SData.bin` into
|
|
367
|
+
* `<namespace>/` through the host-side OPFS API. `null` is what turns that off.
|
|
368
|
+
*/
|
|
369
|
+
persist?: 'opfs' | null;
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
/** One of RSDKv4's four save slots, as the engine's own save-select screen sees it. */
|
|
373
|
+
export interface RsdkSaveSlot {
|
|
374
|
+
/** 0-3. */
|
|
375
|
+
slot: number;
|
|
376
|
+
/** No game stored here — starting it means picking a character first. */
|
|
377
|
+
empty: boolean;
|
|
378
|
+
/** Character index into `play.game.players()`: 0 Sonic, 1 Tails, 2 Knuckles, 3 both. */
|
|
379
|
+
character: number;
|
|
380
|
+
lives: number;
|
|
381
|
+
score: number;
|
|
382
|
+
emeralds: number;
|
|
383
|
+
/** Stage list the save resumes into (1 regular, 3 special), or -1 when empty. */
|
|
384
|
+
list: number;
|
|
385
|
+
/** 0-based scene within `list` — index it against `play.devMenu.getStageList()`. */
|
|
386
|
+
zone: number;
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
/**
|
|
390
|
+
* What this engine announces on top of the contract's core set (`start`, `error`,
|
|
391
|
+
* `exit`, `pause`, `resume`).
|
|
392
|
+
*/
|
|
393
|
+
export interface Rsdkv4Events {
|
|
394
|
+
/**
|
|
395
|
+
* The save file changed, with every slot as it now stands.
|
|
396
|
+
*
|
|
397
|
+
* Emitted when the SDK has just written `<namespace>/SData.bin` out of the wasm and
|
|
398
|
+
* the bytes are not what they were — on its slow timer, on a pause, and on the way
|
|
399
|
+
* down. A host painting save slots subscribes to this instead of polling.
|
|
400
|
+
*/
|
|
401
|
+
saves: RsdkSaveSlot[];
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
/** The four payloads, closed — the single type parameter everything else takes. */
|
|
405
|
+
export interface Rsdkv4Payloads extends EnginePayloads {
|
|
406
|
+
config: Rsdkv4Config;
|
|
407
|
+
options: Rsdkv4Options;
|
|
408
|
+
assets: Rsdkv4Assets;
|
|
409
|
+
storage: Rsdkv4Storage;
|
|
410
|
+
events: Rsdkv4Events;
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
/**
|
|
414
|
+
* Everything the engine declares about its own properties, as data.
|
|
415
|
+
*
|
|
416
|
+
* `default` appears here and nowhere else: the contract's base class seeds the
|
|
417
|
+
* starting state from it, so there is no second table of defaults to drift out of
|
|
418
|
+
* agreement with this one — which is exactly what the old
|
|
419
|
+
* `DEFAULT_RSDKV4_OPTIONS`-alongside-a-JSON-Schema pair did.
|
|
420
|
+
*
|
|
421
|
+
* What is missing from `options` is deliberate: `player` and `stage` get their `enum`
|
|
422
|
+
* filled in from the loaded pack, and the GAME OPTIONS rows are added outright, when a
|
|
423
|
+
* running engine is asked to describe itself.
|
|
424
|
+
*/
|
|
425
|
+
export const RSDKV4_SPEC: EngineSpec<Rsdkv4Payloads> = {
|
|
426
|
+
config: {
|
|
427
|
+
vsync: { default: true, live: false, description: 'VSync the engine window.' },
|
|
48
428
|
devMenu: {
|
|
49
|
-
type: 'boolean',
|
|
50
429
|
default: false,
|
|
51
|
-
|
|
52
|
-
|
|
430
|
+
live: false,
|
|
431
|
+
description: "RSDKv4's native in-canvas Dev Menu. Hosts draw their own from play.devMenu.",
|
|
53
432
|
},
|
|
54
433
|
engineDebugMode: {
|
|
55
|
-
type: 'boolean',
|
|
56
434
|
default: true,
|
|
57
|
-
|
|
435
|
+
live: false,
|
|
436
|
+
description: "Gates the engine's log output. The embind bridges are installed either way.",
|
|
437
|
+
},
|
|
438
|
+
startMenu: {
|
|
439
|
+
default: 'native',
|
|
440
|
+
enum: ['native', 'host'],
|
|
441
|
+
live: false,
|
|
442
|
+
description:
|
|
443
|
+
"Who draws save/character/options: the engine's own menu, or the host from play.game.",
|
|
444
|
+
},
|
|
445
|
+
jsUrl: { live: false, description: 'Emscripten glue URL. Defaults to ./rsdkv4.js.' },
|
|
446
|
+
wasmUrl: { live: false, description: 'WASM URL. Defaults to ./rsdkv4.wasm.' },
|
|
447
|
+
},
|
|
448
|
+
options: {
|
|
449
|
+
// No `default` on any of the three: absence is what "boot normally" means here,
|
|
450
|
+
// and a default would take that away.
|
|
451
|
+
player: {
|
|
452
|
+
live: false,
|
|
453
|
+
description: 'Character for a new game, by name. Choices arrive once the pack is loaded.',
|
|
454
|
+
},
|
|
455
|
+
slot: {
|
|
456
|
+
enum: [null, 0, 1, 2, 3],
|
|
457
|
+
live: false,
|
|
458
|
+
description: 'Save slot 0-3, or null to play without saving.',
|
|
459
|
+
},
|
|
460
|
+
stage: {
|
|
461
|
+
live: false,
|
|
462
|
+
description: 'Jump straight to a stage. Choices arrive once the pack is loaded.',
|
|
463
|
+
},
|
|
464
|
+
// No `default`, for the same reason as the three above: absence is what "the
|
|
465
|
+
// engine polls SDL as usual" means, and only `null` is a release.
|
|
466
|
+
//
|
|
467
|
+
// `live` because it is the one option that reaches a running engine directly
|
|
468
|
+
// rather than through a restart — and the description says the rest out loud,
|
|
469
|
+
// because the contract has no flag for "transient, do not paint, do not
|
|
470
|
+
// persist" and a host reading descriptors to build a settings screen would
|
|
471
|
+
// otherwise put fourteen booleans on it.
|
|
472
|
+
buttons: {
|
|
473
|
+
live: true,
|
|
474
|
+
description:
|
|
475
|
+
'Host-driven input: a live object of 14 booleans the engine reads once per tick, or null to hand input back. Transient — not a settings row, not persistable, and it always reads back as null.',
|
|
476
|
+
},
|
|
477
|
+
},
|
|
478
|
+
assets: {
|
|
479
|
+
data: {
|
|
480
|
+
allowedTypes: ['.rsdk'],
|
|
481
|
+
live: false,
|
|
482
|
+
description: 'The RSDKv4 game data pack. Selects the game; required to start.',
|
|
483
|
+
},
|
|
484
|
+
settings: {
|
|
485
|
+
allowedTypes: ['.ini'],
|
|
486
|
+
live: false,
|
|
487
|
+
description: 'A ready-made settings.ini. Omitted, one is generated from config.',
|
|
488
|
+
},
|
|
489
|
+
},
|
|
490
|
+
storage: {
|
|
491
|
+
namespace: {
|
|
492
|
+
default: 'default',
|
|
493
|
+
live: false,
|
|
494
|
+
description: "Folder for this game's pack, settings and save file.",
|
|
495
|
+
},
|
|
496
|
+
persist: {
|
|
497
|
+
enum: ['opfs', null],
|
|
498
|
+
live: false,
|
|
499
|
+
description: "'opfs' forces persistence, null keeps nothing, absent auto-detects.",
|
|
58
500
|
},
|
|
59
|
-
vsync: { type: 'boolean', default: true },
|
|
60
|
-
startingCategory: { type: 'integer', minimum: 0, default: 0 },
|
|
61
|
-
startingScene: { type: 'integer', minimum: 0, default: 0 },
|
|
62
|
-
startingPlayer: { type: 'integer', minimum: 0, default: 0 },
|
|
63
501
|
},
|
|
64
502
|
};
|