[READ-ONLY] Mirror of https://github.com/excaliburjs/ecs. Extracted and Slightly Modified Excalibur ECS
0

Configure Feed

Select the types of activity you want to include in your feed.

fix slow types

Erik Onarheim (Feb 21, 2025, 9:29 AM -0600) 01bba565 654b6d8a

+29 -29
+4 -4
src/entity-manager.ts
··· 49 49 */ 50 50 public addEntity(entity: Entity): void { 51 51 entity.isActive = true; 52 - entity.scene = this._world.context; 52 + entity.context = this._world.context; 53 53 if (entity && !this._entityIndex[entity.id]) { 54 54 this._entityIndex[entity.id] = entity; 55 55 this.entities.push(entity); ··· 57 57 58 58 // if entity has children 59 59 entity.children.forEach((c) => { 60 - c.scene = entity.scene; 60 + c.context = entity.context; 61 61 this.addEntity(c); 62 62 }); 63 63 const childAdded = this._createChildAddedHandler(); ··· 90 90 91 91 delete this._entityIndex[id]; 92 92 if (entity) { 93 - entity.scene = null; 93 + entity.context = null; 94 94 const index = this.entities.indexOf(entity); 95 95 if (index > -1) { 96 96 this.entities.splice(index, 1); ··· 99 99 100 100 // if entity has children 101 101 entity.children.forEach((c) => { 102 - c.scene = null; 102 + c.context = null; 103 103 this.removeEntity(c, deferred); 104 104 }); 105 105 const childAddedHandler = this._childAddedHandlerMap.get(entity);
+11 -11
src/entity.ts
··· 90 90 */ 91 91 public id: number = Entity._ID++; 92 92 93 - public name = `Entity#${this.id}`; 93 + public name: string = `Entity#${this.id}`; 94 94 95 95 /** 96 96 * Listen to or emit events for an entity 97 97 */ 98 - public events = new EventEmitter<EntityEvents>(); 98 + public events: EventEmitter<EntityEvents> = new EventEmitter<EntityEvents>(); 99 99 private _tags = new Set<string>(); 100 - public componentAdded$ = new Observable<Component>(); 101 - public componentRemoved$ = new Observable<Component>(); 102 - public tagAdded$ = new Observable<string>(); 103 - public tagRemoved$ = new Observable<string>(); 100 + public componentAdded$: Observable<Component> = new Observable<Component>(); 101 + public componentRemoved$: Observable<Component> = new Observable<Component>(); 102 + public tagAdded$: Observable<string> = new Observable<string>(); 103 + public tagRemoved$: Observable<string> = new Observable<string>(); 104 104 /** 105 105 * Current components on the entity 106 106 * ··· 108 108 * 109 109 * Use addComponent/removeComponent otherwise the ECS will not be notified of changes. 110 110 */ 111 - public readonly components = new Map<Function, Component>(); 111 + public readonly components: Map<Function, Component> = new Map<Function, Component>(); 112 112 public componentValues: Component[] = []; 113 113 private _componentsToRemove: ComponentCtor[] = []; 114 114 ··· 175 175 this.emit('kill', new KillEvent(this)); 176 176 } 177 177 178 - public isKilled() { 178 + public isKilled(): boolean { 179 179 return !this.isActive; 180 180 } 181 181 ··· 265 265 return this._parent; 266 266 } 267 267 268 - public childrenAdded$ = new Observable<Entity>(); 269 - public childrenRemoved$ = new Observable<Entity>(); 268 + public childrenAdded$: Observable<Entity> = new Observable<Entity>(); 269 + public childrenRemoved$: Observable<Entity> = new Observable<Entity>(); 270 270 271 271 private _children: Entity[] = []; 272 272 /** ··· 279 279 /** 280 280 * Unparents this entity, if there is a parent. Otherwise it does nothing. 281 281 */ 282 - public unparent() { 282 + public unparent(): void { 283 283 if (this._parent) { 284 284 this._parent.removeChild(this); 285 285 this._parent = null;
+6 -6
src/query.ts
··· 14 14 */ 15 15 export class Query<TKnownComponentCtors extends ComponentCtor<Component> = never> { 16 16 public readonly id: string; 17 - public components = new Set<TKnownComponentCtors>(); 17 + public components: Set<TKnownComponentCtors> = new Set<TKnownComponentCtors>(); 18 18 public entities: Entity<ComponentInstance<TKnownComponentCtors>>[] = []; 19 19 /** 20 20 * This fires right after the component is added 21 21 */ 22 - public entityAdded$ = new Observable<Entity<ComponentInstance<TKnownComponentCtors>>>(); 22 + public entityAdded$: Observable<Entity<ComponentInstance<TKnownComponentCtors>>> = new Observable<Entity<ComponentInstance<TKnownComponentCtors>>>(); 23 23 /** 24 24 * This fires right before the component is actually removed from the entity, it will still be available for cleanup purposes 25 25 */ 26 - public entityRemoved$ = new Observable<Entity<ComponentInstance<TKnownComponentCtors>>>(); 26 + public entityRemoved$: Observable<Entity<ComponentInstance<TKnownComponentCtors>>> = new Observable<Entity<ComponentInstance<TKnownComponentCtors>>>(); 27 27 28 28 constructor(public readonly requiredComponents: TKnownComponentCtors[]) { 29 29 if (requiredComponents.length === 0) { ··· 36 36 this.id = Query.createId(requiredComponents); 37 37 } 38 38 39 - static createId(requiredComponents: Function[]) { 39 + static createId(requiredComponents: Function[]): string { 40 40 // TODO what happens if a user defines the same type name as a built in type 41 41 // ! TODO this could be dangerous depending on the bundler's settings for names 42 42 // Maybe some kind of hash function is better here? ··· 51 51 * Potentially adds an entity to a query index, returns true if added, false if not 52 52 * @param entity 53 53 */ 54 - checkAndAdd(entity: Entity) { 54 + checkAndAdd(entity: Entity): boolean { 55 55 if (!this.entities.includes(entity) && entity.hasAll(Array.from(this.components))) { 56 56 this.entities.push(entity); 57 57 this.entityAdded$.notifyAll(entity); ··· 60 60 return false; 61 61 } 62 62 63 - removeEntity(entity: Entity) { 63 + removeEntity(entity: Entity): void { 64 64 const index = this.entities.indexOf(entity); 65 65 if (index > -1) { 66 66 this.entities.splice(index, 1);
+6 -6
src/tag-query.ts
··· 3 3 4 4 export class TagQuery<TKnownTags extends string = never> { 5 5 public readonly id: string; 6 - public tags = new Set<TKnownTags>(); 6 + public tags: Set<TKnownTags> = new Set<TKnownTags>(); 7 7 public entities: Entity<any>[] = []; 8 8 /** 9 9 * This fires right after the component is added 10 10 */ 11 - public entityAdded$ = new Observable<Entity<any>>(); 11 + public entityAdded$: Observable<Entity<any>> = new Observable<Entity<any>>(); 12 12 /** 13 13 * This fires right before the component is actually removed from the entity, it will still be available for cleanup purposes 14 14 */ 15 - public entityRemoved$ = new Observable<Entity<any>>(); 15 + public entityRemoved$: Observable<Entity<any>> = new Observable<Entity<any>>(); 16 16 17 17 constructor(public readonly requiredTags: TKnownTags[]) { 18 18 if (requiredTags.length === 0) { ··· 25 25 this.id = TagQuery.createId(requiredTags); 26 26 } 27 27 28 - static createId(requiredComponents: string[]) { 28 + static createId(requiredComponents: string[]): string { 29 29 return requiredComponents.slice().sort().join('-'); 30 30 } 31 31 32 - checkAndAdd(entity: Entity) { 32 + checkAndAdd(entity: Entity): boolean { 33 33 if (!this.entities.includes(entity) && entity.hasAllTags(Array.from(this.tags))) { 34 34 this.entities.push(entity); 35 35 this.entityAdded$.notifyAll(entity); ··· 38 38 return false; 39 39 } 40 40 41 - removeEntity(entity: Entity) { 41 + removeEntity(entity: Entity): void { 42 42 const index = this.entities.indexOf(entity); 43 43 if (index > -1) { 44 44 this.entities.splice(index, 1);
+2 -2
src/world.ts
··· 78 78 /** 79 79 * Get a system out of the ECS world 80 80 */ 81 - get(system: SystemCtor<System>) { 81 + get(system: SystemCtor<System>): System<TContext> | null { 82 82 return this.systemManager.get(system); 83 83 } 84 84 ··· 110 110 //); 111 111 } 112 112 113 - get entities() { 113 + get entities(): Entity<any, TContext>[] { 114 114 return this.entityManager.entities; 115 115 } 116 116