Skip to main content

GameBridge

@zylem/game-lib


@zylem/game-lib / bridge / GameBridge

Class: GameBridge

Defined in: packages/game-lib/src/lib/bridge/game-bridge.ts:320

@zylem/game-lib/bridge public API.

Game-side surface of the shared editor ↔ game bridge. External hosts can use getZylemBridge() to subscribe to game→editor messages or send editor→game commands without importing editor internals.

Constructors​

Constructor​

new GameBridge(): GameBridge

Defined in: packages/game-lib/src/lib/bridge/game-bridge.ts:344

Returns​

GameBridge

Methods​

connect()​

connect(host, announceTarget?): void

Defined in: packages/game-lib/src/lib/bridge/game-bridge.ts:353

Subscribe to editor commands and announce the game side as ready.

Parameters​

host​

GameBridgeHost

Live-game context for entity/stage lookups

announceTarget?​

EventTarget

DOM node the zylem:bridge:ready event bubbles from

Returns​

void


disconnect()​

disconnect(): void

Defined in: packages/game-lib/src/lib/bridge/game-bridge.ts:474

Returns​

void


onEditorAttached()​

onEditorAttached(callback): () => void

Defined in: packages/game-lib/src/lib/bridge/game-bridge.ts:598

Run a callback when an editor first subscribes to entity data, so the game can backfill state produced while nothing was listening.

An editor takes out both entity subscriptions as it mounts, and each is a first-subscriber transition. Backfilling on both would republish the config, the whole stage snapshot, and every thumbnail twice per mount, so a signal is ignored while the other entity type still has a listener — that is the same editor finishing its setup, not a new one.

Parameters​

callback​

() => void

Returns​

An unsubscribe function.

() => void


publishCatalog()​

publishCatalog(entities): void

Defined in: packages/game-lib/src/lib/bridge/game-bridge.ts:676

Publish the placeable entity types the editor's Add palette offers.

Parameters​

entities​

EntityTypeDescriptor[]

Returns​

void


publishConfig()​

publishConfig(config): void

Defined in: packages/game-lib/src/lib/bridge/game-bridge.ts:611

Parameters​

config​

GameConfigPayload

Returns​

void


publishCutsceneStatus()​

publishCutsceneStatus(status): void

Defined in: packages/game-lib/src/lib/bridge/game-bridge.ts:465

Cutscene playback progress for Director mode's transport.

Parameters​

status​

CutsceneStatusPayload

Returns​

void


publishCutsceneView()​

publishCutsceneView(view): void

Defined in: packages/game-lib/src/lib/bridge/game-bridge.ts:470

The previewing camera's projection, for Director mode's viewport overlays.

Parameters​

view​

CutsceneViewPayload

Returns​

void


publishLoading()​

publishLoading(payload): void

Defined in: packages/game-lib/src/lib/bridge/game-bridge.ts:615

Parameters​

payload​

BridgeLoadingPayload

Returns​

void


publishNotice()​

publishNotice(level, message): void

Defined in: packages/game-lib/src/lib/bridge/game-bridge.ts:649

Surface a diagnostic message in the editor console.

Parameters​

level​

"info" | "warn" | "error"

message​

string

Returns​

void


publishSceneOperation()​

publishSceneOperation(op): void

Defined in: packages/game-lib/src/lib/bridge/game-bridge.ts:686

Publish a committed, invertible change for the editor's undo stack.

Sent rather than queued: coalescing merges same-type payloads within a frame, which would fuse two operations into one and lose an undo step.

Parameters​

op​

SceneOperationPayload

Returns​

void


publishStageSnapshot()​

publishStageSnapshot(snapshot): void

Defined in: packages/game-lib/src/lib/bridge/game-bridge.ts:653

Parameters​

snapshot​

StageSnapshotPayload

Returns​

void


publishStatus()​

publishStatus(status): void

Defined in: packages/game-lib/src/lib/bridge/game-bridge.ts:619

Parameters​

status​
debug?​

boolean

paused?​

boolean

Returns​

void


publishVariable()​

publishVariable(payload): void

Defined in: packages/game-lib/src/lib/bridge/game-bridge.ts:631

Publish a global's new value.

Sent rather than queued: a queued payload is merged into the pending one for its type, and since each message names a single path, two globals changing in the same frame would collapse into one and the first variable's update would never reach the editor.

Parameters​

payload​

GameVariablePayload

Returns​

void


queueEntityRemoved()​

queueEntityRemoved(uuids): void

Defined in: packages/game-lib/src/lib/bridge/game-bridge.ts:664

RAF-coalesced entity removal stream.

Parameters​

uuids​

string[]

Returns​

void


queueEntityUpsert()​

queueEntityUpsert(entities): void

Defined in: packages/game-lib/src/lib/bridge/game-bridge.ts:658

RAF-coalesced entity add/update stream; merged by uuid per frame.

Parameters​

entities​

EntitySummaryPayload[]

Returns​

void


queueThumbnails()​

queueThumbnails(thumbnails): void

Defined in: packages/game-lib/src/lib/bridge/game-bridge.ts:670

RAF-coalesced thumbnail stream; merged by uuid per frame.

Parameters​

thumbnails​

EntityThumbnailPayload[]

Returns​

void


wantsEntityUpdates()​

wantsEntityUpdates(): boolean

Defined in: packages/game-lib/src/lib/bridge/game-bridge.ts:570

Whether anything is listening for entity list updates. Building entity summaries is pure editor overhead, so publishers skip it when no editor is attached.

Returns​

boolean


wantsSceneOperations()​

wantsSceneOperations(): boolean

Defined in: packages/game-lib/src/lib/bridge/game-bridge.ts:691

Whether an editor is tracking scene operations for undo.

Returns​

boolean


wantsThumbnails()​

wantsThumbnails(): boolean

Defined in: packages/game-lib/src/lib/bridge/game-bridge.ts:582

Whether anything is listening for thumbnails. Each thumbnail costs an offscreen render plus a pixel readback on the renderer the game draws with, so this gate matters far more than the others.

Returns​

boolean