Only poll gamepads while connected

This commit is contained in:
missionfloyd 2023-05-28 20:42:47 -06:00
parent 20ae71faa8
commit df59b74ced

View File

@ -1,7 +1,9 @@
let gamepads = [];
window.addEventListener('gamepadconnected', (e) => {
const index = e.gamepad.index;
let isWaiting = false;
setInterval(async() => {
gamepads[index] = setInterval(async() => {
if (!opts.js_modal_lightbox_gamepad || isWaiting) return;
const gamepad = navigator.getGamepads()[index];
const xValue = gamepad.axes[0];
@ -22,6 +24,7 @@ window.addEventListener('gamepadconnected', (e) => {
isWaiting = false;
}
}, 10);
window.addEventListener('gamepaddisconnected', (e) => clearInterval(gamepads[e.gamepad.index]))
});
/*