new ActionEngine(isServer)
Represents an action based game engine. It's like a normal ECS with Action.
Parameters:
| Name | Type | Argument | Default | Description |
|---|---|---|---|---|
isServer |
Boolean |
<optional> |
false | Whether if it's a server or not |
- Source:
- See:
Extends
Members
-
isServer :Boolean
-
A boolean contains whether if it's a server or not.
Type:
- Boolean
- Source:
-
systems :Array
-
Array of all the System in the Engine. You shouldn't edit this array directly, use Engine#addSystem and Engine#removeSystem instead.
Type:
- Array
- Inherited From:
- Source:
Methods
-
addEntity(entity)
-
Adds an Entity to the Engine.
Parameters:
Name Type Description entityEntity An Entity to add
- Inherited From:
- Source:
Fires:
-
addSystem(key, system)
-
Adds the System to the Engine. The System will be triggered when the Engine#update is called. This will trigger System#add.
Parameters:
Name Type Description keyString The System's string key
systemSystem The System to add
- Inherited From:
- Source:
-
c(key, constructor)
-
Registers a Component type to the Engine.
Parameters:
Name Type Description keyString Component's string key.
constructorfunction Component's constructor.
-
createAction(name, entity, player, options) → {Action}
-
Creates a new Action using registered constructor.
Parameters:
Name Type Description nameString The name of the Action.
entityEntity The entity associated with the action.
playerEntity The player who requested the action.
optionsObject The arguments associated with the action.
- Source:
Returns:
The created Action.
- Type
- Action
-
createEntity() → {Entity}
-
Creates an empty Entity and adds to the Engine.
- Inherited From:
- Source:
Fires:
Returns:
an empty Entity.
- Type
- Entity
-
createSystem(key) → {SystemBuilder}
-
Returns a new SystemBuilder associated the Engine.
Parameters:
Name Type Description keyString The System's string key to use.
- Inherited From:
- Source:
Returns:
A new SystemBuilder
- Type
- SystemBuilder
-
defineAction(name, constructor)
-
Defines an Action type to the Engine.
Parameters:
Name Type Description nameString The name of the Action.
constructorfunction The constructor of the Action.
- Source:
-
deserialize(serialized)
-
Deserializes the Engine object and places on provided engine. The provided Engine object should be clean; it shouldn't contain any Entity object. But it can contain pre-defined Components and Systems. Note that systems won't be included in serialized object, so user should load the systems on their own.
Parameters:
Name Type Description serializedObject Engine object
- Inherited From:
- Source:
-
e()
-
Executes Entity related functions by its arguments.
If no argument is provided, it returns new Entity. If a number is provided, it returns a Entity with that ID. If an object is provided, it returns new Entity populated with the template. Otherwise, it returns an array of Entity having provided list components.
-
emit(event)
-
Emits the event. This will trigger all the listener with that event type. You can supply listener function's arguments by appending arguments after the 'event' parameter.
Parameters:
Name Type Description eventString The name of the event.
args...Arguments to supply to listeners.
- Inherited From:
- Source:
-
getActionConstructor(name) → {function}
-
Returns the Action's construtor with specified name.
Parameters:
Name Type Description nameString The name of the Action.
- Source:
Returns:
The constructor of the Action.
- Type
- function
-
getComponentBit(key)
-
Returns Component type's unique ID in the Engine. This unique ID is used in BitSet's bit position. This will call Engine#registerComponent if needed.
Parameters:
Name Type Description keyString Component's string key.
- Inherited From:
- Source:
Returns:
the Component's unique ID.
-
getComponentConstructor(key)
-
Returns Component's constructor registered in the Engine/
Parameters:
Name Type Description keyString Component's string key.
- Inherited From:
- Source:
Returns:
the Component's constructor.
-
getComponentGroup(entities) → {ComponentGroup}
-
Searches ComponentGroup by its array.
Parameters:
Name Type Description entitiesArray An array of ComponentGroup
- Inherited From:
- Source:
Returns:
The ComponentGroup linked with the array
- Type
- ComponentGroup
-
getComponentName(key)
-
Returns Component type's key by its unique ID.
Parameters:
Name Type Description keyNumber Component's unique ID
- Inherited From:
- Source:
Returns:
the Component's string key.
-
getComponentsBitSet(components) → {BitSet}
-
Returns a BitSet holding combination of Components type's unique ID.
Parameters:
Name Type Description componentsArray An array holding Component keys.
- Inherited From:
- Source:
Returns:
A BitSet holding combination of Components.
- Type
- BitSet
-
getEntities() → {Array}
-
Returns an array of Entity. It shouldn't be edited since the Engine uses it directly.
- Inherited From:
- Source:
Returns:
An array holding Entity
- Type
- Array
-
getEntitiesFor(componentGroup) → {Array}
-
Returns an array having Entity matching ComponentGroup's criteria. The array will keep updated, so you can call this method only once and check its contents if needed. It's an alias function to Engine#registerComponentGroup
Parameters:
Name Type Description componentGroupComponentGroup The ComponentGroup
- Inherited From:
- Source:
- See:
Fires:
Returns:
An array holding Entity matching its criteria
- Type
- Array
-
getEntity(id) → {Entity}
-
Returns an Entity with given ID. This will return null if it can't be found.
Parameters:
Name Type Description idNumber An ID to find the Entity
- Inherited From:
- Source:
Returns:
The entity with given ID
- Type
- Entity
-
getSystem(key) → {System}
-
Returns the System registered to the Engine.
Parameters:
Name Type Description keyString The System's string key
- Inherited From:
- Source:
Returns:
The system registered to the Engine
- Type
- System
-
listeners(event) → {Array}
-
Returns the array of listeners with specified event type.
Parameters:
Name Type Description eventString The name of the event.
- Inherited From:
- Source:
Returns:
An array holding event listeners.
- Type
- Array
-
obtainEntityId() → {Number}
-
Returns a new Entity ID to use. This changes its value each time it's called.
- Inherited From:
- Source:
- See:
Returns:
An integer that is used for Entity's ID
- Type
- Number
-
on(event, listener)
-
Registers a listener.
Parameters:
Name Type Description eventString The name of the event.
listenerfunction The function to be triggered.
- Inherited From:
- Source:
-
once(event, listener)
-
Registers a one-time listener. The listener will be removed after being triggered once.
Parameters:
Name Type Description eventString The name of the event.
listenerfunction The function to be triggered.
- Inherited From:
- Source:
-
registerComponent(key, constructor)
-
Registers a Component type to the Engine.
Parameters:
Name Type Description keyString Component's string key.
constructor{Function] - Component's constructor.
- Inherited From:
- Source:
-
registerComponentGroup(componentGroup) → {Array}
-
Registers the ComponentGroup to the Engine. Engine will check if an Entity matches ComponentGroup's criteria every time when a Entity is added or removed.
Parameters:
Name Type Description componentGroupComponentGroup The ComponentGroup to register
- Inherited From:
- Source:
- See:
Fires:
Returns:
An array holding Entity matching its criteria
- Type
- Array
-
removeAllEntities()
-
Removes all Entity from the Engine.
- Inherited From:
- Source:
Fires:
-
removeAllListeners(event)
-
Removes all the listener with specified event type. If event parameter is not set, it will remove all the listener of all types.
Parameters:
Name Type Argument Description eventString <optional>
The name of the event.
- Inherited From:
- Source:
-
removeEntity(entity)
-
Removes an Entity from the Engine.
Parameters:
Name Type Description entityEntity An Entity to remove
- Inherited From:
- Source:
Fires:
-
removeListener(event, listener)
-
Removes the listener.
Parameters:
Name Type Description eventString The name of the event.
listenerfunction The function to be removed.
- Inherited From:
- Source:
-
removeSystem(key)
-
Removes the System from the Engine. This will trigger System#remove.
Parameters:
Name Type Description keyString The System's string key to remove.
- Inherited From:
- Source:
-
runAction(action)
-
Runs the Action. Action shouldn't have run yet if ActionEngine#isServer is true, but it should have run on server and have Action#result if not.
Parameters:
Name Type Description actionAction The Action to run.
- Source:
Fires:
- ActionEngine#event:action
- ActionEngine#event:preAction
-
s()
-
Executes System related functions by its arguments.
If a key is provided and the Engine doesn't have a system with that key, it returns a SystemBuilder. If a key is provided and the Engine has a system with that key, it returns that system. If a key is provided and a system is provided, it registers the system.
-
<private> sortSystems()
-
Sorts the System array to match their priority.
- Inherited From:
- Source:
- See:
-
toJSON() → {Object}
-
Serializes the Engine object. Note that systems won't be included in serialized object, so user should load the systems on their own.
- Inherited From:
- Source:
Returns:
serialized Engine object
- Type
- Object
-
update()
-
An update function called by every tick of the game.
- Inherited From:
- Source:
-
<private> updateComponentGroup(entity)
-
Updates the Entity to find if it matches ComponentGroups' criteria.
Parameters:
Name Type Description entityEntity the Entity to update
- Inherited From:
- Source:
- See:
Events
-
entityAdded
-
This event is fired when a Entity has added to Engine.
Type:
- Inherited From:
- Source:
-
entityRemoved
-
This event is fired when a Entity has removed from Engine.
Type:
- Inherited From:
- Source:
-
preAction
-
This event is fired before the action executes.
- Source:
Properties:
Name Type Description 1Action The Action object.