/** * Entity API Object (for storing / loading entities to and from API) * @constructor * @param id * @param name * @param entities GameLib.API.Entity[] * @param parentEntity */ GameLib.API.EntityManager = function( id, name, entities, // systems, parentEntity ) { GameLib.Component.call( this, GameLib.Component.COMPONENT_ENTITY_MANAGER, { 'entities' : [GameLib.Entity] // 'systems' : [GameLib.System] }, null, parentEntity ); if (GameLib.Utils.UndefinedOrNull(id)) { id = GameLib.Utils.RandomId(); } this.id = id; if (GameLib.Utils.UndefinedOrNull(name)) { name = 'Entity Manager (' + this.id + ')'; } this.name = name; if (GameLib.Utils.UndefinedOrNull(entities)) { entities = []; } this.entities = entities; // if (GameLib.Utils.UndefinedOrNull(systems)) { // systems = []; // } // this.systems = systems; }; GameLib.API.EntityManager.prototype = Object.create(GameLib.Component.prototype); GameLib.API.EntityManager.prototype.constructor = GameLib.API.EntityManager; /** * Creates an API entity manager from an Object entity manager * @param objectEntityManager * @constructor */ GameLib.API.EntityManager.FromObjectEntityManager = function(objectEntityManager) { var apiEntities = objectEntityManager.entities.map( function (objectEntity) { return GameLib.API.Entity.FromObjectEntity(objectEntity); } ); // var apiSystems = objectEntityManager.systems.map( // function (objectSystem) { // return GameLib.API.System.FromObjectComponent(objectSystem); // } // ); return new GameLib.API.EntityManager( objectEntityManager.id, objectEntityManager.name, apiEntities, // apiSystems, objectEntityManager.parentEntity ); };