object

package
v0.0.0-...-124f97e Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2023 License: GPL-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

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

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

func New[K Object](name string, obj K) K

func NewComponent

func NewComponent[K Component](cmp K) K

func Register

func Register[T Serializable](info TypeInfo)

func Save

func Save(writer io.Writer, obj Component) error

func Serialize

func Serialize(enc Encoder, obj Component) error

func Toggle

func Toggle(object Component, enabled bool)

Types

type Component

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

	// 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 object. Called on every frame.
	Update(Component, float32)

	// Destroy the object
	Destroy()
	// contains filtered or unexported methods
}

func Children

func Children(object Component) []Component

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

func Components

func Components(object Component) []Component

Returns the components attached to an object

func Copy

func Copy(obj Component) Component

func Deserialize

func Deserialize(decoder Decoder) (Component, error)

func DeserializeObject

func DeserializeObject(dec Decoder) (Component, error)

func Load

func Load(reader io.Reader) (Component, error)

func Root

func Root(obj Component) Component

Root returns the first ancestor of the given component/object

type ComponentState

type ComponentState struct {
	ID      uint
	Name    string
	Enabled bool
}

func NewComponentState

func NewComponentState(c Component) ComponentState

func (ComponentState) New

func (c ComponentState) New() Component

type CreateFn

type CreateFn func() (Component, error)

type Decoder

type Decoder interface {
	Decode(e any) error
}

type DeserializeFn

type DeserializeFn func(Decoder) (Component, error)

type DisableHandler

type DisableHandler interface {
	Component
	OnDisable()
}

type EnableHandler

type EnableHandler interface {
	Component
	OnEnable()
}

type Encoder

type Encoder interface {
	Encode(data any) error
}

type GenericProp

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

type MemorySerializer

type MemorySerializer struct {
	// 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 returns a slice containing the objects children.
	Children() []Component
	// contains filtered or unexported methods
}

func Empty

func Empty(name string) Object

Empty creates a new, empty object.

func Float

func Float(name string) Object

Floating objects are not part of the transform heirarchy

func Ghost

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

func Scene

func Scene() Object

func Subgroups

func Subgroups(object Component) []Object

Returns the child objects attached to an object

type ObjectState

type ObjectState struct {
	ComponentState
	Position vec3.T
	Rotation quat.T
	Scale    vec3.T
	Children int
}

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 events.Event[T]
	// contains filtered or unexported fields
}

func NewProperty

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

func (*Property[T]) Get

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

func (*Property[T]) GetAny

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

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 Registry

type Registry map[string]TypeInfo

func Types

func Types() Registry

type Serializable

type Serializable interface {
	Serialize(Encoder) error
}

type TypeInfo

type TypeInfo struct {
	Name        string
	Path        []string
	Create      CreateFn
	Deserialize DeserializeFn
}

Jump to

Keyboard shortcuts

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