Documentation
¶
Overview ¶
Package selection turns Select commands into a Selected tag on Selectable world entities. Its default bindings make a left drag one (Shift adds) and C has the camera follow the one selected unit; the renderer outlines what is selected, each kind in its Highlight.
Selectable, Selected and Hovered ¶
Tags are bits of selection's tag Family, which every unit carries, all off: Selectable marks an entity the player may select, told Allow as it is made (kind.Entry.Told) or later and taken back by Forbid; Selected one the player has selected; Hovered the one the cursor points at, given by a Hover every tick the cursor lies over the world. Plugin.Tags is for the plugins reading them; a drawing rule asks Read.IsSelected. A Select names entities by id or by a box, additive or not, and with a Camera the screen rectangle the player drew picks them where that camera draws them; SelectionSystem carries it out. Where the world draws a kind's loose units far off as one banner (world.Banners), a click on the banner picks them all, and none where they stand. A part of an aggregate (world.PartOf) not Selectable itself stands for its whole, which while unfolded is hit through its parts alone: a Select or a Hover reaching the part picks the whole where the player may select it, and the renderer outlines the parts of a selected whole unfolded in the whole's Highlight.
Whose units ¶
A player selects its own units alone (owner.Obeys), so one Selected tag serves every player; only a Select nobody gave reaches the units nobody owns. Plugin.FollowKey (C by default) fastens the camera the player looks through over the one unit it has selected (Read.Chosen); Plugin.RideKey (V by default) fastens it behind that unit while the camera is fastened to nothing, the cameras' own V taking it on from there. Read.Any is whether a player has any, which navigation's right drag asks.
Selected and Pointed ¶
A command about an effect (ceremony.Put, Take, Toggle) says whom it is for with On, and the selection carries out two: Plugin.Selected, the units the player who gives it has selected, those playing one of the roles named when any is, and Plugin.Pointed, the entity drawn under the cursor as the command's key is pressed.
hasten := ceremony.Put(haste).On(s.selection.Selected(hasty)) freeze := ceremony.Put(frozen).On(s.selection.Pointed()).For(3 * time.Second)
Renderer ¶
The plugin draws with a Renderer, outlining every Selected entity in its kind's Highlight (DefaultHighlight a thin red outline) and the box of a selection being dragged (Marquee), one per camera: marks over the world, the box over the outlines.
Vocabulary ¶
Commands: Select, Marquee, Hover (a player's); Allow, Forbid (a player's or an entity's own: whether it may be selected). The commands about effects for Plugin.Selected and Plugin.Pointed are routed here.
Styles, for a figure's Look on the world's atlas (Slot.Styled): Highlight, how a kind's selected entities are outlined, DefaultHighlight without.
Index ¶
- Variables
- type Allow
- type Family
- type Forbid
- type Highlight
- type Hover
- type Marquee
- type Plugin
- func (p *Plugin) DefaultBindings() []control.Binding
- func (p *Plugin) EventHandler() control.EventHandler
- func (p *Plugin) FollowKey(key control.Key) control.Binding
- func (p *Plugin) Install(ctx plugin.Installer) error
- func (p *Plugin) KindTemplates(r *kind.Roster)
- func (p *Plugin) Name() string
- func (p *Plugin) Pointed() ceremony.Target
- func (p *Plugin) Queues() []command.CommandQueue
- func (p *Plugin) Read(w int) *Read
- func (p *Plugin) RideKey(key control.Key) control.Binding
- func (p *Plugin) RunPlan(ctx goke.RunCtx, d time.Duration)
- func (p *Plugin) Selected(roles ...*ceremony.Part) ceremony.Target
- func (p *Plugin) Serializable() plugin.Serializable
- func (p *Plugin) Tags() Tags
- type Read
- type Renderer
- type Select
- type SelectionSystem
- type Tags
Constants ¶
This section is empty.
Variables ¶
var DefaultHighlight = Highlight{Line: color.RGBA{R: 220, G: 40, B: 40, A: 255}, Width: 2}
DefaultHighlight is a thin red outline.
var MarqueeColor = color.RGBA{R: 255, G: 140, B: 0, A: 255}
MarqueeColor is the outline of a selection box being dragged.
Functions ¶
This section is empty.
Types ¶
type Allow ¶ added in v0.3.0
type Allow struct{ Selected bool }
Allow is the command by which an entity may be selected from now on, with Selected selected at once too. An entity gives it itself (kind.Entry.Told); a player's goes to its selected units.
type Family ¶ added in v0.3.0
type Family struct{}
Family is selection's tag family: Selectable and Selected live in it.
type Forbid ¶ added in v0.3.0
type Forbid struct{}
Forbid is the command by which an entity may be selected no longer, and is unselected.
type Highlight ¶ added in v0.3.0
Highlight is how a Selected entity of a kind is outlined: its footprint, the ground under it on screen, stroked in Line, Width pixels wide, a mark on top (render.OnTop). A figure declares it on the world's atlas (Slot.Styled); a kind without one is outlined by DefaultHighlight.
type Hover ¶ added in v0.3.0
Hover is the command noting the entity drawn under the cursor as Hovered, given every tick the cursor lies over the player's picture. A tick without one, nobody is Hovered.
type Marquee ¶ added in v0.3.0
Marquee is the box of a selection being dragged, in the pixels of the view Camera draws: shown until the Select that ends it.
type Plugin ¶
Plugin wires selection into a Game; it depends on world and defines the Select command.
func NewPlugin ¶
NewPlugin builds the selection plugin over worldPlugin's space; hand it to the players plugin for its Select command and default bindings.
func (*Plugin) DefaultBindings ¶ added in v0.3.0
DefaultBindings is a left drag (a click is a drag of no length) into a Select of the box it drew, Shift for an additive one, the box shown as a Marquee while the button is held, C to follow the one unit chosen (FollowKey), V to ride behind it with the camera loose (RideKey), and the cursor over the world into a Hover.
func (*Plugin) EventHandler ¶
func (p *Plugin) EventHandler() control.EventHandler
EventHandler is nil: a player's bindings issue the commands.
func (*Plugin) FollowKey ¶ added in v0.3.0
FollowKey is key fastening the camera the player looks through over the one unit it has chosen (Chosen), or letting it go: a cameras.Follow.
func (*Plugin) KindTemplates ¶ added in v0.3.0
KindTemplates is what selection asks of the kinds a game defines: every unit marked, so it may be told Allow.
func (*Plugin) Pointed ¶ added in v0.3.0
Pointed is whom a command is for (ceremony.Take(frozen).On(sel.Pointed())): the entity under the cursor as the command's key is pressed. A command given without a cursor reaches nobody.
func (*Plugin) Queues ¶ added in v0.3.0
func (p *Plugin) Queues() []command.CommandQueue
Queues are where the selection's commands land.
func (*Plugin) Read ¶ added in v0.4.0
Read reads the selection on worker w of the game's pool, 0 the game's own goroutine; the other workers' reads come with Install.
func (*Plugin) RideKey ¶ added in v0.6.0
RideKey is key fastening the camera the player looks through behind the one unit it has chosen (Chosen), a cameras.Ride: held while the camera is fastened to nothing, the cameras' own key taking it on from there.
func (*Plugin) Selected ¶ added in v0.3.0
Selected is whom a command is for (ceremony.Put(haste).On(sel.Selected(hasty))): the units the player who gives it has selected, those playing one of roles alone when any is named.
func (*Plugin) Serializable ¶
func (p *Plugin) Serializable() plugin.Serializable
Serializable is nil: selection has nothing to persist.
type Read ¶ added in v0.4.0
type Read struct {
// contains filtered or unexported fields
}
Read reads the selection on one goroutine at a time: Plugin.Read(w), worker w's, through a query of its own.
func (*Read) Any ¶ added in v0.6.0
Any reports whether by has a Selected unit it commands; false before the plugin is installed.
func (*Read) Chosen ¶ added in v0.4.0
Chosen is the one Selected unit player by owns; false with none, or several. Nothing before the plugin is installed.
type Renderer ¶
type Renderer struct {
// contains filtered or unexported fields
}
Renderer outlines every Selected entity and, when the plugin built it, the box being dragged in the viewport's camera, as published once a frame.
func NewRenderer ¶
func NewRenderer( selected tag.Tag[Family], look func() world.Look, styles func() *render.Styles, ) *Renderer
NewRenderer builds a Renderer outlining what look draws, each kind as the Highlight styles hold for it, DefaultHighlight without; styles may give nil.
func (*Renderer) Compose ¶ added in v0.3.0
Compose outlines the Selected entities through cam, and the box being dragged in it, marks on top.
func (*Renderer) Overlies ¶ added in v0.3.0
func (*Renderer) Overlies()
Overlies: drawn over the figures' ground (render.Overlying).
type Select ¶ added in v0.3.0
type Select struct {
IDs []uid.UID64
Box geom.AABB
// Screen is the rectangle the player picked in, in the pixels of the view Camera draws; with
// Camera, it decides which of the entities in Box are hit by where they are drawn.
Screen geom.AABB
Camera camera.Camera
Additive bool
}
Select is the command to select: exactly IDs when given, else every Selectable entity in Box (world units); Additive keeps what was selected before.
type SelectionSystem ¶
type SelectionSystem struct {
// contains filtered or unexported fields
}
SelectionSystem carries out the selection's commands: Select as the Selected tag on the Selectable entities the player owns, a command for the selected or the pointed at, Hovered on the entity each Hover points at.
func NewSelectionSystem ¶
func NewSelectionSystem( selects *command.Queue[Select], space *aabbworld.Space, tags Tags, look func() world.Look, ) *SelectionSystem
NewSelectionSystem builds a SelectionSystem draining selects over space, picking through each command's camera what look draws there.
func (*SelectionSystem) Init ¶
func (s *SelectionSystem) Init(si *goke.SysInit)
func (*SelectionSystem) Paced ¶ added in v0.18.0
func (s *SelectionSystem) Paced(pace goke.Opt) *SelectionSystem
Paced has the system walk the marked entities as pace, an option of its query, says; set it before Init.