diff --git a/src/game-lib-a-component-a.js b/src/game-lib-a-component-a.js index 438c942..2317035 100644 --- a/src/game-lib-a-component-a.js +++ b/src/game-lib-a-component-a.js @@ -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]]) { diff --git a/src/game-lib-api-entity.js b/src/game-lib-api-entity.js index 18bbf17..8eb509a 100644 --- a/src/game-lib-api-entity.js +++ b/src/game-lib-api-entity.js @@ -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 diff --git a/src/game-lib-d3-editor.js b/src/game-lib-d3-editor.js index 142f38b..758a8ea 100644 --- a/src/game-lib-d3-editor.js +++ b/src/game-lib-d3-editor.js @@ -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(); }; diff --git a/src/game-lib-d3-game.js b/src/game-lib-d3-game.js index 0c366d5..4d19be8 100644 --- a/src/game-lib-d3-game.js +++ b/src/game-lib-d3-game.js @@ -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); diff --git a/src/game-lib-entity-manager.js b/src/game-lib-entity-manager.js index 8304b41..815edfb 100644 --- a/src/game-lib-entity-manager.js +++ b/src/game-lib-entity-manager.js @@ -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; - } - ) - } - ); - -}; \ No newline at end of file +// 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; +// } +// ) +// } +// ); +// +// }; \ No newline at end of file