ServeWorldOptions beta
Interface of @v12-engine/engine
export interface ServeWorldOptionsWhat the worker's file gives besides the game: its code that runs on the world, which cannot be sent
Members
about
about?: (world: World, context: {
player: PlayerId;
map?: GameMap;
args: unknown;
}) => unknown;What the page is told of the world as the game starts, which it cannot reach into: where the player's base is, who the other side is. Plain data, as it crosses; the page reads it on its session (WorkerSession.about). Asked once the world is made and started (onStart), for a new game and for one loaded
beforePlay
beforePlay?: (world: World, context: WorkerGameContext & {
fresh: boolean;
}) => void | Promise<void>;What the game does before anyone plays, a new world or one loaded from a save (fresh), after onStart: as prepareGame's beforePlay, which a worker's game has here. What it listens to on the world it listens to for this game alone, as a loaded game has none of what the game before listened to
onStart
onStart?: (world: World, context: WorkerGameContext) => void | Promise<void>;What the game does once a new world is made, before anyone plays: as launch's start, which a worker's game has here
player
player?: (world: World, map?: GameMap) => PlayerId;Who the player at the screen is, where the page does not say
port
port?: WorldPort;Where it hears: the worker's own scope when left out (a page's worker); Node's parentPort in a worker thread
reload
reload?: (version: number) => Promise<Rules | undefined> | Rules | undefined;A new version of the game, loaded again in the worker as the page asks (hot reload: the page's game took one, and a worker has no hot reload of its own). The game's module imported anew, so that the dev server gives it as it is now: (version) => import(/* @vite-ignore *\/ ./index.ts?t=$version).then((module) => module.myGame) (a path from the worker's file). Only ever asked for in the dev server. Without it, a game in the worker keeps the version it began with
world
world?: (context: {
rules: Rules;
seed: number;
args: unknown;
log: Logger;
}) => World | Promise<World>;A world made in code, where the page gives neither a map nor a save: generated ground, players of its own