# 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).

```gizlang
import * as Host from "gizgame/host";
```

## Types

### `WorldPatch`

```gizlang
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`: `string`
- `target`: `_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`

```gizlang
type PatchOutcome = { ok: bool; action: string; inverse?: WorldPatch; error?: string; }
```

Result of validating or applying a WorldPatch transaction.

- `ok`: `bool`
- `action`: `string`
- `inverse`: `_gizlang_sdk_core.Option<M226.WorldPatch>`
- `error`: `_gizlang_sdk_core.Option<string>`

### `PatchHistory`

```gizlang
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`

```gizlang
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`

```gizlang
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`

```gizlang
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`: `() => bool`
- `scene`: `(arg0: i64) => M248.Scene3D throws string`
- `carry`: `(arg0: bytes) => bytes`

## Functions

### `validatePatch`

```gizlang
function validatePatch(p: WorldPatch, prevValue: f64 = 0.0, prevText: string = ""): PatchOutcome
```

Validates a WorldPatch and constructs its canonical undo inverse when reversible.

Effects: fail, alloc.

### `constructor`

```gizlang
constructor(limit: i64 = 64)
```

A history of at most LIMIT patches.

Effects: fail, read, write, alloc.

### `world`

```gizlang
function world(fields: Json = schema<Realms.Fields>()): Game
```

A 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`

```gizlang
function hosted(game: Game = world(), made?: Made): Hosted
```

GAME (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`

```gizlang
function seats(): Seats
```

The 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`

```gizlang
push(outcome: PatchOutcome): void
```

Records an inverse patch if present, trimming the oldest entry past limit.

Effects: fail, read, write, alloc.

### `PatchHistory.undo`

```gizlang
undo(): WorldPatch | undefined
```

Pops the most recent undo patch, or undefined if empty.

Effects: fail, read, write, alloc.

### `PatchHistory.size`

```gizlang
size(): i64
```

Number of undoable patches currently recorded.

Effects: fail, read.

