object

package
v0.0.0-...-8e5a076 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2024 License: GPL-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrSerialize = errors.New("serialization error")
View Source
var GlobalPool = NewPool()

Functions

func Attach

func Attach(parent Object, child Component)

Attach a child component/object to a parent object If the object already has a parent, it will be detached first.

func Builder

func Builder[K Object](object K) *builder[K]

Builder instantiates a new group builder.

func Children

func Children(object Component) iter.Seq[Component]

Returns all the children of an object. Returns the empty slice if the object is a component.

func Copy

func Copy[T Component](pool Pool, obj T) T

func Deserialize

func Deserialize[T Component](pool Pool, decoder Decoder) (T, error)

deserialization

func Destroy

func Destroy(object Component)

func Detach

func Detach(child Component)

Detach a child component/object from its parent object Does nothing if the given object has no parent.

func Disable

func Disable(object Component)

func Enable

func Enable(object Component)

func Get

func Get[K Component](self Component) K

Gets a reference to a component of type K on the same object as the component/object specified.

func GetAll

func GetAll[K Component](self Component) []K

Gets references to all components of type K on the same object as the component/object specified.

func GetAllInChildren

func GetAllInChildren[K Component](self Component) []K

Gets references to all components of type K on the same object as the component/object specified, or any child of the object.

func GetAllInParents

func GetAllInParents[K Component](self Component) []K

Gets references to all components of type K in any parent of the object/component. For component targets, sibling components will be returned.

func GetInChildren

func GetInChildren[K Component](self Component) K

Gets a reference to a component of type K on the same object as the component/object specified, or any child of the object.

func GetInParents

func GetInParents[K Component](self Component) K

Gets the first reference to a component of type K in any parent of the object/component. For component targets, sibling components will be returned.

func ID

func ID() uint

func Is

func Is[K any](c Component) bool

func Key

func Key(prefix string, object Component) string

func Load

func Load[T Component](pool Pool, assets fs.Filesystem, key string) (T, error)

func NewComponent

func NewComponent[K Component](pool Pool, cmp K) K

func NewObject

func NewObject[K Object](pool Pool, name string, obj K) K

func Register

func Register[T any](info Type)

func Save

func Save(assets fs.Filesystem, key string, obj Component) error

func Serialize

func Serialize(enc Encoder, obj Component) error

func Toggle

func Toggle(object Component, enabled bool)

Types

type Array

type Array[T PropValue] struct {
	// contains filtered or unexported fields
}

func NewArray

func NewArray[T PropValue]() Array[T]

func (*Array[T]) Append

func (a *Array[T]) Append(value T)

func (*Array[T]) AppendAny

func (a *Array[T]) AppendAny(value any)

func (*Array[T]) Delete

func (a *Array[T]) Delete(index int)

func (*Array[T]) Deserialize

func (a *Array[T]) Deserialize(dec Decoder) error

func (*Array[T]) Get

func (a *Array[T]) Get(index int) T

func (*Array[T]) GetAny

func (a *Array[T]) GetAny(index int) any

func (*Array[T]) Length

func (a *Array[T]) Length() int

func (*Array[T]) Serialize

func (a *Array[T]) Serialize(enc Encoder) error

func (*Array[T]) Set

func (a *Array[T]) Set(index int, value T)

func (*Array[T]) SetAny

func (a *Array[T]) SetAny(index int, value any)

type Component

type Component interface {
	// ID returns a unique identifier for this object.
	ID() Handle

	// Pool returns the object pool this object belongs to.
	Pool() Pool

	// Name is used to identify the object within the scene.
	Name() string

	// Parent returns the parent of this object, or nil
	Parent() Object

	// Transform returns the object transform
	Transform() transform.T

	// Active indicates whether the object is active in the scene or not.
	// E.g. the object/component and all its parents are enabled and active.
	Active() bool

	// Enabled indicates whether the object is currently enabled or not.
	// Note that the object can still be inactive if an ancestor is disabled.
	Enabled() bool

	// Update the component. Called on every frame.
	Update(Component, float32)
	// contains filtered or unexported methods
}

func Components

func Components(object Component) []Component

Returns the components attached to an object

func Root

func Root(obj Component) Component

Root returns the first ancestor of the given component/object

type CreateFn

type CreateFn func(Pool) (Component, error)

type Decoder

type Decoder interface {
	Decode(e any) error
}

type Dict

type Dict[K comparable, V any] struct {
	// contains filtered or unexported fields
}

func NewDict

func NewDict[K comparable, V any]() Dict[K, V]

func (*Dict[K, V]) Delete

func (d *Dict[K, V]) Delete(key K)

func (*Dict[K, V]) Deserialize

func (d *Dict[K, V]) Deserialize(dec Decoder) error

func (*Dict[K, V]) Get

func (d *Dict[K, V]) Get(key K) (V, bool)

func (*Dict[K, V]) GetAny

func (d *Dict[K, V]) GetAny(key K) (any, bool)

func (*Dict[K, V]) Serialize

func (d *Dict[K, V]) Serialize(enc Encoder) error

