effect

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 13, 2026 License: MIT Imports: 6 Imported by: ? modules, 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 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

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

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

type Alteration struct {
	Comp reflect.Type
	Fn   func(v unsafe.Pointer)
}

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

func (e Effect) Description() string

Description is what the Spec's Described said of the effect, "" without one.

func (Effect) ID added in v0.2.0

func (e Effect) ID() uint8

ID is the effect's place in its register, what a store's binding keeps on an entity.

func (Effect) Mark

func (e Effect) Mark() tag.Tag[States]

Mark is the effect's own marker, on while it runs.

func (Effect) Shows

func (e Effect) Shows()

Shows says something is drawn by the effect's marker: the entity's Changed goes on as the effect begins and ends, though it alters nothing.

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

func New(name func(name string) tag.Tag[States]) *Effects

New makes the register, naming each effect's marker with name, which must give Changed first.

func (*Effects) Count added in v0.2.0

func (e *Effects) Count() int

Count is how many effects are defined.

func (*Effects) Define

func (e *Effects) Define(name string, spec Spec)

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

func (e *Effects) Guard(guard func(name string))

Guard has Define call guard with each effect's name first.

func (*Effects) Lasts added in v0.2.0

func (e *Effects) Lasts(effect Effect) time.Duration

Lasts is how long a cast of effect lasts by its Spec: Forever without a Lasts.

func (*Effects) Lookup

func (e *Effects) Lookup(name string) (Effect, bool)

Lookup is Named for a name that may be unknown: false for one.

func (*Effects) Named

func (e *Effects) Named(name string) Effect

Named is the effect defined as name. An unknown name panics.

type Granted added in v0.2.0

type Granted struct {
	Family reflect.Type
	Bits   uint64
}

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

func Alter[T Knob](fn func(v *T)) Trait

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

func Described(text string) Trait

Described gives the effect a description for a UI, handed back by Effect.Description.

func Grant

func Grant[F any](tags ...tag.Tag[F]) Trait

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

func Lasts(d time.Duration) Trait

Lasts is the default length of every cast of the effect; without it, an effect lasts until Dispel. CastFor overrides it per cast.

func Stacking

func Stacking() Trait

Stacking makes a repeated Cast add a slot instead of refreshing the one there.

func Then

func Then(next Effect) Trait

Then casts next once the effect runs out, not when it is dispelled. next is one of the same Effects, defined before.

Jump to

Keyboard shortcuts

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