gizgame/host
A game that is a folder of data on the one host program (hosted), a typed patch of a running world with its inverse (WorldPatch).
import * as Host from "gizgame/host";Types
WorldPatch
type WorldPatch = { action: string; target?: string; value?: f64; text?: string; x?: f64; y?: f64; z?: f64; enabled?: bool; }Single typed live-edit transaction replacing fragmented edit protocols.
action:stringtarget:_gizlang_sdk_core.Option<string>value:_gizlang_sdk_core.Option<f64>text:_gizlang_sdk_core.Option<string>x:_gizlang_sdk_core.Option<f64>y:_gizlang_sdk_core.Option<f64>z:_gizlang_sdk_core.Option<f64>enabled:_gizlang_sdk_core.Option<bool>
PatchOutcome
type PatchOutcome = { ok: bool; action: string; inverse?: WorldPatch; error?: string; }Result of validating or applying a WorldPatch transaction.
ok:boolaction:stringinverse:_gizlang_sdk_core.Option<M226.WorldPatch>error:_gizlang_sdk_core.Option<string>
PatchHistory
class PatchHistory { entries: Vec<WorldPatch> = []; limit: i64; constructor(limit: i64 = 64) { this.limit = limit; } push(outcome: PatchOutcome): void { if (!outcome.ok || outcome.inverse === undefined) { return; } this.entries.push(outcome.inverse!); if (this.entries.length> this.limit) { this.entries = this.entries.slice(this.entries.length - this.limit); } } undo(): WorldPatch | undefined { if (this.entries.length === 0) { return undefined; } const last = this.entries[this.entries.length - 1]; this.entries = this.entries.slice(0, this.entries.length - 1); return last; } size(): i64 { return this.entries.length; } }Bounded undo stack for WorldPatch live prompt edits.
entries:Vec<M226.WorldPatch>limit:i64
Stage
type Stage = { scene?: Scene; sprites?: Sprites; }What a hosted game's play holds: its SCENE in 3D, or the SPRITES of a world that declares a 2D arena (Atlas.arena).
scene:_gizlang_sdk_core.Option<Ref<M248.Scene>>sprites:_gizlang_sdk_core.Option<Ref<M258.Sprites>>
Hosted
type Hosted = { game: Game; play: Play<Stage>; realm: Realms.Realms; }A game that is a folder of data, with no program of its own: the GAME, its PLAY (in 3D, or in 2D where its world declares an arena), and its REALM (the online world its file may hold).
game:Ref<M224.Game>play:Ref<M241.Play<M226.Stage>>realm:M245.Realms
Made
type Made = { on: () => bool; scene: (map: i64) => Scene3D throws string; carry: (input: bytes) => bytes; }A made world's play, which the host program brings: while ON (the world file in hand is a made one), its SCENE and what it CARRYs between maps stand in place of the realm's.
on:() => boolscene:(arg0: i64) => M248.Scene3D throws stringcarry:(arg0: bytes) => bytes
Functions
validatePatch
function validatePatch(p: WorldPatch, prevValue: f64 = 0.0, prevText: string = ""): PatchOutcomeValidates a WorldPatch and constructs its canonical undo inverse when reversible.
Effects: fail, alloc.
constructor
constructor(limit: i64 = 64)A history of at most LIMIT patches.
Effects: fail, read, write, alloc.
world
function world(fields: Json = schema<Realms.Fields>()): GameA new game of the folder a host gives: world.json declares it whole (Atlas: its kinds, keys, sounds, rate, seed and solid world), each map's file its land and its rules (gizgame/rules), and the world's realm, if any, its online world (gizgame/realm). The world file holds FIELDS beside the engine's.
Effects: fail, read, write, console, io, alloc.
hosted
function hosted(game: Game = world(), made?: Made): HostedGAME (a new one of the folder's files unless given) with its play and its realm. One program is every such game; a server of several makes one of these a folder. MADE plays a made world.
Effects: fail, read, write, console, io, alloc.
seats
function seats(): SeatsThe seats of a hosted game's room. A function of its own: a page (WebAssembly) calls it nowhere and holds no server.
Effects: fail, read, write, console, io, alloc.
Methods
PatchHistory.push
push(outcome: PatchOutcome): voidRecords an inverse patch if present, trimming the oldest entry past limit.
Effects: fail, read, write, alloc.
PatchHistory.undo
undo(): WorldPatch | undefinedPops the most recent undo patch, or undefined if empty.
Effects: fail, read, write, alloc.
PatchHistory.size
size(): i64Number of undoable patches currently recorded.
Effects: fail, read.