Skip to main content

latest

TypeScript entity component system favouring simple objects.

This package works with Node.js, Deno, Bun, BrowsersIt is unknown whether this package works with Cloudflare Workers
It is unknown whether this package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
This package works with Bun
This package works with Browsers
JSR Score
94%
Published
7 months ago (0.1.7)
class World

Container for entity and archetype management.

Examples

Example 1

type Entity = {
  position: { x: number; y: number };
  velocity: { x: number; y: number };
};

const world = new World<Entity>();

const entity = world.createEntity({
  position: { x: 0, y: 0 },
  velocity: { x: 0, y: 0 },
});

Type Parameters

Entity extends JsonObject

Properties

readonly
entities: ReadonlySet<Entity>

Methods

addEntityComponents<
T extends Entity,
Component extends keyof Entity,
>
(
entity: T,
component: Component,
value: NonNullable<Entity[Component]>,
): T & Record<component, value>
archetype<Components extends Array<keyof Entity>>(...components: Components): Archetype<SafeEntity<Entity, (components)[number]>, components>

Returns a new archetype that will guarantee that all entities within it will have the given components.

Removes all entities from the world and all archetypes.

createEntity<T extends Entity>(entity: T): keyof entity extends never ? never : Pick<Entity & T, keyof entity>

Create an entity with the given components. This is a type-safe version but it is of a point in time. When the entity is created. So don't rely on it to be type-safe in the future when used within systems.

removeEntityComponents<
T extends Entity,
Component extends keyof Entity,
>
(
entity: T,
...components: Array<Component>,
): void

Add Package

deno add jsr:@gamedev/objecs

Import symbol

import { World } from "@gamedev/objecs";

---- OR ----

Import directly with a jsr specifier

import { World } from "jsr:@gamedev/objecs";

Add Package

npx jsr add @gamedev/objecs

Import symbol

import { World } from "@gamedev/objecs";

Add Package

yarn dlx jsr add @gamedev/objecs

Import symbol

import { World } from "@gamedev/objecs";

Add Package

pnpm dlx jsr add @gamedev/objecs

Import symbol

import { World } from "@gamedev/objecs";

Add Package

bunx jsr add @gamedev/objecs

Import symbol

import { World } from "@gamedev/objecs";