Skip to content

@pierre/ecs

Typed Entity-Component-System primitives for 2D and 3D games and simulations — component stores, queries, a spatial index, a scheduler, and opt-in modules.

The core is domain-neutral: it knows nothing about players, enemies, or tiles. Genre-specific helpers live in modules you opt into, each a separate subpath import, so unused code stays out of your bundle.

The engine is pre-release (0.0.0) and not published to npm. Consume it as a sibling folder via a file: install — the package’s exports map points at TypeScript sources, so no build step is needed for a TS-aware bundler.

import { simpleComponent } from '@pierre/ecs/component-store';
import { HashGrid2D } from '@pierre/ecs/modules/spatial';
import { EcsWorld } from '@pierre/ecs/world';
interface Pos { x: number; y: number }
const PosDef = simpleComponent<Pos>('pos', { x: 'number', y: 'number' });
const world = new EcsWorld();
world.registerComponent(PosDef);
world.enableSpatial(PosDef, new HashGrid2D());
const id = world.spawn({ name: 'marker', components: { pos: { x: 0, y: 0 } } });
world.move(id, 3, 4);
for (const [entity, pos] of world.query(PosDef)) {
console.log(entity, pos.x, pos.y);
}