From 68a8eef4bb86d89893a20dc36bb379d8c72a5186 Mon Sep 17 00:00:00 2001 From: -=yb4f310 Date: Fri, 16 Jun 2017 20:03:55 +0200 Subject: [PATCH] fixes --- src/game-lib-a-component-a.js | 25 +++++++++++++------ {bak => src}/game-lib-api-entity-manager.js | 0 src/game-lib-d3-api-image.js | 21 +++++++--------- src/game-lib-d3-api-raycaster.js | 3 +++ src/game-lib-d3-helper.js | 27 ++++++++++++--------- src/game-lib-d3-image.js | 5 +++- src/game-lib-d3-material.js | 6 +++-- src/game-lib-d3-raycaster.js | 5 +++- src/game-lib-d3-scene.js | 15 +++++++++--- 9 files changed, 69 insertions(+), 38 deletions(-) rename {bak => src}/game-lib-api-entity-manager.js (100%) diff --git a/src/game-lib-a-component-a.js b/src/game-lib-a-component-a.js index 8cb9fba..e161972 100644 --- a/src/game-lib-a-component-a.js +++ b/src/game-lib-a-component-a.js @@ -57,13 +57,24 @@ GameLib.Component.prototype.getDependencies = function() { var dependencies = []; for (var property in this.linkedObjects) { + //TODO array linked objects if (this.linkedObjects.hasOwnProperty(property)){ - if ( - this.hasOwnProperty(property) && - typeof this[property] === 'string' - ) { - dependencies.push(this[property]); + if (this.hasOwnProperty(property)) { + + if (typeof this[property] === 'string') { + dependencies.push(this[property]); + } + + if (this[property] instanceof Array) { + this[property].map(function(arrayProperty){ + if (typeof arrayProperty === 'string') { + dependencies.push(arrayProperty); + } + }); + } } + + } } @@ -88,7 +99,7 @@ GameLib.Component.COMPONENT_COMPOSER = 0xb; GameLib.Component.COMPONENT_RENDER_TARGET = 0xc; GameLib.Component.COMPONENT_PASS = 0xd; GameLib.Component.COMPONENT_SCENE = 0xe; -GameLib.Component.COMPONENT_GAME = 0xf; +GameLib.Component.COMPONENT_RAYCASTER = 0xf; GameLib.Component.COMPONENT_INPUT_EDITOR = 0x10; GameLib.Component.COMPONENT_EDITOR = 0x11; GameLib.Component.COMPONENT_VIEWPORT = 0x12; @@ -129,7 +140,7 @@ GameLib.Component.GetComponentName = function(number) { case 0xc : return 'GameLib.D3.RenderTarget'; case 0xd : return 'GameLib.D3.Pass'; case 0xe : return 'GameLib.D3.Scene'; - case 0xf : return 'GameLib.D3.Game'; + case 0xf : return 'GameLib.D3.Raycaster'; case 0x10 : return 'GameLib.D3.InputEditor'; case 0x11 : return 'GameLib.D3.Editor'; case 0x12 : return 'GameLib.D3.Viewport'; diff --git a/bak/game-lib-api-entity-manager.js b/src/game-lib-api-entity-manager.js similarity index 100% rename from bak/game-lib-api-entity-manager.js rename to src/game-lib-api-entity-manager.js diff --git a/src/game-lib-d3-api-image.js b/src/game-lib-d3-api-image.js index 969f772..7a17122 100644 --- a/src/game-lib-d3-api-image.js +++ b/src/game-lib-d3-api-image.js @@ -16,14 +16,6 @@ GameLib.D3.API.Image = function( size, parentEntity ) { - - GameLib.Component.call( - this, - GameLib.Component.COMPONENT_IMAGE, - null, - parentEntity - ); - if (GameLib.Utils.UndefinedOrNull(id)) { id = GameLib.Utils.RandomId(); } @@ -57,10 +49,15 @@ GameLib.D3.API.Image = function( } this.contentType = contentType; - if (GameLib.Utils.UndefinedOrNull(size)) { - size = 0; - } - this.size = size; + if (GameLib.Utils.UndefinedOrNull(size)) { + size = 0; + } + this.size = size; + + if (GameLib.Utils.UndefinedOrNull(parentEntity)) { + parentEntity = null; + } + this.parentEntity = parentEntity; }; GameLib.D3.API.Image.prototype = Object.create(GameLib.Component.prototype); diff --git a/src/game-lib-d3-api-raycaster.js b/src/game-lib-d3-api-raycaster.js index 5dcf78e..b953615 100644 --- a/src/game-lib-d3-api-raycaster.js +++ b/src/game-lib-d3-api-raycaster.js @@ -34,6 +34,9 @@ GameLib.D3.API.Raycaster = function( this.direction = direction; }; +GameLib.D3.API.Raycaster.prototype = Object.create(GameLib.Component.prototype); +GameLib.D3.API.Raycaster.prototype.constructor = GameLib.D3.API.Raycaster; + /** * Returns an API raycaster from an Object raycaster * @param objectRaycaster diff --git a/src/game-lib-d3-helper.js b/src/game-lib-d3-helper.js index 978e4e3..57611ef 100644 --- a/src/game-lib-d3-helper.js +++ b/src/game-lib-d3-helper.js @@ -5,6 +5,7 @@ * @param name * @param object * @param helperType + * @param parentEntity * @constructor */ GameLib.D3.Helper = function( @@ -12,16 +13,12 @@ GameLib.D3.Helper = function( id, name, object, - helperType + helperType, + parentEntity ) { this.graphics = graphics; this.graphics.isNotThreeThrow(); - GameLib.Component.call( - this, - GameLib.Component.COMPONENT_HELPER - ); - if (GameLib.Utils.UndefinedOrNull(id)) { id = GameLib.Utils.RandomId(); } @@ -69,7 +66,15 @@ GameLib.D3.Helper = function( } this.helperType = helperType; - this.instance = this.createInstance(); + if (GameLib.Utils.UndefinedOrNull(parentEntity)) { + parentEntity = null; + } + this.parentEntity = parentEntity; + + GameLib.Component.call( + this, + GameLib.Component.COMPONENT_HELPER + ); }; GameLib.D3.Helper.prototype = Object.create(GameLib.Component.prototype); @@ -98,12 +103,12 @@ GameLib.D3.Helper.prototype.createInstance = function(update) { return null; } - var instance = null; - if (update) { - instance = this.instance; + return; } + var instance = null; + if (this.helperType === GameLib.D3.Helper.HELPER_TYPE_EDGES) { instance = new THREE.EdgesHelper(this.object.instance, 0x00FF00); } @@ -135,5 +140,5 @@ GameLib.D3.Helper.prototype.createInstance = function(update) { * Updates the instance with the current state */ GameLib.D3.Helper.prototype.updateInstance = function() { - this.instance = this.createInstance(true); + this.createInstance(true); }; diff --git a/src/game-lib-d3-image.js b/src/game-lib-d3-image.js index f890d01..b7bebe3 100644 --- a/src/game-lib-d3-image.js +++ b/src/game-lib-d3-image.js @@ -26,7 +26,10 @@ GameLib.D3.Image = function( apiImage.parentEntity ); - this.instance = this.createInstance(); + GameLib.Component.call( + this, + GameLib.Component.COMPONENT_IMAGE + ); }; GameLib.D3.Image.prototype = Object.create(GameLib.D3.API.Image.prototype); diff --git a/src/game-lib-d3-material.js b/src/game-lib-d3-material.js index 456a89b..a7290f8 100644 --- a/src/game-lib-d3-material.js +++ b/src/game-lib-d3-material.js @@ -239,8 +239,6 @@ GameLib.D3.Material = function( 'specularMap' : GameLib.D3.Texture } ); - - this.updateTextures(); }; GameLib.D3.Material.prototype = Object.create(GameLib.D3.API.Material.prototype); @@ -919,6 +917,10 @@ GameLib.D3.Material.prototype.createInstance = function(update) { } ); + this.instance = instance; + + this.updateTextures(); + return instance; } diff --git a/src/game-lib-d3-raycaster.js b/src/game-lib-d3-raycaster.js index d2ee3af..05a38d9 100644 --- a/src/game-lib-d3-raycaster.js +++ b/src/game-lib-d3-raycaster.js @@ -40,7 +40,10 @@ GameLib.D3.Raycaster = function( this ); - this.instance = this.createInstance(); + GameLib.Component.call( + this, + GameLib.Component.COMPONENT_RAYCASTER + ); }; GameLib.D3.Raycaster.prototype = Object.create(GameLib.D3.API.Raycaster.prototype); diff --git a/src/game-lib-d3-scene.js b/src/game-lib-d3-scene.js index 65e6728..6411d7e 100644 --- a/src/game-lib-d3-scene.js +++ b/src/game-lib-d3-scene.js @@ -325,9 +325,14 @@ GameLib.D3.Scene.prototype.addObject = function(object) { object.parentScene = this; - this.instance.add(object.instance); + if (this.instance) { + this.instance.add(object.instance); + } - this.buildIdToObject(); + + // this.instance.add(object.instance); + // + // this.buildIdToObject(); }; /** @@ -353,11 +358,13 @@ GameLib.D3.Scene.prototype.removeObject = function(object) { return; } - this.instance.remove(object.instance); + if (this.instance) { + this.instance.remove(object.instance); + } if (object.parentScene === this) { object.parentScene = null; } - this.buildIdToObject(); + // this.buildIdToObject(); }; \ No newline at end of file