Commit df59b74c authored by missionfloyd's avatar missionfloyd

Only poll gamepads while connected

parent 20ae71fa
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]))
});
/*
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment