effect

package
v0.1.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: 7 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. The store that makes the effects runs their system every step, 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.

Active, Cast and Dispel

Active is what an entity is under, saved with it; Wide is the same with a slot for every effect, for an entity standing for a whole pass or for the whole. Effects.Cast and Effects.CastFor put an effect on an entity, landing with the effects' next pass; Effects.Dispel ends one; Effects.Has and the handle's Effect.On ask.

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 Left of a slot that lasts until Dispel.

Variables

This section is empty.

Functions

This section is empty.

Types

type Active

type Active struct {
	Slots [maxEffects]effectSlot
}

Active is what an entity is under: up to eight effects, saved with the entity.

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

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

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

func (Effect) On

func (e Effect) On(id uid.UID64) bool

On reports whether id is under the effect.

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 Stage's register of effects, which the world makes and runs (world.Plugin.Effects).

func New

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

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

func (*Effects) Cast

func (e *Effects) Cast(cb *goke.CmdBuf, id uid.UID64, effect Effect)

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.

func (*Effects) CastFor

func (e *Effects) CastFor(cb *goke.CmdBuf, id uid.UID64, effect Effect, d time.Duration)

CastFor is Cast for a set time of the clock's; Forever for one that lasts until Dispel.

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 game is set up, or past 63 effects.

func (*Effects) Dispel

func (e *Effects) Dispel(id uid.UID64, effect Effect)

Dispel ends effect on id with the effects' next pass.

func (*Effects) Guard

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

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

func (*Effects) Has

func (e *Effects) Has(id uid.UID64, effect Effect) bool

Has reports whether id is under effect.

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

func (e *Effects) Module() goke.Module

Module is the effects as a goke.Module, for the world to install.

func (*Effects) Named

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

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

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

type Wide

type Wide struct {
	Slots [wideEffects]effectSlot
}

Wide is an Active with a slot for every effect a game may define: what a plugin's own entity is under, saved with it.

Jump to

Keyboard shortcuts

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