Documentation
¶
Overview ¶
Package bridge connects an editor.Session to a host over JSON messages: the VSCode extension (through the webview, see transport_js.go) or, in tests, a fake. The protocol is transport-agnostic; doc/design/editor.md lists every message.
Game → host: ready, applied, objects, selection, edit, mode, create, choose, camera, mapLayers, screenshot, entities, status, scriptParams, error. Host → game: document, open, assetsChanged, select, drop, create, assetField, play, stop, step, pause, frame, camera, settings, visible, mapLayerHidden, screenshot, inspect, status, input, scriptParams.
Index ¶
Constants ¶
const ( // EnvBridge is the address (host:port) of the host's listener. EnvBridge = "WPIX_BRIDGE" // EnvBridgeToken is the secret the game sends as the first line. EnvBridgeToken = "WPIX_BRIDGE_TOKEN" )
Environment variables a native host sets to connect a game to itself (see ConnectHost). They are read on every platform except the browser, where the page's script is the host. The variables that name the stage, the first file and headless mode are in package hostlink.
const Version = hostlink.Version
Version is the protocol version, sent in "ready". A host refuses a game with a version it does not know. It is hostlink.Version, which the tool shell sends too.
Variables ¶
var AssetKinds = map[string]string{
".anim.json": "clip",
".fx.json": "effect",
".prefab.json": "prefab",
".voice.json": "voice",
".dialogue.json": "dialogue",
".gs": "script",
".png": "sprite",
".jpg": "sprite",
".jpeg": "sprite",
".kage": "shader",
".wav": "sound",
".ogg": "sound",
".mp3": "sound",
}
AssetKinds maps file suffixes to the asset kind (x-asset) a dropped file of that type fills; longer suffixes are checked first. It is sent in "ready" so the host's inspector uses the same mapping.
Functions ¶
This section is empty.
Types ¶
type Bridge ¶
Bridge is an editor.Session driven by a host. It is the game.Tool to set as game.Config.Tool: it embeds the session, sends "ready" on its first tick, and handles the messages queued by Bridge.Receive at the start of every tick, on the game goroutine.
func ConnectHost ¶
ConnectHost returns a bridge to the host named by the WPIX_BRIDGE environment variable (host:port, with the secret in WPIX_BRIDGE_TOKEN; see DialHost), or false when the variable is not set. A game started by an MCP server or another native host runs this way. A host that cannot be reached is logged and also gives false.
func DialHost ¶
DialHost connects to a host listening on the TCP address addr ("127.0.0.1:port") and returns a bridge to it. The protocol is the same as in the browser; only the transport differs: once the connection is open the game sends token and a newline, then both sides exchange one JSON message per line (a JSON text never holds a raw newline). When the host closes the connection the bridge quits the engine at its next tick, so a game started by a host ends with it.
func New ¶
New returns a bridge around a new session. cfg.Events is replaced: the bridge turns the session's events into messages.
func (*Bridge) Open ¶
Open opens the level like editor.Session.Open and tells the host the object list, so a level the game opened itself shows in the outline.
func (*Bridge) Receive ¶
Receive queues one message from the host. It is safe to call from any goroutine (a JavaScript callback, a reader of stdin); the message is handled at the start of the next tick, which comes within a frame: Receive wakes the session (editor.Session.Wake).
func (*Bridge) ReportError ¶
ReportError sends err to the extension as an "error" message, which it shows to the developer. The host uses it for asset load and reload failures (a .kage that no longer compiles), which would otherwise only reach the webview console. Call it on the game goroutine.
type ObjectInfo ¶
type ObjectInfo struct {
ID string `json:"id"`
Group string `json:"group"`
Class string `json:"class"`
Prefab string `json:"prefab,omitempty"`
// Part is the id within the prefab of an object of a multi-object
// instance that is not its root ("sword"); its ID is "<root id>/<part>".
Part string `json:"part,omitempty"`
}
ObjectInfo is one object of the level, for the host's outline. Prefab is the prefab key of an instance.