bridge

package
v0.0.0-...-94fff03 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 5, 2026 License: MIT Imports: 31 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
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.

View Source
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

View Source
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

type Bridge struct {
	*editor.Session
	// contains filtered or unexported fields
}

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

func ConnectHost(cfg editor.Config) (*Bridge, bool)

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

func DialHost(addr, token string, cfg editor.Config) (*Bridge, error)

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

func New(cfg editor.Config, t Transport) *Bridge

New returns a bridge around a new session. cfg.Events is replaced: the bridge turns the session's events into messages.

func (*Bridge) Close

func (b *Bridge) Close() error

Close closes the connection to the host, if the bridge has one.

func (*Bridge) Open

func (b *Bridge) Open(text []byte) error

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

func (b *Bridge) Receive(msg []byte)

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

func (b *Bridge) ReportError(err error)

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.

func (*Bridge) Tick

func (b *Bridge) Tick(e *game.Engine) game.TickMode

Tick implements game.Tool: it handles the queued messages, then lets the session run the tick.

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.

type Transport

type Transport = hostlink.Transport

Transport sends one message to the host. It is called on the game goroutine. It is the transport type the tool shell uses too.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL