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.GAME_RESTART = 0x5a;
GameLib.Event.LOAD_PROGRESS = 0x5b; GameLib.Event.LOAD_PROGRESS = 0x5b;
GameLib.Event.ENTITY_LOADED = 0x5c; 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 * Returns string name of event ID
@ -209,6 +213,10 @@ GameLib.Event.GetEventName = function(number) {
case 0x5a : return 'game_restart'; case 0x5a : return 'game_restart';
case 0x5b : return 'load_progress'; case 0x5b : return 'load_progress';
case 0x5c : return 'entity_loaded'; 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; break;
} }

View File

@ -269,6 +269,15 @@ GameLib.Component.COMPONENT_CANVAS = 0x3d;
GameLib.Component.COMPONENT_BONE = 0x3e; GameLib.Component.COMPONENT_BONE = 0x3e;
GameLib.Component.COMPONENT_MESH_BOX = 0x3f; 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 * Returns string name for component number
@ -342,6 +351,15 @@ GameLib.Component.GetComponentName = function(number) {
case 0x3e : return 'GameLib.D3.Bone'; case 0x3e : return 'GameLib.D3.Bone';
case 0x3f : return 'GameLib.D3.Mesh.Box'; case 0x3f : return 'GameLib.D3.Mesh.Box';
case 0x40 : return 'GameLib.D3.Mesh.Cylinder'; 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; break;
} }

View File

@ -28,9 +28,51 @@ GameLib.System = function(
this.paused = false; 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( GameLib.Component.call(
this, this,
GameLib.Component.COMPONENT_SYSTEM componentType
); );
}; };

View File

@ -21,11 +21,8 @@ GameLib.System.Input = function(
* window event handlers when we need to * window event handlers when we need to
* @type {function()} * @type {function()}
*/ */
this.mouseMove = null;
this.mouseDown = null;
this.keyDown = null; this.keyDown = null;
this.mouseUp = null;
this.mouseWheel = null;
this.selectAll = false; this.selectAll = false;
@ -47,10 +44,15 @@ GameLib.System.Input = function(
this.keyboardKeyUp = this.onKeyboardKeyUp.bind(this); this.keyboardKeyUp = this.onKeyboardKeyUp.bind(this);
this.keyboardKeyDown = this.onKeyboardKeyDown.bind(this); this.keyboardKeyDown = this.onKeyboardKeyDown.bind(this);
this.mouseDown = this.onMouseDown.bind(this); this.mouseDown = null;
this.mouseMove = this.onMouseMove.bind(this); this.mouseMove = null;
this.mouseWheel = this.onMouseWheel.bind(this); this.mouseWheel = null;
this.mouseUp = this.onMouseUp.bind(this); this.mouseUp = null;
this.mouseDownEdit = null;
this.mouseMoveEdit = null;
this.mouseWheelEdit = null;
this.mouseUpEdit = null;
this.keyDown = this.onKeyDown.bind(this); this.keyDown = this.onKeyDown.bind(this);
this.keyUp = this.onKeyUp.bind(this); this.keyUp = this.onKeyUp.bind(this);
@ -83,7 +85,26 @@ GameLib.System.Input.prototype.start = function() {
this.delayedInstanceEncounteredSubscription = GameLib.Event.Subscribe( this.delayedInstanceEncounteredSubscription = GameLib.Event.Subscribe(
GameLib.Event.DELAYED_INSTANCE_ENCOUNTERED, GameLib.Event.DELAYED_INSTANCE_ENCOUNTERED,
function() { function() {
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(); this.restart();
}
}.bind(this)
)
}
}.bind(this)
)
}
//this.restart();
}.bind(this) }.bind(this)
); );
@ -146,20 +167,67 @@ GameLib.System.Input.prototype.start = function() {
) )
} }
if (this.editorControls.length > 0) { if (this.mouseControls.length > 0) {
this.editorControls.map(
function(editorControl) { this.mouseDown = this.onMouseDown.bind(this);
editorControl.domElement.instance.addEventListener( 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', 'mousedown',
this.mouseDown, this.mouseDown,
false false
); );
editorControl.domElement.instance.addEventListener( mouseControl.domElement.instance.addEventListener(
'mousemove', 'mousemove',
this.mouseMove, this.mouseMove,
false 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 * 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(); 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( editorControl.domElement.instance.addEventListener(
'mousewheel', 'wheel',
this.mouseWheel, this.mouseWheelEdit,
false false
); );
editorControl.domElement.instance.addEventListener( editorControl.domElement.instance.addEventListener(
'mouseup', 'mouseup',
this.mouseUp, this.mouseUpEdit,
false false
); );
// }
}.bind(this) }.bind(this)
) )
} }
@ -427,6 +505,47 @@ GameLib.System.Input.prototype.onKeyUp = function(event) {
}; };
GameLib.System.Input.prototype.onMouseDown = 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) { if (event.button === 2) {
@ -518,7 +637,7 @@ GameLib.System.Input.prototype.onMouseDown = function(event) {
* *
* @param 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} * @returns {Function}
* @param event * @param event
*/ */
GameLib.System.Input.prototype.onMouseUp = function(event) { GameLib.System.Input.prototype.onMouseUpEdit = function(event) {
this.editorControls.map( this.editorControls.map(
function(editorControl) { function(editorControl) {
editorControl.camera.position.x = editorControl.camera.instance.position.x; editorControl.camera.position.x = editorControl.camera.instance.position.x;
@ -552,7 +671,7 @@ GameLib.System.Input.prototype.onMouseUp = function(event) {
* @returns {Function} * @returns {Function}
* @param event * @param event
*/ */
GameLib.System.Input.prototype.onMouseWheel = function(event) { GameLib.System.Input.prototype.onMouseWheelEdit = function(event) {
this.editorControls.map( this.editorControls.map(
function(editorControl) { function(editorControl) {
editorControl.camera.position.x = editorControl.camera.instance.position.x; editorControl.camera.position.x = editorControl.camera.instance.position.x;
@ -616,18 +735,24 @@ GameLib.System.Input.prototype.stop = function() {
*/ */
this.editorControls.map( this.editorControls.map(
function(editorControl) { function(editorControl) {
// if (this.mouseControls.length < 1) {
editorControl.domElement.instance.removeEventListener( editorControl.domElement.instance.removeEventListener(
'mousedown', 'mousedown',
this.mouseDown, this.mouseDownEdit,
false false
); );
editorControl.domElement.instance.removeEventListener( editorControl.domElement.instance.removeEventListener(
'mousemove', 'mousemove',
this.mouseMove, this.mouseMoveEdit,
false false
); );
// }
if (this.keyboardControls.length < 1) {
editorControl.domElement.instance.removeEventListener( editorControl.domElement.instance.removeEventListener(
'keydown', 'keydown',
this.keyDown, this.keyDown,
@ -639,20 +764,23 @@ GameLib.System.Input.prototype.stop = function() {
this.keyUp, this.keyUp,
false false
); );
}
editorControl.instance.dispose(); editorControl.instance.dispose();
// if (this.mouseControls.length < 1) {
editorControl.domElement.instance.removeEventListener( editorControl.domElement.instance.removeEventListener(
'mousewheel', 'wheel',
this.mouseWheel, this.mouseWheelEdit,
false false
); );
editorControl.domElement.instance.removeEventListener( editorControl.domElement.instance.removeEventListener(
'mouseup', 'mouseup',
this.mouseUp, this.mouseUpEdit,
false false
); );
// }
}.bind(this) }.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)
)
}
}; };