Constructor
new System(config)
Example
#Creating a new system.
const system = new System({
name: 'spawn',
requirements: ['player', 'spawn'],
interval: 16,
executor: ({ entity }) => {
entity.addComponents(new Component('position', { x: 0, y: 0, z:0 }));
entity.removeComponents('spawn');
const name = entity.getComponents('player').getState('name');
console.log(`${name} has come into the world.`);
},
});
- Mixes In:
Parameters
Name | Type | Description | |||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
config |
Object | The system configuration.
Properties
|
Members
(private) latency :number
The number of milliseconds that the system has fallen behind.
(private) manager :EntityManager
The entity manager for the scope of entities the system is watching.
(private) requirements :Array.<string>
The component types that an entity must have to be watched by the system.
Methods
execute(context) → {Promise}
Executes the system executor for each entity within scope. The system will pass a context object to
the executor that exposes resources to be used within the executor.
Parameters
Name | Type | Description |
---|---|---|
context |
Object | A context from a parent scopes. |
Throws
- ReferenceError
- Will throw this error if invoked after being disposed.
Returns
The system execution.
- Type
- Promise
getExecutedOn() → {number}
Get the time last executed.
Throws
- ReferenceError
- Will throw this error if invoked after being disposed.
Returns
The last execution time.
- Type
- number
getInterval() → {number}
Get the execution interval.
Throws
- ReferenceError
- Will throw this error if invoked after being disposed.
Returns
The execution interval.
- Type
- number
getName() → {string}
Get the system name.
Throws
- ReferenceError
- Will throw this error if invoked after being disposed.
Returns
The system name.
- Type
- string
getRequirements() → {Array.<string>}
Get the system requirements.
Throws
- ReferenceError
- Will throw this error if invoked after being disposed.
Returns
The system requirements.
- Type
- Array.<string>
getScope() → {Array.<Entity>}
Get the entities in scope of the system.
Throws
- ReferenceError
- Will throw this error if invoked after being disposed.
getState() → {string}
Get the system state.
Throws
- ReferenceError
- Will throw this error if invoked after being disposed.
Returns
The system state.
- Type
- string
init(source) → {Promise}
Initialize the system by providing it with a source entity manager. The system sets up the
appropriate listeners that is will need to identify the entities that are within scope of
the system requirements and then identify the initial scope from the already existing entities.
Parameters
Name | Type | Description |
---|---|---|
source |
EntityManager | The source entity manager for the system. |
Throws
- ReferenceError
- Will throw this error if invoked after being disposed.
- TypeError
- Will throw this error is the source is not an EntityManager.
Returns
The system initialization.
- Type
- Promise
unwatchEntity(entity) → {System}
Will remove the entity from the scope of entities that are updated by the system, if
the entity no longer meets the system requirements.
Parameters
Name | Type | Description |
---|---|---|
entity |
Entity | The entity to watch. |
Fires:
Throws
- ReferenceError
- Will throw this error if invoked after being disposed.
watchEntity(entity) → {System}
Will add the entity to the scope of entities that are updated by the system, if the entity meets
the system requirements.
Parameters
Name | Type | Description |
---|---|---|
entity |
Entity | The entity to watch. |
Fires:
Throws
- ReferenceError
- Will throw this error if invoked after being disposed.
Events
system:unwatch
A system:unwatch event occurs when the systems unwatches an entity.