-
Notifications
You must be signed in to change notification settings - Fork 0
Home
Arse09 edited this page Sep 9, 2025
·
13 revisions
Welcome to the just-an-ecs wiki!
Components are data containers attached to entities. They store state but do not contain behavior.
import { Component, createComponent } from "@arse09/just-an-ecs";
@createComponent
export class ComponentNameC extends Component<{ x: number; y: number; }> {
public x = this.args.x;
public y = this.args.y;
}Components can also be "tag" components, which contain no data and are used to mark entities.
import { Component, createComponent } from "@arse09/just-an-ecs";
@createComponent
export class ComponentNameTagC extends Component { }Resources are global data stores accessible by all systems. Unlike components, which are per-entity, resources exist only once and are ideal for things like time tracking, game state, or configuration data.
import { Resource, createResource } from "@arse09/just-an-ecs";
@createResource
export class ResourceNameR extends Resource<{
canvas: HTMLCanvasElement;
ctx: CanvasRenderingContext2D
}> {
public canvas = this.args.canvas;
public ctx = this.args.canvas;
}Systems contain the logic of your game. They query entities and resources, then update or process data each frame. Systems are executed in the order they are registered in the ECS.
import { Sys, type SysInstance } from "@arse09/just-an-ecs";
export class SystemNameS extends Sys implements SysInstance {
// Query components
readonly query = this.ecs.query(ComponentNameC);
// Query resources
readonly res = this.ecs.queryRes(ResourceNameR);
// Runs once before the loop
setup(): void {
/*
If fail is true, the function will throw
if the resource/component doesn't exist on the ecs.
*/
// read() returns a read-only reference to the component
const resource = this.query.read(ResourceNameR, /* fail?: */ true);
const component = this.res.read(ResourceNameR, /* fail?: */ true);
/* Do something */
}
// Runs once every frame
update(): void {
// write() returns a writable reference to the component
const resource = this.query.write(ResourceNameR, /* fail?: */ true);
const component = this.res.write(ResourceNameR, /* fail?: */ true);
/* Do something */
}
}