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

54 lines
1.3 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
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
*/
2017-06-14 14:21:57 +02:00
GameLib.API.EntityManager.FromObject = function(objectEntityManager) {
2017-01-05 19:34:28 +01:00
2017-01-06 16:53:53 +01:00
var apiEntities = objectEntityManager.entities.map(
function (objectEntity) {
2017-06-14 14:21:57 +02:00
return GameLib.API.Entity.FromObject(objectEntity);
2017-01-06 16:53:53 +01:00
}
);
2017-05-11 17:52:33 +02:00
// var apiSystems = objectEntityManager.systems.map(
// function (objectSystem) {
2017-06-14 14:21:57 +02:00
// return GameLib.API.System.FromObject(objectSystem);
2017-05-11 17:52:33 +02:00
// }
// );
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
};