Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
samme committed May 1, 2020
1 parent 341ecf0 commit 7392fc2
Showing 1 changed file with 34 additions and 26 deletions.
60 changes: 34 additions & 26 deletions src/input/MSPointer.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ Phaser.MSPointer.prototype = {

event.identifier = event.pointerId;

if (event.pointerType === 'mouse' || event.pointerType === 0x00000004)
if (this.isMousePointerEvent(event))
{
this.input.mousePointer.start(event);
}
Expand Down Expand Up @@ -316,7 +316,7 @@ Phaser.MSPointer.prototype = {

event.identifier = event.pointerId;

if (event.pointerType === 'mouse' || event.pointerType === 0x00000004)
if (this.isMousePointerEvent(event))
{
this.input.mousePointer.move(event);
}
Expand Down Expand Up @@ -356,7 +356,7 @@ Phaser.MSPointer.prototype = {

event.identifier = event.pointerId;

if (event.pointerType === 'mouse' || event.pointerType === 0x00000004)
if (this.isMousePointerEvent(event))
{
this.input.mousePointer.stop(event);
}
Expand All @@ -378,7 +378,7 @@ Phaser.MSPointer.prototype = {

event.identifier = event.pointerId;

if ((event.pointerType === 'mouse' || event.pointerType === 0x00000004) && !this.input.mousePointer.withinGame)
if (this.isMousePointerEvent(event) && !this.input.mousePointer.withinGame)
{
this.onPointerUp(event);
}
Expand Down Expand Up @@ -412,18 +412,11 @@ Phaser.MSPointer.prototype = {

event.identifier = event.pointerId;

if (event.pointerType === 'mouse' || event.pointerType === 0x00000004)
{
this.input.mousePointer.withinGame = false;
}
else
{
var pointer = this.input.getPointerFromIdentifier(event.identifier);
var pointer = this.getPointerFromEvent(event);

if (pointer)
{
pointer.withinGame = false;
}
if (pointer)
{
pointer.withinGame = false;
}

if (this.pointerOutCallback)
Expand Down Expand Up @@ -470,18 +463,11 @@ Phaser.MSPointer.prototype = {

event.identifier = event.pointerId;

if (event.pointerType === 'mouse' || event.pointerType === 0x00000004)
{
this.input.mousePointer.withinGame = true;
}
else
{
var pointer = this.input.getPointerFromIdentifier(event.identifier);
var pointer = this.getPointerFromEvent(event);

if (pointer)
{
pointer.withinGame = true;
}
if (pointer)
{
pointer.withinGame = true;
}

if (this.pointerOverCallback)
Expand Down Expand Up @@ -520,6 +506,28 @@ Phaser.MSPointer.prototype = {

this.active = false;

},

/**
* @private
* @param {PointerEvent} event
* @return {boolean}
*/
isMousePointerEvent: function (event)
{
return (event.pointerType === 'mouse' || event.pointerType === 0x00000004);
},

/**
* @private
* @param {PointerEvent} event
* @return {?Phaser.Pointer}
*/
getPointerFromEvent: function (event)
{
return this.isMousePointerEvent(event)
? this.input.mousePointer
: this.input.getPointerFromIdentifier(event.identifier);
}

};
Expand Down

0 comments on commit 7392fc2

Please sign in to comment.