/** * Entity API Object (for storing / loading entities to and from API) * @param id * @param name * @param components GameLib.Component[] * @constructor */ GameLib.API.Entity = function( id, name, components ) { if (GameLib.Utils.UndefinedOrNull(id)) { id = GameLib.Utils.RandomId(); } this.id = id; if (GameLib.Utils.UndefinedOrNull(name)) { name = this.constructor.name; } this.name = name; if (GameLib.Utils.UndefinedOrNull(components)) { components = []; } this.components = components; }; /** * Adds a components to the entity * @param component GameLib.Component */ GameLib.API.Entity.prototype.addComponent = function(component) { this.components.push(component); this.instance.addComponent(component) }; /** * Removes a component from this entity * @param component GameLib.Component */ GameLib.API.Entity.prototype.removeComponent = function(component) { this.instance.removeComponent(component); var index = this.components.indexOf(component); if (index == -1) { console.log('failed to remove component'); return false; } this.components.splice(index, 1); return true; };