Documentation
¶
Overview ¶
Package control is the input vocabulary: what the engine captures each frame, and the commands and bindings a game is driven by.
InputEvents ¶
InputEvents is one tick's input: the mouse (where it is, and whether the window has it), the modifiers, the scroll delta and a queue of [ClickEvent]s and [KeyEvent]s. An EventHandler reacts to it once a tick; the active Scene's HandleEvents is one.
Commands and bindings ¶
A command is an intention in the game's vocabulary, as data: a type is a command.Command by its method command.Command, confirmed where it is defined (var _ command.Command = MoveTo{}). The plugin that defines a command's type keeps a [Queue] of it and drains it in its own pass, each command.Issued with the command.Issuer that gave it, or the entity that gave it itself; a command.Carrier sorts commands into the queues of their types. Traits a command may have besides are asked for where they matter: command.Routed, Contextual. A Binding is a Trigger (KeyPress, KeyDown, KeyHeld, KeyReleased — let go, Context.Held how long it was down — ButtonPress, Drag, Wheel, ButtonHeld, CursorAtEdge — the cursor within EdgeMargin of the picture's edge, or in a corner's square of CornerReach a side, CornerSide for a small picture (Edges, Corner, Edges.Depth how deep in, for a scroll quickening to the edge), CursorInCorner there alone — CursorMove, CursorOver) with exactly its Mods, the command Build makes from a Context or Give names, and a label for the list of keys; a key held, down or let go fires with Shift, Ctrl or Alt held only Binding.InChords; a binding Binding.Yielding fires only when no other on its trigger builds a command. A Context carries the player, its camera, the cursor in the camera's pixels (Context.Dragged: past a click's slop from where the button went down) and the point picked in the world through the camera.
Settings ¶
A Setting is one thing of a plugin's the players adjust on the settings screen: a Switch on or off, a Choice among options, a Range of a number. Each reads its value every frame and builds, from the value chosen, the command that sets it; a key bound to the same command builds the next value instead. A setting names the section of the screen it is listed under (Picture, Graphics, Game and the rest), or is listed under its plugin's; a Range may lie beside a Switch of its section (Range.Beside), in its row, live while the switch is on.
Tools ¶
A Tool is what a player holds in hand, taken with Take and put down with Drop. A binding With a tool fires only while the player holds it, in place of the bindings with none.
Index ¶
- Constants
- func CaptureCursor(on bool)
- func CornerSide(w, h float32) float32
- func FullscreenKey() (key, label string)
- func ScreenRect(a, b geom.Vec) geom.AABB
- func SectionOf(s Setting) string
- func SetCursorCapture(fn func(on bool))
- func SetFullscreenKey(key, label string)
- type Binding
- func (b Binding) Build(c Context) (command.Command, bool)
- func (b Binding) Holds(how camera.How) bool
- func (b Binding) In(hows ...camera.How) Binding
- func (b Binding) InChords() Binding
- func (b Binding) Overlaps(o Binding) bool
- func (b Binding) Takes(mods Mods) bool
- func (b Binding) Tool() Tool
- func (b Binding) Type() reflect.Type
- func (b Binding) With(tool Tool) Binding
- func (b Binding) Yielding() Binding
- func (b Binding) Yields() bool
- type ButtonHeld
- type ButtonPress
- type Choice
- type ClickEvent
- type Context
- func (c Context) Dragged() bool
- func (c Context) Edges() Edges
- func (c Context) Pixels(shown float32) float32
- func (c Context) Point(s geom.Vec) (at geom.Vec, z float32, picked bool)
- func (c Context) Shown(v geom.Vec) geom.Vec
- func (c Context) World(s geom.Vec) geom.Vec
- func (c Context) WorldBox(a, b geom.Vec) geom.AABB
- type Contextual
- type Corner
- type CursorAtEdge
- type CursorInCorner
- type CursorMove
- type CursorOver
- type Drag
- type Drop
- type Edges
- type EventHandler
- type InputEvents
- type Key
- type KeyAction
- type KeyDown
- type KeyEvent
- type KeyHeld
- type KeyPress
- type KeyReleased
- type Mods
- type MouseButton
- type Range
- type Setting
- type Switch
- type Take
- type Tool
- type Trigger
- type Wheel
Constants ¶
const ( // EdgeMargin is how close to a window edge, in pixels, the cursor rests at it (CursorAtEdge). EdgeMargin = 60 // CornerReach is the side of the square at each corner, in pixels, within which the cursor // rests in the corner; CornerSide caps it for a small picture. CornerReach = 120 // DragSlop is how far, in shown pixels, the cursor may move from where a button went down // for a click, not a drag (Context.Dragged). DragSlop = 4 )
const ( Picture = "Picture" PictureTactical = "Picture/Tactical" PictureTacticalLayers = "Picture/Tactical/Layers" PictureRiding = "Picture/Riding" PictureRidingLayers = "Picture/Riding/Layers" PictureShadows = "Picture/Shadows" PictureAreas = "Picture/Areas" Graphics = "Picture/Graphics" Game = "Game" )
The sections of the settings screen the plugins share: the picture, how it is drawn in a tactical view and riding in first person and the layers of each, the areas shown, the graphics, and the game: what a player sees of the world's own rules.
const Keys = int(keyCount)
Keys is how many keys there are, for going over all of them.
Variables ¶
This section is empty.
Functions ¶
func CaptureCursor ¶ added in v0.3.0
func CaptureCursor(on bool)
CaptureCursor catches the window's cursor — hidden, the mouse moving without end — or shows it again; nothing without a window.
func CornerSide ¶ added in v0.3.0
CornerSide is the side of a corner's square in a picture w by h pixels: CornerReach, or a quarter of the shorter side where that is less.
func FullscreenKey ¶ added in v0.6.0
func FullscreenKey() (key, label string)
FullscreenKey is the key that switches full screen and its label for the controls screen: F11, unless the engine said otherwise.
func ScreenRect ¶ added in v0.3.0
ScreenRect is the screen rectangle between a and b, at least a pixel a side.
func SectionOf ¶ added in v0.3.0
SectionOf is the section s is listed under; empty for the plugin's own.
func SetCursorCapture ¶ added in v0.3.0
func SetCursorCapture(fn func(on bool))
SetCursorCapture is the engine's: how the window catches its cursor and lets it go.
func SetFullscreenKey ¶ added in v0.6.0
func SetFullscreenKey(key, label string)
SetFullscreenKey is the engine's: the key that switches full screen on this platform and what the controls screen says of it, where the system keeps F11 for itself.
Types ¶
type Binding ¶ added in v0.3.0
Binding is one thing a player can do: a Trigger, the command it issues and a label for a help screen. Make one with Build or Give.
func Build ¶ added in v0.3.0
func Build[C command.Command]( trigger Trigger, label string, build func(c Context) (C, bool), ) Binding
Build is a Binding issuing a C built from the Context when trigger fires; build may decline.
func Give ¶ added in v0.3.0
Give is a Binding issuing cmd whenever trigger fires, a Contextual one for the Context. A command kept in a register (a ceremony.command.Command) must come from it: one made on the spot panics.
func (Binding) Holds ¶ added in v0.3.0
Holds reports whether b holds while the camera is fastened how.
func (Binding) In ¶ added in v0.3.0
In is b holding only while the player's camera is fastened one of hows (camera.HowOf). A binding never given hows holds whatever the camera does.
func (Binding) InChords ¶ added in v0.3.0
InChords is b, on a key held, down or let go, firing with Shift, Ctrl or Alt held too: a sprint with Shift, a jump while sprinting. Without it such a binding leaves the chords to the shortcuts.
func (Binding) Overlaps ¶ added in v0.3.0
Overlaps reports whether b and o hold in some How both with one tool, both yielding or neither: two such bindings on one Trigger would both fire.
func (Binding) Takes ¶ added in v0.3.0
Takes reports whether b fires with mods held: a key's or a button's press and a drag as their triggers ask; a key held, down or let go with no modifier but the key itself, unless InChords.
func (Binding) Tool ¶ added in v0.3.0
Tool is the tool b holds with; none for a binding holding whatever the player holds.
func (Binding) Type ¶ added in v0.3.0
Type is the type of command the binding issues; nil for one made with neither Build nor Give.
func (Binding) With ¶ added in v0.3.0
With is b holding only while the player holds tool, its trigger taken from the bindings with no tool.
type ButtonHeld ¶ added in v0.3.0
type ButtonHeld struct{ Button MouseButton }
ButtonHeld fires every pass Button is down and the cursor moved inside the window; Context.Delta is by how much and Context.Start where the button went down.
type ButtonPress ¶ added in v0.3.0
type ButtonPress struct {
Button MouseButton
Mods Mods
}
ButtonPress fires when Button goes down with Mods held; Context.Cursor is where.
type Choice ¶ added in v0.3.0
type Choice struct {
Label string
Section string
Options []string
Get func() int
Set func(i int) command.Command
}
Choice is a setting with one of its Options chosen, Get and Set by its index.
type ClickEvent ¶
type ClickEvent struct {
Pos geom.Vec
Button MouseButton
Action KeyAction
}
type Context ¶ added in v0.3.0
type Context struct {
Player command.Issuer
Camera camera.Camera
Cursor geom.Vec // where the cursor is, or where a button went down or up
Start geom.Vec // where a Drag began
Delta geom.Vec
Wheel float32
Screen geom.Vec // the picture's size in the camera's pixels
Resolution float32 // camera pixels a shown pixel; 0 as 1
Mods Mods
Held time.Duration // how long a key was held, for KeyReleased
}
Context is what a binding builds its command from: the player, its camera and this tick's input in the camera's pixels, Resolution of them a shown one; World and WorldBox go through the camera.
func (Context) Dragged ¶ added in v0.6.0
Dragged reports whether the cursor has moved past DragSlop from where the button went down (Start): a drag, not a click.
func (Context) Edges ¶ added in v0.3.0
Edges is which window edges the cursor rests near and in which corner's square of CornerReach a side, the margins in shown pixels; a cursor outside the window rests near none.
func (Context) Pixels ¶ added in v0.3.0
Pixels is shown pixels in the camera's: a speed in pixels of the screen as the camera has it.
func (Context) Point ¶ added in v0.3.0
Point is what screen position s sees and its height, through a camera.Picker's own Pick. Where the camera picks nothing (no Picker, or the sky) picked is false and at is World.
func (Context) Shown ¶ added in v0.3.0
Shown is v, in the camera's pixels, in the shown ones: a move of the mouse as the hand made it.
type Contextual ¶ added in v0.3.0
Contextual is a command that reads where it was given: In is the command for the Context its trigger fired in — the one pointed at with the cursor.
type Corner ¶ added in v0.3.0
type Corner uint8
Corner is which corner of the window a cursor rests in, NoCorner for none.
type CursorAtEdge ¶ added in v0.3.0
type CursorAtEdge struct{}
CursorAtEdge fires every tick the cursor rests near a window edge; the carrier says how near.
type CursorInCorner ¶ added in v0.3.0
type CursorInCorner struct{}
CursorInCorner fires every tick the cursor rests in a corner's square, as CursorAtEdge does too; Context.Edges says which corner.
type CursorMove ¶ added in v0.3.0
type CursorMove struct{}
CursorMove fires every pass the cursor moves, Context.Delta by how much. It reaches the player the cursor is over, and one whose camera rides in an entity wherever the cursor is.
type CursorOver ¶ added in v0.3.0
type CursorOver struct{}
CursorOver fires once a tick while the cursor lies over the player's picture of the world, still or not, its command landing in the tick after.
type Drag ¶ added in v0.3.0
type Drag struct {
Button MouseButton
Mods Mods
}
Drag fires when Button comes up with Mods held, after going down: Context.Start is where it went down, Context.Cursor where it came up. A click is a Drag of no length.
type Drop ¶ added in v0.3.0
type Drop struct{}
Drop has the player who gives it put down the tool it holds.
type Edges ¶ added in v0.3.0
Edges are the window edges a cursor rests near, the corner it rests in, and how Deep in the strip or the corner's square it stands: 0 at the inner bound, 1 at the window's edge, in a corner the deeper of the two ways.
type EventHandler ¶
type EventHandler interface {
HandleEvents(events *InputEvents)
}
EventHandler reacts to this tick's input events.
type InputEvents ¶
type InputEvents struct {
MousePos geom.Vec
CursorDelta geom.Vec
Modifiers struct {
Shift, Ctrl, Alt bool
}
MiddleDown bool
// CursorInWindow reports whether the window has the cursor: it came in and has not left
// since. MousePos is where it was last seen, zero before any.
CursorInWindow bool
ClickQueue []ClickEvent
KeyEvents []KeyEvent
ScrollDelta float32
}
func (*InputEvents) AddClickEvent ¶
func (e *InputEvents) AddClickEvent(x, y int, button MouseButton, action KeyAction)
func (*InputEvents) AddKeyEvent ¶
func (e *InputEvents) AddKeyEvent(key Key, action KeyAction)
func (*InputEvents) ResetTransient ¶
func (e *InputEvents) ResetTransient()
type Key ¶ added in v0.3.0
type Key uint16
Key is a key of the keyboard, by its place on it; Shift, Control and Alt are either of the two.
const ( KeyUnknown Key = iota KeyA KeyB KeyC KeyD KeyE KeyF KeyG KeyH KeyI KeyJ KeyK KeyL KeyM KeyN KeyO KeyP KeyQ KeyR KeyS KeyT KeyU KeyV KeyW KeyX KeyY KeyZ Key0 Key1 Key2 Key3 Key4 Key5 Key6 Key7 Key8 Key9 KeyF1 KeyF2 KeyF3 KeyF4 KeyF5 KeyF6 KeyF7 KeyF8 KeyF9 KeyF10 KeyF11 KeyF12 KeyEscape KeyEnter KeySpace KeyTab KeyBackspace KeyDelete KeyInsert KeyHome KeyEnd KeyPageUp KeyPageDown KeyArrowUp KeyArrowDown KeyArrowLeft KeyArrowRight KeyShift KeyControl KeyAlt KeyMinus KeyEqual KeyBracketLeft KeyBracketRight KeyBackslash KeySemicolon KeyQuote KeyBackquote KeyComma KeyPeriod KeySlash KeyCapsLock KeyNumpad0 KeyNumpad1 KeyNumpad2 KeyNumpad3 KeyNumpad4 KeyNumpad5 KeyNumpad6 KeyNumpad7 KeyNumpad8 KeyNumpad9 KeyNumpadAdd KeyNumpadSubtract KeyNumpadMultiply KeyNumpadDivide KeyNumpadDecimal KeyNumpadEnter )
The keys, named as Ebitengine named them.
type KeyDown ¶ added in v0.3.0
type KeyDown struct{ Key Key }
KeyDown fires when Key goes down, whatever other key is held; with Shift, Ctrl or Alt held only as a binding InChords: a jump while sprinting with Shift.
type KeyHeld ¶ added in v0.3.0
type KeyHeld struct{ Key Key }
KeyHeld fires once a tick while Key is down, whatever other key is held, with Shift, Ctrl or Alt only as a binding InChords; its command lands in the tick after. A key tapped between two ticks never fires.
type KeyReleased ¶ added in v0.3.0
type KeyReleased struct{ Key Key }
KeyReleased fires when Key comes up, Context.Held saying how long it was down: a throw as strong as the key was held. A key held for a chord with modifiers (Shift+X) does not fire it, nor one let go with a modifier held besides it, unless the binding is InChords.
type Mods ¶ added in v0.3.0
type Mods struct {
Shift, Ctrl, Alt bool
// contains filtered or unexported fields
}
Mods is the modifier keys a trigger asks for, and at most one other key held down with them (see Holding); a trigger fires only with exactly these held.
type MouseButton ¶ added in v0.3.0
type MouseButton uint8
MouseButton is a button of the mouse.
const ( MouseButtonLeft MouseButton = iota MouseButtonRight MouseButtonMiddle )
type Range ¶ added in v0.3.0
type Range struct {
Label string
Section string
Beside string
Min float64
Max float64
Step float64
Get func() float64
Set func(v float64) command.Command
Shows func(v float64) string
}
Range is a setting of a number between Min and Max, moved a Step at a time; Shows writes the number for the player (nil: as it is). Beside names a Switch of the same section the range lies beside, in its row, live while the switch is on; empty, the range has a row of its own.
type Setting ¶ added in v0.3.0
type Setting interface {
// contains filtered or unexported methods
}
Setting is one thing of a plugin's the players adjust on the settings screen, a control each: a Switch, a Choice or a Range. Get is read every frame; Set builds the command carrying the value chosen, which the screen issues as a button issues its commands. Section is the section the setting is listed under, a path of levels ("Picture/Graphics"); empty, the plugin's own.
type Switch ¶ added in v0.3.0
type Switch struct {
Label string
Section string
Get func() bool
Set func(on bool) command.Command
}
Switch is a setting that is on or off.
type Take ¶ added in v0.3.0
type Take struct{ Tool Tool }
Take has the player who gives it hold Tool in hand, putting down whatever it held.
type Tool ¶ added in v0.3.0
type Tool string
Tool is what a player holds in hand, by name. While it holds one, the bindings With it take their triggers from the bindings with none.