package keybinding
import "git.teletypegames.org/engines/inkwell/inkbase/keybinding"
Package keybinding is an inkbase widget: KeyBinding, a key and the action it queues — the whole widget. It draws nothing and occupies nothing; it exists so that "Escape opens the main menu" is a registration like everything else rather than a special case in the loop.
The key is claimed, so nothing underneath sees it, and When is how a binding belongs to one Stage. DuringScript lets it answer while a script holds the frame, which is what a pause key needs.
The widget reaches its game through Host: WidgetInput (an input.Input) and Do. inkwell's *Game is a Host and the root package re-exports KeyBinding.
Index
Types
type Host
type Host interface { // WidgetInput is the frame's consume-on-use input; the binding claims // its key. WidgetInput() *input.Input // Do queues the binding's action. Do(a inkbase.Action) }
Host is what a KeyBinding needs from the game it is ticked for, the UICtx's Game. On a Game that does not implement it the binding is inert.
type KeyBinding
type KeyBinding struct { // Name is the key the widget is registered under. Name string // When gates the binding; nil keeps it live always. When inkbase.Condition // Key is the key that triggers it; zero binds nothing. Key ebiten.Key // Do is the action run on a press; nil does nothing. Do inkbase.Action // DuringScript lets the binding answer on the frames a running script // holds — what a pause key needs, since a cutscene is exactly when the // player reaches for one. DuringScript bool }
KeyBinding is a key and what it does — the whole widget. It draws nothing and occupies nothing; it exists so that "Escape opens the main menu" is a registration like everything else rather than a special case somewhere in the loop.
The key is claimed, so nothing underneath sees it. When gates it the way it gates any widget, which is how a binding belongs to one Stage.
func (*KeyBinding) Draw
func (k *KeyBinding) Draw(dst *ebiten.Image, ctx *widget.UICtx)
Draw does nothing; a binding has no picture.
func (*KeyBinding) GetName
func (k *KeyBinding) GetName() string
GetName returns the name the binding is registered under.
func (*KeyBinding) Layer
func (k *KeyBinding) Layer() widget.Layer
Layer puts the binding on widget.LayerMenu, so it claims its key before the widgets under the menus see it.
func (*KeyBinding) Tick
func (k *KeyBinding) Tick(ctx *widget.UICtx)
Tick claims Key when it was pressed this frame and hands Do to the game. A zero Key or a nil Do makes the binding inert.
func (*KeyBinding) TicksDuringScript
func (k *KeyBinding) TicksDuringScript() bool
TicksDuringScript reports DuringScript.
func (*KeyBinding) VisibleWhen
func (k *KeyBinding) VisibleWhen() inkbase.Condition
VisibleWhen returns the condition that switches the binding on; nil means always.