Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

cem

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cem

component-entity manager

  • 0.0.1
  • unpublished
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
9
increased by12.5%
Maintainers
1
Weekly downloads
 
Created
Source

Component entity manager

Build

npm install
grunt

Test

npm test

Usage

//instantiate new manager
var manager = new CEM.Manager();


//create some components
manager.c('alive', {
    health: 100,
    dead: false,
    requires: 'evented',

    take_damage: function(amount) {
        if(this.health > 0){
            this.health -= amount;
            this.trigger('took_damage', [amount]); //trigger event
            if(this.health <= 0){
                this.die();
            }
        }
    },

    event_die: function () {  //explicit event declaration
        this.dead = true;
        console.log('Died!');
    }
});

manager.c('fighter', {
    requires: 'object alive',  //base component; includes events
    name: 'Jhon Doe',
    attack_power: 30,
    attack: function(object) {
        if(object.is('alive')) {
            object.take_damage(this.attack_power);
        }
    }
});

manager.c('wuss', {
    requires: 'evented',
    on_took_damage_exclaim: function () { //event handler. Starts with "on_[event name]", can have any suffix
        console.log('Ouch!');
    }
});

//spawn entities
var bob = manager.e('fighter', {
    name: 'Bob'
});

var troll = manager.e('alive', 'wuss', {
    health: 200
});


//register event handler
troll.on('die', function(){
     console.log('Bob has slain troll!');
});

//slay troll
while(!troll.dead) {
    bob.attack(troll);
}


//and other great features

Keywords

FAQs

Package last updated on 15 Jan 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc