kind

package
v0.24.0 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2026 License: MIT Imports: 6 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 kind is how a game says what its entities are. A Spec lists the components a kind carries, each made in package comp (the same for all, comp.Const, or read from the entity's own row, comp.Load); Define registers it with a world, and the kind's Entry puts one entity on the roster.

Define, Named and Of

Define registers a Spec under a name with a Registry, a world's; Named is the kind as Of, typed by its row: Entry builds one Entry for world.Write.Seed with the row checked by the compiler, ID is the ID every entity of the kind carries, SpriteID the atlas slot its entities are drawn from. A world.Position and a world.Velocity must each appear once in a Spec, or Define panics by name; so does a Load over a row type other than the kind's.

Roster

A Template is a sort of kind a plugin brings in by name (NewTemplate: what the world spawns, what moves, a board's cell), under a parent whose asks come with its own; the package knows none. A Roster is what the plugins of a world ask of the kinds of each template: what they require (Require: the game must supply a component of that type) and what they bring themselves (Roster.Default, which the game may override or leave out with comp.Without). It is written once, as it is first read, by every plugin's KindTemplates in the order made, and refuses a write anywhere else; Roster.Spec builds a kind's Spec of a template and panics naming every requirement left unmet.

Registry

Registry is where kinds are kept, behind an interface because kind never imports world. One Registry holds at most MaxKinds kinds.

Index

Constants

View Source
const MaxKinds = 1 << 8

MaxKinds is how many kinds one Registry can hold, bounded by ID.

Variables

This section is empty.

Functions

func Define

func Define[P any](reg Registry, name string, spec Spec)

Define registers spec under name as a kind whose rows are P; a Load of another row type panics. It hands nothing back: Named is the kind, for whoever spawns its entities.

func Require

func Require[T any](r *Roster, t *Template, by, why string)

Require says plugin by needs every entity of a kind of template t to carry a T, and why.

Types

type Entry

type Entry struct {
	// contains filtered or unexported fields
}

Entry is one entity to spawn: its kind and its row — built by Of.Entry or EntryOf.

func EntryOf

func EntryOf(name string, row any) Entry

EntryOf is one entity of the kind defined as name, described by row, for whoever knows the row's type only as the program runs. The world refuses a row of another type.

func (Entry) Commands

func (e Entry) Commands() []command.Command

Commands are the commands the entity gives itself as it is made.

func (Entry) Group

func (e Entry) Group() string

Group is the group the entity is in, empty for none.

func (Entry) InGroup

func (e Entry) InGroup(group string) Entry

InGroup is the entry of an entity in group, with any number of others: what ceremony.Group finds it by.

func (Entry) Kind

func (e Entry) Kind() string

Kind names the kind this entity is of.

func (Entry) Name

func (e Entry) Name() string

Name is the name the entity bears, empty for none.

func (Entry) Named

func (e Entry) Named(name string) Entry

Named is the entry of an entity bearing name, its alone: what ceremony.Named finds it by.

func (Entry) Row

func (e Entry) Row() any

Row is what describes this entity to its kind's Loads.

func (Entry) Told

func (e Entry) Told(cmds ...command.Command) Entry

Told is the entry of an entity given cmds as it is made: the commands it gives itself then.

type ID

type ID uint8

ID identifies an entity's kind, carried on every entity a world spawns.

type Of

type Of[P any] struct {
	// contains filtered or unexported fields
}

Of is one defined kind, whose entities are each described by a row of type P.

func Named

func Named[P any](reg Registry, name string) Of[P]

Named is the kind defined as name, whose rows are P; an unknown name, or a kind of other rows, panics.

func (Of[P]) Entry

func (k Of[P]) Entry(row P) Entry

Entry is one entity of this kind, described by row — hand it to world.Write.Seed.

func (Of[P]) ID

func (k Of[P]) ID() ID

ID is what every entity of this kind carries to say so.

func (Of[P]) Name

func (k Of[P]) Name() string

Name is what the kind was defined as.

func (Of[P]) SpriteID

func (k Of[P]) SpriteID() render.SpriteID

SpriteID is the atlas slot this kind's entities are drawn from.

type Registry

type Registry interface {
	Register(name string, row reflect.Type, spec Spec) (ID, render.SpriteID)
	// Lookup is the kind registered as name: its ID, its sprite and the type of its rows.
	Lookup(name string) (id ID, sprite render.SpriteID, row reflect.Type, ok bool)
}

Registry is where kinds are kept — a world's, reached through world.Plugin.Kinds.

type Roster

type Roster struct {
	// contains filtered or unexported fields
}

Roster is what the plugins of a world ask of the kinds a game defines, by template: written by every plugin's KindTemplates as it is first read, never after.

func NewRoster

func NewRoster(fill func(r *Roster)) *Roster

NewRoster is a roster fill writes as it is first read, the plugins' asks in the order made.

func (*Roster) Default

func (r *Roster) Default(t *Template, c comp.Comp)

Default is a component every entity of a kind of template t carries unless the game gives its own of that type or leaves it out with comp.Without.

func (*Roster) Filled

func (r *Roster) Filled() bool

Filled reports whether the roster has been written, its plugins asked.

func (*Roster) Spec

func (r *Roster) Spec(t *Template, own ...comp.Comp) Spec

Spec is template t's defaults and its parents', less those own overrides or drops, plus own; it panics naming every requirement own leaves unmet. A template's default takes the place of its parent's of the same type.

type Spec

type Spec []comp.Comp

Spec is the definition of one kind: the components every entity of it carries — see package comp.

type Template

type Template struct {
	// contains filtered or unexported fields
}

Template is a sort of kind a plugin brings in by name — what the world spawns, what moves, a board's cell — the asks of its parent coming with its own.

func NewTemplate

func NewTemplate(name string, parent *Template) *Template

NewTemplate is a template named name under parent, nil for none: a handle, its asks a world's Roster's.

Jump to

Keyboard shortcuts

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