players

package
v0.23.0 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2026 License: MIT Imports: 28 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 players is whoever acts in the game: a Player acting through a picture of the world a scene wires it to and, at this keyboard, the bindings that turn its input into commands, carried to the plugin that defined each one.

A carrier to the command handlers

NewPlugin takes the world and every plugin.CommandHandler the game uses: the world carries their queues and the players gather their default bindings (Plugin.Defaults). The plugins never know players; they know plugin.CommandHandler and the vocabulary in package control. Write.Issue is how a command comes in, from a binding, an AI or a network; a type no handler defines is ErrUnknownCommand.

Owners

A unit belongs to the player it was given to: the command Give, which the unit gives itself as it is made (kind.Entry.Told) or later, sets its one owner, a tag of the owners' family (plugins/players/owner) every unit carries. The plugins that take commands read the tag through owner.Obeys: a player selects, orders and drives its own units alone; a unit nobody owns is command.Nobody's. A side of its own, the wild or a rival, is a player without a keyboard (Plugin.Add) owning its units.

Pictures of the world

A player owns no camera: it acts through a picture on a ui scene's screen, which the scene makes with a camera beside it. ui.Image(render.NewFeed(cam, picture)).Input(Plugin.Through(pl)) is the wire: the active scene tells the player before each pass of input where its picture lies (Player.Area) and what it shows, so the mouse over it is the player's and every command it gives carries that picture's camera (control.Context.Camera). A scene gives a player one view: two of its pictures in one pass panic. Where an element lies over the picture under the cursor (a minimap), and while the window has no cursor (control.InputEvents.CursorInWindow: not seen yet, or gone out), the cursor's place does nothing: no scrolling at an edge, no turning in a corner. Plugin.IssueAs is how the scene's buttons and keys give their commands as the player. Players draw nothing.

Players and bindings

Plugin.Local adds a player at this keyboard, Plugin.Add one without. A game binds a player with Player.Bind: the Defaults whole, or entries of its own. Two bindings on one trigger holding in one fastening of the camera are refused at Bind unless one yields (control.Binding.Yielding: it fires only when no other built a command); one whose command nobody defines when the Stage is set up. A binding may hold in some fastenings of the camera only (control.Binding.In): only those holding in the camera's How fire. A player holds a tool in hand (control.Take, control.Drop; Player.Tool): while it does, the bindings With that tool fire in place of those with no tool. While a local player's camera rides inside an entity or is kept behind one (camera.Inside, camera.Behind), the window's cursor is captured and control.CursorMove reaches that player.

From input to commands

Plugin.EventHandler is the layer between the device and the game: it matches each pass's control.InputEvents against every local player's bindings and hands what they build to Write.Issue. Keys reach every local player, the mouse the one whose picture it is over, in the pixels of that picture's camera, so local players split the screen as the scene lays their pictures out. A control.KeyHeld fires from Plugin.RunPlan instead, once a tick while its key is down; call RunPlan last in Update. Nothing is dropped: a command given after its handler's pass waits for the next frame's.

Scene keys, the controls and the settings

