Fix gamepad support (see changelog)

This commit is contained in:
Ethan O'Brien 2023-07-28 09:16:50 -05:00
parent 6ea21a9748
commit 093eb492e5
3 changed files with 12 additions and 4 deletions

View file

@ -8,6 +8,11 @@
- Added picodrive core (sega32x)
- Cleaned up documentation
- Fixed/updated rar de-compression
- Added segaMD, segaCD, sega32x button labels and virtual gamepad (Thanks to [@n-at](https://github.com/n-at))
- Added ability to use threads (pre compiled cores not yet available)
- Fixed reversed gamepad button events (down was up, up was down)
- Fixed Gamepad axis release not triggering
- Add ***highly beta*** psp core - see readme
# 4.0.4 [View Tree](https://github.com/EmulatorJS/EmulatorJS/tree/41491a738cf92ef9cee7d53f323aa2ab9732c053)
- Fix cheats "x" button

View file

@ -2228,7 +2228,7 @@ class EmulatorJS {
for (let i=0; i<4; i++) {
for (let j=0; j<27; j++) {
if (['buttonup', 'buttondown'].includes(e.type) && (this.controls[i][j] && this.controls[i][j].value2 === e.index)) {
this.gameManager.simulateInput(i, j, (e.type === 'buttondown' ? 0 : (special.includes(j) ? 0x7fff : 1)));
this.gameManager.simulateInput(i, j, (e.type === 'buttonup' ? 0 : (special.includes(j) ? 0x7fff : 1)));
} else if (e.type === "axischanged") {
if (this.controls[i][j] && typeof this.controls[i][j].value2 === 'string' && this.controls[i][j].value2.split(":")[0] === e.axis) {
if (special.includes(j)) {

View file

@ -42,13 +42,16 @@ class GamepadHandler {
hasGamepad = true;
oldGamepad.axes.forEach((axis, axisIndex) => {
if (gamepad.axes[axisIndex] !== axis) {
const val = (axis < 0.01 && axis > -0.01) ? 0 : axis;
const newVal = (gamepad.axes[axisIndex] < 0.01 && gamepad.axes[axisIndex] > -0.01) ? 0 : gamepad.axes[axisIndex];
if (newVal !== val) {
const axis = ['LEFT_STICK_X', 'LEFT_STICK_Y', 'RIGHT_STICK_X', 'RIGHT_STICK_Y'][axisIndex];
if (!axis) return;
this.dispatchEvent('axischanged', {axis: axis, value: gamepad.axes[axisIndex], index: gamepad.index, gamepadIndex: gamepad.index});
this.dispatchEvent('axischanged', {axis: axis, value: newVal, index: gamepad.index, gamepadIndex: gamepad.index});
}
gamepadToSave.axes[axisIndex] = axis;
gamepadToSave.axes[axisIndex] = newVal;
})
gamepad.buttons.forEach((button, buttonIndex) => {
let pressed = oldGamepad.buttons[buttonIndex] === 1.0;
if (typeof oldGamepad.buttons[buttonIndex] === "object") {