2026-08-22 14:30:14 +02:00
|
|
|
/**
|
2026-08-22 19:06:44 +02:00
|
|
|
* Public TypeScript surface for vpinball-wasm.
|
2026-08-22 14:30:14 +02:00
|
|
|
*
|
|
|
|
|
* This wraps the raw Emscripten-generated module (dist/vpinball.js) so
|
|
|
|
|
* consumers don't need to know about ccall/cwrap/FS internals directly.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
export interface LoadPinballOptions {
|
|
|
|
|
/** Canvas the engine renders into via SDL3's WebGL2 backend. */
|
|
|
|
|
canvas: HTMLCanvasElement;
|
|
|
|
|
/**
|
2026-08-22 16:45:04 +02:00
|
|
|
* Raw bytes of a self-contained .vpx table file to play instead of the
|
|
|
|
|
* bundled default table. Real-world tables that reference an external
|
|
|
|
|
* .vbs script override or a Music/ folder are not supported this way -
|
|
|
|
|
* see the README's "Browser file-loading UX" section.
|
2026-08-22 14:30:14 +02:00
|
|
|
*/
|
|
|
|
|
tableData?: ArrayBuffer;
|
2026-08-22 16:45:04 +02:00
|
|
|
/** Base URL to fetch dist/vpinball.wasm/.data (and vpinball.js) from. */
|
2026-08-22 14:30:14 +02:00
|
|
|
baseUrl?: string;
|
2026-08-22 16:45:04 +02:00
|
|
|
/**
|
|
|
|
|
* Called as the wasm binary and preloaded asset package download,
|
|
|
|
|
* with a 0-1 fraction of bytes received. Not called at all if the
|
|
|
|
|
* browser doesn't support streaming fetch progress (falls back to
|
|
|
|
|
* Emscripten's own default loading behavior with no progress callback).
|
|
|
|
|
*/
|
|
|
|
|
onProgress?: (fraction: number) => void;
|
2026-08-22 14:30:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface PinballInstance {
|
2026-08-22 16:45:04 +02:00
|
|
|
/**
|
|
|
|
|
* Stage a different self-contained .vpx table to play on the *next*
|
|
|
|
|
* start() call. Does not affect an already-running session - table
|
|
|
|
|
* switching mid-session isn't supported; call stop() first (a fresh
|
|
|
|
|
* loadPinball() call is the supported way to load a genuinely new
|
|
|
|
|
* session with a different table).
|
|
|
|
|
*/
|
2026-08-22 14:30:14 +02:00
|
|
|
loadTable(vpxBytes: ArrayBuffer): void;
|
2026-08-22 16:45:04 +02:00
|
|
|
/** Start the simulation's main loop. No-op if already running. */
|
2026-08-22 14:30:14 +02:00
|
|
|
start(): void;
|
2026-08-22 16:45:04 +02:00
|
|
|
/** Stop the simulation; the engine tears down (script Exit event, settings save) on its next step. */
|
2026-08-22 14:30:14 +02:00
|
|
|
stop(): void;
|
2026-08-22 16:45:04 +02:00
|
|
|
/** Tear down the instance immediately and free its WebAssembly memory. */
|
2026-08-22 14:30:14 +02:00
|
|
|
dispose(): void;
|
2026-08-22 16:45:04 +02:00
|
|
|
/**
|
|
|
|
|
* Request fullscreen on the canvas via the standard Fullscreen API.
|
|
|
|
|
* Must be called from within a user gesture (e.g. a click handler) -
|
|
|
|
|
* browsers reject fullscreen requests otherwise. Returns the promise
|
|
|
|
|
* from the underlying requestFullscreen() call.
|
|
|
|
|
*/
|
|
|
|
|
requestFullscreen(): Promise<void>;
|
2026-08-22 18:14:49 +02:00
|
|
|
/**
|
|
|
|
|
* Runs arbitrary VBScript against the running table's script interpreter
|
|
|
|
|
* (the same entry point the interpreter's own debug console uses).
|
|
|
|
|
* Returns false if no table is currently running. Intended for debugging
|
|
|
|
|
* and for exercising script-driven engine APIs (e.g. the DMD pixel API)
|
|
|
|
|
* from JS - not sandboxed, so only run scripts you trust.
|
|
|
|
|
*/
|
|
|
|
|
evalScript(script: string): boolean;
|
2026-08-22 14:30:14 +02:00
|
|
|
}
|