JSPM

archetype-ecs-lib

1.0.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 17
  • Score
    100M100P100Q48574F
  • License MIT

An Archetype Entity Component System (AECS)

Package Exports

  • archetype-ecs-lib
  • archetype-ecs-lib/lib/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (archetype-ecs-lib) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Coverage

Archetype ECS Lib

A tiny archetype-based ECS (Entity Component System) for TypeScript.

  • Archetypes (tables) store entities in a SoA layout (one column per component type).
  • Queries iterate matching archetypes efficiently.
  • Commands let you defer structural changes (spawn/despawn/add/remove) safely.
  • Resources (singletons) store global world state (Input, Time, Config, Asset caches…) keyed by type, without using entities.
  • Events transient messages (Hit happened, Click happened, Play sound).
  • A minimal Schedule runs systems by phases and flushes commands between phases.

Exports are defined in index.ts:

  • Types, TypeRegistry, Commands, World, Schedule

❗ The full documentation is at https://piratejl.github.io/archetype-ecs-lib/
Can view the Changelog here


Install

npm i archetype-ecs-lib

Quick start

import { World, Schedule } from "archetype-ecs-lib";

class Position { constructor(public x = 0, public y = 0) {} }
class Velocity { constructor(public x = 0, public y = 0) {} }

const world = new World();

// Spawn immediately
const e = world.spawn();
world.add(e, Position, new Position(0, 0));
world.add(e, Velocity, new Velocity(1, 0));

// A simple system
world.addSystem((w) => {
  for (const { e, c1: pos, c2: vel } of w.query(Position, Velocity)) {
    pos.x += vel.x * dt;
    pos.y += vel.y * dt;

    // Defer structural changes safely
    if (pos.x > 10) w.cmd().despawn(e);
  }
});

world.update(1 / 60);

Note: SystemFn is typed as (world: WorldApi, dt) => void.


Notes & limitations

  • This is intentionally minimal: no parallelism, no borrow-checking, no automatic conflict detection.
  • Query results use c1/c2/... fields for stability and speed; you can wrap this in helpers if you prefer tuple returns.
  • TypeId assignment is process-local and based on constructor identity (WeakMap).

License

This code is distributed under the terms and conditions of the MIT license.