shotproto

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: 2 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 shotproto is the screenshot message pair both editor protocols share, the level editor's bridge and the tool shell: a host asks for a capture with a "screenshot" request, the game answers with a "screenshot" message that carries the PNG. See doc/design/editor-protocol.md#protocol.

Under an editor the game never writes a file: Sink sends every capture to the host, which decides where it goes. A capture the game took itself (hotkey, a tool's button, environment variables) is sent too, with an empty ID.

Index

Constants

View Source
const Type = "screenshot"

Type is the "type" of both messages.

Variables

This section is empty.

Functions

func Serve

func Serve(e *game.Engine, r Request, send func(Answer))

Serve queues the capture r asks for on e. The answer, a failure included, goes to send on the game goroutine: successes through the sink Sink installs, failures through the request itself. A bad target is answered at once.

func Sink

func Sink(e *game.Engine, send func(Answer))

Sink installs the sink that sends every successful capture of e to send, the ones Serve queued and the ones the game took itself (ID ""). Failures of the latter are logged by the engine.

Types

type Answer

type Answer struct {
	Type   string `json:"type"` // "screenshot"
	ID     string `json:"id"`
	PNG    []byte `json:"png"`
	Width  int    `json:"width"`
	Height int    `json:"height"`
	Tick   uint64 `json:"tick"`
	Error  string `json:"error,omitempty"`
}

Answer is the game-to-host message. PNG is base64 in the JSON. Error is set (and PNG empty) when the capture failed.

type Request

type Request struct {
	ID        string `json:"id"`
	Target    string `json:"target"`
	Scale     int    `json:"scale"`
	KeepAlpha bool   `json:"keepAlpha"`
}

Request is the host-to-game message. Target is "game" (the default) or "window"; Scale is 1..game.MaxShotScale for "game", 0 meaning 1.

Jump to

Keyboard shortcuts

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