Make gamepad navigation optional
This commit is contained in:
parent
5ab7f213be
commit
a46c23b10f
|
@ -1,36 +1,33 @@
|
||||||
let delay = 350//ms
|
const delay = 250//ms
|
||||||
window.addEventListener('gamepadconnected', (e) => {
|
window.addEventListener('gamepadconnected', (e) => {
|
||||||
console.log("Gamepad connected!")
|
setInterval(() => {
|
||||||
const gamepad = e.gamepad;
|
if (!opts.js_modal_lightbox_gamepad) return;
|
||||||
setInterval(() => {
|
const gamepad = navigator.getGamepads()[0];
|
||||||
const xValue = gamepad.axes[0].toFixed(2);
|
const xValue = gamepad.axes[0];
|
||||||
if (xValue < -0.3) {
|
if (xValue < -0.3) {
|
||||||
modalPrevImage(e);
|
|
||||||
} else if (xValue > 0.3) {
|
|
||||||
modalNextImage(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
}, delay);
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
Primarily for vr controller type pointer devices.
|
|
||||||
I use the wheel event because there's currently no way to do it properly with web xr.
|
|
||||||
*/
|
|
||||||
|
|
||||||
let isScrolling = false;
|
|
||||||
window.addEventListener('wheel', (e) => {
|
|
||||||
if (isScrolling) return;
|
|
||||||
isScrolling = true;
|
|
||||||
|
|
||||||
if (e.deltaX <= -0.6) {
|
|
||||||
modalPrevImage(e);
|
modalPrevImage(e);
|
||||||
} else if (e.deltaX >= 0.6) {
|
} else if (xValue > 0.3) {
|
||||||
modalNextImage(e);
|
modalNextImage(e);
|
||||||
}
|
}
|
||||||
|
}, delay);
|
||||||
|
});
|
||||||
|
|
||||||
setTimeout(() => {
|
/*
|
||||||
isScrolling = false;
|
Primarily for vr controller type pointer devices.
|
||||||
}, delay);
|
I use the wheel event because there's currently no way to do it properly with web xr.
|
||||||
});
|
*/
|
||||||
|
let isScrolling = false;
|
||||||
|
window.addEventListener('wheel', (e) => {
|
||||||
|
if (!opts.js_modal_lightbox_gamepad || isScrolling) return;
|
||||||
|
isScrolling = true;
|
||||||
|
|
||||||
|
if (e.deltaX <= -0.6) {
|
||||||
|
modalPrevImage(e);
|
||||||
|
} else if (e.deltaX >= 0.6) {
|
||||||
|
modalNextImage(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
setTimeout(() => {
|
||||||
|
isScrolling = false;
|
||||||
|
}, delay);
|
||||||
|
});
|
||||||
|
|
|
@ -399,6 +399,7 @@ options_templates.update(options_section(('ui', "User interface"), {
|
||||||
"font": OptionInfo("", "Font for image grids that have text"),
|
"font": OptionInfo("", "Font for image grids that have text"),
|
||||||
"js_modal_lightbox": OptionInfo(True, "Enable full page image viewer"),
|
"js_modal_lightbox": OptionInfo(True, "Enable full page image viewer"),
|
||||||
"js_modal_lightbox_initially_zoomed": OptionInfo(True, "Show images zoomed in by default in full page image viewer"),
|
"js_modal_lightbox_initially_zoomed": OptionInfo(True, "Show images zoomed in by default in full page image viewer"),
|
||||||
|
"js_modal_lightbox_gamepad": OptionInfo(True, "Navagete image viewer with gamepad"),
|
||||||
"show_progress_in_title": OptionInfo(True, "Show generation progress in window title."),
|
"show_progress_in_title": OptionInfo(True, "Show generation progress in window title."),
|
||||||
"samplers_in_dropdown": OptionInfo(True, "Use dropdown for sampler selection instead of radio group"),
|
"samplers_in_dropdown": OptionInfo(True, "Use dropdown for sampler selection instead of radio group"),
|
||||||
"dimensions_and_batch_together": OptionInfo(True, "Show Width/Height and Batch sliders in same row"),
|
"dimensions_and_batch_together": OptionInfo(True, "Show Width/Height and Batch sliders in same row"),
|
||||||
|
|
Loading…
Reference in New Issue