r3-legacy/src/game-lib-api-entity-manager.js

76 lines
1.8 KiB
JavaScript
Raw Normal View History

2016-12-15 14:53:39 +01:00
/**
* Entity API Object (for storing / loading entities to and from API)
* @constructor
2017-01-19 17:50:11 +01:00
* @param id
* @param name
2016-12-15 14:53:39 +01:00
* @param entities GameLib.API.Entity[]
2017-01-19 17:50:11 +01:00
* @param parentEntity
2016-12-15 14:53:39 +01:00
*/
GameLib.API.EntityManager = function(
2017-01-19 17:50:11 +01:00
id,
name,
entities,
2017-05-11 17:52:33 +02:00
// systems,
2017-01-19 17:50:11 +01:00
parentEntity
2016-12-15 14:53:39 +01:00
) {
2017-01-19 17:50:11 +01:00
GameLib.Component.call(
this,
GameLib.Component.COMPONENT_ENTITY_MANAGER,
{
'entities' : [GameLib.Entity]
},
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;
2016-12-15 14:53:39 +01:00
if (GameLib.Utils.UndefinedOrNull(entities)) {
entities = [];
}
this.entities = entities;
2017-05-11 17:52:33 +02:00
// if (GameLib.Utils.UndefinedOrNull(systems)) {
// systems = [];
// }
// this.systems = systems;
2016-12-15 14:53:39 +01:00
};
2017-01-05 19:34:28 +01:00
2017-01-19 17:50:11 +01:00
GameLib.API.EntityManager.prototype = Object.create(GameLib.Component.prototype);
GameLib.API.EntityManager.prototype.constructor = GameLib.API.EntityManager;
2017-01-05 19:34:28 +01:00
/**
* Creates an API entity manager from an Object entity manager
* @param objectEntityManager
* @constructor
*/
GameLib.API.EntityManager.FromObjectEntityManager = function(objectEntityManager) {
2017-01-06 16:53:53 +01:00
var apiEntities = objectEntityManager.entities.map(
function (objectEntity) {
return GameLib.API.Entity.FromObjectEntity(objectEntity);
}
);
2017-05-11 17:52:33 +02:00
// var apiSystems = objectEntityManager.systems.map(
// function (objectSystem) {
// return GameLib.API.System.FromObjectComponent(objectSystem);
// }
// );
2017-01-06 16:53:53 +01:00
return new GameLib.API.EntityManager(
2017-01-19 17:50:11 +01:00
objectEntityManager.id,
objectEntityManager.name,
apiEntities,
2017-05-11 17:52:33 +02:00
// apiSystems,
2017-01-19 17:50:11 +01:00
objectEntityManager.parentEntity
2017-01-06 16:53:53 +01:00
);
2017-01-05 19:34:28 +01:00
};