entities are components

beta.r3js.org
Theunis J. Botha 2017-02-22 16:06:27 +01:00
parent 585c8e0d6f
commit 4832eb5b3d
5 changed files with 52 additions and 34 deletions

View File

@ -169,18 +169,14 @@ GameLib.Component.prototype.linkObjects = function(idToObject) {
} else {
if (this[property] instanceof Object) {
//
// this[property].parentObjects.push(this);
/**
* This object is already an object
* This object is already an object, perform deep linking
*/
if (this[property].linkObjects) {
this[property].linkObjects(idToObject);
}
return this[property];
} else if (typeof this[property] == 'string') {
if (!idToObject[this[property]]) {

View File

@ -3,13 +3,30 @@
* @param id
* @param name
* @param components GameLib.Component[]
* @param parentEntity GameLib.Entity
* @constructor
*/
GameLib.API.Entity = function(
id,
name,
components
components,
parentEntity
) {
if (GameLib.Utils.UndefinedOrNull(parentEntity)) {
parentEntity = null;
}
this.parentEntity = parentEntity;
GameLib.Component.call(
this,
GameLib.Component.COMPONENT_ENTITY,
{
'components' : [GameLib.Component]
},
null,
parentEntity
);
if (GameLib.Utils.UndefinedOrNull(id)) {
id = GameLib.Utils.RandomId();
}
@ -26,6 +43,9 @@ GameLib.API.Entity = function(
this.components = components;
};
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

View File

@ -195,13 +195,15 @@ GameLib.D3.Editor = function(
}
this.onDeSelectObject = onDeSelectObject;
this.buildIdToObject();
this.meshMoveMode = false;
this.meshMoveXMode = false;
this.meshMoveYMode = false;
this.meshMoveZMode = false;
this.buildIdToObject();
this.linkObjects(this.idToObject);
this.instance = this.createInstance();
};

View File

@ -139,7 +139,7 @@ GameLib.D3.Game = function (
this.buildIdToObject();
this.entityManager.linkObjects(this.idToObject);
this.linkObjects(this.idToObject);
};
GameLib.D3.Game.prototype = Object.create(GameLib.D3.API.Game.prototype);

View File

@ -210,28 +210,28 @@ GameLib.EntityManager.FromObjectEntityManager = function(graphics, objectEntityM
* Links object Ids to actual objects
* @param idToObject
*/
GameLib.EntityManager.prototype.linkObjects = function(idToObject) {
this.entities.map(
function(entity) {
entity.components.map(
function (componentId, index, array) {
if (componentId instanceof GameLib.Component) {
array[index] = componentId;
} else {
array[index] = idToObject[componentId];
}
Object.keys(array[index].linkedObjects).map(
function (propertyName) {
array[index][propertyName] = idToObject[array[index][propertyName]];
}
);
array[index].loaded = true;
}
)
}
);
};
// GameLib.EntityManager.prototype.linkObjects = function(idToObject) {
//
// this.entities.map(
// function(entity) {
// entity.components.map(
// function (componentId, index, array) {
// if (componentId instanceof GameLib.Component) {
// array[index] = componentId;
// } else {
// array[index] = idToObject[componentId];
// }
//
// Object.keys(array[index].linkedObjects).map(
// function (propertyName) {
// array[index][propertyName] = idToObject[array[index][propertyName]];
// }
// );
//
// array[index].loaded = true;
// }
// )
// }
// );
//
// };