@wasm-gaming/rsdkv4-wasm 0.1.5 → 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 +54 -0
- package/dist/rsdkv4/rsdkv4.options.d.ts +350 -23
- package/dist/rsdkv4/rsdkv4.options.d.ts.map +1 -1
- package/dist/rsdkv4/rsdkv4.options.js +164 -52
- package/dist/rsdkv4/rsdkv4.options.js.map +1 -1
- package/dist/rsdkv4/rsdkv4.sdk.d.ts +201 -64
- package/dist/rsdkv4/rsdkv4.sdk.d.ts.map +1 -1
- package/dist/rsdkv4/rsdkv4.sdk.js +950 -434
- package/dist/rsdkv4/rsdkv4.sdk.js.map +1 -1
- package/package.json +7 -12
- package/src/rsdkv4.options.ts +476 -73
- package/src/rsdkv4.sdk.ts +1164 -508
- package/dist/manifest.json +0 -94
- 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 -51
- package/dist/rsdkv4/rsdkv4.manifest.js.map +0 -1
- package/src/rsdkv4.manifest.ts +0 -57
|
@@ -1,67 +1,179 @@
|
|
|
1
|
-
// Engine-specific options for RSDKv4.
|
|
2
|
-
//
|
|
3
|
-
// This is the authoritative description of what `EngineConfig.options` accepts
|
|
4
|
-
// for this engine. It provides both:
|
|
5
|
-
// - `Rsdkv4Options` — the compile-time type (for TS hosts/launchers)
|
|
6
|
-
// - `RSDKV4_OPTIONS_SCHEMA` — the JSON Schema mirrored into manifest.json's
|
|
7
|
-
// `options` (for runtime host UI + validation)
|
|
8
|
-
// - `DEFAULT_RSDKV4_OPTIONS` — defaults the SDK falls back to.
|
|
9
|
-
//
|
|
10
|
-
// At runtime these options are serialized into RSDKv4's `settings.ini` (see the
|
|
11
|
-
// SDK's settings serializer) when the host does not pass an explicit `settings`
|
|
12
|
-
// asset.
|
|
13
1
|
/**
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
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
|
|
17
25
|
*/
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
26
|
+
/**
|
|
27
|
+
* RSDKv4's fourteen buttons, in the engine's own `InputButtons` order.
|
|
28
|
+
*
|
|
29
|
+
* The order is not cosmetic: it is the bit order of the mask the SDK hands the
|
|
30
|
+
* engine once per tick, so this array is the wire format and not merely a list.
|
|
31
|
+
*
|
|
32
|
+
* Sonic 1 and Sonic 2 read only the four directions, A, B, C and start. The other
|
|
33
|
+
* six exist in the engine and are free for a host to do as it likes with.
|
|
34
|
+
*/
|
|
35
|
+
export const RSDKV4_BUTTONS = [
|
|
36
|
+
'up',
|
|
37
|
+
'down',
|
|
38
|
+
'left',
|
|
39
|
+
'right',
|
|
40
|
+
'a',
|
|
41
|
+
'b',
|
|
42
|
+
'c',
|
|
43
|
+
'x',
|
|
44
|
+
'y',
|
|
45
|
+
'z',
|
|
46
|
+
'l',
|
|
47
|
+
'r',
|
|
48
|
+
'start',
|
|
49
|
+
'select',
|
|
50
|
+
];
|
|
51
|
+
/**
|
|
52
|
+
* The engine's own default bindings. See {@link Rsdkv4InputDefaults}.
|
|
53
|
+
*
|
|
54
|
+
* This replaces the old `RSDKV4_KEYMAP`, which nothing read and which was wrong in
|
|
55
|
+
* three ways for want of ever being checked against the engine: it listed 9 of the
|
|
56
|
+
* 14 buttons, and bound `select` to `ShiftLeft` where the engine's default is `Tab`.
|
|
57
|
+
*/
|
|
58
|
+
export const RSDKV4_INPUT = {
|
|
59
|
+
keyboard: {
|
|
60
|
+
up: 'ArrowUp',
|
|
61
|
+
down: 'ArrowDown',
|
|
62
|
+
left: 'ArrowLeft',
|
|
63
|
+
right: 'ArrowRight',
|
|
64
|
+
a: 'KeyZ',
|
|
65
|
+
b: 'KeyX',
|
|
66
|
+
c: 'KeyC',
|
|
67
|
+
x: 'KeyA',
|
|
68
|
+
y: 'KeyS',
|
|
69
|
+
z: 'KeyD',
|
|
70
|
+
l: 'KeyQ',
|
|
71
|
+
r: 'KeyE',
|
|
72
|
+
start: 'Enter',
|
|
73
|
+
select: 'Tab',
|
|
74
|
+
},
|
|
75
|
+
gamepad: {
|
|
76
|
+
up: 12,
|
|
77
|
+
down: 13,
|
|
78
|
+
left: 14,
|
|
79
|
+
right: 15,
|
|
80
|
+
a: 0,
|
|
81
|
+
b: 1,
|
|
82
|
+
c: 2,
|
|
83
|
+
x: 3,
|
|
84
|
+
y: 6,
|
|
85
|
+
z: 7,
|
|
86
|
+
l: 4,
|
|
87
|
+
r: 5,
|
|
88
|
+
start: 9,
|
|
89
|
+
select: null,
|
|
90
|
+
},
|
|
27
91
|
};
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
92
|
+
/**
|
|
93
|
+
* Everything the engine declares about its own properties, as data.
|
|
94
|
+
*
|
|
95
|
+
* `default` appears here and nowhere else: the contract's base class seeds the
|
|
96
|
+
* starting state from it, so there is no second table of defaults to drift out of
|
|
97
|
+
* agreement with this one — which is exactly what the old
|
|
98
|
+
* `DEFAULT_RSDKV4_OPTIONS`-alongside-a-JSON-Schema pair did.
|
|
99
|
+
*
|
|
100
|
+
* What is missing from `options` is deliberate: `player` and `stage` get their `enum`
|
|
101
|
+
* filled in from the loaded pack, and the GAME OPTIONS rows are added outright, when a
|
|
102
|
+
* running engine is asked to describe itself.
|
|
103
|
+
*/
|
|
104
|
+
export const RSDKV4_SPEC = {
|
|
105
|
+
config: {
|
|
106
|
+
vsync: { default: true, live: false, description: 'VSync the engine window.' },
|
|
32
107
|
devMenu: {
|
|
33
|
-
type: 'boolean',
|
|
34
108
|
default: false,
|
|
35
|
-
|
|
109
|
+
live: false,
|
|
110
|
+
description: "RSDKv4's native in-canvas Dev Menu. Hosts draw their own from play.devMenu.",
|
|
36
111
|
},
|
|
37
112
|
engineDebugMode: {
|
|
38
|
-
type: 'boolean',
|
|
39
113
|
default: true,
|
|
40
|
-
|
|
114
|
+
live: false,
|
|
115
|
+
description: "Gates the engine's log output. The embind bridges are installed either way.",
|
|
41
116
|
},
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
description: "
|
|
117
|
+
startMenu: {
|
|
118
|
+
default: 'native',
|
|
119
|
+
enum: ['native', 'host'],
|
|
120
|
+
live: false,
|
|
121
|
+
description: "Who draws save/character/options: the engine's own menu, or the host from play.game.",
|
|
47
122
|
},
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
123
|
+
jsUrl: { live: false, description: 'Emscripten glue URL. Defaults to ./rsdkv4.js.' },
|
|
124
|
+
wasmUrl: { live: false, description: 'WASM URL. Defaults to ./rsdkv4.wasm.' },
|
|
125
|
+
},
|
|
126
|
+
options: {
|
|
127
|
+
// No `default` on any of the three: absence is what "boot normally" means here,
|
|
128
|
+
// and a default would take that away.
|
|
129
|
+
player: {
|
|
130
|
+
live: false,
|
|
131
|
+
description: 'Character for a new game, by name. Choices arrive once the pack is loaded.',
|
|
132
|
+
},
|
|
133
|
+
slot: {
|
|
134
|
+
enum: [null, 0, 1, 2, 3],
|
|
135
|
+
live: false,
|
|
136
|
+
description: 'Save slot 0-3, or null to play without saving.',
|
|
137
|
+
},
|
|
138
|
+
stage: {
|
|
139
|
+
live: false,
|
|
140
|
+
description: 'Jump straight to a stage. Choices arrive once the pack is loaded.',
|
|
141
|
+
},
|
|
142
|
+
// No `default`, for the same reason as the three above: absence is what "the
|
|
143
|
+
// engine polls SDL as usual" means, and only `null` is a release.
|
|
144
|
+
//
|
|
145
|
+
// `live` because it is the one option that reaches a running engine directly
|
|
146
|
+
// rather than through a restart — and the description says the rest out loud,
|
|
147
|
+
// because the contract has no flag for "transient, do not paint, do not
|
|
148
|
+
// persist" and a host reading descriptors to build a settings screen would
|
|
149
|
+
// otherwise put fourteen booleans on it.
|
|
150
|
+
buttons: {
|
|
151
|
+
live: true,
|
|
152
|
+
description: '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.',
|
|
53
153
|
},
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
154
|
+
},
|
|
155
|
+
assets: {
|
|
156
|
+
data: {
|
|
157
|
+
allowedTypes: ['.rsdk'],
|
|
158
|
+
live: false,
|
|
159
|
+
description: 'The RSDKv4 game data pack. Selects the game; required to start.',
|
|
160
|
+
},
|
|
161
|
+
settings: {
|
|
162
|
+
allowedTypes: ['.ini'],
|
|
163
|
+
live: false,
|
|
164
|
+
description: 'A ready-made settings.ini. Omitted, one is generated from config.',
|
|
165
|
+
},
|
|
166
|
+
},
|
|
167
|
+
storage: {
|
|
168
|
+
namespace: {
|
|
169
|
+
default: 'default',
|
|
170
|
+
live: false,
|
|
171
|
+
description: "Folder for this game's pack, settings and save file.",
|
|
59
172
|
},
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
description: 'Player/character index; 255 = unset (normal boot flow).',
|
|
173
|
+
persist: {
|
|
174
|
+
enum: ['opfs', null],
|
|
175
|
+
live: false,
|
|
176
|
+
description: "'opfs' forces persistence, null keeps nothing, absent auto-detects.",
|
|
65
177
|
},
|
|
66
178
|
},
|
|
67
179
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rsdkv4.options.js","sourceRoot":"","sources":["../../src/rsdkv4.options.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"rsdkv4.options.js","sourceRoot":"","sources":["../../src/rsdkv4.options.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAwFH;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,IAAI;IACJ,MAAM;IACN,MAAM;IACN,OAAO;IACP,GAAG;IACH,GAAG;IACH,GAAG;IACH,GAAG;IACH,GAAG;IACH,GAAG;IACH,GAAG;IACH,GAAG;IACH,OAAO;IACP,QAAQ;CACA,CAAC;AAgDX;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,YAAY,GAAwB;IAC/C,QAAQ,EAAE;QACR,EAAE,EAAE,SAAS;QACb,IAAI,EAAE,WAAW;QACjB,IAAI,EAAE,WAAW;QACjB,KAAK,EAAE,YAAY;QACnB,CAAC,EAAE,MAAM;QACT,CAAC,EAAE,MAAM;QACT,CAAC,EAAE,MAAM;QACT,CAAC,EAAE,MAAM;QACT,CAAC,EAAE,MAAM;QACT,CAAC,EAAE,MAAM;QACT,CAAC,EAAE,MAAM;QACT,CAAC,EAAE,MAAM;QACT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AAC,IAAI,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;YACxB,IAAI,EAAE,KAAK;YACX,WAAW,EAAE,gDAAgD;SAC9D;QACD,KAAK,EAAE;YACL,IAAI,EAAE,KAAK;YACX,WAAW,EAAE,mEAAmE;SACjF;QACD,6EAA6E;QAC7E,kEAAkE;QAClE,EAAE;QACF,6EAA6E;QAC7E,8EAA8E;QAC9E,wEAAwE;QACxE,2EAA2E;QAC3E,yCAAyC;QACzC,OAAO,EAAE;YACP,IAAI,EAAE,IAAI;YACV,WAAW,EACT,gMAAgM;SACnM;KACF;IACD,MAAM,EAAE;QACN,IAAI,EAAE;YACJ,YAAY,EAAE,CAAC,OAAO,CAAC;YACvB,IAAI,EAAE,KAAK;YACX,WAAW,EAAE,iEAAiE;SAC/E;QACD,QAAQ,EAAE;YACR,YAAY,EAAE,CAAC,MAAM,CAAC;YACtB,IAAI,EAAE,KAAK;YACX,WAAW,EAAE,mEAAmE;SACjF;KACF;IACD,OAAO,EAAE;QACP,SAAS,EAAE;YACT,OAAO,EAAE,SAAS;YAClB,IAAI,EAAE,KAAK;YACX,WAAW,EAAE,sDAAsD;SACpE;QACD,OAAO,EAAE;YACP,IAAI,EAAE,CAAC,MAAM,EAAE,IAAI,CAAC;YACpB,IAAI,EAAE,KAAK;YACX,WAAW,EAAE,qEAAqE;SACnF;KACF;CACF,CAAC"}
|
|
@@ -1,7 +1,60 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
/**
|
|
2
|
+
* The engine package's entry point: an `EngineSDK` for RSDKv4.
|
|
3
|
+
*
|
|
4
|
+
* ```ts
|
|
5
|
+
* import Rsdkv4SDK from '@wasm-gaming/rsdkv4-wasm';
|
|
6
|
+
*
|
|
7
|
+
* const play = await new Rsdkv4SDK()
|
|
8
|
+
* .mount(document.querySelector('#stage'))
|
|
9
|
+
* .assets({ data: () => library.readBytes('Sonic2') })
|
|
10
|
+
* .storage({ namespace: 'rsdkv4/Sonic2' })
|
|
11
|
+
* .config({ startMenu: 'host' })
|
|
12
|
+
* .on('saves', ({ detail }) => paintSlots(detail))
|
|
13
|
+
* .start({ slot: 0 });
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* Everything a host drives is the contract's, and documented there: the four payloads
|
|
17
|
+
* with their descriptors, `mount`, `on`/`off`, `start`, `restart`, `destroy`. What is
|
|
18
|
+
* this engine's own lives in two places — {@link Rsdkv4Config} and friends, which say
|
|
19
|
+
* what the payloads accept *here*, and the extra members of {@link Rsdkv4Play} below:
|
|
20
|
+
* {@link Rsdkv4Play.game} and {@link Rsdkv4Play.devMenu}, for a host that draws
|
|
21
|
+
* RSDKv4's start screens itself, owner-aware {@link Rsdkv4Play.pause}, and
|
|
22
|
+
* {@link Rsdkv4Play.input}, for a host that would rather drive the buttons than let
|
|
23
|
+
* the engine read the keyboard.
|
|
24
|
+
*
|
|
25
|
+
* One game-agnostic `rsdkv4.wasm` runs both Sonic 1 and Sonic 2 — the difference is
|
|
26
|
+
* only which `Data.rsdk` the host hands over in `assets.data`, written into the
|
|
27
|
+
* filesystem at runtime (not baked with `--preload-file`).
|
|
28
|
+
*
|
|
29
|
+
* Filesystem: built with `-sWASMFS`. The working dir is mounted on **OPFS** when the
|
|
30
|
+
* page is cross-origin isolated *and* the build can create the OPFS backend from the
|
|
31
|
+
* main thread (an Asyncify/JSPI build — today's is not, see `WebFS.cpp`); otherwise it
|
|
32
|
+
* falls back to the WASMFS in-memory backend, which boots fine but forgets everything.
|
|
33
|
+
* That fallback is why the SDK mirrors `SData.bin` into OPFS itself: see
|
|
34
|
+
* {@link Rsdkv4Storage.persist}.
|
|
35
|
+
*
|
|
36
|
+
* @module
|
|
37
|
+
* @see [The engine contract](https://wasm-gaming.github.io/engine-specs/api-docs/)
|
|
38
|
+
*/
|
|
39
|
+
import { EnginePlayBase, EngineSDKBase, EventEmitter } from '@wasm-gaming/engine-specs';
|
|
40
|
+
import type { EngineInit, EngineSDKConstructor, EventsOf, PayloadKind, PromisePlay, PropertiesDefinition } from '@wasm-gaming/engine-specs';
|
|
41
|
+
import { type Rsdkv4Buttons, type Rsdkv4Options, type Rsdkv4Payloads, type RsdkSaveSlot } from './rsdkv4.options.js';
|
|
42
|
+
export type { Rsdkv4Asset, Rsdkv4AssetData, Rsdkv4Assets, Rsdkv4Button, Rsdkv4Buttons, Rsdkv4Config, Rsdkv4Events, Rsdkv4InputDefaults, Rsdkv4Options, Rsdkv4Payloads, Rsdkv4Stage, Rsdkv4Storage, RsdkSaveSlot, } from './rsdkv4.options.js';
|
|
43
|
+
export { RSDKV4_BUTTONS, RSDKV4_INPUT, RSDKV4_SPEC } from './rsdkv4.options.js';
|
|
44
|
+
/** The core events unioned with this engine's own — what `on`/`off` accept. */
|
|
45
|
+
export type Rsdkv4Events_ = EventsOf<Rsdkv4Payloads>;
|
|
46
|
+
/**
|
|
47
|
+
* The picture's native size, which is what the SDK scales to fit its mount.
|
|
48
|
+
*
|
|
49
|
+
* A module constant rather than a manifest field: `EngineManifest` left the contract
|
|
50
|
+
* in 0.3.0, and this was one of only two things the SDK ever read back out of it.
|
|
51
|
+
*/
|
|
52
|
+
export declare const RSDKV4_VIDEO: {
|
|
53
|
+
readonly baseWidth: 424;
|
|
54
|
+
readonly baseHeight: 240;
|
|
55
|
+
readonly aspect: "16:9";
|
|
56
|
+
};
|
|
57
|
+
/** RSDKv4-specific bridge for a host's debug/stage-select UI. */
|
|
5
58
|
export interface RsdkDevMenuBridge {
|
|
6
59
|
getStageList(): Array<{
|
|
7
60
|
name: string;
|
|
@@ -12,23 +65,14 @@ export interface RsdkDevMenuBridge {
|
|
|
12
65
|
loadStage(categoryIdx: number, stageIdx: number): void;
|
|
13
66
|
setPaused(paused: boolean): void;
|
|
14
67
|
}
|
|
15
|
-
/**
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
lives: number;
|
|
24
|
-
score: number;
|
|
25
|
-
emeralds: number;
|
|
26
|
-
/** Stage list the save resumes into (1 regular, 3 special), or -1 when empty. */
|
|
27
|
-
list: number;
|
|
28
|
-
/** 0-based scene within `list` — index it against `devMenu.getStageList()`. */
|
|
29
|
-
zone: number;
|
|
30
|
-
}
|
|
31
|
-
/** A row of the engine's GAME OPTIONS screen (differs between Sonic 1 and 2). */
|
|
68
|
+
/**
|
|
69
|
+
* A row of the engine's GAME OPTIONS screen (differs between Sonic 1 and 2), as the
|
|
70
|
+
* engine reports it — with `value` as the raw number it stores.
|
|
71
|
+
*
|
|
72
|
+
* The same rows also come back through `play.options()` as descriptors, where a
|
|
73
|
+
* boolean row reads as a boolean and an enum row as one of its choice labels. This is
|
|
74
|
+
* the untranslated view, for a host that wants it.
|
|
75
|
+
*/
|
|
32
76
|
export interface RsdkGameOption {
|
|
33
77
|
key: string;
|
|
34
78
|
label: string;
|
|
@@ -39,8 +83,8 @@ export interface RsdkGameOption {
|
|
|
39
83
|
}
|
|
40
84
|
/**
|
|
41
85
|
* The engine's Start Menu as data, so a host can render save-slot / character /
|
|
42
|
-
* game-option screens itself. Everything here mirrors what RSDKv4's own in-canvas
|
|
43
|
-
*
|
|
86
|
+
* game-option screens itself. Everything here mirrors what RSDKv4's own in-canvas menu
|
|
87
|
+
* does — see WebGame.cpp.
|
|
44
88
|
*/
|
|
45
89
|
export interface RsdkGameBridge {
|
|
46
90
|
/** 1 = Sonic 1, 2 = Sonic 2, 0 = unrecognised pack. */
|
|
@@ -49,9 +93,12 @@ export interface RsdkGameBridge {
|
|
|
49
93
|
players(): string[];
|
|
50
94
|
saveSlots(): RsdkSaveSlot[];
|
|
51
95
|
/**
|
|
52
|
-
* Start a game the way the native menu would: a slot with data continues it,
|
|
53
|
-
*
|
|
54
|
-
*
|
|
96
|
+
* Start a game the way the native menu would: a slot with data continues it, an
|
|
97
|
+
* empty slot starts a new game as `player`, and `slot: null` plays without saving.
|
|
98
|
+
* Resumes the engine if the SDK had it paused.
|
|
99
|
+
*
|
|
100
|
+
* This is the index-taking form. `play.restart({ slot, player })` is the same thing
|
|
101
|
+
* through the contract, with the character named rather than numbered.
|
|
55
102
|
*/
|
|
56
103
|
start(slot: number | null, player?: number): void;
|
|
57
104
|
/** Wipe a slot back to "NEW GAME". */
|
|
@@ -60,48 +107,138 @@ export interface RsdkGameBridge {
|
|
|
60
107
|
/** Set an option; written through to the engine and its save file, as the engine does. */
|
|
61
108
|
setOption(key: string, value: number): void;
|
|
62
109
|
}
|
|
63
|
-
|
|
110
|
+
/**
|
|
111
|
+
* Input ownership, named — the same thing as `options({ buttons })` and
|
|
112
|
+
* `options({ buttons: null })`, for a host that would rather say what it means.
|
|
113
|
+
*
|
|
114
|
+
* See {@link Rsdkv4Options.buttons} for what a claim costs the host: keyup on focus
|
|
115
|
+
* loss, the gamepad, and remembering to release.
|
|
116
|
+
*/
|
|
117
|
+
export interface RsdkInputBridge {
|
|
64
118
|
/**
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
*
|
|
119
|
+
* Take input over. The object is kept by reference and read once per tick — write
|
|
120
|
+
* to it, do not replace it.
|
|
121
|
+
*
|
|
122
|
+
* All fourteen keys of {@link Rsdkv4Buttons} must be present and nothing else may
|
|
123
|
+
* be: a missing key would read `false` for ever, and a misspelled one would be
|
|
124
|
+
* written to and never read. Both throw here instead.
|
|
69
125
|
*/
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
126
|
+
claim(buttons: Rsdkv4Buttons): PromisePlay<Rsdkv4Payloads>;
|
|
127
|
+
/** Hand input back; the engine polls SDL again from the next tick. */
|
|
128
|
+
release(): PromisePlay<Rsdkv4Payloads>;
|
|
129
|
+
/** Whether a claim is held. The `options()` descriptor deliberately will not say. */
|
|
130
|
+
readonly claimed: boolean;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* What `start()` and `restart()` hand back: the contract's chainable promise, narrowed
|
|
134
|
+
* so that awaiting it gives this engine's {@link Rsdkv4Play} rather than the contract's
|
|
135
|
+
* `EnginePlay` — which is what puts {@link Rsdkv4Play.game} within reach without a cast.
|
|
136
|
+
*
|
|
137
|
+
* Chaining (`.mount(…)`, `.options(…)`) returns the contract's own `PromisePlay`, so
|
|
138
|
+
* put the `await` at the end of the chain to keep the narrowing.
|
|
139
|
+
*/
|
|
140
|
+
export interface Rsdkv4Session extends PromisePlay<Rsdkv4Payloads> {
|
|
141
|
+
then<TResult1 = Rsdkv4Play, TResult2 = never>(onfulfilled?: ((value: Rsdkv4Play) => TResult1 | PromiseLike<TResult1>) | null, onrejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | null): Promise<TResult1 | TResult2>;
|
|
142
|
+
}
|
|
84
143
|
/**
|
|
85
|
-
*
|
|
86
|
-
*
|
|
87
|
-
*
|
|
144
|
+
* The running engine.
|
|
145
|
+
*
|
|
146
|
+
* Most of it is the contract's, inherited: the four getter/setter pairs, the cumulative
|
|
147
|
+
* merge, the chainable promise, the event channel, and `destroy()`. What this class
|
|
148
|
+
* adds is the four hooks the base leaves to an engine — {@link open}, {@link close},
|
|
149
|
+
* {@link mounted}, {@link patched} — plus the members below, which have no contract
|
|
150
|
+
* equivalent and exist because RSDKv4 has a start menu worth drawing from HTML.
|
|
88
151
|
*/
|
|
89
|
-
export
|
|
90
|
-
|
|
91
|
-
|
|
152
|
+
export declare class Rsdkv4Play extends EnginePlayBase<Rsdkv4Payloads> {
|
|
153
|
+
#private;
|
|
154
|
+
constructor(init?: EngineInit<Rsdkv4Payloads>, events?: EventEmitter<Rsdkv4Events_>);
|
|
92
155
|
/**
|
|
93
|
-
*
|
|
94
|
-
*
|
|
156
|
+
* Open or reopen a session. The first call brings the wasm up; every call after that
|
|
157
|
+
* reuses it, because RSDKv4 cannot power-cycle in process and does not need to — a
|
|
158
|
+
* session is a save slot, a character and a stage, and all three are reachable on a
|
|
159
|
+
* running engine.
|
|
95
160
|
*/
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
161
|
+
protected open(options: Rsdkv4Options): Promise<void>;
|
|
162
|
+
/**
|
|
163
|
+
* Stop and release. The base emits `exit` once this resolves.
|
|
164
|
+
*
|
|
165
|
+
* There is no coming back: RSDKv4 cannot be restarted in process, so a later
|
|
166
|
+
* `start()` on the same factory reports that rather than quietly doing nothing.
|
|
167
|
+
*/
|
|
168
|
+
protected close(): Promise<void>;
|
|
169
|
+
/**
|
|
170
|
+
* Where the picture goes. Called by the base before the first `open()`, which is what
|
|
171
|
+
* guarantees the canvas exists before Emscripten's SDL2 port goes looking for it.
|
|
172
|
+
*
|
|
173
|
+
* Hand over a `<canvas>` and it is used as-is, untouched apart from the id SDL needs;
|
|
174
|
+
* hand over any other element and the SDK creates a canvas inside it and keeps it
|
|
175
|
+
* scaled to fit. Reparenting a live engine is legal — the same canvas moves.
|
|
176
|
+
*/
|
|
177
|
+
protected mounted(target: HTMLElement): Promise<void>;
|
|
178
|
+
/**
|
|
179
|
+
* A payload changed on a running engine. Only the GAME OPTIONS rows are `live` here —
|
|
180
|
+
* `config` is `settings.ini`, read once at boot, and `player`/`slot`/`stage` are what
|
|
181
|
+
* a `restart()` is for.
|
|
182
|
+
*/
|
|
183
|
+
protected patched(kind: PayloadKind, patch: object): Promise<void>;
|
|
184
|
+
/**
|
|
185
|
+
* The session's descriptors, enriched with what only a loaded pack can say: the
|
|
186
|
+
* playable characters, the stage list, and the engine's own GAME OPTIONS rows.
|
|
187
|
+
*
|
|
188
|
+
* The base builds descriptors from a spec fixed at construction, which is right for
|
|
189
|
+
* every other payload and cannot work for this one — Sonic 1 and Sonic 2 do not offer
|
|
190
|
+
* the same characters or the same options, and neither is knowable before
|
|
191
|
+
* `Data.rsdk` is read. Before the engine is up this answers the static spec, which is
|
|
192
|
+
* still enough for a host to know the keys exist.
|
|
193
|
+
*/
|
|
194
|
+
options(): Promise<PropertiesDefinition<Rsdkv4Options>>;
|
|
195
|
+
options(patch: Partial<Rsdkv4Options>): PromisePlay<Rsdkv4Payloads>;
|
|
196
|
+
restart(options?: Partial<Rsdkv4Options>): Rsdkv4Session;
|
|
197
|
+
/**
|
|
198
|
+
* Pause, on behalf of `owner`. The first caller to pause owns it and only that
|
|
199
|
+
* owner's `resume()` lifts it, so a pause overlay cannot resume a game a start
|
|
200
|
+
* screen — or the host — had already frozen. Audio stops with the engine.
|
|
201
|
+
*
|
|
202
|
+
* Emits the contract's `pause` event, whose detail carries the owner.
|
|
203
|
+
*/
|
|
204
|
+
pause(owner?: string): void;
|
|
205
|
+
resume(owner?: string): void;
|
|
206
|
+
/** Who is holding the engine paused, or null. */
|
|
207
|
+
get pausedBy(): string | null;
|
|
208
|
+
/** True when the working dir is OPFS-backed rather than in-memory. */
|
|
209
|
+
get persistent(): boolean;
|
|
210
|
+
/** The normalised {@link Rsdkv4Storage.namespace} this session actually used. */
|
|
211
|
+
get namespace(): string;
|
|
212
|
+
/**
|
|
213
|
+
* Input ownership, named. `play.input.claim(buttons)` and `play.input.release()`
|
|
214
|
+
* are exactly `options({ buttons })` and `options({ buttons: null })` — same state,
|
|
215
|
+
* same survival across `restart()`, same everything.
|
|
216
|
+
*/
|
|
217
|
+
get input(): RsdkInputBridge;
|
|
218
|
+
/** RSDKv4's Start Menu as data. Available once the engine is up. */
|
|
219
|
+
get game(): RsdkGameBridge;
|
|
220
|
+
/** The engine's stage list and loader. Available once the engine is up. */
|
|
221
|
+
get devMenu(): RsdkDevMenuBridge;
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* The factory a host imports: identity on the constructor, one live engine per
|
|
225
|
+
* instance, and a `start()` that brings the wasm up and opens a session.
|
|
226
|
+
*
|
|
227
|
+
* Everything on it is the contract's — see the module doc for the shape of a call.
|
|
228
|
+
*/
|
|
229
|
+
export declare class Rsdkv4SDK extends EngineSDKBase<Rsdkv4Payloads> {
|
|
230
|
+
static readonly id = "rsdkv4";
|
|
231
|
+
/** Kept in step with package.json by `node scripts/sync-version.mjs`. */
|
|
232
|
+
static readonly version = "0.2.0";
|
|
233
|
+
static readonly name = "Retro Software Development Kit v4";
|
|
234
|
+
static readonly description = "RSDKv4 compiled to WebAssembly via Emscripten. One game-agnostic WASM binary runs both Sonic 1 and Sonic 2 \u2014 the difference is only which Data.rsdk the host supplies at runtime. Ships none of the game: the player provides their own Data.rsdk, and it never leaves their browser.";
|
|
235
|
+
protected createPlay(init: EngineInit<Rsdkv4Payloads>, events: EventEmitter<Rsdkv4Events_>): Rsdkv4Play;
|
|
236
|
+
start(options?: Partial<Rsdkv4Options>): Rsdkv4Session;
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* The line that puts the contract in CI: if this file stops satisfying
|
|
240
|
+
* `EngineSDKConstructor`, `make typecheck` says so.
|
|
241
|
+
*/
|
|
242
|
+
export declare const RSDKV4_ENGINE: EngineSDKConstructor<Rsdkv4Payloads>;
|
|
243
|
+
export default Rsdkv4SDK;
|
|
107
244
|
//# sourceMappingURL=rsdkv4.sdk.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rsdkv4.sdk.d.ts","sourceRoot":"","sources":["../../src/rsdkv4.sdk.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"rsdkv4.sdk.d.ts","sourceRoot":"","sources":["../../src/rsdkv4.sdk.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AAEH,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACxF,OAAO,KAAK,EACV,UAAU,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