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[]
|
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,
|
2016-12-15 14:53:39 +01:00
|
|
|
components
|
2016-11-29 12:54:25 +01:00
|
|
|
) {
|
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-01-05 19:34:28 +01:00
|
|
|
/**
|
|
|
|
* Returns an API entity from an Object entity
|
|
|
|
* @param objectEntity
|
|
|
|
* @constructor
|
|
|
|
*/
|
|
|
|
GameLib.API.Entity.FromObjectEntity = function(objectEntity) {
|
2017-01-06 16:53:53 +01:00
|
|
|
|
|
|
|
var apiComponents = objectEntity.components.map(
|
|
|
|
function (objectComponent) {
|
|
|
|
return GameLib.API.Component.FromObjectComponent(objectComponent);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2017-01-05 19:34:28 +01:00
|
|
|
return new GameLib.API.Entity(
|
|
|
|
objectEntity.id,
|
|
|
|
objectEntity.name,
|
2017-01-06 16:53:53 +01:00
|
|
|
apiComponents
|
2017-01-05 19:34:28 +01:00
|
|
|
)
|
|
|
|
};
|