Documentation
¶
Overview ¶
Package effect puts states on entities for a while: each effect with its own marker, tags granted, components altered and restored. An effect is defined once, from a Spec of traits, and cast from anywhere — a rule's act.Self.Put, Hold and Take, a command, another pass. A store's binding runs them every step on its entities, so they count down in its time.
Spec, the marker, Grant and Alter ¶
Effects.Define registers an effect from a Spec under a name and Effects.Named is the effect wherever it is built on. Every effect has its own marker of States, "effect.<name>", on while it runs (Effect.Mark; a cond clause of the effect, cond.Self.If(e), asks it in any pass). Lasts is how long a cast holds (without it, until Dispel); Stacking lets casts pile up instead of refreshing; Then casts another effect when this one's time is up, not when it is dispelled; Grant gives tags of a family while the effect runs; Alter changes a Knob — a component its owner only reads — and restores the original after, several Alters of one component stacking in slot order; Described gives it a sentence for a UI. At most 63 effects are defined.
Runtime ¶
Runtime is the effects as a store's binding runs them: Cast and CastFor put an effect on an entity, landing with the effects' next pass, Dispel ends one, Has asks. A binding reads the register's [Definition]s (Effects.Definition, Granted, Alteration) and freezes it as it sets up (Effects.Freeze).
Changed ¶
An entity's markers have Changed on for the step after an Alter rewrote one of its components, as the effect began or ended, so the owner of that component learns of the change without keeping a copy to compare. An effect something is drawn by (Effect.Shows) turns it on as it begins and ends, altering nothing.
Index ¶
- Constants
- type Alteration
- type Definition
- type Effect
- type Effects
- func (e *Effects) Count() int
- func (e *Effects) Define(name string, spec Spec)
- func (e *Effects) Definition(id uint8) *Definition
- func (e *Effects) Freeze()
- func (e *Effects) Guard(guard func(name string))
- func (e *Effects) Lasts(effect Effect) time.Duration
- func (e *Effects) Lookup(name string) (Effect, bool)
- func (e *Effects) Named(name string) Effect
- type Granted
- type Knob
- type Runtime
- type Spec
- type States
- type Trait
Constants ¶
const Changed tag.Tag[States] = 0
Changed is on for the one step after an effect changed the entity's components, as an Alter began or ended.
const Forever = time.Duration(-1)
Forever is the length of a cast that lasts until Dispel.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Alteration ¶ added in v0.2.0
Alteration is a change an effect makes to one component while it runs: Fn turns the value at its address.
type Definition ¶ added in v0.2.0
type Definition struct {
Name string
Lasts time.Duration // 0: Forever
Stacking bool
Grants []Granted
Alters []Alteration
Next uint8 // the effect Then casts, while Follows
Follows bool
Shows bool
// contains filtered or unexported fields
}
Definition is an effect as defined, what a store's binding runs: how long it lasts, what it grants and alters, what follows it.
type Effect ¶
type Effect struct {
// contains filtered or unexported fields
}
Effect is one effect defined with its Effects: what a rule or a plan casts.
func (Effect) Description ¶
Description is what the Spec's Described said of the effect, "" without one.
func (Effect) ID ¶ added in v0.2.0
ID is the effect's place in its register, what a store's binding keeps on an entity.
type Effects ¶
type Effects struct {
// contains filtered or unexported fields
}
Effects is a register of effects: their definitions, by name, which a store's binding runs.
func New ¶
New makes the register, naming each effect's marker with name, which must give Changed first.
func (*Effects) Define ¶
Define registers an effect under name, with its own marker on while it runs (Effect.Mark). It panics once the register is frozen, or past 63 effects.
func (*Effects) Definition ¶ added in v0.2.0
func (e *Effects) Definition(id uint8) *Definition
Definition is the definition of the effect with the id, for the binding; Shows may turn on after the binding is set up, so it reads the definition where it stands.
func (*Effects) Freeze ¶ added in v0.2.0
func (e *Effects) Freeze()
Freeze closes the register: the binding calls it as it is set up, and a Define after panics.
func (*Effects) Lasts ¶ added in v0.2.0
Lasts is how long a cast of effect lasts by its Spec: Forever without a Lasts.
type Granted ¶ added in v0.2.0
Granted is tags of one family an effect gives while it runs: the family's component type, tag.Tags[F], and the bits.
type Knob ¶
type Knob interface{ Knob() }
Knob marks a component an effect may turn: one its owner only reads, so that an Alter ending puts back what it found. A type is one by its method Knob, a mark never called, confirmed where it is defined: var _ effect.Knob = Steering{}.
type Runtime ¶ added in v0.2.0
type Runtime interface {
// Has reports whether id is under effect.
Has(id uid.UID64, effect Effect) bool
// Cast puts effect on id for as long as its Spec says, landing with the effects' next pass;
// cast again, it is refreshed unless it stacks.
Cast(id uid.UID64, effect Effect)
// CastFor is Cast for a set time of the clock's; Forever for one that lasts until Dispel.
CastFor(id uid.UID64, effect Effect, d time.Duration)
// Dispel ends effect on id with the effects' next pass.
Dispel(id uid.UID64, effect Effect)
}
Runtime is the effects as a store's binding runs them on its entities: what a rule's steps, a plan's and a plugin's pass cast and ask through.
type Spec ¶
type Spec []Trait
Spec is the definition of one effect: what it does to an entity and for how long.
type States ¶
type States struct{}
States is the family of an entity's effect markers: Changed and each effect's own (Effect.Mark).
type Trait ¶
type Trait interface {
// contains filtered or unexported methods
}
Trait is one part of a Spec.
func Alter ¶
Alter changes the entity's T while the effect runs; the original comes back after. Several running Alters of one T stack from the original in slot order, whichever ends first.
func Described ¶
Described gives the effect a description for a UI, handed back by Effect.Description.
func Grant ¶
Grant gives the entity these tags of family F while the effect runs, and takes them back after unless another running effect grants them; an entity without the family gets it attached.
func Lasts ¶
Lasts is the default length of every cast of the effect; without it, an effect lasts until Dispel. CastFor overrides it per cast.