2017-07-13 16:21:37 +00:00
|
|
|
// Phaser.Input.GlobalInputManager
|
2017-02-21 01:04:11 +00:00
|
|
|
|
2017-06-30 14:47:51 +00:00
|
|
|
var Class = require('../utils/Class');
|
|
|
|
var EventDispatcher = require('../events/EventDispatcher');
|
|
|
|
var GetTransformedPoint = require('./components/GetTransformedPoint');
|
2017-02-21 01:04:11 +00:00
|
|
|
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/');
|
2017-07-13 16:21:37 +00:00
|
|
|
var Pointer = require('./Pointer');
|
|
|
|
var PointScreenToWorldHitTest = require('./components/PointScreenToWorldHitTest');
|
|
|
|
var HitTest = require('./components/HitTest');
|
2017-06-14 01:20:55 +00:00
|
|
|
var PointWithinGameObject = require('./components/PointWithinGameObject');
|
2017-07-04 00:59:31 +00:00
|
|
|
var TransformMatrix = require('../gameobjects/components/TransformMatrix');
|
2017-02-21 01:04:11 +00:00
|
|
|
|
2017-06-30 14:47:51 +00:00
|
|
|
var GlobalInputManager = new Class({
|
2017-02-21 01:04:11 +00:00
|
|
|
|
2017-06-30 14:47:51 +00:00
|
|
|
initialize:
|
2017-02-21 01:04:11 +00:00
|
|
|
|
2017-06-30 14:47:51 +00:00
|
|
|
function GlobalInputManager (game, config)
|
|
|
|
{
|
|
|
|
this.game = game;
|
2017-06-14 00:20:01 +00:00
|
|
|
|
2017-06-30 14:47:51 +00:00
|
|
|
this.config = config;
|
2017-06-14 00:20:01 +00:00
|
|
|
|
2017-06-30 14:47:51 +00:00
|
|
|
this.enabled = true;
|
2017-06-14 00:20:01 +00:00
|
|
|
|
2017-06-30 14:47:51 +00:00
|
|
|
this.events = new EventDispatcher();
|
2017-06-14 01:20:55 +00:00
|
|
|
|
2017-06-30 14:47:51 +00:00
|
|
|
// Standard FIFO queue
|
|
|
|
this.queue = [];
|
2017-02-21 01:04:11 +00:00
|
|
|
|
2017-06-30 14:47:51 +00:00
|
|
|
// Listeners
|
|
|
|
this.keyboard = new Keyboard(this);
|
|
|
|
this.mouse = new Mouse(this);
|
2017-02-21 01:04:11 +00:00
|
|
|
|
2017-07-13 16:21:37 +00:00
|
|
|
this.activePointer = new Pointer(this);
|
|
|
|
|
2017-06-30 14:47:51 +00:00
|
|
|
this._tempMatrix = new TransformMatrix();
|
|
|
|
this._tempPoint = { x: 0, y: 0 };
|
2017-07-07 19:59:17 +00:00
|
|
|
this._tempHitTest = [];
|
2017-06-30 14:47:51 +00:00
|
|
|
},
|
2017-02-21 01:04:11 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
},
|
|
|
|
|
2017-07-13 23:37:54 +00:00
|
|
|
update: function (time, delta)
|
2017-02-21 01:04:11 +00:00
|
|
|
{
|
|
|
|
this.keyboard.update();
|
2017-06-14 00:20:01 +00:00
|
|
|
|
|
|
|
var len = this.queue.length;
|
|
|
|
|
2017-07-14 00:38:21 +00:00
|
|
|
// Currently just 1 pointer supported
|
2017-07-13 23:37:54 +00:00
|
|
|
var pointer = this.activePointer;
|
|
|
|
|
2017-07-14 00:38:21 +00:00
|
|
|
pointer.reset();
|
2017-07-13 23:37:54 +00:00
|
|
|
|
2017-06-14 00:20:01 +00:00
|
|
|
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];
|
|
|
|
|
2017-07-14 00:38:21 +00:00
|
|
|
// Move to CONSTs so we can do integer comparisons instead of strings
|
2017-06-14 00:20:01 +00:00
|
|
|
switch (event.type)
|
|
|
|
{
|
|
|
|
case 'mousemove':
|
2017-07-13 16:21:37 +00:00
|
|
|
|
2017-07-14 00:38:21 +00:00
|
|
|
pointer.move(event);
|
2017-06-14 00:20:01 +00:00
|
|
|
this.events.dispatch(new MouseEvent.MOVE(event));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'mousedown':
|
2017-07-13 16:21:37 +00:00
|
|
|
|
2017-07-14 00:38:21 +00:00
|
|
|
pointer.down(event);
|
2017-06-14 00:20:01 +00:00
|
|
|
this.events.dispatch(new MouseEvent.DOWN(event));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'mouseup':
|
2017-07-13 16:21:37 +00:00
|
|
|
|
2017-07-14 00:38:21 +00:00
|
|
|
pointer.up(event);
|
2017-06-14 00:20:01 +00:00
|
|
|
this.events.dispatch(new MouseEvent.UP(event));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2017-06-14 01:20:55 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
getTransformedPoint: function (gameObject, x, y)
|
|
|
|
{
|
|
|
|
return GetTransformedPoint(this._tempMatrix, gameObject, x, y, this._tempPoint);
|
|
|
|
},
|
|
|
|
|
|
|
|
pointWithinGameObject: function (gameObject, x, y)
|
|
|
|
{
|
|
|
|
return PointWithinGameObject(gameObject, x, y);
|
2017-07-07 19:59:17 +00:00
|
|
|
},
|
|
|
|
|
2017-07-13 16:21:37 +00:00
|
|
|
hitTest: function (gameObjects, x, y, camera)
|
2017-07-07 19:59:17 +00:00
|
|
|
{
|
2017-07-13 16:21:37 +00:00
|
|
|
return HitTest(this._tempMatrix, x, y, gameObjects, camera, this._tempHitTest);
|
2017-07-13 01:06:00 +00:00
|
|
|
},
|
|
|
|
|
2017-07-13 16:21:37 +00:00
|
|
|
pointScreenToWorldHitTest: function (gameObjects, x, y, camera)
|
2017-07-13 01:06:00 +00:00
|
|
|
{
|
2017-07-13 16:21:37 +00:00
|
|
|
return PointScreenToWorldHitTest(this._tempMatrix, x, y, gameObjects, camera, this._tempHitTest);
|
2017-02-21 01:04:11 +00:00
|
|
|
}
|
|
|
|
|
2017-06-30 14:47:51 +00:00
|
|
|
});
|
2017-02-21 01:04:11 +00:00
|
|
|
|
|
|
|
module.exports = GlobalInputManager;
|