Skip to content
This repository was archived by the owner on Apr 13, 2025. It is now read-only.

Commit 5a8a565

Browse files
committed
typescript: add EntityManager types
1 parent 7795dc0 commit 5a8a565

2 files changed

Lines changed: 70 additions & 0 deletions

File tree

src/Entity.d.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Component, ComponentConstructor } from "./Component";
2+
import { EntityManager } from "./EntityManager";
23

34
/**
45
* An entity in the world.
@@ -14,6 +15,11 @@ export class Entity {
1415
*/
1516
alive: boolean;
1617

18+
/**
19+
* Creates a new Entity.
20+
*/
21+
constructor(entityManager?: EntityManager);
22+
1723
/**
1824
* Get an immutable reference to a component on this entity.
1925
* @param Component Type of component to get

src/EntityManager.d.ts

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import { ObjectPool } from "./ObjectPool.js";
2+
import QueryManager from "./QueryManager.js";
3+
import EventDispatcher from "./EventDispatcher.js";
4+
import { SystemStateComponent } from "./SystemStateComponent.js";
5+
6+
export class EntityManager {
7+
8+
constructor(world);
9+
10+
getEntityByName(name);
11+
12+
/**
13+
* Create a new entity
14+
*/
15+
createEntity(name);
16+
17+
entityAddComponent(entity, Component, values);
18+
19+
/**
20+
* Remove a component from an entity
21+
* @param {Entity} entity Entity which will get removed the component
22+
* @param {*} Component Component to remove from the entity
23+
* @param {Bool} immediately If you want to remove the component immediately instead of deferred (Default is false)
24+
*/
25+
entityRemoveComponent(entity, Component, immediately);
26+
27+
_entityRemoveComponentSync(entity, Component, index);
28+
29+
/**
30+
* Remove all the components from an entity
31+
* @param {Entity} entity Entity from which the components will be removed
32+
*/
33+
entityRemoveAllComponents(entity, immediately);
34+
35+
/**
36+
* Remove the entity from this manager. It will clear also its components
37+
* @param {Entity} entity Entity to remove from the manager
38+
* @param {Bool} immediately If you want to remove the component immediately instead of deferred (Default is false)
39+
*/
40+
removeEntity(entity, immediately);
41+
42+
/**
43+
* Remove all entities from this manager
44+
*/
45+
removeAllEntities();
46+
47+
processDeferredRemoval();
48+
49+
/**
50+
* Get a query based on a list of components
51+
* @param {Array(Component)} Components List of components that will form the query
52+
*/
53+
queryComponents(Components);
54+
55+
/**
56+
* Return number of entities
57+
*/
58+
count();
59+
60+
/**
61+
* Return some stats
62+
*/
63+
stats();
64+
}

0 commit comments

Comments
 (0)