input system updates

beta.r3js.org
-=yb4f310 2017-10-30 06:47:40 +01:00
parent 1fb49ac3c1
commit 02a1365712
4 changed files with 278 additions and 52 deletions

View File

@ -107,6 +107,10 @@ GameLib.Event.GAME_LOADED = 0x59;
GameLib.Event.GAME_RESTART = 0x5a;
GameLib.Event.LOAD_PROGRESS = 0x5b;
GameLib.Event.ENTITY_LOADED = 0x5c;
GameLib.Event.MOUSE_DOWN = 0x5d;
GameLib.Event.MOUSE_MOVE = 0x5e;
GameLib.Event.MOUSE_WHEEL = 0x5f;
GameLib.Event.MOUSE_UP = 0x60;
/**
* Returns string name of event ID
@ -209,6 +213,10 @@ GameLib.Event.GetEventName = function(number) {
case 0x5a : return 'game_restart';
case 0x5b : return 'load_progress';
case 0x5c : return 'entity_loaded';
case 0x5d : return 'mouse_down';
case 0x5e : return 'mouse_move';
case 0x5f : return 'mouse_wheel';
case 0x60 : return 'mouse_up';
break;
}

View File

@ -268,7 +268,16 @@ GameLib.Component.COMPONENT_FONT = 0x3c;
GameLib.Component.COMPONENT_CANVAS = 0x3d;
GameLib.Component.COMPONENT_BONE = 0x3e;
GameLib.Component.COMPONENT_MESH_BOX = 0x3f;
GameLib.Component.COMPONENT_MESH_CYLINDER = 0x40;
GameLib.Component.COMPONENT_MESH_CYLINDER = 0x40;
GameLib.Component.COMPONENT_SYSTEM_ANIMATION = 0x41;
GameLib.Component.COMPONENT_SYSTEM_CUSTOM_CODE = 0x42;
GameLib.Component.COMPONENT_SYSTEM_GUI = 0x43;
GameLib.Component.COMPONENT_SYSTEM_INPUT = 0x44;
GameLib.Component.COMPONENT_SYSTEM_LINKING = 0x45;
GameLib.Component.COMPONENT_SYSTEM_PHYSICS = 0x46;
GameLib.Component.COMPONENT_SYSTEM_RENDER = 0x47;
GameLib.Component.COMPONENT_SYSTEM_STORAGE = 0x48;
GameLib.Component.COMPONENT_SYSTEM_VISUALIZATION = 0x49;
/**
* Returns string name for component number
@ -342,6 +351,15 @@ GameLib.Component.GetComponentName = function(number) {
case 0x3e : return 'GameLib.D3.Bone';
case 0x3f : return 'GameLib.D3.Mesh.Box';
case 0x40 : return 'GameLib.D3.Mesh.Cylinder';
case 0x41 : return 'GameLib.D3.System.Animation';
case 0x42 : return 'GameLib.D3.System.CustomCode';
case 0x43 : return 'GameLib.D3.System.GUI';
case 0x44 : return 'GameLib.D3.System.Input';
case 0x45 : return 'GameLib.D3.System.Linking';
case 0x46 : return 'GameLib.D3.System.Physics';
case 0x47 : return 'GameLib.D3.System.Render';
case 0x48 : return 'GameLib.D3.System.Storage';
case 0x49 : return 'GameLib.D3.System.Visualization';
break;
}

View File

@ -28,9 +28,51 @@ GameLib.System = function(
this.paused = false;
var componentType = GameLib.Component.COMPONENT_SYSTEM;
var linkedObjects = {};
if (apiSystem.systemType === GameLib.System.SYSTEM_TYPE_ANIMATION) {
componentType = GameLib.Component.COMPONENT_SYSTEM_ANIMATION;
}
if (apiSystem.systemType === GameLib.System.SYSTEM_TYPE_CUSTOM) {
componentType = GameLib.Component.COMPONENT_SYSTEM_CUSTOM_CODE;
}
if (apiSystem.systemType === GameLib.System.SYSTEM_TYPE_GUI) {
componentType = GameLib.Component.COMPONENT_SYSTEM_GUI;
}
if (apiSystem.systemType === GameLib.System.SYSTEM_TYPE_INPUT) {
componentType = GameLib.Component.COMPONENT_SYSTEM_INPUT;
linkedObjects.mouseControls = [GameLib.D3.Controls.Mouse];
linkedObjects.keyboardControls = [GameLib.D3.Controls.Keyboard];
linkedObjects.touchControls = [GameLib.D3.Controls.Touch];
linkedObjects.editorControls = [GameLib.D3.Controls.Editor];
}
if (apiSystem.systemType === GameLib.System.SYSTEM_TYPE_LINKING) {
componentType = GameLib.Component.COMPONENT_SYSTEM_LINKING;
}
if (apiSystem.systemType === GameLib.System.SYSTEM_TYPE_PHYSICS) {
componentType = GameLib.Component.COMPONENT_SYSTEM_PHYSICS;
}
if (apiSystem.systemType === GameLib.System.SYSTEM_TYPE_RENDER) {
componentType = GameLib.Component.COMPONENT_SYSTEM_RENDER;
}
if (apiSystem.systemType === GameLib.System.SYSTEM_TYPE_STORAGE) {
componentType = GameLib.Component.COMPONENT_SYSTEM_STORAGE;
}
if (apiSystem.systemType === GameLib.System.SYSTEM_TYPE_VISUALIZATION) {
componentType = GameLib.Component.COMPONENT_SYSTEM_VISUALIZATION;
}
GameLib.Component.call(
this,
GameLib.Component.COMPONENT_SYSTEM
componentType
);
};

View File

@ -21,11 +21,8 @@ GameLib.System.Input = function(
* window event handlers when we need to
* @type {function()}
*/
this.mouseMove = null;
this.mouseDown = null;
this.keyDown = null;
this.mouseUp = null;
this.mouseWheel = null;
this.selectAll = false;
@ -47,10 +44,15 @@ GameLib.System.Input = function(
this.keyboardKeyUp = this.onKeyboardKeyUp.bind(this);
this.keyboardKeyDown = this.onKeyboardKeyDown.bind(this);
this.mouseDown = this.onMouseDown.bind(this);
this.mouseMove = this.onMouseMove.bind(this);
this.mouseWheel = this.onMouseWheel.bind(this);
this.mouseUp = this.onMouseUp.bind(this);
this.mouseDown = null;
this.mouseMove = null;
this.mouseWheel = null;
this.mouseUp = null;
this.mouseDownEdit = null;
this.mouseMoveEdit = null;
this.mouseWheelEdit = null;
this.mouseUpEdit = null;
this.keyDown = this.onKeyDown.bind(this);
this.keyUp = this.onKeyUp.bind(this);
@ -83,7 +85,26 @@ GameLib.System.Input.prototype.start = function() {
this.delayedInstanceEncounteredSubscription = GameLib.Event.Subscribe(
GameLib.Event.DELAYED_INSTANCE_ENCOUNTERED,
function() {
this.restart();
if (this.editorControls) {
this.editorControls.map(
function(editorControl) {
if (editorControl.linked && !editorControl.loaded) {
editorControl.createInstance();
this.entityCreatedSubscription = GameLib.Event.Subscribe(
GameLib.Event.ENTITY_LOADED,
function(data){
if (data.entity === editorControl.parentEntity) {
editorControl.dispose();
this.entityCreatedSubscription.remove();
this.restart();
}
}.bind(this)
)
}
}.bind(this)
)
}
//this.restart();
}.bind(this)
);
@ -146,20 +167,67 @@ GameLib.System.Input.prototype.start = function() {
)
}
if (this.editorControls.length > 0) {
this.editorControls.map(
function(editorControl) {
editorControl.domElement.instance.addEventListener(
if (this.mouseControls.length > 0) {
this.mouseDown = this.onMouseDown.bind(this);
this.mouseMove = this.onMouseMove.bind(this);
this.mouseWheel = this.onMouseWheel.bind(this);
this.mouseUp = this.onMouseUp.bind(this);
/**
* Do Nothing
*/
this.mouseControls.map(
function(mouseControl) {
mouseControl.domElement.instance.addEventListener(
'mousedown',
this.mouseDown,
false
);
editorControl.domElement.instance.addEventListener(
mouseControl.domElement.instance.addEventListener(
'mousemove',
this.mouseMove,
false
);
mouseControl.domElement.instance.addEventListener(
'wheel',
this.mouseWheel,
false
);
mouseControl.domElement.instance.addEventListener(
'mouseup',
this.mouseUp,
false
);
}.bind(this)
)
}
if (this.editorControls.length > 0) {
this.editorControls.map(
function(editorControl) {
/**
* If we already have mouse controls, we don't want to add another event listener onto the DOM
*/
// if (this.mouseControls.length < 1) {
this.mouseDownEdit = this.onMouseDownEdit.bind(this);
this.mouseMoveEdit = this.onMouseMoveEdit.bind(this);
editorControl.domElement.instance.addEventListener(
'mousedown',
this.mouseDownEdit,
false
);
editorControl.domElement.instance.addEventListener(
'mousemove',
this.mouseMoveEdit,
false
);
// }
/**
* If we already have keyboard controls, we don't want to add another event listener onto the DOM
@ -186,17 +254,27 @@ GameLib.System.Input.prototype.start = function() {
editorControl.createInstance();
/**
* If we already have mouse controls, we don't want to add another event listener onto the DOM
*/
// if (this.mouseControls.length < 1) {
this.mouseWheelEdit = this.onMouseWheelEdit.bind(this);
this.mouseUpEdit = this.onMouseUpEdit.bind(this);
editorControl.domElement.instance.addEventListener(
'mousewheel',
this.mouseWheel,
'wheel',
this.mouseWheelEdit,
false
);
editorControl.domElement.instance.addEventListener(
'mouseup',
this.mouseUp,
this.mouseUpEdit,
false
);
// }
}.bind(this)
)
}
@ -427,6 +505,47 @@ GameLib.System.Input.prototype.onKeyUp = function(event) {
};
GameLib.System.Input.prototype.onMouseDown = function(event) {
console.log('mouse down');
GameLib.Event.Emit(
GameLib.Event.MOUSE_DOWN,
{
event : event
}
)
};
GameLib.System.Input.prototype.onMouseMove = function(event) {
console.log('mouse move');
GameLib.Event.Emit(
GameLib.Event.MOUSE_MOVE,
{
event : event
}
)
};
GameLib.System.Input.prototype.onMouseWheel = function(event) {
console.log('mouse wheel');
GameLib.Event.Emit(
GameLib.Event.MOUSE_WHEEL,
{
event : event
}
)
};
GameLib.System.Input.prototype.onMouseUp = function(event) {
console.log('mouse up');
GameLib.Event.Emit(
GameLib.Event.MOUSE_UP,
{
event : event
}
)
};
GameLib.System.Input.prototype.onMouseDownEdit = function(event) {
if (event.button === 2) {
@ -518,7 +637,7 @@ GameLib.System.Input.prototype.onMouseDown = function(event) {
*
* @param event
*/
GameLib.System.Input.prototype.onMouseMove = function(event) {
GameLib.System.Input.prototype.onMouseMoveEdit = function(event) {
};
@ -527,7 +646,7 @@ GameLib.System.Input.prototype.onMouseMove = function(event) {
* @returns {Function}
* @param event
*/
GameLib.System.Input.prototype.onMouseUp = function(event) {
GameLib.System.Input.prototype.onMouseUpEdit = function(event) {
this.editorControls.map(
function(editorControl) {
editorControl.camera.position.x = editorControl.camera.instance.position.x;
@ -552,7 +671,7 @@ GameLib.System.Input.prototype.onMouseUp = function(event) {
* @returns {Function}
* @param event
*/
GameLib.System.Input.prototype.onMouseWheel = function(event) {
GameLib.System.Input.prototype.onMouseWheelEdit = function(event) {
this.editorControls.map(
function(editorControl) {
editorControl.camera.position.x = editorControl.camera.instance.position.x;
@ -616,43 +735,52 @@ GameLib.System.Input.prototype.stop = function() {
*/
this.editorControls.map(
function(editorControl) {
editorControl.domElement.instance.removeEventListener(
'mousedown',
this.mouseDown,
false
);
editorControl.domElement.instance.removeEventListener(
'mousemove',
this.mouseMove,
false
);
// if (this.mouseControls.length < 1) {
editorControl.domElement.instance.removeEventListener(
'keydown',
this.keyDown,
false
);
editorControl.domElement.instance.removeEventListener(
'mousedown',
this.mouseDownEdit,
false
);
editorControl.domElement.instance.removeEventListener(
'keyup',
this.keyUp,
false
);
editorControl.domElement.instance.removeEventListener(
'mousemove',
this.mouseMoveEdit,
false
);
// }
if (this.keyboardControls.length < 1) {
editorControl.domElement.instance.removeEventListener(
'keydown',
this.keyDown,
false
);
editorControl.domElement.instance.removeEventListener(
'keyup',
this.keyUp,
false
);
}
editorControl.instance.dispose();
editorControl.domElement.instance.removeEventListener(
'mousewheel',
this.mouseWheel,
false
);
// if (this.mouseControls.length < 1) {
editorControl.domElement.instance.removeEventListener(
'wheel',
this.mouseWheelEdit,
false
);
editorControl.domElement.instance.removeEventListener(
'mouseup',
this.mouseUp,
false
);
editorControl.domElement.instance.removeEventListener(
'mouseup',
this.mouseUpEdit,
false
);
// }
}.bind(this)
)
}
@ -707,6 +835,36 @@ GameLib.System.Input.prototype.stop = function() {
)
}
if (this.mouseControls.length > 0) {
this.mouseControls.map(
function(mouseControl) {
mouseControl.domElement.instance.removeEventListener(
'mousedown',
this.mouseDown,
false
);
mouseControl.domElement.instance.removeEventListener(
'mousemove',
this.mouseMove,
false
);
mouseControl.domElement.instance.removeEventListener(
'wheel',
this.mouseWheel,
false
);
mouseControl.domElement.instance.removeEventListener(
'mouseup',
this.mouseUp,
false
);
}.bind(this)
)
}
};