entities are components
parent
585c8e0d6f
commit
4832eb5b3d
|
@ -169,18 +169,14 @@ GameLib.Component.prototype.linkObjects = function(idToObject) {
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
if (this[property] instanceof Object) {
|
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) {
|
if (this[property].linkObjects) {
|
||||||
this[property].linkObjects(idToObject);
|
this[property].linkObjects(idToObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
return this[property];
|
|
||||||
|
|
||||||
} else if (typeof this[property] == 'string') {
|
} else if (typeof this[property] == 'string') {
|
||||||
|
|
||||||
if (!idToObject[this[property]]) {
|
if (!idToObject[this[property]]) {
|
||||||
|
|
|
@ -3,13 +3,30 @@
|
||||||
* @param id
|
* @param id
|
||||||
* @param name
|
* @param name
|
||||||
* @param components GameLib.Component[]
|
* @param components GameLib.Component[]
|
||||||
|
* @param parentEntity GameLib.Entity
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
GameLib.API.Entity = function(
|
GameLib.API.Entity = function(
|
||||||
id,
|
id,
|
||||||
name,
|
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)) {
|
if (GameLib.Utils.UndefinedOrNull(id)) {
|
||||||
id = GameLib.Utils.RandomId();
|
id = GameLib.Utils.RandomId();
|
||||||
}
|
}
|
||||||
|
@ -26,6 +43,9 @@ GameLib.API.Entity = function(
|
||||||
this.components = components;
|
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
|
* Returns an API entity from an Object entity
|
||||||
* @param objectEntity
|
* @param objectEntity
|
||||||
|
|
|
@ -195,13 +195,15 @@ GameLib.D3.Editor = function(
|
||||||
}
|
}
|
||||||
this.onDeSelectObject = onDeSelectObject;
|
this.onDeSelectObject = onDeSelectObject;
|
||||||
|
|
||||||
this.buildIdToObject();
|
|
||||||
|
|
||||||
this.meshMoveMode = false;
|
this.meshMoveMode = false;
|
||||||
this.meshMoveXMode = false;
|
this.meshMoveXMode = false;
|
||||||
this.meshMoveYMode = false;
|
this.meshMoveYMode = false;
|
||||||
this.meshMoveZMode = false;
|
this.meshMoveZMode = false;
|
||||||
|
|
||||||
|
this.buildIdToObject();
|
||||||
|
|
||||||
|
this.linkObjects(this.idToObject);
|
||||||
|
|
||||||
this.instance = this.createInstance();
|
this.instance = this.createInstance();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -139,7 +139,7 @@ GameLib.D3.Game = function (
|
||||||
|
|
||||||
this.buildIdToObject();
|
this.buildIdToObject();
|
||||||
|
|
||||||
this.entityManager.linkObjects(this.idToObject);
|
this.linkObjects(this.idToObject);
|
||||||
};
|
};
|
||||||
|
|
||||||
GameLib.D3.Game.prototype = Object.create(GameLib.D3.API.Game.prototype);
|
GameLib.D3.Game.prototype = Object.create(GameLib.D3.API.Game.prototype);
|
||||||
|
|
|
@ -210,28 +210,28 @@ GameLib.EntityManager.FromObjectEntityManager = function(graphics, objectEntityM
|
||||||
* Links object Ids to actual objects
|
* Links object Ids to actual objects
|
||||||
* @param idToObject
|
* @param idToObject
|
||||||
*/
|
*/
|
||||||
GameLib.EntityManager.prototype.linkObjects = function(idToObject) {
|
// GameLib.EntityManager.prototype.linkObjects = function(idToObject) {
|
||||||
|
//
|
||||||
this.entities.map(
|
// this.entities.map(
|
||||||
function(entity) {
|
// function(entity) {
|
||||||
entity.components.map(
|
// entity.components.map(
|
||||||
function (componentId, index, array) {
|
// function (componentId, index, array) {
|
||||||
if (componentId instanceof GameLib.Component) {
|
// if (componentId instanceof GameLib.Component) {
|
||||||
array[index] = componentId;
|
// array[index] = componentId;
|
||||||
} else {
|
// } else {
|
||||||
array[index] = idToObject[componentId];
|
// array[index] = idToObject[componentId];
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
Object.keys(array[index].linkedObjects).map(
|
// Object.keys(array[index].linkedObjects).map(
|
||||||
function (propertyName) {
|
// function (propertyName) {
|
||||||
array[index][propertyName] = idToObject[array[index][propertyName]];
|
// array[index][propertyName] = idToObject[array[index][propertyName]];
|
||||||
}
|
// }
|
||||||
);
|
// );
|
||||||
|
//
|
||||||
array[index].loaded = true;
|
// array[index].loaded = true;
|
||||||
}
|
// }
|
||||||
)
|
// )
|
||||||
}
|
// }
|
||||||
);
|
// );
|
||||||
|
//
|
||||||
};
|
// };
|
Loading…
Reference in New Issue