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

59 lines
1.2 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[]
2019-07-24 08:08:02 +02:00
* @param parent R3.Entity
2018-04-09 09:35:04 +02:00
* @constructor
*/
R3.API.Entity = function(
id,
name,
components,
2019-07-24 08:08:02 +02:00
parent
2018-04-09 09:35:04 +02:00
) {
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;
2019-07-24 08:08:02 +02:00
var componentType = R3.Component.ENTITY;
if (this instanceof R3.API.Project) {
componentType = R3.Component.PROJECT;
}
2018-04-09 09:35:04 +02:00
R3.API.Component.call(
this,
2019-07-24 08:08:02 +02:00
componentType,
parent
2018-04-09 09:35:04 +02:00
);
};
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,
2019-07-24 08:08:02 +02:00
objectEntity.parent
2018-04-09 09:35:04 +02:00
)
};