A scene showing the world hands its input to Plugin.Handle and nothing else. ShowControls (K) opens ControlsScene, the players' own screen of every key and mouse action of the game, a framed section a group, over the paused game; every Stage that uses the players has it in its stack (Plugin.Scenes), and Esc or K closes it. ShowSettings (F10) opens SettingsScene, the screen of every setting the plugins carried announce (plugin.Tunable): a control each, a checkbox, a dropdown or a slider, giving the plugin's command as it is used, in sections centred on the screen: first those the plugins share (control.Picture and its parts, a setting's Section), then one a plugin for its own; Esc or F10 closes it. Both screens are laid alike, in the default theme: the title in a framed panel at the top, the sections in as many columns as the width takes, scrolled where they do not fit. While it is up the game stands in the tactical pause, unless the players' own setting says it runs on (Settings, KeepRunning); the players' settings are saved with the game, as every plugin's. The players' settings show the telemetry panel or hide it and choose what it shows, the basics or everything. Keys that are no command to a plugin are the game's own: SceneKeys, given to Plugin.OwnKeys, run by Handle and listed under "Game" with what the Stage binds in its Controls section. Plugin.GameBindings are K, F10, ~ (the telemetry panel, telemetry.Panel, carried here: it needs the scene's Composition; from hidden to the basics, to everything and to hidden again), F5 game.Save, F9 game.Load and Shift+Esc game.Quit, the same in every game. Written is a trigger as the screen writes it.

Vocabulary

Commands: Give (an entity's own: whose it is), ShowControls (a player's, K), ShowSettings (F10), KeepRunning; the telemetry panel's telemetry.Panel (~) is carried here too. Settings (Settings, in Resources): the game running behind the settings screen. The owners' family is players/owner's.

Index

Constants

View Source
const ControlsName = "gram.controls"

ControlsName is the name of the controls scene in a game's stack.

View Source
const SettingsName = "gram.settings"

SettingsName is the name of the settings scene in a game's stack.

Variables

View Source
var ErrUnknownCommand = errors.New("players: no plugin listens for this command")

ErrUnknownCommand is what Issue reports for a command type no handler defines.

Functions

func Written

func Written(t control.Trigger) string

Written is a trigger as a help screen writes it: Shift+W, Q (held), right click, L + left drag, wheel, cursor at an edge.

Types

type ControlsScene added in v0.6.0

type ControlsScene struct {
	// contains filtered or unexported fields
}

ControlsScene is the screen of every key and mouse action of the game, laid as the settings screen is, a framed section a group: the game's own under "Game", the plugins' by plugin, the players' and the engine's under "General". K opens it, Esc or K closes it; shown, it holds the game in the engine's pause.

func (*ControlsScene) Close added in v0.6.0

func (s *ControlsScene) Close(runtime game.Runtime, composition game.Composition)

Close hides the screen and lets the game go on, unless it was paused before.

func (*ControlsScene) Drawers added in v0.6.0

func (s *ControlsScene) Drawers() []render.Renderer

func (*ControlsScene) Focusable added in v0.6.0

func (*ControlsScene) Focusable() bool

func (*ControlsScene) HandleEvents added in v0.6.0

func (s *ControlsScene) HandleEvents(events *control.InputEvents, runtime game.Runtime,
	composition game.Composition)

HandleEvents closes the screen on Esc or K and hands the rest to the screen, its scroll; a screen of another size, the window resized or full, has the listing built anew for it.

func (*ControlsScene) Name added in v0.6.0

func (*ControlsScene) Name() string

func (*ControlsScene) Open added in v0.6.0

func (s *ControlsScene) Open(runtime game.Runtime, composition game.Composition)

Open shows the screen on top and holds the game paused while it is up.

type Give

type Give struct{ To command.Issuer }

Give is the command by which an entity becomes To's, its alone; Nobody's for command.Nobody. An entity gives it itself, as it is made (kind.Entry.Told) or later.

func (Give) Command

func (Give) Command()

type KeepRunning

type KeepRunning struct{ On bool }

KeepRunning has the game run on behind the settings screen (Settings.Running), or stand in the tactical pause while it is up.

func (KeepRunning) Command

func (KeepRunning) Command()

type Player

type Player struct {
	ID   command.Issuer
	Name string
	// contains filtered or unexported fields
}

Player is whoever acts in the game: the picture of the world it acts through and, at this keyboard, the bindings that turn its input into commands.

func (*Player) Area

func (p *Player) Area() geom.AABB

Area is the player's part of the screen, in pixels, as its picture was last laid out.

func (*Player) Bind

func (p *Player) Bind(bindings ...control.Binding) error

Bind adds bindings to the player; two on one Trigger holding in one camera mode with one tool are an error unless one of them yields (control.Binding.Yielding). Those bound in the Stage's Controls section are the game's own, listed apart under "Game".

func (*Player) Bindings

func (p *Player) Bindings() []control.Binding

Bindings lists what the player can do, in the order bound.

func (*Player) Tool

func (p *Player) Tool() control.Tool

Tool is what the player holds in hand: none for nothing.

type Plugin

type Plugin struct {
	*world.Self

	Res Resources
	// contains filtered or unexported fields
}

Plugin keeps the game's players and gives their commands to the world's carrier, which takes each to the handler that defines it.

func NewPlugin

func NewPlugin(worldPlugin *world.Plugin, handlers ...plugin.CommandHandler) *Plugin

NewPlugin builds the players plugin over worldPlugin, having the world carry the commands of handlers beside its own and the players'. Two handlers of one command type panic.

func (*Plugin) Add

func (p *Plugin) Add(name string) *Player

Add adds a player without a keyboard, an AI or a remote client, whose commands come in through Issue.

func (*Plugin) DefaultBindings

func (p *Plugin) DefaultBindings() []control.Binding

DefaultBindings are GameBindings.

func (*Plugin) Defaults

func (p *Plugin) Defaults() []control.Binding

Defaults is every handler's default bindings in one list to bind.

func (*Plugin) EventHandler

func (p *Plugin) EventHandler() control.EventHandler

EventHandler translates this tick's input through every local player's bindings.

func (*Plugin) GameBindings

func (p *Plugin) GameBindings() []control.Binding

GameBindings are the keys every game has: K for the controls screen, F10 for the settings, ~ for the telemetry panel (the basics, everything, hidden, in turn), F5 to save, F9 to load, Shift+Esc to quit. A game that binds its own keys in place of the Defaults binds these beside them.

func (*Plugin) Handle

func (p *Plugin) Handle(
	events *control.InputEvents,
	runtime game.Runtime,
	composition game.Composition,
)

Handle takes a scene's input for the tick: the players' bindings turn it into commands, the players' own are carried out at once and the game's own keys (OwnKeys) are run.

func (*Plugin) Install

func (p *Plugin) Install(ctx plugin.Installer) error

func (*Plugin) IssueAs

func (p *Plugin) IssueAs(pl *Player) func(cmd command.Command) error

IssueAs is Issue for pl: how a scene's buttons and keys give their commands (ui.Scene.Issue).

func (*Plugin) KindTemplates

func (p *Plugin) KindTemplates(r *kind.Roster)

KindTemplates is what the players ask of the kinds a game defines: every unit marked, so it may be given an owner.

func (*Plugin) Local

func (p *Plugin) Local(name string) *Player

Local adds a player at this keyboard, acting through the picture of the world a scene wires it to (Through); bind it before Use. Two local players acting through pictures of their own split the screen.

func (*Plugin) Name

func (p *Plugin) Name() string

func (*Plugin) OwnKeys

func (p *Plugin) OwnKeys(keys SceneKeys) *Plugin

OwnKeys gives the game's own keys, run by Handle and listed under "Game". Call it before the Stage is set up.

func (*Plugin) Queues

func (p *Plugin) Queues() []command.CommandQueue

Queues are where the players' own commands land, the telemetry panel's (it needs the scene's Composition, which the players' Handle has), and the tools taken and put down (control.Take, control.Drop).

func (*Plugin) Read added in v0.4.0

func (p *Plugin) Read(int) *Read

Read reads the players on worker w of the game's pool, 0 the game's own goroutine.

func (*Plugin) Restore

func (p *Plugin) Restore()

Restore takes the Settings loaded.

func (*Plugin) RunPlan

func (p *Plugin) RunPlan(ctx goke.RunCtx, d time.Duration)

RunPlan hands over the units given and issues the keys held for the next tick; call it last in Update.

func (*Plugin) Scenes

func (p *Plugin) Scenes() []game.Scene

Scenes are the players' own: the controls screen and the settings screen (game.Scenic).

func (*Plugin) Serializable

func (p *Plugin) Serializable() plugin.Serializable

Serializable is the players' Settings, kept whole.

func (*Plugin) Settings

func (p *Plugin) Settings() []control.Setting

Settings are the players' own: whether the game runs on behind the settings screen, and the telemetry panel, shown or not, the basics or everything.

func (*Plugin) Through

func (p *Plugin) Through(pl *Player) ui.Input

Through is pl as whoever takes the input over a picture of the world on a scene's screen (ui.Image(feed).Input): the picture pl acts through while the scene is active.

func (*Plugin) Write added in v0.4.0

func (p *Plugin) Write() *Write

Write changes the players, on the game's goroutine.

type Read added in v0.4.0

type Read struct {
	// contains filtered or unexported fields
}

Read reads the players, the same on every goroutine.

func (*Read) ByID added in v0.4.0

func (r *Read) ByID(id command.Issuer) *Player

ByID is the player with id, or nil — for Nobody too.

func (*Read) Locals added in v0.4.0

func (r *Read) Locals() []*Player

Locals lists the players at this keyboard.

func (*Read) Players added in v0.4.0

func (r *Read) Players() []*Player

Players lists every player, in the order added.

type Resources

type Resources struct {
	Settings Settings
}

Resources is what the players publish: their Settings.

type SceneKey

type SceneKey struct {
	Key         control.Key
	Shift, Ctrl bool
	Label       string
	Do          func(runtime game.Runtime, composition game.Composition)
}

SceneKey is a key of the game's own, a debug toggle, that is no command to a plugin: what it does, labelled for the controls screen. Shift and Ctrl ask for those held, exactly.

type SceneKeys

type SceneKeys []SceneKey

SceneKeys are a scene's keys: Handle runs the ones this tick's presses hit, and the controls screen lists them under "Game".

func (SceneKeys) Handle

func (ks SceneKeys) Handle(events *control.InputEvents, runtime game.Runtime,
	composition game.Composition)

Handle runs every key of ks pressed this tick with the modifiers it asks for.

type Settings

type Settings struct {
	Running bool
}

Settings is what the players keep of their own, saved with the game: whether the game runs on behind the settings screen, or stands in the tactical pause while it is up.

type SettingsScene

type SettingsScene struct {
	// contains filtered or unexported fields
}

SettingsScene is the screen of every plugin's settings (plugin.Tunable), a control each, in sections: those the plugins share first, then a plugin's own. F10 opens it, Esc or F10 closes it; while it is up the game stands in the tactical pause unless Settings.Running.

func (*SettingsScene) Close

func (s *SettingsScene) Close(runtime game.Runtime, composition game.Composition)

Close hides the screen and lets the game go on, unless it was paused before.

func (*SettingsScene) Drawers

func (s *SettingsScene) Drawers() []render.Renderer

func (*SettingsScene) Focusable

func (*SettingsScene) Focusable() bool

func (*SettingsScene) HandleEvents

func (s *SettingsScene) HandleEvents(events *control.InputEvents, runtime game.Runtime,
	composition game.Composition)

HandleEvents closes the screen on Esc or F10 and hands the rest to the controls; the cursor is let go while the screen is up, a player riding or not; a screen of another size, the window resized or full, has the listing built anew for it.

func (*SettingsScene) Name

func (*SettingsScene) Name() string

func (*SettingsScene) Open

func (s *SettingsScene) Open(runtime game.Runtime, composition game.Composition)

Open shows the screen on top, built afresh of the plugins' settings, and holds the game.

type ShowControls added in v0.6.0

type ShowControls struct{}

ShowControls opens the controls screen (the ControlsScene), every key and mouse action of the game. K by default.

func (ShowControls) Command added in v0.6.0

func (ShowControls) Command()

type ShowSettings

type ShowSettings struct{}

ShowSettings opens the settings screen (the SettingsScene). F10 by default.

func (ShowSettings) Command

func (ShowSettings) Command()

type Write added in v0.4.0

type Write struct {
	// contains filtered or unexported fields
}

Write changes the players, on the game's goroutine.

func (*Write) Issue added in v0.4.0

func (w *Write) Issue(player *Player, cmd command.Command) error

Issue gives cmd as player (nil for Nobody); ErrUnknownCommand when no handler defines its type.

Directories

Path Synopsis
Package owner is whose an entity is: a tag of the Family a player (Of), saved by its Name, carried by every entity the player owns.
Package owner is whose an entity is: a tag of the Family a player (Of), saved by its Name, carried by every entity the player owns.

Jump to

Keyboard shortcuts

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