Files
bworld/client/platform.ts
T

43 lines
2.0 KiB
TypeScript

// SPDX-FileCopyrightText: 2026 Paula Wisnievski
// SPDX-License-Identifier: AGPL-3.0-or-later
// what the client needs from where it runs: a browser page (browser_platform.ts), or the desktop app's window, where
// it runs in deno with no browser (native/). the entry point sets it before anything else runs
import type { GuiScreen } from "./gui/gui_screen.ts";
export interface Platform {
// the page's address. its query has the options (?server=, ?name=, ?singleplayer), and the client's own files
// (/assets/) and the desktop app's requests (/desktop/) are relative to it
page: URL;
// starts the client over at url, like loading the page again. a server's mods can't be taken back out once
// they're loaded, so leaving a server does this
restart(url: URL): void;
// calls frame once it's time for the next frame, with the time like performance.now()
request_frame(frame: (time: number) => void): void;
// calls shown when the game can be seen again after being hidden, there are no frames meanwhile
on_shown(shown: () => void): void;
// what's remembered from one time to the next, like the servers whose mods the player trusts. it can throw, like a
// browser's in a private window
storage: Pick<Storage, "getItem" | "setItem">;
// while playing, leaving asks first
confirm_leaving(confirm: boolean): void;
// replaces the game with a message, for when it can't go on
show_fatal_error(message: string): void;
// who made what: the engine's assets/ASSETS.md, then each loaded mod's credits file
credits_screen(on_back: () => void): GuiScreen;
read_clipboard(): Promise<string>;
write_clipboard(text: string): Promise<void>;
// while the mouse is grabbed it turns the camera and there's no cursor
set_mouse_grabbed(grab: boolean): void;
is_mouse_grabbed(): boolean;
// whether the mouse was let go by something other than the game since the last call, like switching windows
take_lost_mouse(): boolean;
toggle_fullscreen(): void;
}
export let platform: Platform;
export function set_platform(chosen: Platform) {
platform = chosen;
}