game-koi 0.6.0 → 0.7.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 +6 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +25 -6
- package/package.json +1 -1
- package/wasm/game_koi_web.d.ts +10 -0
- package/wasm/game_koi_web.js +21 -0
- package/wasm/game_koi_web_bg.wasm +0 -0
- package/wasm/game_koi_web_bg.wasm.d.ts +1 -0
package/README.md
CHANGED
|
@@ -83,7 +83,9 @@ Games that save — the ones whose cartridge has a battery — keep their saves
|
|
|
83
83
|
`localStorage` automatically, so a reload or a later visit picks up where the player
|
|
84
84
|
left off. Nothing needs configuring. The save is written about every two seconds while
|
|
85
85
|
the game has unsaved changes, and again on `pause()`, `loadRom()`, `dispose()`, and when
|
|
86
|
-
the tab is hidden or closed.
|
|
86
|
+
the tab is hidden or closed. Each write, and each save restored when a ROM loads, is
|
|
87
|
+
logged with `console.info`, so the browser console shows when a game saved and under
|
|
88
|
+
which key.
|
|
87
89
|
|
|
88
90
|
A few things worth knowing:
|
|
89
91
|
|
|
@@ -150,6 +152,9 @@ element. Pass `overlayKey: null` to bind no key.
|
|
|
150
152
|
button edges, from any input path. `on` returns a function that unsubscribes. The
|
|
151
153
|
payload is `{ button, source: "keyboard" | "gamepad" | "api", pressed: Set<Button> }`.
|
|
152
154
|
- `koi.pressed` — everything held right now, as a `Set<Button>` snapshot.
|
|
155
|
+
- `koi.version` — the emulator's version, e.g. `"0.6.0"`. It is also logged once per
|
|
156
|
+
page (`console.info`) when the wasm module loads. It is read from the wasm binary
|
|
157
|
+
itself, so a stale cached `.wasm` shows up as a mismatch here.
|
|
153
158
|
- `koi.toggleOverlay()` / `koi.overlayVisible` — the debug stats panel.
|
|
154
159
|
- `koi.pause()` / `koi.resume()`.
|
|
155
160
|
- `koi.dispose()` — stops the loop and tears down the audio graph. Call this before
|
package/dist/index.d.ts
CHANGED
|
@@ -111,6 +111,8 @@ export declare class GameKoi {
|
|
|
111
111
|
importSave(data: Uint8Array): boolean;
|
|
112
112
|
press(button: Button): void;
|
|
113
113
|
release(button: Button): void;
|
|
114
|
+
/** The version of the emulator core running — the same number logged at startup. */
|
|
115
|
+
get version(): string;
|
|
114
116
|
/** Everything the joypad has down right now — a snapshot, safe to keep. */
|
|
115
117
|
get pressed(): ReadonlySet<Button>;
|
|
116
118
|
/**
|
package/dist/index.js
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* ships as a normal ES module asset next to this file, and the audio worklet is
|
|
8
8
|
* inlined as a Blob URL.
|
|
9
9
|
*/
|
|
10
|
-
import init, { Emulator } from "../wasm/game_koi_web.js";
|
|
10
|
+
import init, { Emulator, version as wasmVersion } from "../wasm/game_koi_web.js";
|
|
11
11
|
import { WORKLET_SOURCE } from "./worklet.js";
|
|
12
12
|
import { DEFAULT_GAMEPAD_MAP, GamepadInput } from "./gamepad.js";
|
|
13
13
|
import { Emitter } from "./events.js";
|
|
@@ -31,11 +31,16 @@ const DEFAULT_KEYMAP = {
|
|
|
31
31
|
ShiftRight: "select",
|
|
32
32
|
};
|
|
33
33
|
// The wasm module only needs instantiating once per page, no matter how many
|
|
34
|
-
// `GameKoi` instances are created.
|
|
34
|
+
// `GameKoi` instances are created. The version line is logged here for the same
|
|
35
|
+
// reason: once per page, not once per instance or per `loadRom`.
|
|
35
36
|
let wasmReady = null;
|
|
36
37
|
function ensureWasm() {
|
|
37
|
-
if (!wasmReady)
|
|
38
|
-
wasmReady = init()
|
|
38
|
+
if (!wasmReady) {
|
|
39
|
+
wasmReady = init().then((wasm) => {
|
|
40
|
+
console.info(`game-koi ${wasmVersion()}`);
|
|
41
|
+
return wasm;
|
|
42
|
+
});
|
|
43
|
+
}
|
|
39
44
|
return wasmReady;
|
|
40
45
|
}
|
|
41
46
|
/** A running Game Boy, attached to a canvas and driving an AudioWorklet. */
|
|
@@ -182,6 +187,10 @@ export class GameKoi {
|
|
|
182
187
|
release(button) {
|
|
183
188
|
this.setButton(button, false, "api");
|
|
184
189
|
}
|
|
190
|
+
/** The version of the emulator core running — the same number logged at startup. */
|
|
191
|
+
get version() {
|
|
192
|
+
return wasmVersion();
|
|
193
|
+
}
|
|
185
194
|
/** Everything the joypad has down right now — a snapshot, safe to keep. */
|
|
186
195
|
get pressed() {
|
|
187
196
|
return new Set(this.held);
|
|
@@ -388,8 +397,15 @@ export class GameKoi {
|
|
|
388
397
|
if (!this.emulator.has_save())
|
|
389
398
|
return;
|
|
390
399
|
const data = this.saves.load(this.saveKey);
|
|
391
|
-
|
|
392
|
-
|
|
400
|
+
// No stored save is the normal first run, and not worth a line.
|
|
401
|
+
if (!data)
|
|
402
|
+
return;
|
|
403
|
+
const where = `localStorage["${this.saveKey}"]`;
|
|
404
|
+
if (this.emulator.load_save(data)) {
|
|
405
|
+
console.info(`game-koi: restored ${data.length} bytes from ${where}`);
|
|
406
|
+
}
|
|
407
|
+
else {
|
|
408
|
+
console.warn(`game-koi: ignoring ${where}, it is smaller than this cartridge's RAM`);
|
|
393
409
|
}
|
|
394
410
|
}
|
|
395
411
|
/**
|
|
@@ -408,6 +424,9 @@ export class GameKoi {
|
|
|
408
424
|
try {
|
|
409
425
|
this.saves.store(this.saveKey, data);
|
|
410
426
|
this.emulator.mark_saved();
|
|
427
|
+
// Only reached when the game wrote its save RAM, so this is one line per in-game
|
|
428
|
+
// save (give or take the ~2 s autosave batching), not one per autosave tick.
|
|
429
|
+
console.info(`game-koi: saved ${data.length} bytes to localStorage["${this.saveKey}"]`);
|
|
411
430
|
}
|
|
412
431
|
catch (error) {
|
|
413
432
|
console.warn("game-koi: could not store save", error);
|
package/package.json
CHANGED
package/wasm/game_koi_web.d.ts
CHANGED
|
@@ -82,6 +82,15 @@ export class Emulator {
|
|
|
82
82
|
static width(): number;
|
|
83
83
|
}
|
|
84
84
|
|
|
85
|
+
/**
|
|
86
|
+
* The workspace version this module was built from.
|
|
87
|
+
*
|
|
88
|
+
* Read from Cargo at compile time rather than from `package.json`, so it names the
|
|
89
|
+
* binary actually loaded: a stale `.wasm` cached next to a newer JS wrapper reports
|
|
90
|
+
* its own, older, number instead of the wrapper's.
|
|
91
|
+
*/
|
|
92
|
+
export function version(): string;
|
|
93
|
+
|
|
85
94
|
export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
|
|
86
95
|
|
|
87
96
|
export interface InitOutput {
|
|
@@ -101,6 +110,7 @@ export interface InitOutput {
|
|
|
101
110
|
readonly emulator_save_dirty: (a: number) => number;
|
|
102
111
|
readonly emulator_take_samples: (a: number) => [number, number];
|
|
103
112
|
readonly emulator_width: () => number;
|
|
113
|
+
readonly version: () => [number, number];
|
|
104
114
|
readonly __wbindgen_externrefs: WebAssembly.Table;
|
|
105
115
|
readonly __wbindgen_malloc: (a: number, b: number) => number;
|
|
106
116
|
readonly __externref_table_dealloc: (a: number) => void;
|
package/wasm/game_koi_web.js
CHANGED
|
@@ -169,6 +169,27 @@ export class Emulator {
|
|
|
169
169
|
}
|
|
170
170
|
}
|
|
171
171
|
if (Symbol.dispose) Emulator.prototype[Symbol.dispose] = Emulator.prototype.free;
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* The workspace version this module was built from.
|
|
175
|
+
*
|
|
176
|
+
* Read from Cargo at compile time rather than from `package.json`, so it names the
|
|
177
|
+
* binary actually loaded: a stale `.wasm` cached next to a newer JS wrapper reports
|
|
178
|
+
* its own, older, number instead of the wrapper's.
|
|
179
|
+
* @returns {string}
|
|
180
|
+
*/
|
|
181
|
+
export function version() {
|
|
182
|
+
let deferred1_0;
|
|
183
|
+
let deferred1_1;
|
|
184
|
+
try {
|
|
185
|
+
const ret = wasm.version();
|
|
186
|
+
deferred1_0 = ret[0];
|
|
187
|
+
deferred1_1 = ret[1];
|
|
188
|
+
return getStringFromWasm0(ret[0], ret[1]);
|
|
189
|
+
} finally {
|
|
190
|
+
wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
172
193
|
function __wbg_get_imports() {
|
|
173
194
|
const import0 = {
|
|
174
195
|
__proto__: null,
|
|
Binary file
|
|
@@ -16,6 +16,7 @@ export const emulator_save_data: (a: number) => [number, number];
|
|
|
16
16
|
export const emulator_save_dirty: (a: number) => number;
|
|
17
17
|
export const emulator_take_samples: (a: number) => [number, number];
|
|
18
18
|
export const emulator_width: () => number;
|
|
19
|
+
export const version: () => [number, number];
|
|
19
20
|
export const __wbindgen_externrefs: WebAssembly.Table;
|
|
20
21
|
export const __wbindgen_malloc: (a: number, b: number) => number;
|
|
21
22
|
export const __externref_table_dealloc: (a: number) => void;
|