selection

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: 25 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 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

Constants

This section is empty.

Variables

View Source
var DefaultHighlight = Highlight{Line: color.RGBA{R: 220, G: 40, B: 40, A: 255}, Width: 2}

DefaultHighlight is a thin red outline.

View Source
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.

func (Allow) Command added in v0.3.0

func (Allow) Command()

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.

func (Forbid) Command added in v0.3.0

func (Forbid) Command()

type Highlight added in v0.3.0

type Highlight struct {
	Line  color.RGBA
	Width float32
}

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.

func (Highlight) Style added in v0.3.0

func (Highlight) Style()

Style: a figure declares it on the world's atlas (render.Style).

type Hover added in v0.3.0

type Hover struct {
	At     geom.Vec
	Screen geom.AABB
	Camera camera.Camera
}

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.

func (Hover) Command added in v0.3.0

func (Hover) Command()

type Marquee added in v0.3.0

type Marquee struct {
	Screen geom.AABB
	Camera camera.Camera
}

Marquee is the box of a selection being dragged, in the pixels of the view Camera draws: shown until the Select that ends it.

func (Marquee) Command added in v0.3.0

func (Marquee) Command()

type Plugin

type Plugin struct {
	*world.Self
	// contains filtered or unexported fields
}

Plugin wires selection into a Game; it depends on world and defines the Select command.

func NewPlugin

func NewPlugin(worldPlugin *world.Plugin) *Plugin

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

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

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

func (p *Plugin) FollowKey(key control.Key) control.Binding

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) Install

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

func (*Plugin) KindTemplates added in v0.3.0

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

KindTemplates is what selection asks of the kinds a game defines: every unit marked, so it may be told Allow.

func (*Plugin) Name

func (p *Plugin) Name() string

func (*Plugin) Pointed added in v0.3.0

func (p *Plugin) Pointed() ceremony.Target

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

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

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

func (p *Plugin) RideKey(key control.Key) control.Binding

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) RunPlan

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

func (*Plugin) Selected added in v0.3.0

func (p *Plugin) Selected(roles ...*ceremony.Part) ceremony.Target

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.

func (*Plugin) Tags added in v0.3.0

func (p *Plugin) Tags() Tags

Tags returns selection's tags: for the plugins reading who is Selected.

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

func (r *Read) Any(by command.Issuer) bool

Any reports whether by has a Selected unit it commands; false before the plugin is installed.

func (*Read) Chosen added in v0.4.0

func (r *Read) Chosen(by command.Issuer) (uid.UID64, bool)

Chosen is the one Selected unit player by owns; false with none, or several. Nothing before the plugin is installed.

func (*Read) Fork added in v0.4.0

func (r *Read) Fork() *Read

Fork reads the same selection through a query of its own, for another goroutine; made before the selection's system is set up, it gets it then.

func (*Read) IsSelected added in v0.4.0

func (r *Read) IsSelected(marks tag.Tags[Family]) bool

IsSelected reports whether an entity carrying marks is selected: a drawing rule's condition.

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

func (r *Renderer) Compose(f *render.Frame, cam camera.Camera)

Compose outlines the Selected entities through cam, and the box being dragged in it, marks on top.

func (*Renderer) Init

func (r *Renderer) Init(si *goke.SysInit)

func (*Renderer) Overlies added in v0.3.0

func (*Renderer) Overlies()

Overlies: drawn over the figures' ground (render.Overlying).

func (*Renderer) Publish added in v0.5.0

func (r *Renderer) Publish()

Publish takes every Selected entity, the parts of one unfolded in its stead, and the boxes being dragged, for the frame drawn next.

func (*Renderer) Swap added in v0.5.0

func (r *Renderer) Swap()

Swap has what was published last drawn.

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.

func (Select) Command added in v0.3.0

func (Select) Command()

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.

func (*SelectionSystem) Update

func (s *SelectionSystem) Update(cb *goke.CmdBuf, _ time.Duration)

type Tags added in v0.3.0

type Tags struct {
	Selectable, Selected, Hovered tag.Tag[Family]
}

Tags is selection's tags: Selectable marks an entity the player may select, Selected one the player has, Hovered the one the cursor points at. A kind gives Selectable with comp.Tagged; the plugin flips Selected and Hovered.

Jump to

Keyboard shortcuts

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