From da84dc459f4a3375ed733985b873e2b8e8c19f8a Mon Sep 17 00:00:00 2001 From: -=yb4f310 Date: Fri, 29 Sep 2017 06:09:47 +0200 Subject: [PATCH] reload image if imagedata available --- src/game-lib-system-gui.js | 2 +- src/game-lib-system-input.js | 67 ++++++++++++++++++++++++++++++++-- src/game-lib-system-storage.js | 42 ++++++++++----------- 3 files changed, 85 insertions(+), 26 deletions(-) diff --git a/src/game-lib-system-gui.js b/src/game-lib-system-gui.js index 6a3beba..8f1d65d 100644 --- a/src/game-lib-system-gui.js +++ b/src/game-lib-system-gui.js @@ -316,7 +316,7 @@ GameLib.System.GUI.prototype.buildQuaternionControl = function(folder, component GameLib.System.GUI.prototype.buildVectorControl = function(folder, componentTemplate, property) { - var step = 0.1; + var step = 0.01; var object = componentTemplate.template; diff --git a/src/game-lib-system-input.js b/src/game-lib-system-input.js index 4299781..51185a7 100644 --- a/src/game-lib-system-input.js +++ b/src/game-lib-system-input.js @@ -42,6 +42,9 @@ GameLib.System.Input = function( this.touchEnd = this.onTouchEnd.bind(this); this.touchCancel = this.onTouchCancel.bind(this); + this.keyboardKeyUp = this.onKeyboardKeyUp.bind(this); + this.keyboardKeyDown = this.onKeyboardKeyDown.bind(this); + }; GameLib.System.Input.prototype = Object.create(GameLib.System.prototype); @@ -92,7 +95,30 @@ GameLib.System.Input.prototype.start = function() { ); }.bind(this) ) - } else if (this.editorControls.length > 0) { + } + + /** + * Same for keyboard controls + */ + if (this.keyboardControls.length > 0) { + this.keyboardControls.map( + function(keyboardControl) { + keyboardControl.domElement.instance.addEventListener( + 'keyup', + this.keyboardKeyUp, + false + ); + + keyboardControl.domElement.instance.addEventListener( + 'keydown', + this.keyboardKeyDown, + false + ); + }.bind(this) + ) + } + + if (this.editorControls.length > 0) { this.renderers = GameLib.EntityManager.Instance.queryComponents(GameLib.D3.Renderer); @@ -164,10 +190,26 @@ GameLib.System.Input.prototype.start = function() { ); } +}; - if (this.keyboardControls.length > 0) { +GameLib.System.Input.prototype.onKeyboardKeyUp = function(event) { + GameLib.Event.Emit( + GameLib.Event.KEY_DOWN, + { + code : event.code + } + ); + +}; + +GameLib.System.Input.prototype.onKeyboardKeyDown = function(event) { + GameLib.Event.Emit( + GameLib.Event.KEY_UP, + { + code : event.code + } + ); - } }; GameLib.System.Input.prototype.onTouchStart = function(event) { @@ -606,6 +648,25 @@ GameLib.System.Input.prototype.stop = function() { ) } + if (this.keyboardControls.length > 0) { + + this.keyboardControls.map( + function(keyboardControl) { + keyboardControl.domElement.instance.removeEventListener( + 'keydown', + this.keyboardKeyDown, + false + ); + + keyboardControl.domElement.instance.removeEventListener( + 'keyup', + this.keyboardKeyUp, + false + ); + }.bind(this) + ) + } + }; diff --git a/src/game-lib-system-storage.js b/src/game-lib-system-storage.js index 290c555..7e20964 100644 --- a/src/game-lib-system-storage.js +++ b/src/game-lib-system-storage.js @@ -737,30 +737,28 @@ GameLib.System.Storage.prototype.imageUploadComplete = function(data) { */ data.images.map(function(imageData){ - var image = runtimeImages.reduce( - function(result, runtimeImage){ + var image = null; - if (imageData.id === runtimeImage.id) { - result = runtimeImage; - } - - return result; - - }, - null - ); - - if (image) { - /** - * Do Nothing - the runtime version of this image already exists and simply needs to load - */ + if (imageData) { + /** + * Overrride this image if possible + * @type {GameLib.D3.Image} + */ + image = GameLib.D3.Image.FromObject(this.graphics, imageData); } else { - /** - * We don't have this runtime version of the image - create it - * @type {GameLib.D3.Image} - */ - image = GameLib.D3.Image.FromObject(this.graphics, imageData); - } + image = runtimeImages.reduce( + function(result, runtimeImage){ + + if (imageData.id === runtimeImage.id) { + result = runtimeImage; + } + + return result; + + }, + null + ); + } GameLib.Event.Emit(