new EntityManager()
Handles creation, deletion, and querying of entities and their components.
- Source:
Methods
addComponent(entityId, componentTypeName, data) → {ComponentData|undefined}
Adds a component to an entity. If a component of the same type already exists, it's overwritten.
Parameters:
Name | Type | Description |
---|---|---|
entityId |
EntityId | The ID of the entity. |
componentTypeName |
ComponentTypeName | The string type/name of the component (e.g., "Position"). |
data |
ComponentData | The data for the component. |
- Source:
Returns:
The added component data, or undefined if the entity doesn't exist.
- Type
- ComponentData | undefined
createEntity() → {EntityId}
Creates a new entity and returns its ID.
- Source:
Returns:
The ID of the newly created entity.
- Type
- EntityId
destroyEntity(entityId)
Destroys an entity and removes all its associated components.
Parameters:
Name | Type | Description |
---|---|---|
entityId |
EntityId | The ID of the entity to destroy. |
- Source:
getAllComponents(entityId) → {Map.<ComponentTypeName, ComponentData>|undefined}
Retrieves all components for a given entity.
Parameters:
Name | Type | Description |
---|---|---|
entityId |
EntityId | The ID of the entity. |
- Source:
Returns:
A map of component type names to component data, or undefined if entity not found.
- Type
- Map.<ComponentTypeName, ComponentData> | undefined
getComponent(entityId, componentTypeName) → {ComponentData|undefined}
Retrieves a component from an entity.
Parameters:
Name | Type | Description |
---|---|---|
entityId |
EntityId | The ID of the entity. |
componentTypeName |
ComponentTypeName | The type/name of the component to retrieve. |
- Source:
Returns:
The component data, or undefined if not found.
- Type
- ComponentData | undefined
getEntitiesWithComponents(componentTypeNames) → {Array.<EntityId>}
Retrieves all entity IDs that possess all of the specified component types.
Parameters:
Name | Type | Description |
---|---|---|
componentTypeNames |
Array.<ComponentTypeName> | An array of component type names. |
- Source:
Returns:
An array of entity IDs that have all the specified components.
Returns an empty array if no component types are specified or no entities match.
- Type
- Array.<EntityId>
hasComponent(entityId, componentTypeName) → {boolean}
Checks if an entity has a specific component.
Parameters:
Name | Type | Description |
---|---|---|
entityId |
EntityId | The ID of the entity. |
componentTypeName |
ComponentTypeName | The type/name of the component to check for. |
- Source:
Returns:
True if the entity has the component, false otherwise.
- Type
- boolean
isEntityAlive(entityId) → {boolean}
Checks if an entity is still alive (exists).
Parameters:
Name | Type | Description |
---|---|---|
entityId |
EntityId | The ID of the entity to check. |
- Source:
Returns:
True if the entity exists, false otherwise.
- Type
- boolean
removeComponent(entityId, componentTypeName) → {boolean}
Removes a component from an entity.
Parameters:
Name | Type | Description |
---|---|---|
entityId |
EntityId | The ID of the entity. |
componentTypeName |
ComponentTypeName | The type/name of the component to remove. |
- Source:
Returns:
True if the component was removed, false otherwise (e.g., entity or component not found).
- Type
- boolean