0.2.15 • Published 1 year ago

@nikolas.karinja/ecs v0.2.15

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

Entity Component System

NPM Package

A simple ECS

Developed by Nikolas Karinja

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

<script src='node_modules/@nikolas.karinja/ecs/src/index.js' type='module'></script>

Script (ES Module)

// 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 descriptions.
  • I will post documentation soon.

Example

I will post more examples and documentation soon. Although, since the functions and classes all have JSDoc descriptions, it's pretty self-explanatory. Here is a simple example.

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 )

    }

} )
0.2.15

1 year ago

0.2.14

1 year ago

0.2.13

1 year ago

0.2.12

2 years ago

0.2.11

2 years ago

0.2.10

2 years ago

0.2.1

2 years ago

0.2.0

2 years ago

0.2.7

2 years ago

0.2.6

2 years ago

0.2.9

2 years ago

0.2.8

2 years ago

0.2.3

2 years ago

0.2.2

2 years ago

0.2.5

2 years ago

0.2.4

2 years ago

0.1.5

2 years ago

0.1.4

2 years ago

0.1.2

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago