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

62 lines
1.5 KiB
JavaScript
Raw Normal View History

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
) {
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;
2017-06-25 13:31:24 +02:00
if (GameLib.Utils.UndefinedOrNull(parentEntity)) {
parentEntity = null;
}
this.parentEntity = parentEntity;
if (GameLib.Utils.UndefinedOrNull(parentEntityManager)) {
parentEntityManager = null;
}
this.parentEntityManager = parentEntityManager;
this.activeComponent = null;
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-05 19:34:28 +01:00
return new GameLib.API.Entity(
objectEntity.id,
objectEntity.name,
2017-06-25 13:31:24 +02:00
objectEntity.components,
2017-05-22 15:42:05 +02:00
objectEntity.parentEntity,
objectEntity.parentEntityManager
2017-01-05 19:34:28 +01:00
)
};