npm package: @nikolas.karinja/ecs
Description: A simple Entity Component System. Comes with Manager, Entity, Component classes and some example components as well.
Author: Nikolas Karinja
Latest version: 0.2.15

# Entity Component System

[![NPM Package][npm]][npm-url]

#### A simple ECS

Developed by [Nikolas Karinja](http://nikolaskarinja.com/)

A very simple yet dynamic way of handling entities and components. It comes with the `ECSManager`, which allows you to create custom and complex entity structures. Now you can have access to them as well, and most of my packages are updated weekly if not daily. 

## Installation

I only have the option for NPM at the moment.

### npm

```
npm i --save @nikolas.karinja/ecs
```

## Usage

This package is meant to be used with ES Modules.

### HTML Tag

```html
<script src='node_modules/@nikolas.karinja/ecs/src/index.js' type='module'></script>
```

### Script (ES Module)

```javascript
// Using parcel or another package manager

import * as ECS from '@nikolas.karinja/ecs'

// Using default file system

import * as ECS from 'node_modules/@nikolas.karinja/ecs/src/index.js'
```

## Usage

- Allows for dynamic creation and storage of components and entities.
- The Manager allows you to create custom entity assemblies.
- Eveything is dynamic and extendable. 
- Most methods have [JSDoc](https://jsdoc.app/) descriptions.
- I will post documentation soon.

#### Example

I will post more examples and documentation soon. Although, since the functions and classes all have [JSDoc](https://jsdoc.app/) descriptions, it's pretty self-explanatory. Here is a simple example.

```javascript
import * as AppUtils from '@nikolas.karinja/app-utils'
import * as ECS      from '@nikolas.karinja/ecs'
import * as THREE    from 'three'

class CubeMesh extends ECS.Component {

    constructor ( parent, scene ) {

        super( parent )

        this.Geometry = new THREE.BoxGeometry( 0.5, 0.5, 0.5 )
        this.Material = new THREE.MeshNormalMaterial()
        this.Mesh     = new THREE.Mesh( this.Geometry, this.Material )

        scene.add( this.Mesh )

    }

    getMesh () {

        return this.Mesh

    }

    onUpdate ( deltaTime, elapsedTime ) {

        this.Mesh.rotation.x += deltaTime
        this.Mesh.rotation.y = elapsedTime

    }

}

class CubeMeshScale extends ECS.Component {

    constructor ( parent ) {

        super( parent )

        console.log( this.getComponent( 'CubeMesh' ) )

        this.Mesh = this.getComponent( 'CubeMesh' ).Mesh

    }

    onUpdate ( deltaTime, elapsedTime ) {

        const scale = Math.sin( elapsedTime )

        this.Mesh.scale.set( scale, scale, scale )

    }

}


AppUtils.Apps.startApp( class App extends AppUtils.Apps.ExampleThreeApp {

    constructor ( settings ) {

        super( settings )

        this.Manager = new ECS.Manager()

    }

    async onStart () {

        this.Manager.createAssembly( 'Cube', async ( entity, scene ) => {

            await entity.addComponent( CubeMesh, scene )
            await entity.addComponent( CubeMeshScale )

        } )

        await this.Manager.assembleAsync( 'Cube', ECS.Entity, {
            assemblyArgs: [ this.Scene ]
        } )

    }

    onUpdate ( deltaTime, elapsedTime, updateAnim ) {

        this.Manager.update( deltaTime, elapsedTime, updateAnim )

    }

} )
```

[npm]: https://shields.io/npm/v/@nikolas.karinja/ecs
[npm-url]: https://www.npmjs.com/package/@nikolas.karinja/ecs