# @rzuppur/recs

> Small entity component system based framework for 2D game development in Typescript

Latest version **0.1.89** (published 2024-03-14) · 0 weekly downloads

## Install

```sh
npm install @rzuppur/recs
pnpm add @rzuppur/recs
yarn add @rzuppur/recs
bun add @rzuppur/recs
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.89 |
| Published | 2024-03-14 |
| First published | 2021-02-24 |
| Weekly downloads | 0 |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=18.0.0 <19.0.0 |
| Dependencies | 0 |
| Unpacked size | 58.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Reino Zuppur |
| Maintainers | rzuppur |

## Links

- npm: https://www.npmjs.com/package/@rzuppur/recs
- npm.io page: https://npm.io/package/@rzuppur/recs

## Recent versions

- 0.1.89 (latest) — 2024-03-14
- 0.1.88 — 2024-03-14
- 0.1.87 — 2023-11-16
- 0.1.86 — 2023-11-16
- 0.1.85 — 2023-11-16
- 0.1.84 — 2023-11-16
- 0.1.82 — 2022-12-11
- 0.1.81 — 2022-12-11
- 0.1.80 — 2022-12-11
- 0.1.78 — 2022-12-11
- 0.1.77 — 2022-12-11
- 0.1.76 — 2022-12-11
- 0.1.75 — 2022-12-11
- 0.1.74 — 2022-12-11
- 0.1.73 — 2022-12-11
- … 73 more at https://npm.io/package/@rzuppur/recs/versions

## README

# RECS
Minimal entity component system for 2D game development in JS/TS

*Example game based on RECS ([Video link](https://reinozuppur.com/screens/space.mp4))*
![Space](https://reinozuppur.com/screens/space.jpg "")

```ts
import { Engine, Entity } from "@rzuppur/recs";

const elementToMountTo = "#app"; // default: body, pointer events break if page is scrolled
const engine = new Engine(elementToMountTo);
const manager = engine.manager;

/* Register custom components (see below) */
manager.registerComponent(new Component());

/* Register custom systems (see below) */
manager.registerSystem(new System());

/* Create entities, returns id */
const entity: Entity = manager.createEntity();

/* Add entity components */
manager.setComponent(entity, new Component({ data }));
```

## Creating a custom component
```ts
import { Component, ComponentData } from "@rzuppur/recs";

interface MyData extends ComponentData {
    value: number;
}

class MyComponent extends Component {
    static key = "My";
    public data: MyData;

    constructor(data?: MyData) {
        super(MyComponent.key, data);
    }
}
```

## Creating a custom system
```ts
import { System, Query, PointableComponent } from "@rzuppur/recs";

const name = "My";
const componentsQuery = [PointableComponent.key];

class MySystem extends System {
    constructor() {
        super(name, componentsQuery);
    }

    public start(query: Query, manager: Manager): boolean {
        // Add custom initialization code here if needed
        return super.start(query, manager);
    }

    public tick(dt: number /* ms since last tick */): void {
        for (const [entity, components] of this.query.getMatching()) {
            const p = Query.getComponent(components, PointableComponent);
            if (p.data.clicked) {
                console.log("clicked", entity);
            }
        }
    }
}
```

## Built in components
https://github.com/rzuppur/recs/tree/main/src/lib/components

## Built in systems
https://github.com/rzuppur/recs/tree/main/src/lib/systems

---
_Source: https://npm.io/package/@rzuppur/recs · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
