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

53 lines
1.1 KiB
JavaScript
Raw Normal View History

2018-04-09 09:35:04 +02:00
/**
* Entity API Object (for storing / loading entities to and from API)
* @param id
* @param name
* @param components R3.Component[]
* @param parentEntity R3.Entity
* @constructor
*/
R3.API.Entity = function(
id,
name,
components,
parentEntity
) {
if (R3.Utils.UndefinedOrNull(id)) {
id = R3.Utils.RandomId();
}
this.id = id;
if (R3.Utils.UndefinedOrNull(name)) {
name = 'Entity (' + this.id + ')';
}
this.name = name;
if (R3.Utils.UndefinedOrNull(components)) {
components = [];
}
this.components = components;
R3.API.Component.call(
this,
R3.Component.ENTITY,
parentEntity
);
};
R3.API.Entity.prototype = Object.create(R3.API.Component.prototype);
R3.API.Entity.prototype.constructor = R3.API.Entity;
/**
* Returns an API entity from an Object entity
* @param objectEntity
* @constructor
*/
R3.API.Entity.FromObject = function(objectEntity) {
return new R3.API.Entity(
objectEntity.id,
objectEntity.name,
objectEntity.components,
objectEntity.parentEntity
)
};