Entity Component System engine for games
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

README.md

typescript/ecs

Build Status

About

Entity Component System engine (for games or other things).

Import

In deno:

import { Engine } from "https://js.thunderk.net/ecs/mod.ts";

In browser:

<script type="module">
import { Engine } from "https://js.thunderk.net/ecs/mod.js";
</script>

Use

Basic example

import { Component, Engine, System } from "./mod.ts";

// Create an engine
const engine = new Engine();

// Prepare some component state typing
type ComponentState = { x: number; y: number };

// Add a system to the engine
class ExampleSystem extends System {
  component: Component<ComponentState>;

  constructor(engine: Engine) {
    super(engine);

    // The system declares a component to be used
    // Parameter is the default state
    this.component = engine.createComponent({ x: 0, y: 0 });
  }
}
const system = engine.createSystem({ ExampleSystem });

// Create an entity
const entity = engine.createEntity();

// Attach the component to the entity
engine.attachComponent(entity, system.component);

// Read the component state
console.log(engine.readState(entity, system.component));
// => {x: 0, y: 0}

// Change the component state (partially)
engine.writeState(entity, system.component, { x: 1 });
console.log(engine.readState(entity, system.component));
// => {x: 1, y: 0}

// Remove the component
engine.detachComponent(entity, system.component);
console.log(engine.readState(entity, system.component));
// => undefined
Michaël Lemaire 7213715771 relations: Add subgroup iterator 3 months ago
doc Add relations system 3 months ago
.editorconfig Initial structure 7 months ago
.gitignore Add relations system 3 months ago
README.md Add relations system 3 months ago
TODO.md relations: Add subgroup iterator 3 months ago
base.test.ts Fix handling of undefined state values 5 months ago
base.ts Add relations system 3 months ago
deps.testing.ts States are stored in entities as maps instead of sparse arrays 5 months ago
deps.ts Fix handling of undefined state values 5 months ago
grid.test.ts Add isPresent function in grid system 6 months ago
grid.ts Add isPresent function in grid system 6 months ago
mod.ts Add missing export 3 months ago
overrides.test.ts Allow to remove previously set override 5 months ago
overrides.ts Allow to remove previously set override 5 months ago
relations.test.ts relations: Add subgroup iterator 3 months ago
relations.ts relations: Add subgroup iterator 3 months ago
run Initial structure 7 months ago
testing.ts States are stored in entities as maps instead of sparse arrays 5 months ago
tsconfig.json Initial structure 7 months ago
turns.test.ts turns: Add immediate dependencies 5 months ago
turns.ts turns: Add immediate dependencies 5 months ago