2017-02-21 01:04:11 +00:00
|
|
|
// GlobalInputManager
|
|
|
|
|
|
|
|
var Keyboard = require('./keyboard/KeyboardManager');
|
2017-06-12 23:38:48 +00:00
|
|
|
var Mouse = require('./mouse/MouseManager');
|
2017-06-14 00:20:01 +00:00
|
|
|
var MouseEvent = require('./mouse/events/');
|
|
|
|
var EventDispatcher = require('../events/EventDispatcher');
|
2017-02-21 01:04:11 +00:00
|
|
|
|
|
|
|
var GlobalInputManager = function (game, gameConfig)
|
|
|
|
{
|
|
|
|
this.game = game;
|
|
|
|
|
|
|
|
this.gameConfig = gameConfig;
|
|
|
|
|
2017-06-14 00:20:01 +00:00
|
|
|
this.enabled = true;
|
|
|
|
|
|
|
|
this.events = new EventDispatcher();
|
|
|
|
|
|
|
|
// Standard FIFO queue
|
|
|
|
this.queue = [];
|
|
|
|
|
|
|
|
// Listeners
|
2017-02-21 01:04:11 +00:00
|
|
|
this.keyboard = new Keyboard(this);
|
2017-06-12 16:03:34 +00:00
|
|
|
this.mouse = new Mouse(this);
|
2017-02-21 01:04:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
GlobalInputManager.prototype.constructor = GlobalInputManager;
|
|
|
|
|
|
|
|
GlobalInputManager.prototype = {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The Boot handler is called by Phaser.Game when it first starts up.
|
|
|
|
* The renderer is available by now.
|
|
|
|
*
|
|
|
|
* @method Phaser.Input.KeyboardManager#boot
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
boot: function ()
|
|
|
|
{
|
|
|
|
this.keyboard.boot();
|
2017-06-12 16:03:34 +00:00
|
|
|
this.mouse.boot();
|
2017-02-21 01:04:11 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
update: function ()
|
|
|
|
{
|
|
|
|
this.keyboard.update();
|
2017-06-14 00:20:01 +00:00
|
|
|
|
|
|
|
var len = this.queue.length;
|
|
|
|
|
|
|
|
if (!this.enabled || len === 0)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Clears the queue array, and also means we don't work on array data that could potentially
|
|
|
|
// be modified during the processing phase
|
|
|
|
var queue = this.queue.splice(0, len);
|
|
|
|
|
|
|
|
// Process the event queue, dispatching all of the events that have stored up
|
|
|
|
for (var i = 0; i < len; i++)
|
|
|
|
{
|
|
|
|
var event = queue[i];
|
|
|
|
|
|
|
|
switch (event.type)
|
|
|
|
{
|
|
|
|
case 'mousemove':
|
|
|
|
this.events.dispatch(new MouseEvent.MOVE(event));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'mousedown':
|
|
|
|
this.events.dispatch(new MouseEvent.DOWN(event));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'mouseup':
|
|
|
|
this.events.dispatch(new MouseEvent.UP(event));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2017-02-21 01:04:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = GlobalInputManager;
|