mirror of
https://github.com/EmulatorJS/EmulatorJS.git
synced 2024-09-20 02:46:23 +00:00
Firefox gamepad support
This commit is contained in:
parent
928a019112
commit
a36b3eba9d
1 changed files with 9 additions and 3 deletions
|
@ -25,6 +25,11 @@ class GamepadHandler {
|
||||||
let hasGamepad = false;
|
let hasGamepad = false;
|
||||||
this.gamepads.forEach((oldGamepad, oldIndex) => {
|
this.gamepads.forEach((oldGamepad, oldIndex) => {
|
||||||
if (oldGamepad.index !== gamepad.index) return;
|
if (oldGamepad.index !== gamepad.index) return;
|
||||||
|
const gamepadToSave = {
|
||||||
|
axes: [],
|
||||||
|
buttons: {},
|
||||||
|
index: oldGamepad.index
|
||||||
|
}
|
||||||
hasGamepad = true;
|
hasGamepad = true;
|
||||||
|
|
||||||
oldGamepad.axes.forEach((axis, axisIndex) => {
|
oldGamepad.axes.forEach((axis, axisIndex) => {
|
||||||
|
@ -33,7 +38,7 @@ class GamepadHandler {
|
||||||
if (!axis) return;
|
if (!axis) return;
|
||||||
this.dispatchEvent('axischanged', {axis: axis, value: gamepad.axes[axisIndex], index: gamepad.index, gamepadIndex: gamepad.index});
|
this.dispatchEvent('axischanged', {axis: axis, value: gamepad.axes[axisIndex], index: gamepad.index, gamepadIndex: gamepad.index});
|
||||||
}
|
}
|
||||||
|
gamepadToSave.axes[axisIndex] = axis;
|
||||||
})
|
})
|
||||||
gamepad.buttons.forEach((button, buttonIndex) => {
|
gamepad.buttons.forEach((button, buttonIndex) => {
|
||||||
let pressed = oldGamepad.buttons[buttonIndex] === 1.0;
|
let pressed = oldGamepad.buttons[buttonIndex] === 1.0;
|
||||||
|
@ -44,6 +49,7 @@ class GamepadHandler {
|
||||||
if (typeof button === "object") {
|
if (typeof button === "object") {
|
||||||
pressed2 = button.pressed;
|
pressed2 = button.pressed;
|
||||||
}
|
}
|
||||||
|
gamepadToSave.buttons[buttonIndex] = {pressed:pressed2};
|
||||||
if (pressed !== pressed2) {
|
if (pressed !== pressed2) {
|
||||||
if (pressed2) {
|
if (pressed2) {
|
||||||
this.dispatchEvent('buttondown', {index: buttonIndex, gamepadIndex: gamepad.index});
|
this.dispatchEvent('buttondown', {index: buttonIndex, gamepadIndex: gamepad.index});
|
||||||
|
@ -53,7 +59,7 @@ class GamepadHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
})
|
})
|
||||||
this.gamepads[oldIndex] = gamepads[index];
|
this.gamepads[oldIndex] = gamepadToSave;
|
||||||
})
|
})
|
||||||
if (!hasGamepad) {
|
if (!hasGamepad) {
|
||||||
this.gamepads.push(gamepads[index]);
|
this.gamepads.push(gamepads[index]);
|
||||||
|
|
Loading…
Reference in a new issue