typescript
/
ecs
Archived
1
0
Fork 0
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.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.
 
 

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 1 year ago
doc Add relations system 1 year ago
.editorconfig Initial structure 2 years ago
.gitignore Add relations system 1 year ago
README.md Add relations system 1 year ago
TODO.md relations: Add subgroup iterator 1 year ago
base.test.ts Fix handling of undefined state values 2 years ago
base.ts Add relations system 1 year ago
deps.testing.ts States are stored in entities as maps instead of sparse arrays 2 years ago
deps.ts Fix handling of undefined state values 2 years ago
grid.test.ts Add isPresent function in grid system 2 years ago
grid.ts Add isPresent function in grid system 2 years ago
mod.ts Add missing export 1 year ago
overrides.test.ts Allow to remove previously set override 2 years ago
overrides.ts Allow to remove previously set override 2 years ago
relations.test.ts relations: Add subgroup iterator 1 year ago
relations.ts relations: Add subgroup iterator 1 year ago
run Initial structure 2 years ago
testing.ts States are stored in entities as maps instead of sparse arrays 2 years ago
tsconfig.json Initial structure 2 years ago
turns.test.ts turns: Add immediate dependencies 2 years ago
turns.ts turns: Add immediate dependencies 2 years ago