62 lines
1.5 KiB
JavaScript
62 lines
1.5 KiB
JavaScript
/**
|
|
* Entity API Object (for storing / loading entities to and from API)
|
|
* @param id
|
|
* @param name
|
|
* @param components GameLib.Component[]
|
|
* @param parentEntity GameLib.Entity
|
|
* @param parentEntityManager
|
|
* @constructor
|
|
*/
|
|
GameLib.API.Entity = function(
|
|
id,
|
|
name,
|
|
components,
|
|
parentEntity,
|
|
parentEntityManager
|
|
) {
|
|
if (GameLib.Utils.UndefinedOrNull(id)) {
|
|
id = GameLib.Utils.RandomId();
|
|
}
|
|
this.id = id;
|
|
|
|
if (GameLib.Utils.UndefinedOrNull(name)) {
|
|
name = 'Entity (' + this.id + ')';
|
|
}
|
|
this.name = name;
|
|
|
|
if (GameLib.Utils.UndefinedOrNull(components)) {
|
|
components = [];
|
|
}
|
|
this.components = components;
|
|
|
|
if (GameLib.Utils.UndefinedOrNull(parentEntity)) {
|
|
parentEntity = null;
|
|
}
|
|
this.parentEntity = parentEntity;
|
|
|
|
if (GameLib.Utils.UndefinedOrNull(parentEntityManager)) {
|
|
parentEntityManager = null;
|
|
}
|
|
this.parentEntityManager = parentEntityManager;
|
|
|
|
this.activeComponent = null;
|
|
};
|
|
|
|
GameLib.API.Entity.prototype = Object.create(GameLib.Component.prototype);
|
|
GameLib.API.Entity.prototype.constructor = GameLib.API.Entity;
|
|
|
|
/**
|
|
* Returns an API entity from an Object entity
|
|
* @param objectEntity
|
|
* @constructor
|
|
*/
|
|
GameLib.API.Entity.FromObject = function(objectEntity) {
|
|
return new GameLib.API.Entity(
|
|
objectEntity.id,
|
|
objectEntity.name,
|
|
objectEntity.components,
|
|
objectEntity.parentEntity,
|
|
objectEntity.parentEntityManager
|
|
)
|
|
};
|