34 lines
1.6 KiB
TypeScript
34 lines
1.6 KiB
TypeScript
// SPDX-FileCopyrightText: 2026 Paula Wisnievski
|
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
// bworld/engine: engine access, for what the game api doesn't cover yet. a mod needs "engine_access": true and a
|
|
// game_version within one minor version in its manifest. see docs/modding/misc/engine.md
|
|
//
|
|
// this is bundled into each mod that imports it, so it only imports types: the engine and hook are the game's own,
|
|
// read from the global the game sets up before it loads mods
|
|
import type { EngineGlobal, Hook } from "../hooks.ts";
|
|
import type { common_engine } from "../engine_modules.ts";
|
|
import type { server_engine } from "../../server/game/engine_modules.ts";
|
|
import type { client_engine } from "../../client/engine_modules.ts";
|
|
|
|
export type { HookHandlers } from "../hooks.ts";
|
|
|
|
// the engine's live classes and objects. common is on every side, server only in server scripts, client only in
|
|
// client scripts
|
|
export interface Engine {
|
|
common: ReturnType<typeof common_engine>;
|
|
server: ReturnType<typeof server_engine>;
|
|
client: ReturnType<typeof client_engine>;
|
|
}
|
|
|
|
const api = (globalThis as unknown as Record<string, EngineGlobal | undefined>)["__bworld_engine"];
|
|
if (!api) throw new Error("bworld/engine only works in a mod's script, loaded by the game");
|
|
api.check_access();
|
|
|
|
export const engine = api.engine as Engine;
|
|
// the version of the game that's running, like "0.4.2"
|
|
export const game_version: string = api.version;
|
|
// hooks a method of target, usually a class's prototype, so every instance already made changes too. returns a
|
|
// function that unhooks it
|
|
export const hook: Hook = api.hook;
|