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
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
|
1 year ago | |
---|---|---|
doc | 1 year ago | |
.editorconfig | 2 years ago | |
.gitignore | 1 year ago | |
README.md | 1 year ago | |
TODO.md | 1 year ago | |
base.test.ts | 2 years ago | |
base.ts | 1 year ago | |
deps.testing.ts | 2 years ago | |
deps.ts | 2 years ago | |
grid.test.ts | 2 years ago | |
grid.ts | 2 years ago | |
mod.ts | 1 year ago | |
overrides.test.ts | 2 years ago | |
overrides.ts | 2 years ago | |
relations.test.ts | 1 year ago | |
relations.ts | 1 year ago | |
run | 2 years ago | |
testing.ts | 2 years ago | |
tsconfig.json | 2 years ago | |
turns.test.ts | 2 years ago | |
turns.ts | 2 years ago |