controls migration

beta.r3js.org
-=yb4f310 2018-01-11 14:33:32 +01:00
parent 1aa01c95a3
commit af43128b0f
17 changed files with 293 additions and 69 deletions

View File

@ -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
);

View File

@ -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
);
};

View File

@ -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
);
};

View File

@ -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
);
};

View File

@ -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);

View File

@ -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;
/**

View File

@ -21,7 +21,7 @@ GameLib.Controls = function (
);
var linkedObjects = {
domElement : GameLib.DomElement
domElement : GameLib.Canvas
};
var delayed = false;

View File

@ -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(

View File

@ -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
);
};

View File

@ -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
);
};

View File

@ -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);
};

View File

@ -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}

View File

@ -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,

View File

@ -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
);
};

View File

@ -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;

View File

@ -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;
/**

View File

@ -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;
/**