Ecs is a simple Typescript library of a bare ecs implementation.
Use the package manager npm to install ecs.
npm install vdkuipb-ecs
import { Entity, System } from "vdkuipb-ecs"
export class RotationComponent {
angle = 0;
}
class RotatorSystem extends System {
protected getRequiredComponents() {
return [ RotationComponent ]
}
protected entityInstantiated(entity: Entity): void {
let rotation: RotationComponent = entity.getComponent(RotationComponent);
rotation.angle = 50;
}
protected entityUpdate(entity: Entity, delta?: number): void {
let rotation: RotationComponent = entity.getComponent(RotationComponent);
rotation.angle += 1;
console.log(rotation.angle);
if (rotation.angle >= 100) {
this.remove(entity);
}
}
protected entityDestroyed(entity: Entity): void {
console.log("removed: " + entity.id);
}
}
var entity = new Entity();
entity.addComponent(PositionComponent);
entity.addComponent(RotationComponent);
var system = new RotatorSystem();
system.add(entity);
let prev = Date.now();
setInterval(() => {
system.update(prev - Date.now());
prev = Date.now();
}, 1000 / 10);
A better example can be found in the example folder.
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.