Skip to content
This repository has been archived by the owner on Jun 1, 2022. It is now read-only.

Commit

Permalink
typescript: parametrize World and System over Entity
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidPeicho committed Aug 17, 2020
1 parent 7795dc0 commit c49a64a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
14 changes: 7 additions & 7 deletions src/System.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export interface SystemQueries {
/**
* A system that manipulates entities in the world.
*/
export abstract class System {
export abstract class System<EntityType extends Entity = Entity> {
/**
* Defines what Components the System will query for.
* This needs to be user defined.
Expand All @@ -30,22 +30,22 @@ export abstract class System {

static isSystem: true;

constructor(world: World, attributes?: Attributes);
constructor(world: World<EntityType>, attributes?: Attributes);

/**
* The results of the queries.
* Should be used inside of execute.
*/
queries: {
[queryName: string]: {
results: Entity[],
added?: Entity[],
removed?: Entity[],
changed?: Entity[],
results: EntityType[],
added?: EntityType[],
removed?: EntityType[],
changed?: EntityType[],
}
}

world: World;
world: World<EntityType>;

/**
* Whether the system will execute during the world tick.
Expand Down
10 changes: 6 additions & 4 deletions src/World.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ export interface WorldOptions {
/**
* The World is the root of the ECS.
*/
export class World {
export class World<EntityType extends Entity = Entity> {

/**
* Whether the world tick should execute.
*/
Expand All @@ -28,7 +29,7 @@ export class World {
*/
registerComponent<C extends Component<any>>(Component: ComponentConstructor<C>, objectPool?: ObjectPool<C> | false): this;

/**
/**
* Evluate whether a component has been registered to this world or not.
* @param Component Type of component to to evaluate
*/
Expand Down Expand Up @@ -68,7 +69,7 @@ export class World {
* Resume execution of this world.
*/
play(): void

/**
* Stop execution of this world.
*/
Expand All @@ -77,5 +78,6 @@ export class World {
/**
* Create a new entity
*/
createEntity(name?: string): Entity
createEntity(name?: string): EntityType

}

0 comments on commit c49a64a

Please sign in to comment.