# entts

> An Entity Component System written in TypeScript

Latest version **1.2.0** (published 2022-11-30) · MIT license · 0 weekly downloads

## Install

```sh
npm install entts
pnpm add entts
yarn add entts
bun add entts
```

## Health

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

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.2.0 |
| Published | 2022-11-30 |
| First published | 2022-06-01 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 26.9 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 4 |
| Author | Salem Cresswell |
| Maintainers | salemc |
| Keywords | Typescript, ECS |

## Links

- npm: https://www.npmjs.com/package/entts
- Repository: https://github.com/SalemC/EntTS
- Homepage: https://github.com/SalemC/EntTS#readme
- Issues: https://github.com/SalemC/EntTS/issues
- npm.io page: https://npm.io/package/entts

## Dependencies (1)

- [uuid](https://npm.io/package/uuid.md) ^8.3.2

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 1.2.0 (latest) — 2022-11-30
- 1.1.0 — 2022-11-26
- 1.0.3 — 2022-06-01

## README

# EntTS &middot; [![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/SalemC/EntTS/blob/main/LICENSE) [![npm version](https://img.shields.io/npm/v/entts)](https://www.npmjs.com/package/entts)

An Entity Component System, written in TypeScript for JavaScript/TypeScript applications.

## Installation

You can install this package with either NPM or Yarn:

-   NPM: `npm install --save entts`
-   Yarn: `yarn add entts`

## Basic Example

```ts
import { EntityManager, SystemManager, System, Entity } from 'entts';

// Firstly, create yourself some `POD` components!
class PositionComponent {
    public x: number = 0;
    public y: number = 0;
}

class GravityComponent {
    public amount: number = 0.1;
}

// Then, you'll want at least one system to handle your components!
class MovementSystem extends System {
    // Any entities with *exactly* these components will be available in the `onUpdate` method.
    public components = [PositionComponent, GravityComponent];

    // This method is called every time the SystemManager updates.
    public onUpdate() {
        this.entities.forEach((entityId) => {
            const entity = new Entity(entityId);

            // Grab a reference to the components for the current entity.
            const position = entity.getComponent(PositionComponent);
            const gravity = entity.getComponent(GravityComponent);

            // These components should never be null, but better safe than sorry!
            if (!position || !gravity) return;

            // Then, let's perform some changes to that component!
            position.y -= gravity.amount;
        });
    }
}

// Make sure you add your system to the `SystemManager`, otherwise it won't be aware of it!
SystemManager.add(MovementSystem);

// Now that the setup is all done, let's create an entity.
const entity = EntityManager.createEntity();

// Be sure to add any relevant components to entities you create too!
// This can be done at any time, but so we don't forget we'll do it now.
entity.addComponent(PositionComponent);
entity.addComponent(GravityComponent);

// SystemManager needs to be updated periodically in order for it to perform changes.
// We'll use a setInterval here, but you could use any kind of loop.
setInterval(() => {
    SystemManager.update();
}, 1);

// That's it! Let's make sure things are occurring though...
setInterval(() => {
    console.log(entity.getComponent(PositionComponent));
    console.log(entity.getComponent(GravityComponent));
}, 500);
```

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