mirror of
https://github.com/linuxserver/emulatorjs.git
synced 2026-02-23 00:01:26 +08:00
stop blocking out edge and try not to break controller in menu
This commit is contained in:
parent
3f36deb276
commit
e65c91993d
@ -483,9 +483,9 @@ async function rendermenu(datas) {
|
||||
if (window.scrollKill == false) {
|
||||
if (ev.additionalEvent == 'panup') {
|
||||
moveDown(5);
|
||||
} else if (ev.additionalEvent == 'pandown') {
|
||||
} else if (ev.additionalEvent == 'pandown') {
|
||||
moveUp(5);
|
||||
} else {
|
||||
} else {
|
||||
clearInterval(scrolling);
|
||||
};
|
||||
} else {
|
||||
@ -527,104 +527,117 @@ async function rendermenu(datas) {
|
||||
return false;
|
||||
});
|
||||
//// GamePad controls ////
|
||||
// Do not allow gamepad controls on Chromium Edge
|
||||
if (! navigator.userAgent.includes('Edg/')) {
|
||||
let scrollDelay
|
||||
let animReq
|
||||
let homeTimer;
|
||||
let home = 0;
|
||||
let homePressed = false;
|
||||
let gpUpdate;
|
||||
function gameLoop() {
|
||||
let gamePads = navigator.getGamepads();
|
||||
if (!gamePads?.[0]) return;
|
||||
let gp = gamePads[0];
|
||||
if (window.location.hash != "#game") {
|
||||
gameStarted = false;
|
||||
if (!scrollDelay) {
|
||||
if (gp.axes[1] > .5 || gp.axes[3] > .5 || gp.buttons[13].pressed) {
|
||||
scrollDelay = setTimeout(() => scrollDelay = undefined, 200);
|
||||
if (gp.axes[1] >= .75 || gp.axes[3] >= .75)
|
||||
moveDown(5);
|
||||
else
|
||||
moveDown();
|
||||
} else if (gp.axes[1] < -.5 || gp.axes[3] < -.5 || gp.buttons[12].pressed) {
|
||||
scrollDelay = setTimeout(() => scrollDelay = undefined, 200);
|
||||
if (gp.axes[1] <= -.75 || gp.axes[3] <= -.75)
|
||||
moveUp(5);
|
||||
else
|
||||
moveUp();
|
||||
} else if (gp.buttons[5].pressed) {
|
||||
scrollDelay = setTimeout(() => scrollDelay = undefined, 200);
|
||||
indexDown();
|
||||
} else if (gp.buttons[4].pressed) {
|
||||
scrollDelay = setTimeout(() => scrollDelay = undefined, 200);
|
||||
indexUp();
|
||||
let scrollDelay
|
||||
let animReq
|
||||
let homeTimer;
|
||||
let home = 0;
|
||||
let homePressed = false;
|
||||
let gpUpdate;
|
||||
function gameLoop() {
|
||||
let gamePads = navigator.getGamepads();
|
||||
if (!gamePads?.[0]) return;
|
||||
let gp = gamePads[0];
|
||||
if (window.location.hash != "#game") {
|
||||
// Handle if buttons are missing
|
||||
function buttonsMissing(axes,buttons) {
|
||||
var missing = true;
|
||||
axes.forEach(function(i) {
|
||||
if (typeof gp.axes[i] === 'undefined') {
|
||||
missing = false;
|
||||
}
|
||||
}
|
||||
if (gp.timestamp == gpUpdate) {
|
||||
animReq = requestAnimationFrame(gameLoop);
|
||||
return;
|
||||
}
|
||||
gpUpdate = gp.timestamp
|
||||
if (gp.buttons[0].pressed) {
|
||||
if ($('#i' + active_item.toString()).data('type') == "game") {
|
||||
cancelAnimationFrame(animReq);
|
||||
}
|
||||
$('#i' + active_item).click();
|
||||
return;
|
||||
} else if (gp.buttons[1].pressed && parent && '#' + parent != window.location.hash) {
|
||||
window.location.href = '#' + parent;
|
||||
return;
|
||||
} else if (gp.buttons[16].pressed && window.location.hash != '#main') {
|
||||
window.location.href = '#main';
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
if (gp.timestamp == gpUpdate) {
|
||||
animReq = requestAnimationFrame(gameLoop);
|
||||
return;
|
||||
}
|
||||
gpUpdate = gp.timestamp
|
||||
try {
|
||||
if (!gameStarted && gp.buttons[1].pressed && parent) {
|
||||
window.location.href = '#' + parent;
|
||||
return;
|
||||
}
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
}
|
||||
if (!gp.buttons[16].pressed && homePressed) {
|
||||
home++;
|
||||
homePressed = false;
|
||||
}
|
||||
if (gp.buttons[16].pressed) {
|
||||
clearTimeout(homeTimer)
|
||||
homeTimer = setTimeout(() => home = 0, 500)
|
||||
homePressed = true
|
||||
}
|
||||
if (gp.buttons[16].pressed && home >= 2)
|
||||
window.location.href = '#' + parent;
|
||||
});
|
||||
buttons.forEach(function(i) {
|
||||
if (typeof gp.buttons[i] === 'undefined') {
|
||||
missing = false;
|
||||
}
|
||||
});
|
||||
return missing;
|
||||
}
|
||||
gameStarted = false;
|
||||
if (!scrollDelay) {
|
||||
if ((buttonsMissing([1,3],[13])) && (gp.axes[1] > .5 || gp.axes[3] > .5 || gp.buttons[13].pressed)) {
|
||||
scrollDelay = setTimeout(() => scrollDelay = undefined, 200);
|
||||
if (gp.axes[1] >= .75 || gp.axes[3] >= .75)
|
||||
moveDown(5);
|
||||
else
|
||||
moveDown();
|
||||
} else if ((buttonsMissing([1,3],[12])) && (gp.axes[1] < -.5 || gp.axes[3] < -.5 || gp.buttons[12].pressed)) {
|
||||
scrollDelay = setTimeout(() => scrollDelay = undefined, 200);
|
||||
if (gp.axes[1] <= -.75 || gp.axes[3] <= -.75)
|
||||
moveUp(5);
|
||||
else
|
||||
moveUp();
|
||||
} else if ((buttonsMissing([],[5])) && (gp.buttons[5].pressed)) {
|
||||
scrollDelay = setTimeout(() => scrollDelay = undefined, 200);
|
||||
indexDown();
|
||||
} else if ((buttonsMissing([],[4])) && (gp.buttons[4].pressed)) {
|
||||
scrollDelay = setTimeout(() => scrollDelay = undefined, 200);
|
||||
indexUp();
|
||||
}
|
||||
}
|
||||
if (gp.timestamp == gpUpdate) {
|
||||
animReq = requestAnimationFrame(gameLoop);
|
||||
return;
|
||||
}
|
||||
gpUpdate = gp.timestamp
|
||||
if (gp.buttons[0].pressed) {
|
||||
if ($('#i' + active_item.toString()).data('type') == "game") {
|
||||
cancelAnimationFrame(animReq);
|
||||
}
|
||||
$('#i' + active_item).click();
|
||||
return;
|
||||
} else if (gp.buttons[1].pressed && parent && '#' + parent != window.location.hash) {
|
||||
window.location.href = '#' + parent;
|
||||
return;
|
||||
} else if ((buttonsMissing([],[16])) && (gp.buttons[16].pressed && window.location.hash != '#main')) {
|
||||
window.location.href = '#main';
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
if (gp.timestamp == gpUpdate) {
|
||||
animReq = requestAnimationFrame(gameLoop);
|
||||
return;
|
||||
}
|
||||
gpUpdate = gp.timestamp
|
||||
try {
|
||||
if (!gameStarted && gp.buttons[1].pressed && parent) {
|
||||
window.location.href = '#' + parent;
|
||||
return;
|
||||
}
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
}
|
||||
if ((buttonsMissing([],[16])) && (!gp.buttons[16].pressed && homePressed)) {
|
||||
home++;
|
||||
homePressed = false;
|
||||
}
|
||||
if ((buttonsMissing([],[16])) && (gp.buttons[16].pressed)) {
|
||||
clearTimeout(homeTimer)
|
||||
homeTimer = setTimeout(() => home = 0, 500)
|
||||
homePressed = true
|
||||
}
|
||||
if ((buttonsMissing([],[16])) && (gp.buttons[16].pressed && home >= 2)) {
|
||||
window.location.href = '#' + parent;
|
||||
}
|
||||
animReq = requestAnimationFrame(gameLoop);
|
||||
}
|
||||
window.addEventListener("gamepadconnected", gameLoop)
|
||||
window.addEventListener("gamepaddisconnected", cancelAnimationFrame(animReq))
|
||||
window.addEventListener("load", () => {
|
||||
var gameStarted = false;
|
||||
let gps = navigator.getGamepads();
|
||||
if (gps) {
|
||||
for (let gp of gps) {
|
||||
let gpEvt = new GamepadEvent("gamepadconnected", {
|
||||
gamepad: gp
|
||||
})
|
||||
window.dispatchEvent(gpEvt)
|
||||
}
|
||||
}
|
||||
});
|
||||
window.addEventListener("hashchange", gameLoop);
|
||||
animReq = requestAnimationFrame(gameLoop);
|
||||
}
|
||||
};
|
||||
window.addEventListener("gamepadconnected", gameLoop)
|
||||
window.addEventListener("gamepaddisconnected", cancelAnimationFrame(animReq))
|
||||
window.addEventListener("load", () => {
|
||||
var gameStarted = false;
|
||||
let gps = navigator.getGamepads();
|
||||
if (gps) {
|
||||
for (let gp of gps) {
|
||||
let gpEvt = new GamepadEvent("gamepadconnected", {
|
||||
gamepad: gp
|
||||
})
|
||||
window.dispatchEvent(gpEvt)
|
||||
}
|
||||
}
|
||||
});
|
||||
window.addEventListener("hashchange", gameLoop);
|
||||
}
|
||||
|
||||
// Go fullscreen
|
||||
function fullscreen() {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user