An entity component system (ECS) created with TypeScript in mind.
- No dependencies
- Very good TypeScript typings
- Simple, but powerful API
- Designed for performance
- Struct of Arrays for storing entity component values
- Entities are queryable by:
- Component
- Absence of Component
- Added Entity
- Removed Entity
- Systems can have 1 or more queries
npm install flock-ecs
const flock = require("flock-ecs");
//or
import * as flock from "flock-ecs";
import * as flock from 'flock-ecs';
const world = new flock.World();
const Position = new flock.Component(
() => ({
x: 0,
y: 0,
})
);
world.registerComponent(Position);
const logSystem = new flock.System(
(entities) => {
entities.forEach(entity => {
const position = entity.getComponent(Position)!;
console.log(`{ x: ${position.value.x}, y: ${position.value.y} }`);
});
},
[ Position ],
);
for (let i=0; i<10; i++) {
const entity = world.createEntity();
entity.addComponent(Position, { x: Math.random() * 100, y: Math.random() * 100 });
}
logSystem.run(world);
world.maintain();
This repo uses Yarn workspaces, so make sure you're using yarn instead of npm.
To build the library in watch mode:
yarn workspace flock-ecs dev
And then to live build one of the examples, in another terminal:
yarn workspace boids start
To run tests:
yarn test
To run tests in watch mode:
yarn test:dev