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
- Variables
- func Written(t control.Trigger) string
- type ControlsScene
- func (s *ControlsScene) Close(runtime game.Runtime, composition game.Composition)
- func (s *ControlsScene) Drawers() []render.Renderer
- func (*ControlsScene) Focusable() bool
- func (s *ControlsScene) HandleEvents(events *control.InputEvents, runtime game.Runtime, ...)
- func (*ControlsScene) Name() string
- func (s *ControlsScene) Open(runtime game.Runtime, composition game.Composition)
- type Give
- type KeepRunning
- type Player
- type Plugin
- func (p *Plugin) Add(name string) *Player
- func (p *Plugin) DefaultBindings() []control.Binding
- func (p *Plugin) Defaults() []control.Binding
- func (p *Plugin) EventHandler() control.EventHandler
- func (p *Plugin) GameBindings() []control.Binding
- func (p *Plugin) Handle(events *control.InputEvents, runtime game.Runtime, ...)
- func (p *Plugin) Install(ctx plugin.Installer) error
- func (p *Plugin) IssueAs(pl *Player) func(cmd command.Command) error
- func (p *Plugin) KindTemplates(r *kind.Roster)
- func (p *Plugin) Local(name string) *Player
- func (p *Plugin) Name() string
- func (p *Plugin) OwnKeys(keys SceneKeys) *Plugin
- func (p *Plugin) Queues() []command.CommandQueue
- func (p *Plugin) Read(int) *Read
- func (p *Plugin) Restore()
- func (p *Plugin) RunPlan(ctx goke.RunCtx, d time.Duration)
- func (p *Plugin) Scenes() []game.Scene
- func (p *Plugin) Serializable() plugin.Serializable
- func (p *Plugin) Settings() []control.Setting
- func (p *Plugin) Through(pl *Player) ui.Input
- func (p *Plugin) Write() *Write
- type Read
- type Resources
- type SceneKey
- type SceneKeys
- type Settings
- type SettingsScene
- func (s *SettingsScene) Close(runtime game.Runtime, composition game.Composition)
- func (s *SettingsScene) Drawers() []render.Renderer
- func (*SettingsScene) Focusable() bool
- func (s *SettingsScene) HandleEvents(events *control.InputEvents, runtime game.Runtime, ...)
- func (*SettingsScene) Name() string
- func (s *SettingsScene) Open(runtime game.Runtime, composition game.Composition)
- type ShowControls
- type ShowSettings
- type Write
Constants ¶
const ControlsName = "gram.controls"
ControlsName is the name of the controls scene in a game's stack.
const SettingsName = "gram.settings"
SettingsName is the name of the settings scene in a game's stack.
Variables ¶
var ErrUnknownCommand = errors.New("players: no plugin listens for this command")
ErrUnknownCommand is what Issue reports for a command type no handler defines.
Functions ¶
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 ¶
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.
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 ¶
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 ¶
Area is the player's part of the screen, in pixels, as its picture was last laid out.
func (*Player) Bind ¶
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".
type Plugin ¶
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 ¶
Add adds a player without a keyboard, an AI or a remote client, whose commands come in through Issue.
func (*Plugin) DefaultBindings ¶
DefaultBindings are GameBindings.
func (*Plugin) EventHandler ¶
func (p *Plugin) EventHandler() control.EventHandler
EventHandler translates this tick's input through every local player's bindings.
func (*Plugin) GameBindings ¶
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) IssueAs ¶
IssueAs is Issue for pl: how a scene's buttons and keys give their commands (ui.Scene.Issue).
func (*Plugin) KindTemplates ¶
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 ¶
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) OwnKeys ¶
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
Read reads the players on worker w of the game's pool, 0 the game's own goroutine.
func (*Plugin) RunPlan ¶
RunPlan hands over the units given and issues the keys held for the next tick; call it last in Update.
func (*Plugin) Scenes ¶
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 ¶
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.
type Read ¶ added in v0.4.0
type Read struct {
// contains filtered or unexported fields
}
Read reads the players, the same on every goroutine.
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()