From ce3ad977a13fb5604ac914057c97e1845e2387fe Mon Sep 17 00:00:00 2001 From: -=yb4f310 Date: Sat, 30 Dec 2017 11:39:07 +0100 Subject: [PATCH 1/4] start api.mesh.plane --- ...-api-mesh.js => game-lib-d3-api-mesh-0.js} | 0 src/game-lib-d3-api-mesh-plane.js | 106 ++++++++++++++++++ src/game-lib-d3-mesh-plane.js | 88 ++++----------- 3 files changed, 130 insertions(+), 64 deletions(-) rename src/{game-lib-d3-api-mesh.js => game-lib-d3-api-mesh-0.js} (100%) create mode 100644 src/game-lib-d3-api-mesh-plane.js diff --git a/src/game-lib-d3-api-mesh.js b/src/game-lib-d3-api-mesh-0.js similarity index 100% rename from src/game-lib-d3-api-mesh.js rename to src/game-lib-d3-api-mesh-0.js diff --git a/src/game-lib-d3-api-mesh-plane.js b/src/game-lib-d3-api-mesh-plane.js new file mode 100644 index 0000000..46862ec --- /dev/null +++ b/src/game-lib-d3-api-mesh-plane.js @@ -0,0 +1,106 @@ +/** + * Raw Mesh.Plane API object + * @constructor + * @param apiMesh + * @param width + * @param height + * @param widthSegments + * @param heightSegments + * @param heightMapScale + * @param isHeightMap + * @param isDotMap + * @param distanceFromOrigin + */ +GameLib.D3.API.Mesh.Plane = function( + apiMesh, + width, + height, + widthSegments, + heightSegments, + heightMapScale, + isHeightMap, + isDotMap, + distanceFromOrigin +) { + + if (GameLib.Utils.UndefinedOrNull(apiMesh)) { + apiMesh = {}; + } + + GameLib.D3.API.Mesh.call( + this, + apiMesh + ); + + if (GameLib.Utils.UndefinedOrNull(width)) { + width = 1; + } + this.width = width; + + if (GameLib.Utils.UndefinedOrNull(height)) { + height = 1; + } + this.height = height; + + if (GameLib.Utils.UndefinedOrNull(widthSegments)) { + widthSegments = 1; + } + this.widthSegments = widthSegments; + + if (GameLib.Utils.UndefinedOrNull(heightSegments)) { + heightSegments = 1 + } + this.heightSegments = heightSegments; + + if (GameLib.Utils.UndefinedOrNull(heightMapScale)) { + heightMapScale = 1; + } + this.heightMapScale = heightMapScale; + + if (GameLib.Utils.UndefinedOrNull(isHeightMap)) { + isHeightMap = false; + } + this.isHeightMap = isHeightMap; + + if (GameLib.Utils.UndefinedOrNull(isDotMap)) { + isDotMap = false; + } + this.isDotMap = isDotMap; + + if (GameLib.Utils.UndefinedOrNull(distanceFromOrigin)) { + distanceFromOrigin = 0; + } + this.distanceFromOrigin = distanceFromOrigin; + + GameLib.API.Component.call( + this, + GameLib.Component.SOCKET_CAST + ); +}; + +GameLib.D3.API.Mesh.Plane.prototype = Object.create(GameLib.D3.API.Mesh.prototype); +GameLib.D3.API.Mesh.Plane.prototype.constructor = GameLib.D3.API.Mesh.Plane; + +/** + * Returns an API Mesh from an Object mesh + * @param objectMesh + * @constructor + */ +GameLib.D3.API.Mesh.Plane.FromObject = function (objectMesh){ + + + var apiMesh = GameLib.D3.API.Mesh.FromObject(objectMesh); + + return new GameLib.D3.API.Mesh.Plane( + apiMesh, + objectMesh.width, + objectMesh.height, + objectMesh.widthSegments, + objectMesh.heightSegments, + objectMesh.heightMapScale, + objectMesh.isHeightMap, + objectMesh.isDotMap, + objectMesh.distanceFromOrigin + ); + +}; diff --git a/src/game-lib-d3-mesh-plane.js b/src/game-lib-d3-mesh-plane.js index e253ccf..2afb3b0 100644 --- a/src/game-lib-d3-mesh-plane.js +++ b/src/game-lib-d3-mesh-plane.js @@ -1,87 +1,47 @@ /** * Mesh Superset - The apiMesh properties get moved into the Mesh object itself, and then the instance is created * @param graphics GameLib.GraphicsRuntime - * @param apiMesh GameLib.D3.API.Mesh - * @param width - * @param height - * @param widthSegments - * @param heightSegments - * @param heightMapScale - * @param isHeightMap - * @param isClippingPlane - * @param distanceFromOrigin + * @param apiMeshPlane * @constructor */ GameLib.D3.Mesh.Plane = function ( graphics, - apiMesh, - width, - height, - widthSegments, - heightSegments, - heightMapScale, - isHeightMap, - isClippingPlane, - distanceFromOrigin + apiMeshPlane ) { + + this.graphics = graphics; this.graphics.isNotThreeThrow(); - if (GameLib.Utils.UndefinedOrNull(apiMesh)) { - apiMesh = { - meshType: GameLib.D3.API.Mesh.MESH_TYPE_PLANE + if (GameLib.Utils.UndefinedOrNull(apiMeshPlane)) { + apiMeshPlane = { + meshType : GameLib.D3.API.Mesh.MESH_TYPE_PLANE }; } - if (apiMesh instanceof GameLib.D3.Mesh.Plane) { - return apiMesh; + if (apiMeshPlane instanceof GameLib.D3.Mesh.Plane) { + return apiMeshPlane; } - if (GameLib.Utils.UndefinedOrNull(width)) { - width = 1; - } - this.width = width; - - if (GameLib.Utils.UndefinedOrNull(height)) { - height = 1; - } - this.height = height; - - if (GameLib.Utils.UndefinedOrNull(widthSegments)) { - widthSegments = 1; - } - this.widthSegments = widthSegments; - - if (GameLib.Utils.UndefinedOrNull(heightSegments)) { - heightSegments = 1 - } - this.heightSegments = heightSegments; - - if (GameLib.Utils.UndefinedOrNull(heightMapScale)) { - heightMapScale = 1; - } - this.heightMapScale = heightMapScale; - - if (GameLib.Utils.UndefinedOrNull(isHeightMap)) { - isHeightMap = false; - } - this.isHeightMap = isHeightMap; - - if (GameLib.Utils.UndefinedOrNull(isClippingPlane)) { - isClippingPlane = false; - } - this.isClippingPlane = isClippingPlane; - - if (GameLib.Utils.UndefinedOrNull(distanceFromOrigin)) { - distanceFromOrigin = 0; - } - this.distanceFromOrigin = distanceFromOrigin; + GameLib.D3.API.Mesh.Plane.call( + this, + apiMeshPlane, + apiMeshPlane.width, + apiMeshPlane.height, + apiMeshPlane.widthSegments, + apiMeshPlane.heightSegments, + apiMeshPlane.heightMapScale, + apiMeshPlane.isHeightMap, + apiMeshPlane.isDotMap, + apiMeshPlane.distanceFromOrigin + ); GameLib.D3.Mesh.call( this, - this.graphics, - apiMesh + graphics, + apiMeshPlane ); + }; GameLib.D3.Mesh.Plane.prototype = Object.create(GameLib.D3.Mesh.prototype); From 5236d0965c8a5731b9d56c77b63abc0d6c8e0e55 Mon Sep 17 00:00:00 2001 From: -=yb4f310 Date: Sat, 30 Dec 2017 12:43:58 +0100 Subject: [PATCH 2/4] mesh plane streamline --- src/game-lib-d3-api-mesh-plane.js | 55 +++++++++------ src/game-lib-d3-mesh-0.js | 4 ++ src/game-lib-d3-mesh-plane.js | 107 ++++++++++-------------------- 3 files changed, 73 insertions(+), 93 deletions(-) diff --git a/src/game-lib-d3-api-mesh-plane.js b/src/game-lib-d3-api-mesh-plane.js index 46862ec..cf3359f 100644 --- a/src/game-lib-d3-api-mesh-plane.js +++ b/src/game-lib-d3-api-mesh-plane.js @@ -9,7 +9,7 @@ * @param heightMapScale * @param isHeightMap * @param isDotMap - * @param distanceFromOrigin + * @param dotObject */ GameLib.D3.API.Mesh.Plane = function( apiMesh, @@ -20,18 +20,15 @@ GameLib.D3.API.Mesh.Plane = function( heightMapScale, isHeightMap, isDotMap, - distanceFromOrigin + dotObject ) { if (GameLib.Utils.UndefinedOrNull(apiMesh)) { - apiMesh = {}; + apiMesh = { + meshType : GameLib.D3.API.Mesh.MESH_TYPE_PLANE + }; } - GameLib.D3.API.Mesh.call( - this, - apiMesh - ); - if (GameLib.Utils.UndefinedOrNull(width)) { width = 1; } @@ -43,12 +40,12 @@ GameLib.D3.API.Mesh.Plane = function( this.height = height; if (GameLib.Utils.UndefinedOrNull(widthSegments)) { - widthSegments = 1; + widthSegments = 5; } this.widthSegments = widthSegments; if (GameLib.Utils.UndefinedOrNull(heightSegments)) { - heightSegments = 1 + heightSegments = 5; } this.heightSegments = heightSegments; @@ -67,14 +64,35 @@ GameLib.D3.API.Mesh.Plane = function( } this.isDotMap = isDotMap; - if (GameLib.Utils.UndefinedOrNull(distanceFromOrigin)) { - distanceFromOrigin = 0; + if (GameLib.Utils.UndefinedOrNull(dotObject)) { + dotObject = null; } - this.distanceFromOrigin = distanceFromOrigin; + this.dotObject = dotObject; - GameLib.API.Component.call( + GameLib.D3.API.Mesh.call( this, - GameLib.Component.SOCKET_CAST + apiMesh.id, + apiMesh.meshType, + apiMesh.name, + apiMesh.vertices, + apiMesh.faces, + apiMesh.materials, + apiMesh.parentMesh, + apiMesh.parentScene, + apiMesh.skeleton, + apiMesh.skinIndices, + apiMesh.skinWeights, + apiMesh.position, + apiMesh.quaternion, + apiMesh.rotation, + apiMesh.scale, + apiMesh.up, + apiMesh.modelMatrix, + apiMesh.renderOrder, + apiMesh.isBufferMesh, + apiMesh.useQuaternion, + apiMesh.visible, + apiMesh.parentEntity ); }; @@ -88,11 +106,8 @@ GameLib.D3.API.Mesh.Plane.prototype.constructor = GameLib.D3.API.Mesh.Plane; */ GameLib.D3.API.Mesh.Plane.FromObject = function (objectMesh){ - - var apiMesh = GameLib.D3.API.Mesh.FromObject(objectMesh); - return new GameLib.D3.API.Mesh.Plane( - apiMesh, + GameLib.D3.API.Mesh.FromObject(objectMesh), objectMesh.width, objectMesh.height, objectMesh.widthSegments, @@ -100,7 +115,7 @@ GameLib.D3.API.Mesh.Plane.FromObject = function (objectMesh){ objectMesh.heightMapScale, objectMesh.isHeightMap, objectMesh.isDotMap, - objectMesh.distanceFromOrigin + GameLib.Utils.IdOrNull(objectMesh.dotObject) ); }; diff --git a/src/game-lib-d3-mesh-0.js b/src/game-lib-d3-mesh-0.js index 482647c..b9dbbb5 100644 --- a/src/game-lib-d3-mesh-0.js +++ b/src/game-lib-d3-mesh-0.js @@ -138,6 +138,10 @@ GameLib.D3.Mesh = function ( 'skeleton' : GameLib.D3.Skeleton }; + if (this.meshType === GameLib.D3.API.Mesh.MESH_TYPE_PLANE) { + linkedObjects.dotObject = GameLib.D3.Mesh; + } + if (this.meshType === GameLib.D3.API.Mesh.MESH_TYPE_TEXT) { linkedObjects.font = GameLib.D3.Font; } diff --git a/src/game-lib-d3-mesh-plane.js b/src/game-lib-d3-mesh-plane.js index 2afb3b0..a3083bc 100644 --- a/src/game-lib-d3-mesh-plane.js +++ b/src/game-lib-d3-mesh-plane.js @@ -9,7 +9,6 @@ GameLib.D3.Mesh.Plane = function ( apiMeshPlane ) { - this.graphics = graphics; this.graphics.isNotThreeThrow(); @@ -19,10 +18,6 @@ GameLib.D3.Mesh.Plane = function ( }; } - if (apiMeshPlane instanceof GameLib.D3.Mesh.Plane) { - return apiMeshPlane; - } - GameLib.D3.API.Mesh.Plane.call( this, apiMeshPlane, @@ -33,7 +28,7 @@ GameLib.D3.Mesh.Plane = function ( apiMeshPlane.heightMapScale, apiMeshPlane.isHeightMap, apiMeshPlane.isDotMap, - apiMeshPlane.distanceFromOrigin + apiMeshPlane.dotObject ); GameLib.D3.Mesh.call( @@ -47,7 +42,6 @@ GameLib.D3.Mesh.Plane = function ( GameLib.D3.Mesh.Plane.prototype = Object.create(GameLib.D3.Mesh.prototype); GameLib.D3.Mesh.Plane.prototype.constructor = GameLib.D3.Mesh.Plane; - GameLib.D3.Mesh.Plane.prototype.createInstance = function() { var geometry = null; @@ -79,23 +73,8 @@ GameLib.D3.Mesh.Plane.prototype.createInstance = function() { */ GameLib.D3.Mesh.prototype.createInstance.call(this); - /** - * Apply some plane specific data to the instance - */ - this.instance.userData.width = this.width; - this.instance.userData.height = this.height; - this.instance.userData.widthSegments = this.widthSegments; - this.instance.userData.heightSegments = this.heightSegments; - this.instance.userData.heightMapScale = this.heightMapScale; - this.instance.userData.isHeightMap = this.isHeightMap; - this.instance.userData.isClippingPlane = this.isClippingPlane; - this.instance.userData.distanceFromOrigin = this.distanceFromOrigin; - - if (this.isClippingPlane) { - this.instance.clipping = new THREE.Plane( - geometry.faces[0].normal, - this.distanceFromOrigin - ); + if (this.isDotMap && this.dotObject) { + console.log('todo: construct dotmap here') } }; @@ -106,26 +85,16 @@ GameLib.D3.Mesh.Plane.prototype.updateInstance = function(property) { var geometry = null; - if ( - this.instance.userData.width !== this.width || - this.instance.userData.height !== this.height || - this.instance.userData.widthSegments !== this.widthSegments || - this.instance.userData.heightSegments !== this.heightSegments || - this.instance.userData.isHeightMap !== this.isHeightMap || - this.instance.userData.heightMapScale !== this.heightMapScale || - this.instance.userData.isClippingPlane !== this.isClippingPlane || - this.instance.userData.distanceFromOrigin !== this.distanceFromOrigin + if ( + property === 'width' || + property === 'height' || + property === 'widthSegments' || + property === 'heightSegments' || + property === 'isHeightMap' || + property === 'heightMapScale' ) { - this.instance.userData.width = this.width; - this.instance.userData.height = this.height; - this.instance.userData.widthSegments = this.widthSegments; - this.instance.userData.heightSegments = this.heightSegments; - this.instance.userData.isHeightMap = this.isHeightMap; - this.instance.userData.heightMapScale = this.heightMapScale; - this.instance.userData.isClippingPlane = this.isClippingPlane; - this.instance.userData.distanceFromOrigin = this.distanceFromOrigin; - geometry = new THREE.PlaneGeometry( + geometry = new THREE.PlaneGeometry( this.width, this.height, this.widthSegments, @@ -135,19 +104,19 @@ GameLib.D3.Mesh.Plane.prototype.updateInstance = function(property) { this.updateVerticesFromGeometryInstance(geometry); if (this.isHeightMap) { - this.generateHeightMapFromBumpMap(); - } + this.generateHeightMapFromBumpMap(); + } - geometry = this.createInstanceGeometry(); + geometry = this.createInstanceGeometry(); this.instance.geometry = geometry; + } - if (this.isClippingPlane) { - this.instance.clipping = new THREE.Plane( - geometry.faces[0].normal, - this.distanceFromOrigin - ) - } + if ( + property === 'isDotMap' || + property === 'dotObject' + ) { + console.log('todo: implement dotmap'); } GameLib.D3.Mesh.prototype.updateInstance.call(this, property); @@ -159,22 +128,22 @@ GameLib.D3.Mesh.Plane.prototype.updateInstance = function(property) { */ GameLib.D3.Mesh.Plane.prototype.toApiObject = function() { - var apiMesh = GameLib.D3.Mesh.prototype.toApiObject.call(this); + var apiMeshPlane = new GameLib.D3.API.Mesh.Plane( + GameLib.D3.API.Mesh.prototype.toApiObject.call(this), + this.width, + this.height, + this.widthSegments, + this.heightSegments, + this.heightMapScale, + this.isHeightMap, + this.isDotMap, + this.dotObject + ); - apiMesh.width = this.width; - apiMesh.height = this.height; - apiMesh.widthSegments = this.widthSegments; - apiMesh.heightSegments = this.heightSegments; - apiMesh.heightMapScale = this.heightMapScale; - apiMesh.isHeightMap = this.isHeightMap; - apiMesh.isClippingPlane = this.isClippingPlane; - apiMesh.distanceFromOrigin = this.distanceFromOrigin; - - return apiMesh; + return apiMeshPlane; }; /** - * TODO fix all this weird loading shit * Converts a standard object mesh to a GameLib.D3.Mesh * @param graphics GameLib.GraphicsRuntime * @param objectMesh {Object} @@ -182,19 +151,11 @@ GameLib.D3.Mesh.Plane.prototype.toApiObject = function() { */ GameLib.D3.Mesh.Plane.FromObject = function(graphics, objectMesh) { - var apiMesh = GameLib.D3.API.Mesh.FromObject(objectMesh); + var apiMeshPlane = GameLib.D3.API.Mesh.Plane.FromObject(objectMesh); return new GameLib.D3.Mesh.Plane( graphics, - apiMesh, - objectMesh.width, - objectMesh.height, - objectMesh.widthSegments, - objectMesh.heightSegments, - objectMesh.heightMapScale, - objectMesh.isHeightMap, - objectMesh.isClippingPlane, - objectMesh.distanceFromOrigin + apiMeshPlane ); }; From e8ee24a12af29aba88e07d86430f300581500103 Mon Sep 17 00:00:00 2001 From: -=yb4f310 Date: Sat, 30 Dec 2017 19:49:04 +0100 Subject: [PATCH 3/4] entities have renderers, sometimes --- src/game-lib-api-entity.js | 22 +++++++--------- src/game-lib-entity.js | 19 +++++--------- src/game-lib-system-gui.js | 54 +++----------------------------------- 3 files changed, 20 insertions(+), 75 deletions(-) diff --git a/src/game-lib-api-entity.js b/src/game-lib-api-entity.js index 659e5ab..1223ee8 100644 --- a/src/game-lib-api-entity.js +++ b/src/game-lib-api-entity.js @@ -3,16 +3,16 @@ * @param id * @param name * @param components GameLib.Component[] + * @param renderer * @param parentEntity GameLib.Entity - * @param parentEntityManager * @constructor */ GameLib.API.Entity = function( id, name, components, - parentEntity, - parentEntityManager + renderer, + parentEntity ) { if (GameLib.Utils.UndefinedOrNull(id)) { id = GameLib.Utils.RandomId(); @@ -29,18 +29,16 @@ GameLib.API.Entity = function( } this.components = components; + if (GameLib.Utils.UndefinedOrNull(renderer)) { + renderer = null; + } + this.renderer = renderer; + GameLib.API.Component.call( this, GameLib.Component.ENTITY, parentEntity ); - - if (GameLib.Utils.UndefinedOrNull(parentEntityManager)) { - parentEntityManager = null; - } - this.parentEntityManager = parentEntityManager; - - this.activeComponent = null; }; GameLib.API.Entity.prototype = Object.create(GameLib.Component.prototype); @@ -56,7 +54,7 @@ GameLib.API.Entity.FromObject = function(objectEntity) { objectEntity.id, objectEntity.name, objectEntity.components, - objectEntity.parentEntity, - objectEntity.parentEntityManager + objectEntity.renderer, + objectEntity.parentEntity ) }; diff --git a/src/game-lib-entity.js b/src/game-lib-entity.js index 8935012..2037a48 100644 --- a/src/game-lib-entity.js +++ b/src/game-lib-entity.js @@ -19,15 +19,15 @@ GameLib.Entity = function ( apiEntity.id, apiEntity.name, apiEntity.components, - apiEntity.parentEntity, - apiEntity.parentEntityManager + apiEntity.renderer, + apiEntity.parentEntity ); GameLib.Component.call( this, { 'components' : [GameLib.Component], - 'activeComponent' : GameLib.Component + 'renderer' : GameLib.D3.Renderer } ); }; @@ -195,8 +195,8 @@ GameLib.Entity.prototype.toApiObject = function() { this.id, this.name, apiComponents, - GameLib.Utils.IdOrNull(this.parentEntity), - GameLib.Utils.IdOrNull(this.parentEntityManager) + GameLib.Utils.IdOrNull(this.renderer), + GameLib.Utils.IdOrNull(this.parentEntity) ); }; @@ -204,11 +204,10 @@ GameLib.Entity.prototype.toApiObject = function() { /** * Entity from Object * @param objectEntity Object - * @param parentEntityManager GameLib.D3.EntityManager * @returns {GameLib.Entity} * @constructor */ -GameLib.Entity.FromObject = function(objectEntity, parentEntityManager) { +GameLib.Entity.FromObject = function(objectEntity) { var apiEntity = GameLib.API.Entity.FromObject(objectEntity); @@ -216,11 +215,7 @@ GameLib.Entity.FromObject = function(objectEntity, parentEntityManager) { apiEntity ); - if (GameLib.Utils.UndefinedOrNull(parentEntityManager)) { - return entity; - } - - parentEntityManager.addEntity(entity); + GameLib.EntityManager.Instance.addEntity(entity); return entity; }; diff --git a/src/game-lib-system-gui.js b/src/game-lib-system-gui.js index bbbca2f..ec7f705 100644 --- a/src/game-lib-system-gui.js +++ b/src/game-lib-system-gui.js @@ -244,11 +244,6 @@ GameLib.System.GUI.prototype.start = function() { this.meshDeslected ); - this.newEntitySubscription = this.subscribe( - GameLib.Event.NEW_ENTITY, - this.newEntity - ); - this.componentRemovedSubscription = this.subscribe( GameLib.Event.REMOVE_COMPONENT, this.removeComponent @@ -452,7 +447,7 @@ GameLib.System.GUI.prototype.buildVectorControl = function(folder, componentTemp }; /** - * Builds an Entity Selection control + * Builds a Paren Selection control * @param folder * @param componentTemplate * @param property @@ -1869,10 +1864,7 @@ GameLib.System.GUI.prototype.buildGUI = function(data) { } if ( - templateProperty === 'parentEntity' || - templateProperty === 'parentPhysicsWorld' || - templateProperty === 'parentMesh' || - templateProperty === 'parentScene' + templateProperty.indexOf('parent') === 0 ) { this.buildParentSelectionControl(folder, componentTemplate, templateProperty); continue; @@ -1919,42 +1911,7 @@ GameLib.System.GUI.prototype.buildGUI = function(data) { } this.buildControl(folder, componentTemplate, templateProperty); - // if ( - // component.linkedObjects && - // component.linkedObjects[property] - // ) { - // if (property === 'parentEntity') { - // this.buildEntitySelectionControlFromArray( - // folder, - // component, - // property, - // entityManager - // ) - // } else if (component.linkedObjects[property] instanceof Array) { - // this.buildArrayManager( - // folder, - // component, - // property, - // component.linkedObjects[property], - // entityManager - // ) - // } else { - // this.buildSelectControl(folder, component, property, entityManager, component.linkedObjects[property]); - // } - // - // } else if (typeof (component[property]) === 'object') { - // - // if (this.isColor(component[property])) { - // this.buildControl(folder, component, property); - // } else { - // //console.log('ignored: ' + property); - // } - // } else { - // this.buildControl(folder, component, property, entityManager); - // } - - - } + } } }.bind(this) ); @@ -1987,11 +1944,6 @@ GameLib.System.GUI.prototype.removeComponent = function(data) { }; - -GameLib.System.GUI.prototype.newEntity = function(data) { - -}; - GameLib.System.GUI.prototype.castSourceChanged = function(data) { this.buildGUI(null); }; From 58785caef3f9b0245b87d426e304aa18b7a94413 Mon Sep 17 00:00:00 2001 From: -=yb4f310 Date: Sat, 30 Dec 2017 20:05:23 +0100 Subject: [PATCH 4/4] no more parent entity manager, new renderer for entity --- src/game-lib-entity-manager.js | 46 ++++++++-------------------------- 1 file changed, 11 insertions(+), 35 deletions(-) diff --git a/src/game-lib-entity-manager.js b/src/game-lib-entity-manager.js index 6a21b49..d2a9841 100644 --- a/src/game-lib-entity-manager.js +++ b/src/game-lib-entity-manager.js @@ -36,6 +36,11 @@ GameLib.EntityManager = function(apiEntityManager) { this.registerComponent.bind(this) ); + GameLib.Event.Subscribe( + GameLib.Event.INSTANCE_CREATED, + this.instanceCreated.bind(this) + ); + GameLib.Event.Subscribe( GameLib.Event.REMOVE_COMPONENT, this.removeComponent.bind(this) @@ -59,6 +64,12 @@ GameLib.EntityManager.prototype.createInstance = function() { GameLib.Component.prototype.createInstance.call(this); }; +GameLib.EntityManager.prototype.instanceCreated = function(data) { + if (data.component instanceof GameLib.Entity) { + this.addEntity(data.component); + } +}; + GameLib.EntityManager.prototype.registerComponent = function(data) { var updated = false; @@ -139,38 +150,6 @@ GameLib.EntityManager.prototype.removeComponent = function(data) { }; -/** - * Creates an GameLib.Entity and adds it to entities array - * @returns {*} - */ -GameLib.EntityManager.prototype.createEntity = function(name) { - - var apiEntity = new GameLib.API.Entity( - null, - name, - null, - null, - this - ); - - var entity = new GameLib.Entity( - apiEntity - ); - - this.entities.push(entity); - - this.defaultEntity = entity; - - GameLib.Event.Emit( - GameLib.Event.NEW_ENTITY, - { - entity : entity - } - ); - - return entity; -}; - /** * Returns an entity by ID or null * @param id @@ -253,7 +232,6 @@ GameLib.EntityManager.prototype.findSceneByObject = function(object) { * @param entity GameLib.Entity */ GameLib.EntityManager.prototype.addEntity = function(entity) { - entity.parentEntityManager = this; this.entities.push(entity); }; @@ -289,8 +267,6 @@ GameLib.EntityManager.prototype.removeEntity = function(entity) { } this.entities.splice(index, 1); - entity.parentEntityManager = null; - return true; };