From af43128b0fd1aae5d6d5c7af1e564a02b5525faf Mon Sep 17 00:00:00 2001 From: -=yb4f310 Date: Thu, 11 Jan 2018 14:33:32 +0100 Subject: [PATCH] controls migration --- src/game-lib-api-controls-0.js | 2 +- src/game-lib-api-controls-keyboard.js | 45 +++++++++++++++++++ src/game-lib-api-controls-mouse.js | 45 +++++++++++++++++++ src/game-lib-api-controls-touch.js | 53 ++++++++++++++++++++++ src/game-lib-canvas.js | 2 + src/game-lib-color.js | 2 +- src/game-lib-controls-0.js | 2 +- src/game-lib-controls-d3-editor.js | 2 - src/game-lib-controls-keyboard.js | 22 ++++++--- src/game-lib-controls-mouse.js | 24 +++++++--- src/game-lib-controls-touch.js | 33 +++++++------- src/game-lib-d3-mesh-plane.js | 45 ++++++++++++++++++- src/game-lib-system-gui.js | 15 ++++++- src/game-lib-system-input.js | 64 +++++++++++++-------------- src/game-lib-vector2.js | 2 +- src/game-lib-vector3.js | 2 +- src/game-lib-vector4.js | 2 +- 17 files changed, 293 insertions(+), 69 deletions(-) create mode 100644 src/game-lib-api-controls-keyboard.js create mode 100644 src/game-lib-api-controls-mouse.js create mode 100644 src/game-lib-api-controls-touch.js diff --git a/src/game-lib-api-controls-0.js b/src/game-lib-api-controls-0.js index bb70d1e..d4a8b87 100644 --- a/src/game-lib-api-controls-0.js +++ b/src/game-lib-api-controls-0.js @@ -118,8 +118,8 @@ GameLib.API.Controls.CONTROLS_TYPE_MOUSE = 0x3; GameLib.API.Controls.FromObject = function (objectControls){ return new GameLib.API.Controls( objectControls.id, - objectControls.controlsType, objectControls.name, + objectControls.controlsType, objectControls.domElement, objectControls.parentEntity ); diff --git a/src/game-lib-api-controls-keyboard.js b/src/game-lib-api-controls-keyboard.js new file mode 100644 index 0000000..33e7ad7 --- /dev/null +++ b/src/game-lib-api-controls-keyboard.js @@ -0,0 +1,45 @@ +/** + * @param apiControls + * @constructor + */ +GameLib.API.Controls.Keyboard = function( + apiControls +) { + + if (GameLib.Utils.UndefinedOrNull(apiControls)) { + apiControls = { + controlsType : GameLib.API.Controls.CONTROLS_TYPE_KEYBOARD + }; + } + + GameLib.API.Controls.call( + this, + apiControls.id, + apiControls.name, + apiControls.controlsType, + apiControls.domElement, + apiControls.parentEntity + ); + + GameLib.API.Component.call( + this, + GameLib.Component.CONTROLS_KEYBOARD + ); +}; + +GameLib.API.Controls.Keyboard.prototype = Object.create(GameLib.API.Controls.prototype); +GameLib.API.Controls.Keyboard.prototype.constructor = GameLib.API.Controls.Keyboard; + +/** + * Creates an API.Controls.Keyboard from an Object Cast + * @param objectControls + * @constructor + */ +GameLib.API.Controls.Keyboard.FromObject = function(objectControls) { + + var apiControls = GameLib.API.Controls.FromObject(objectControls); + + return new GameLib.API.Controls.Keyboard( + apiControls + ); +}; diff --git a/src/game-lib-api-controls-mouse.js b/src/game-lib-api-controls-mouse.js new file mode 100644 index 0000000..c7cb99b --- /dev/null +++ b/src/game-lib-api-controls-mouse.js @@ -0,0 +1,45 @@ +/** + * @param apiControls + * @constructor + */ +GameLib.API.Controls.Mouse = function( + apiControls +) { + + if (GameLib.Utils.UndefinedOrNull(apiControls)) { + apiControls = { + controlsType : GameLib.API.Controls.CONTROLS_TYPE_MOUSE + }; + } + + GameLib.API.Controls.call( + this, + apiControls.id, + apiControls.name, + apiControls.controlsType, + apiControls.domElement, + apiControls.parentEntity + ); + + GameLib.API.Component.call( + this, + GameLib.Component.CONTROLS_MOUSE + ); +}; + +GameLib.API.Controls.Mouse.prototype = Object.create(GameLib.API.Controls.prototype); +GameLib.API.Controls.Mouse.prototype.constructor = GameLib.API.Controls.Mouse; + +/** + * Creates an API.Controls.Mouse from an Object Cast + * @param objectControls + * @constructor + */ +GameLib.API.Controls.Mouse.FromObject = function(objectControls) { + + var apiControls = GameLib.API.Controls.FromObject(objectControls); + + return new GameLib.API.Controls.Mouse( + apiControls + ); +}; diff --git a/src/game-lib-api-controls-touch.js b/src/game-lib-api-controls-touch.js new file mode 100644 index 0000000..76eb945 --- /dev/null +++ b/src/game-lib-api-controls-touch.js @@ -0,0 +1,53 @@ +/** + * @param apiControls + * @param sensitivity + * @constructor + */ +GameLib.API.Controls.Touch = function( + apiControls, + sensitivity +) { + + if (GameLib.Utils.UndefinedOrNull(apiControls)) { + apiControls = { + controlsType : GameLib.API.Controls.CONTROLS_TYPE_TOUCH + }; + } + + GameLib.API.Controls.call( + this, + apiControls.id, + apiControls.name, + apiControls.controlsType, + apiControls.domElement, + apiControls.parentEntity + ); + + if (GameLib.Utils.UndefinedOrNull(sensitivity)) { + sensitivity = 5; + } + this.sensitivity = sensitivity; + + GameLib.API.Component.call( + this, + GameLib.Component.CONTROLS_TOUCH + ); +}; + +GameLib.API.Controls.Touch.prototype = Object.create(GameLib.API.Controls.prototype); +GameLib.API.Controls.Touch.prototype.constructor = GameLib.API.Controls.Touch; + +/** + * Creates an API.Controls.Touch from an Object Cast + * @param objectControls + * @constructor + */ +GameLib.API.Controls.Touch.FromObject = function(objectControls) { + + var apiControls = GameLib.API.Controls.FromObject(objectControls); + + return new GameLib.API.Controls.Touch( + apiControls, + objectControls.sensitivity + ); +}; diff --git a/src/game-lib-canvas.js b/src/game-lib-canvas.js index 620d3f5..8650499 100644 --- a/src/game-lib-canvas.js +++ b/src/game-lib-canvas.js @@ -36,6 +36,8 @@ GameLib.Canvas.prototype.createInstance = function() { this.instance.setAttribute('id', this.id); + this.instance.setAttribute('tabindex', '1'); + this.width = Math.round(this.width); this.height = Math.round(this.height); diff --git a/src/game-lib-color.js b/src/game-lib-color.js index a49b31b..275caab 100644 --- a/src/game-lib-color.js +++ b/src/game-lib-color.js @@ -41,7 +41,7 @@ GameLib.Color = function ( this.createInstance(); }; -GameLib.Color.prototype = Object.create(GameLib.Component.prototype); +GameLib.Color.prototype = Object.create(GameLib.API.Color.prototype); GameLib.Color.prototype.constructor = GameLib.Color; /** diff --git a/src/game-lib-controls-0.js b/src/game-lib-controls-0.js index 68f73e3..a1e597f 100644 --- a/src/game-lib-controls-0.js +++ b/src/game-lib-controls-0.js @@ -21,7 +21,7 @@ GameLib.Controls = function ( ); var linkedObjects = { - domElement : GameLib.DomElement + domElement : GameLib.Canvas }; var delayed = false; diff --git a/src/game-lib-controls-d3-editor.js b/src/game-lib-controls-d3-editor.js index 735321a..77cf95d 100644 --- a/src/game-lib-controls-d3-editor.js +++ b/src/game-lib-controls-d3-editor.js @@ -108,8 +108,6 @@ GameLib.Controls.D3.Editor.prototype.toApiObject = function() { */ GameLib.Controls.D3.Editor.FromObject = function(graphics, objectControls) { - var apiControls = GameLib.API.Controls.FromObject(objectControls); - var apiEditorControls = GameLib.API.Controls.D3.Editor.FromObject(objectControls); return new GameLib.Controls.D3.Editor( diff --git a/src/game-lib-controls-keyboard.js b/src/game-lib-controls-keyboard.js index 0c1b09c..667ab9d 100644 --- a/src/game-lib-controls-keyboard.js +++ b/src/game-lib-controls-keyboard.js @@ -1,14 +1,26 @@ /** * Keyboard Controls - * @param apiControls GameLib.API.Controls + * @param apiKeyboardControls GameLib.API.Controls * @constructor */ GameLib.Controls.Keyboard = function ( - apiControls + apiKeyboardControls ) { + + if (GameLib.Utils.UndefinedOrNull(apiKeyboardControls)) { + apiKeyboardControls = { + controlsType : GameLib.API.Controls.CONTROLS_TYPE_KEYBOARD + }; + } + + GameLib.API.Controls.Keyboard.call( + this, + apiKeyboardControls + ); + GameLib.Controls.call( this, - apiControls + apiKeyboardControls ); }; @@ -58,10 +70,10 @@ GameLib.Controls.Keyboard.prototype.toApiObject = function() { */ GameLib.Controls.Keyboard.FromObject = function(objectControls) { - var apiControls = GameLib.API.Controls.FromObject(objectControls); + var apiKeyboardControls = GameLib.API.Controls.Keyboard.FromObject(objectControls); return new GameLib.Controls.Keyboard( - apiControls + apiKeyboardControls ); }; \ No newline at end of file diff --git a/src/game-lib-controls-mouse.js b/src/game-lib-controls-mouse.js index 1b4e7d8..4154fdb 100644 --- a/src/game-lib-controls-mouse.js +++ b/src/game-lib-controls-mouse.js @@ -1,14 +1,26 @@ /** * Mouse Controls - * @param apiControls GameLib.API.Controls + * @param apiMouseControls GameLib.API.Controls * @constructor */ GameLib.Controls.Mouse = function ( - apiControls + apiMouseControls ) { - GameLib.Controls.call( + + if (GameLib.Utils.UndefinedOrNull(apiMouseControls)) { + apiMouseControls = { + controlsType : GameLib.API.Controls.CONTROLS_TYPE_MOUSE + }; + } + + GameLib.API.Controls.Mouse.call( this, - apiControls + apiMouseControls + ); + + GameLib.Controls.call( + this, + apiMouseControls ); }; @@ -58,10 +70,10 @@ GameLib.Controls.Mouse.prototype.toApiObject = function() { */ GameLib.Controls.Mouse.FromObject = function(objectControls) { - var apiControls = GameLib.API.Controls.FromObject(objectControls); + var apiMouseControls = GameLib.API.Controls.Mouse.FromObject(objectControls); return new GameLib.Controls.Mouse( - apiControls + apiMouseControls ); }; \ No newline at end of file diff --git a/src/game-lib-controls-touch.js b/src/game-lib-controls-touch.js index 6c9d813..2801d33 100644 --- a/src/game-lib-controls-touch.js +++ b/src/game-lib-controls-touch.js @@ -1,21 +1,27 @@ /** * Touch Controls - * @param apiControls GameLib.API.Controls - * @param sensitivity * @constructor + * @param apiTouchControls */ GameLib.Controls.Touch = function ( - apiControls, - sensitivity + apiTouchControls ) { - if (GameLib.Utils.UndefinedOrNull(sensitivity)) { - sensitivity = 5; - } - this.sensitivity = sensitivity; - GameLib.Controls.call( + if (GameLib.Utils.UndefinedOrNull(apiTouchControls)) { + apiTouchControls = { + controlsType : GameLib.API.Controls.CONTROLS_TYPE_TOUCH + }; + } + + GameLib.API.Controls.Touch.call( this, - apiControls + apiTouchControls, + apiTouchControls.sensitivity + ); + + GameLib.Controls.call( + this, + apiTouchControls ); }; @@ -69,11 +75,8 @@ GameLib.Controls.Touch.prototype.toApiObject = function() { */ GameLib.Controls.Touch.FromObject = function(objectControls) { - var apiControls = GameLib.API.Controls.FromObject(objectControls); + var apiTouchControls = GameLib.API.Controls.Touch.FromObject(objectControls); - return new GameLib.Controls.Touch( - apiControls, - objectControls.sensitivity - ); + return new GameLib.Controls.Touch(apiTouchControls); }; \ No newline at end of file diff --git a/src/game-lib-d3-mesh-plane.js b/src/game-lib-d3-mesh-plane.js index d62ae74..94cae5e 100644 --- a/src/game-lib-d3-mesh-plane.js +++ b/src/game-lib-d3-mesh-plane.js @@ -31,6 +31,8 @@ GameLib.D3.Mesh.Plane = function ( apiMeshPlane.dotObject ); + this.dots = []; + GameLib.D3.Mesh.call( this, graphics, @@ -74,7 +76,7 @@ GameLib.D3.Mesh.Plane.prototype.createInstance = function() { GameLib.D3.Mesh.prototype.createInstance.call(this); if (this.isDotMap && this.dotObject) { - console.log('todo: construct dotmap here') + this.generateDotMap(); } }; @@ -116,7 +118,7 @@ GameLib.D3.Mesh.Plane.prototype.updateInstance = function(property) { property === 'isDotMap' || property === 'dotObject' ) { - console.log('todo: implement dotmap'); + this.generateDotMap(); } GameLib.D3.Mesh.prototype.updateInstance.call(this, property); @@ -211,6 +213,45 @@ GameLib.D3.Mesh.Plane.prototype.getHeightData = function() { return data; }; +GameLib.D3.Mesh.Plane.prototype.generateDotMap = function() { + + this.dots.map( + function(dot){ + this.parentScene.instance.remove(dot); + dot.geometry.dispose(); + }.bind(this) + ); + + this.dots = []; + + var data = this.getHeightData(); + + var width = Math.sqrt(data.length); + var height = width; + + for (var x = 0; x < width; x++) { + for (var y = 0; y < height; y++ ) { + + var geometry = new THREE.BoxBufferGeometry(0.5,0.5,0.5); + var dot = new THREE.Mesh(geometry, this.materials[0].instance); + dot.position.x = x; + dot.position.y = y; + dot.position.z = data[(y * width) + x]; + + var scale = data[(y * width) + x] / 100; + + dot.scale.x = scale; + dot.scale.y = scale; + dot.scale.z = scale; + + this.parentScene.instance.add(dot); + + this.dots.push(dot); + } + } + +}; + /** * * @returns {THREE.PlaneGeometry} diff --git a/src/game-lib-system-gui.js b/src/game-lib-system-gui.js index 90ce1d8..6798c20 100644 --- a/src/game-lib-system-gui.js +++ b/src/game-lib-system-gui.js @@ -836,7 +836,20 @@ GameLib.System.GUI.prototype.buildControl = function(folder, componentTemplate, } ) ); - } else if (property === 'socketType') { + } else if (property === 'controlsType') { + controllers.push( + folder.add( + object, + property, + { + 'touch' : GameLib.API.Controls.CONTROLS_TYPE_TOUCH, + 'mouse' : GameLib.API.Controls.CONTROLS_TYPE_MOUSE, + 'keyboard' : GameLib.API.Controls.CONTROLS_TYPE_KEYBOARD, + 'editor' : GameLib.API.Controls.CONTROLS_TYPE_EDITOR + } + ) + ); + } else if (property === 'socketType') { controllers.push( folder.add( object, diff --git a/src/game-lib-system-input.js b/src/game-lib-system-input.js index b6ac75d..4ad7130 100644 --- a/src/game-lib-system-input.js +++ b/src/game-lib-system-input.js @@ -315,23 +315,23 @@ GameLib.System.Input.prototype.registerTouchControls = function(touchControl) { touchControl.domElement.instance.addEventListener( 'touchstart', this.touchStart, - false + true ); touchControl.domElement.instance.addEventListener( 'touchmove', this.touchMove, - false + true ); touchControl.domElement.instance.addEventListener( 'touchend', this.touchEnd, - false + true ); touchControl.domElement.instance.addEventListener( 'touchcancel', this.touchCancel, - false + true ); }; @@ -340,13 +340,13 @@ GameLib.System.Input.prototype.registerKeyboardControls = function(keyboardContr keyboardControl.domElement.instance.addEventListener( 'keyup', this.keyboardKeyUp, - false + true ); keyboardControl.domElement.instance.addEventListener( 'keydown', this.keyboardKeyDown, - false + true ); }; @@ -355,24 +355,24 @@ GameLib.System.Input.prototype.registerMouseControls = function(mouseControl) { mouseControl.domElement.instance.addEventListener( 'mousedown', this.mouseDown, - false + true ); mouseControl.domElement.instance.addEventListener( 'mousemove', this.mouseMove, - false + true ); mouseControl.domElement.instance.addEventListener( 'wheel', this.mouseWheel, - false + true ); mouseControl.domElement.instance.addEventListener( 'mouseup', this.mouseUp, - false + true ); }; @@ -403,25 +403,25 @@ GameLib.System.Input.prototype.registerEditorControls = function(editorControl) editorControl.domElement.instance.addEventListener( 'mousedown', this.mouseDownEdit, - false + true ); editorControl.domElement.instance.addEventListener( 'mousemove', this.mouseMoveEdit, - false + true ); editorControl.domElement.instance.addEventListener( 'keydown', this.keyDown, - false + true ); editorControl.domElement.instance.addEventListener( 'keyup', this.keyUp, - false + true ); /** @@ -432,13 +432,13 @@ GameLib.System.Input.prototype.registerEditorControls = function(editorControl) editorControl.domElement.instance.addEventListener( 'wheel', this.mouseWheelEdit, - false + true ); editorControl.domElement.instance.addEventListener( 'mouseup', this.mouseUpEdit, - false + true ); }; @@ -447,25 +447,25 @@ GameLib.System.Input.prototype.deRegisterEditorControls = function(editorControl editorControl.domElement.instance.removeEventListener( 'mousedown', this.mouseDownEdit, - false + true ); editorControl.domElement.instance.removeEventListener( 'mousemove', this.mouseMoveEdit, - false + true ); editorControl.domElement.instance.removeEventListener( 'keydown', this.keyDown, - false + true ); editorControl.domElement.instance.removeEventListener( 'keyup', this.keyUp, - false + true ); editorControl.instance.dispose(); @@ -473,13 +473,13 @@ GameLib.System.Input.prototype.deRegisterEditorControls = function(editorControl editorControl.domElement.instance.removeEventListener( 'wheel', this.mouseWheelEdit, - false + true ); editorControl.domElement.instance.removeEventListener( 'mouseup', this.mouseUpEdit, - false + true ); }; @@ -489,25 +489,25 @@ GameLib.System.Input.prototype.deRegisterTouchControls = function(touchControl) touchControl.domElement.instance.removeEventListener( 'touchstart', this.touchStart, - false + true ); touchControl.domElement.instance.removeEventListener( 'touchmove', this.touchMove, - false + true ); touchControl.domElement.instance.removeEventListener( 'touchend', this.touchEnd, - false + true ); touchControl.domElement.instance.removeEventListener( 'touchcancel', this.touchCancel, - false + true ); }; @@ -517,13 +517,13 @@ GameLib.System.Input.prototype.deRegisterKeyboardControls = function(keyboardCon keyboardControl.domElement.instance.removeEventListener( 'keydown', this.keyboardKeyDown, - false + true ); keyboardControl.domElement.instance.removeEventListener( 'keyup', this.keyboardKeyUp, - false + true ); }; @@ -534,24 +534,24 @@ GameLib.System.Input.prototype.deRegisterMouseControls = function(mouseControl) mouseControl.domElement.instance.removeEventListener( 'mousedown', this.mouseDown, - false + true ); mouseControl.domElement.instance.removeEventListener( 'mousemove', this.mouseMove, - false + true ); mouseControl.domElement.instance.removeEventListener( 'wheel', this.mouseWheel, - false + true ); mouseControl.domElement.instance.removeEventListener( 'mouseup', this.mouseUp, - false + true ); }; diff --git a/src/game-lib-vector2.js b/src/game-lib-vector2.js index 68baa02..dec7ff6 100644 --- a/src/game-lib-vector2.js +++ b/src/game-lib-vector2.js @@ -39,7 +39,7 @@ GameLib.Vector2 = function ( this.createInstance(); }; -GameLib.Vector2.prototype = Object.create(GameLib.Component.prototype); +GameLib.Vector2.prototype = Object.create(GameLib.API.Vector2.prototype); GameLib.Vector2.prototype.constructor = GameLib.Vector2; diff --git a/src/game-lib-vector3.js b/src/game-lib-vector3.js index a5d1b53..1717d4d 100644 --- a/src/game-lib-vector3.js +++ b/src/game-lib-vector3.js @@ -51,7 +51,7 @@ GameLib.Vector3 = function ( this.createInstance(); }; -GameLib.Vector3.prototype = Object.create(GameLib.Component.prototype); +GameLib.Vector3.prototype = Object.create(GameLib.API.Vector3.prototype); GameLib.Vector3.prototype.constructor = GameLib.Vector3; /** diff --git a/src/game-lib-vector4.js b/src/game-lib-vector4.js index c83745c..b908012 100644 --- a/src/game-lib-vector4.js +++ b/src/game-lib-vector4.js @@ -41,7 +41,7 @@ GameLib.Vector4 = function ( this.createInstance(); }; -GameLib.Vector4.prototype = Object.create(GameLib.Component.prototype); +GameLib.Vector4.prototype = Object.create(GameLib.API.Vector4.prototype); GameLib.Vector4.prototype.constructor = GameLib.Vector4; /**