2016-11-29 12:54:25 +01:00
|
|
|
/**
|
2016-12-12 17:24:05 +01:00
|
|
|
* Entity API Object (for storing / loading entities to and from API)
|
2016-11-29 12:54:25 +01:00
|
|
|
* @param id
|
|
|
|
* @param name
|
2016-12-15 14:53:39 +01:00
|
|
|
* @param components GameLib.Component[]
|
2017-02-22 16:06:27 +01:00
|
|
|
* @param parentEntity GameLib.Entity
|
2017-05-22 15:42:05 +02:00
|
|
|
* @param parentEntityManager
|
2016-11-29 12:54:25 +01:00
|
|
|
* @constructor
|
|
|
|
*/
|
2016-12-15 14:53:39 +01:00
|
|
|
GameLib.API.Entity = function(
|
2016-11-29 12:54:25 +01:00
|
|
|
id,
|
|
|
|
name,
|
2017-02-22 16:06:27 +01:00
|
|
|
components,
|
2017-05-22 15:42:05 +02:00
|
|
|
parentEntity,
|
|
|
|
parentEntityManager
|
2016-11-29 12:54:25 +01:00
|
|
|
) {
|
2017-02-22 16:06:27 +01:00
|
|
|
if (GameLib.Utils.UndefinedOrNull(parentEntity)) {
|
|
|
|
parentEntity = null;
|
|
|
|
}
|
|
|
|
this.parentEntity = parentEntity;
|
|
|
|
|
2017-05-22 15:42:05 +02:00
|
|
|
if (GameLib.Utils.UndefinedOrNull(parentEntityManager)) {
|
|
|
|
parentEntityManager = null;
|
|
|
|
}
|
|
|
|
this.parentEntityManager = parentEntityManager;
|
|
|
|
|
2017-06-06 11:25:02 +02:00
|
|
|
this.activeComponent = null;
|
|
|
|
|
2016-12-15 14:53:39 +01:00
|
|
|
if (GameLib.Utils.UndefinedOrNull(id)) {
|
|
|
|
id = GameLib.Utils.RandomId();
|
2016-11-29 12:54:25 +01:00
|
|
|
}
|
|
|
|
this.id = id;
|
|
|
|
|
2016-12-15 14:53:39 +01:00
|
|
|
if (GameLib.Utils.UndefinedOrNull(name)) {
|
2017-01-19 17:50:11 +01:00
|
|
|
name = 'Entity (' + this.id + ')';
|
2016-11-29 12:54:25 +01:00
|
|
|
}
|
|
|
|
this.name = name;
|
|
|
|
|
2016-12-15 14:53:39 +01:00
|
|
|
if (GameLib.Utils.UndefinedOrNull(components)) {
|
2016-12-12 17:24:05 +01:00
|
|
|
components = [];
|
2016-11-29 12:54:25 +01:00
|
|
|
}
|
2016-12-12 17:24:05 +01:00
|
|
|
this.components = components;
|
2016-12-15 14:53:39 +01:00
|
|
|
};
|
2016-11-29 12:54:25 +01:00
|
|
|
|
2017-02-22 16:06:27 +01:00
|
|
|
GameLib.API.Entity.prototype = Object.create(GameLib.Component.prototype);
|
|
|
|
GameLib.API.Entity.prototype.constructor = GameLib.API.Entity;
|
|
|
|
|
2017-01-05 19:34:28 +01:00
|
|
|
/**
|
|
|
|
* Returns an API entity from an Object entity
|
|
|
|
* @param objectEntity
|
|
|
|
* @constructor
|
|
|
|
*/
|
2017-06-14 14:21:57 +02:00
|
|
|
GameLib.API.Entity.FromObject = function(objectEntity) {
|
2017-01-06 16:53:53 +01:00
|
|
|
|
|
|
|
var apiComponents = objectEntity.components.map(
|
|
|
|
function (objectComponent) {
|
2017-06-14 14:21:57 +02:00
|
|
|
return GameLib.API.Component.FromObject(objectComponent);
|
2017-01-06 16:53:53 +01:00
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2017-01-05 19:34:28 +01:00
|
|
|
return new GameLib.API.Entity(
|
|
|
|
objectEntity.id,
|
|
|
|
objectEntity.name,
|
2017-05-22 15:42:05 +02:00
|
|
|
apiComponents,
|
|
|
|
objectEntity.parentEntity,
|
|
|
|
objectEntity.parentEntityManager
|
2017-01-05 19:34:28 +01:00
|
|
|
)
|
|
|
|
};
|