entity

package
v0.0.0-...-ba58dea Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2025 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrContextClosed = errors.New("registry context is closed")
View Source
var ErrEntityDuplicateID = errors.New("duplicate entity id")
View Source
var ErrEntityDuplicateName = errors.New("duplicate entity name in context")
View Source
var ErrInvalidCommandType = errors.New("invalid command type")

Functions

func GetComponent

func GetComponent[C any](e *Entity) (C, bool)

func HasComponent

func HasComponent[C any](e *Entity) bool

func HasHandler

func HasHandler[C any](e *Entity) bool

func RemoveComponent

func RemoveComponent[C any](e *Entity)

func RemoveHandler

func RemoveHandler[C any](e *Entity)

func SetComponent

func SetComponent[C any](e *Entity, component C)

func SetHandler

func SetHandler[C any](e *Entity, handler Handler[C])

func WithComponents

func WithComponents(components []any) func(*Entity)

func WithHandlers

func WithHandlers(handlers typemap.TypeMap[Handler[any]]) func(*Entity)

func WithID

func WithID(id ID) func(*Entity)

func WithName

func WithName(name string) func(*Entity)

Types

type CommandType

type CommandType = typeset.ValType

type ComponentRemovedEvent

type ComponentRemovedEvent struct {
	Entity    *Entity
	Component any
}

type ComponentType

type ComponentType = typemap.KeyType

type ComponentUpdatedEvent

type ComponentUpdatedEvent struct {
	Entity    *Entity
	Component any
}

type Context

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

func NewContext

func NewContext(events *event.Bus) *Context

func (*Context) Add

func (c *Context) Add(ent *Entity) error

func (*Context) All

func (c *Context) All() iter.Seq[*Entity]

func (*Context) Close

func (c *Context) Close() error

func (*Context) EventBus

func (c *Context) EventBus() *event.Bus

func (*Context) Get

func (c *Context) Get(id ID) (*Entity, bool)

func (*Context) GetNamed

func (c *Context) GetNamed(name string) (*Entity, bool)

func (*Context) Has

func (c *Context) Has(ent *Entity) bool

func (*Context) HasId

func (c *Context) HasId(id ID) bool

func (*Context) HasNamed

func (c *Context) HasNamed(name string) bool

func (*Context) IsActive

func (c *Context) IsActive() bool

func (*Context) Owns

func (c *Context) Owns(ent *Entity) bool

func (*Context) OwnsDeep

func (c *Context) OwnsDeep(ent *Entity) bool

func (*Context) Remove

func (c *Context) Remove(ent *Entity) error

func (*Context) RemoveId

func (c *Context) RemoveId(id ID) error

func (*Context) SubContext

func (c *Context) SubContext() *Context

type Entity

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

func NewEntity

func NewEntity(options ...func(*Entity)) *Entity

func (*Entity) Components

func (e *Entity) Components() []any

func (*Entity) GetComponent

func (e *Entity) GetComponent(component any) (any, bool)

func (*Entity) GetComponentType

func (e *Entity) GetComponentType(component ComponentType) (any, bool)

func (*Entity) GetHandler

func (e *Entity) GetHandler(command any) (Handler[any], bool)

func (*Entity) GetHandlerType

func (e *Entity) GetHandlerType(command CommandType) (Handler[any], bool)

func (*Entity) Handlers

func (e *Entity) Handlers() []Handler[any]

func (*Entity) HasComponent

func (e *Entity) HasComponent(component any) bool

func (*Entity) HasComponentType

func (e *Entity) HasComponentType(typ ComponentType) bool

func (*Entity) HasHandler

func (e *Entity) HasHandler(command any) bool

func (*Entity) HasHandlerType

func (e *Entity) HasHandlerType(command CommandType) bool

func (*Entity) HasName

func (e *Entity) HasName() bool

func (*Entity) ID

func (e *Entity) ID() ID

func (*Entity) IsBound

func (e *Entity) IsBound() bool

func (*Entity) Name

func (e *Entity) Name() string

func (*Entity) RemoveComponent

func (e *Entity) RemoveComponent(component any)

func (*Entity) RemoveComponentType

func (e *Entity) RemoveComponentType(component ComponentType)

func (*Entity) RemoveComponentTypes

func (e *Entity) RemoveComponentTypes(components ...ComponentType)

func (*Entity) RemoveComponents

func (e *Entity) RemoveComponents(components ...any)

func (*Entity) RemoveHandler

func (e *Entity) RemoveHandler(command any)

func (*Entity) RemoveHandlerType

func (e *Entity) RemoveHandlerType(command CommandType)

func (*Entity) RemoveHandlerTypes

func (e *Entity) RemoveHandlerTypes(commands ...CommandType)

func (*Entity) RemoveHandlers

func (e *Entity) RemoveHandlers(commands ...any)

func (*Entity) SetComponent

func (e *Entity) SetComponent(component any)

func (*Entity) SetComponents

func (e *Entity) SetComponents(components ...any)

func (*Entity) SetHandler

func (e *Entity) SetHandler(command any, handler Handler[any])

func (*Entity) SetHandlerType

func (e *Entity) SetHandlerType(command CommandType, handler Handler[any])

func (*Entity) String

func (e *Entity) String() string

type EntityAddedEvent

type EntityAddedEvent struct {
	Entity *Entity
}

type EntityRemovedEvent

type EntityRemovedEvent struct {
	Entity *Entity
}

type Handler

type Handler[C any] func(ent *Entity, cmd C) error

func GetHandler

func GetHandler[C any](e *Entity) (Handler[any], bool)

type HandlersUpdatedEvent

type HandlersUpdatedEvent struct {
	Entity *Entity
}

type ID

type ID = uuid.UUID

Jump to

Keyboard shortcuts

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