func (*Dict[K, V]) Set

func (d *Dict[K, V]) Set(key K, value V)

func (*Dict[K, V]) SetAny

func (d *Dict[K, V]) SetAny(key K, value any)

type DisableHandler

type DisableHandler interface {
	Component
	OnDisable()
}

type EnableHandler

type EnableHandler interface {
	Component
	OnEnable()
}

type EncodedProp

type EncodedProp interface {
	Encode() ([]byte, error)
	Decode([]byte) (PropValue, error)
}

type Encoder

type Encoder interface {
	Encode(data any) error
}

type GenericProp

type GenericProp interface {
	Type() reflect.Type
	GetAny() any
	SetAny(any)
}

type Handle

type Handle uint

type MemorySerializer

type MemorySerializer struct {
	Stream []any
	// contains filtered or unexported fields
}

func (*MemorySerializer) Decode

func (m *MemorySerializer) Decode(target any) error

func (*MemorySerializer) Encode

func (m *MemorySerializer) Encode(data any) error

type Object

type Object interface {
	Component
	input.Handler

	// Children iterates over the objects children.
	Children() iter.Seq[Component]

	// Child returns the child at the given index.
	Child(index int) Component

	// Len returns the number of children attached to the object.
	Len() int
	// contains filtered or unexported methods
}

func Empty

func Empty(pool Pool, name string) Object

Empty creates a new, empty object.

func Floating

func Floating(pool Pool, name string) Object

Floating objects are not part of the transform heirarchy

func Ghost

func Ghost(pool Pool, name string, target transform.T) Object

func Scene

func Scene(pool Pool, funcs ...SceneFunc) Object

func Subgroups

func Subgroups(object Component) []Object

Returns the child objects attached to an object

type Pool

type Pool interface {
	Resolve(Handle) (Component, bool)
	// contains filtered or unexported methods
}

func NewPool

func NewPool() Pool

type PropInfo

type PropInfo struct {
	GenericProp
	Key  string
	Name string
}

func Properties

func Properties(target Component) []PropInfo

type PropValue

type PropValue interface {
}

type Property

type Property[T PropValue] struct {

	// OnChange executes callbacks every time the property value is changed.
	// The callback is called with the new value.
	// Only the propertys owner object should subscribe to this event.
	OnChange events.Event[T]
	// contains filtered or unexported fields
}

func NewProperty

func NewProperty[T PropValue](def T) Property[T]

func (*Property[T]) Deserialize

func (p *Property[T]) Deserialize(pool Pool, dec Decoder) error

func (*Property[T]) Get

func (p *Property[T]) Get() T

func (*Property[T]) GetAny

func (p *Property[T]) GetAny() any

func (*Property[T]) Serialize

func (p *Property[T]) Serialize(enc Encoder) error

func (*Property[T]) Set

func (p *Property[T]) Set(value T)

func (*Property[T]) SetAny

func (p *Property[T]) SetAny(value any)

func (*Property[T]) String

func (p *Property[T]) String() string

func (*Property[T]) Type

func (p *Property[T]) Type() reflect.Type

type Query

type Query[K Component] struct {
	// contains filtered or unexported fields
}

func NewQuery

func NewQuery[K Component]() *Query[K]

NewQuery returns a new query for the given component type

func (*Query[K]) Collect

func (q *Query[K]) Collect(roots ...Component) []K

Collect returns all matching components

func (*Query[K]) CollectObjects

func (q *Query[K]) CollectObjects(roots ...Component) []Component

func (*Query[K]) First

func (q *Query[K]) First(root Component) (K, bool)

First returns the first match in a depth-first fashion

func (*Query[K]) Reset

func (q *Query[K]) Reset() *Query[K]

Clear the query results, without freeing the memory.

func (*Query[K]) Sort

func (q *Query[K]) Sort(sorter func(a, b K) bool) *Query[K]

Sort the result using a compare function. The compare function should return true if a is "less than" b

func (*Query[K]) Where

func (q *Query[K]) Where(predicate func(K) bool) *Query[K]

Where applies a filter predicate to the results

type Ref

type Ref[T Component] struct {
	Property[Handle]
	// contains filtered or unexported fields
}

func EmptyRef

func EmptyRef[T Component]() Ref[T]

func NewRef

func NewRef[T Component](cmp T) Ref[T]

func (*Ref[T]) Deserialize

func (r *Ref[T]) Deserialize(pool Pool, dec Decoder) error

func (*Ref[T]) Get

func (r *Ref[T]) Get() (T, bool)

func (*Ref[T]) Serialize

func (r *Ref[T]) Serialize(enc Encoder) error

func (*Ref[T]) Set

func (r *Ref[T]) Set(cmp T)

type Registry

type Registry map[string]*Type

func Types

func Types() Registry

type SceneFunc

type SceneFunc func(Pool, Object)

type Serializable

type Serializable interface {
	Serialize(Encoder) error
	Deserialize(Pool, Decoder) error
}

type Type

type Type struct {
	Name   string
	Path   []string
	Create CreateFn
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

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