ecs
Properties​
Types​
Currently, storing dynamically sized objects or lists isn’t supported. We’re actively exploring this feature and would love to hear about your specific use cases.
The following data types are useful for creating Schema properties on a Custom Component or references to a specific type.
Type | Description |
---|---|
ecs.eid | Entity Reference |
ecs.f32 | 32-bit floating-point number |
ecs.f64 | 64-bit floating-point number |
ecs.i32 | 32-bit integer |
ecs.ui8 | 8-bit unsigned integer |
ecs.ui32 | 32-bit unsigned integer |
ecs.string | String |
ecs.boolean | Boolean |
Functions​
registerComponent​
Registers a component with the ECS.
ecs.registerComponent({
name: string,
schema: Schema,
data: Schema,
schemaDefaults: Object,
add: function
remove: function,
tick: function
}) // -> Component Handle
State​
Parameter | Type | Description |
---|---|---|
triggers (Required) | Record<String, Trigger[]> | Name of the next states that this state and transition to and the triggers to do so. |
onEnter | function | Function called before the state is entered. |
onExit | function | Function called before the state is entered. |
Trigger​
EventTrigger​
Parameter | Type | Description |
---|---|---|
type (Required) | constant: 'event' | A constant to indicate the type of the trigger |
event (Required) | string | The event type that triggers this |
target | eid | The entity you want this trigger to change state for |
beforeTransition | (event) => boolean | A function that run before the transition, if the result is truthy then the transition will terminate and the state will not change |
TimeoutTrigger​
Parameter | Type | Description |
---|---|---|
type (Required) | constant: 'timeout' | A constant to indicate the type of the trigger |
timeout (Required) | number | The number of milliseconds before the transition |
createStateMachine​
Create a state machine.
ecs.createStateMachine(world, owner, {initialState: string, states: Record<string, State>}) // -> State Machine ID
deleteStateMachine​
Delete a state machine.
ecs.deleteStateMachine(world, machineId) // -> void
defineState​
Define a state.
ecs.defineState(name: string) // -> State
initial​
Mark this state as the initial state of the state machine
ecs.defineState(name).initial() // -> void
onEnter​
Set a callback to run when entering this state.
ecs.defineState(name).onEnter(callback) // -> void
onEvent​
Event​
Parameter | Type | Description |
---|---|---|
target | eid | the entity you want this trigger to change state for |
beforeTransition | (event) => boolean | Function that run before the transition, if the result is truthy then the transition will terminate and the state will not change |
Trigger a transition to the next state when an event is received.
ecs.defineState(name).onEvent(event: string, nextState: string | State, args: EventObject) // -> void
onExit​
Set a callback to run when exiting this state.
ecs.defineState(name).onExit(callback) // -> void
wait​
Wait before transitioning state.
ecs.defineState(name).wait(waitTime: number, nextState: string | State) // -> void
defineSystem​
Define a system.
ecs.defineSystem([terms]: string[], behavior: function) // -> System
defineQuery​
Define a query.
ecs.defineQuery([terms: string]) // -> callback
getAttribute​
Built-in components are also exposed as a property of ecs.
ecs.getAttribute(attributeName: string) // -> the attribute that has been registered with that name.
listAttributes​
Returns a list of attributes.
ecs.listAttributes() // -> string[]
getBehaviors​
Returns a list of registered behaviors.
ecs.getBehaviors() // -> function[]
registerBehavior​
Register a function that runs on the world every tick.
ecs.registerBehavior(behavior: function) // -> void
unregisterBehavior​
Deactivate a behavior.
ecs.unregisterBehavior(behavior: function) // -> void