diff --git a/src/game-lib-a-api-component.js b/src/game-lib-a-api-component.js index 72983dd..f5dfef7 100644 --- a/src/game-lib-a-api-component.js +++ b/src/game-lib-a-api-component.js @@ -11,30 +11,7 @@ GameLib.API.Component = function( this.componentType = componentType; if (GameLib.Utils.UndefinedOrNull(parentEntity)) { - - if (this instanceof GameLib.EntityManager) { - parentEntity = this.defaultEntity; - } else { - - parentEntity = GameLib.EntityManager.Instance.defaultEntity; - - if (parentEntity) { - - if (parentEntity.id === this.id) { - - /** - * This is the default entity, it cannot be the parent entity of itself - so terminate here. - */ - console.log('terminating here'); - - parentEntity = null; - - } else { - - parentEntity.addComponent(this); - } - } - } + parentEntity = null; } this.parentEntity = parentEntity; }; diff --git a/src/game-lib-a-component-a.js b/src/game-lib-a-component-a.js index be6050c..6ac7dea 100644 --- a/src/game-lib-a-component-a.js +++ b/src/game-lib-a-component-a.js @@ -1266,22 +1266,12 @@ GameLib.Component.ConstructFromObject = function(rawComponentObject) { var info = GameLib.Component.GetComponentInfo(rawComponentObject.componentType); - var componentClass = info.constructor; - - var fn = componentClass['FromObject']; - - if (rawComponentObject.componentType === GameLib.Component.ENTITY) { - - runtimeComponent = fn(rawComponentObject, GameLib.EntityManager.Instance); + var runtime = GameLib.Component.GetRuntimeObject(info.runtime); + if (runtime) { + runtimeComponent = new info.constructor(runtime, rawComponentObject); } else { - var runtime = GameLib.Component.GetRuntimeObject(info.runtime); - - if (runtime) { - runtimeComponent = fn(runtime, rawComponentObject); - } else { - runtimeComponent = fn(rawComponentObject); - } + runtimeComponent = new info.constructor(rawComponentObject); } return runtimeComponent; diff --git a/src/game-lib-canvas.js b/src/game-lib-canvas.js index 4e7fdc3..8a70198 100644 --- a/src/game-lib-canvas.js +++ b/src/game-lib-canvas.js @@ -91,9 +91,5 @@ GameLib.Canvas.prototype.toApiObject = function() { * @returns {GameLib.Canvas} */ GameLib.Canvas.FromObject = function(objectCanvas) { - - return new GameLib.Canvas( - GameLib.API.Canvas.FromObject(objectCanvas) - ); - + return new GameLib.Canvas(objectCanvas); }; \ No newline at end of file diff --git a/src/game-lib-d3-camera.js b/src/game-lib-d3-camera.js index 266715c..6a5345a 100644 --- a/src/game-lib-d3-camera.js +++ b/src/game-lib-d3-camera.js @@ -41,38 +41,23 @@ GameLib.D3.Camera = function( apiCamera.parentEntity ); - if (this.position instanceof GameLib.API.Vector3) { - this.position = new GameLib.Vector3( - graphics, - this.position, - this - ); - } else { - console.warn('position not instance of API.Vector3'); - throw new Error('position not instance of API.Vector3'); - } + this.position = new GameLib.Vector3( + graphics, + this.position, + this + ); - if (this.quaternion instanceof GameLib.API.Quaternion) { - this.quaternion = new GameLib.Quaternion( - graphics, - this.quaternion, - this - ); - } else { - console.warn('quaternion not instance of API.Quaternion'); - throw new Error('quaternion not instance of API.Quaternion'); - } + this.quaternion = new GameLib.Quaternion( + graphics, + this.quaternion, + this + ); - if (this.lookAt instanceof GameLib.API.Vector3) { - this.lookAt = new GameLib.Vector3( - graphics, - this.lookAt, - this - ); - } else { - console.warn('lookAt not instance of API.Vector3'); - throw new Error('lookAt not instance of API.Vector3'); - } + this.lookAt = new GameLib.Vector3( + graphics, + this.lookAt, + this + ); GameLib.Component.call( this, diff --git a/src/game-lib-d3-face.js b/src/game-lib-d3-face.js index 04cfd9f..b83649a 100644 --- a/src/game-lib-d3-face.js +++ b/src/game-lib-d3-face.js @@ -65,21 +65,15 @@ GameLib.D3.Face = function Face( } - this.vertexNormals = this.vertexNormals.map(function(vertexNormal){ - if (vertexNormal instanceof GameLib.Vector3) { - return vertexNormal; - } - - if (vertexNormal instanceof GameLib.API.Vector3) { - return new GameLib.Vector3( - this.implementation, - vertexNormal, - this - ) - } - - console.warn('unknown vertex normal type', vertexNormal); - }.bind(this)); + this.vertexNormals = this.vertexNormals.map( + function(vertexNormal) { + return new GameLib.Vector3( + this.implementation, + vertexNormal, + this + ); + }.bind(this) + ); this.uvs = this.uvs.reduce( @@ -88,17 +82,13 @@ GameLib.D3.Face = function Face( result[index] = uvArray.reduce( function(uvResult, uv) { - if (uv instanceof GameLib.API.Vector2) { - uvResult.push( - new GameLib.Vector2( - this.implementation, - uv, - this - ) - ); - } else { - console.warn('unknown uv type'); - } + uvResult.push( + new GameLib.Vector2( + this.implementation, + uv, + this + ) + ); return uvResult; }.bind(this), diff --git a/src/game-lib-d3-mesh-0.js b/src/game-lib-d3-mesh-0.js index 91406f1..6c83667 100644 --- a/src/game-lib-d3-mesh-0.js +++ b/src/game-lib-d3-mesh-0.js @@ -45,27 +45,25 @@ GameLib.D3.Mesh = function ( this.faces = this.faces.map( function(face) { - if (face instanceof GameLib.D3.API.Face) { - return new GameLib.D3.Face( - this.graphics, - face - ) - } else { - return face; - } + return new GameLib.D3.Face( + this.graphics, + face + ) }.bind(this) ); this.materials = this.materials.map( function(material) { - if (material instanceof GameLib.D3.API.Material) { - return new GameLib.D3.Material( - this.graphics, - material - ) - } else { + + if (typeof material === 'string') { return material; } + + return new GameLib.D3.Material( + this.graphics, + material + ); + }.bind(this) ); @@ -77,10 +75,10 @@ GameLib.D3.Mesh = function ( } this.vertices = this.vertices.map( - function (apiVertex) { + function (vertex) { return new GameLib.D3.Vertex( this.graphics, - apiVertex + vertex ); }.bind(this) ); diff --git a/src/game-lib-d3-scene.js b/src/game-lib-d3-scene.js index f6547ce..faa35dd 100644 --- a/src/game-lib-d3-scene.js +++ b/src/game-lib-d3-scene.js @@ -36,17 +36,15 @@ GameLib.D3.Scene = function ( this.meshes = this.meshes.map( function(apiMesh) { - if (apiMesh instanceof GameLib.D3.API.Mesh) { - + if (typeof apiMesh === 'string') { + return apiMesh; + } else { apiMesh.parentScene = this; return new GameLib.D3.Mesh( this.graphics, apiMesh ); - - } else { - return apiMesh; } }.bind(this) @@ -55,15 +53,14 @@ GameLib.D3.Scene = function ( this.lights = this.lights.map( function(apiLight) { - if (apiLight instanceof GameLib.D3.API.Light) { - + if (typeof apiLight === 'string') { + return apiLight; + } else { return new GameLib.D3.Light( this.graphics, apiLight ); - } else { - return apiLight; } }.bind(this) @@ -72,72 +69,60 @@ GameLib.D3.Scene = function ( this.textures = this.textures.map( function(apiTexture) { - if (apiTexture instanceof GameLib.D3.API.Texture) { - - var texture = new GameLib.D3.Texture( - this.graphics, - apiTexture - ); - - return texture; - } else { + if (typeof apiTexture === 'string') { return apiTexture; } + return new GameLib.D3.Texture( + this.graphics, + apiTexture + ); + }.bind(this) ); this.materials = this.materials.map( function(apiMaterial) { - if (apiMaterial instanceof GameLib.D3.API.Material) { - - var material = new GameLib.D3.Material( - this.graphics, - apiMaterial - ); - - return material; - - } else { + if (typeof apiMaterial === 'string') { return apiMaterial; } + return new GameLib.D3.Material( + this.graphics, + apiMaterial + ); + }.bind(this) ); this.images = this.images.map( function(apiImage) { - if (apiImage instanceof GameLib.API.Image) { - - var image = new GameLib.Image( - this.graphics, - apiImage - ); - - return image; - } else { + if (typeof apiImage === 'string') { return apiImage; } + return new GameLib.Image( + this.graphics, + apiImage + ); + }.bind(this) ); - if (this.fog instanceof GameLib.D3.API.Fog) { + if (typeof this.fog !== 'string') { this.fog = new GameLib.D3.Fog( this.graphics, this.fog ) } - if (this.gridColor instanceof GameLib.API.Color) { - this.gridColor = new GameLib.Color( - this.graphics, - this.gridColor, - this - ) - } + this.gridColor = new GameLib.Color( + this.graphics, + this.gridColor, + this + ); /** * Runtime scenes have helpers (just used to store which helper belongs to which scene) diff --git a/src/game-lib-entity.js b/src/game-lib-entity.js index ff251df..4b72b5d 100644 --- a/src/game-lib-entity.js +++ b/src/game-lib-entity.js @@ -205,10 +205,8 @@ GameLib.Entity.prototype.toApiObject = function() { */ GameLib.Entity.FromObject = function(objectEntity) { - var apiEntity = GameLib.API.Entity.FromObject(objectEntity); - var entity = new GameLib.Entity( - apiEntity + objectEntity ); GameLib.EntityManager.Instance.addEntity(entity); diff --git a/src/game-lib-matrix-4.js b/src/game-lib-matrix-4.js index 89c3fca..1fd803e 100644 --- a/src/game-lib-matrix-4.js +++ b/src/game-lib-matrix-4.js @@ -40,17 +40,14 @@ GameLib.Matrix4 = function( this.rows = this.rows.map( function(row) { - if (row instanceof GameLib.API.Vector4) { - return new GameLib.Vector4( - this.graphics, - row, - this, - this.grain - ); - } else { - console.warn('Attempted conversion of wrong instance'); - throw new Error('Attempted conversion of wrong instance'); - } + + return new GameLib.Vector4( + this.graphics, + row, + this, + this.grain + ); + }.bind(this) ); diff --git a/src/game-lib-system-input.js b/src/game-lib-system-input.js index 8118f96..d238f4e 100644 --- a/src/game-lib-system-input.js +++ b/src/game-lib-system-input.js @@ -411,28 +411,28 @@ GameLib.System.Input.prototype.registerMouseControls = function(mouseControl) { }; GameLib.System.Input.prototype.registerEditorControls = function(editorControl) { - // - // /** - // * If we already have mouse controls, we don't want to add another event listener onto the DOM - // */ - // this.mouseControls.map( - // function(mouseControl) { - // if (mouseControl.domElement.instance === editorControl.domElement.instance) { - // this.deRegisterMouseControls(mouseControl); - // } - // }.bind(this) - // ); - // - // /** - // * If we already have keyboard controls, we don't want to add another event listener onto the DOM - // */ - // this.keyboardControls.map( - // function(keyboardControl) { - // if (keyboardControl.domElement.instance === editorControl.domElement.instance) { - // this.deRegisterKeyboardControls(keyboardControl); - // } - // }.bind(this) - // ); + + /** + * If we already have mouse controls, we don't want to add another event listener onto the DOM + */ + this.mouseControls.map( + function(mouseControl) { + if (mouseControl.domElement.instance === editorControl.domElement.instance) { + this.deRegisterMouseControls(mouseControl); + } + }.bind(this) + ); + + /** + * If we already have keyboard controls, we don't want to add another event listener onto the DOM + */ + this.keyboardControls.map( + function(keyboardControl) { + if (keyboardControl.domElement.instance === editorControl.domElement.instance) { + this.deRegisterKeyboardControls(keyboardControl); + } + }.bind(this) + ); if (!editorControl.domElement || !editorControl.domElement.instance) { console.warn('no domElement at time of registration of editor controls - are you sure you know what you are doing?'); diff --git a/src/game-lib-system-linking.js b/src/game-lib-system-linking.js index 6901a67..8d260e2 100644 --- a/src/game-lib-system-linking.js +++ b/src/game-lib-system-linking.js @@ -574,7 +574,11 @@ GameLib.System.Linking.prototype.imageChanged = function(data) { var textures = material.getTextures(); if (textures.indexOf(data.texture) !== -1) { - material.updateInstance('diffuseMap'); + + if (material.loaded) { + material.updateInstance('diffuseMap'); + } + } }); diff --git a/src/game-lib-system-storage.js b/src/game-lib-system-storage.js index 4f4866a..faea28c 100644 --- a/src/game-lib-system-storage.js +++ b/src/game-lib-system-storage.js @@ -289,7 +289,7 @@ GameLib.System.Storage.prototype.save = function(data) { })); }, function error(error){ - console.log(error); + console.error(error); } );