aboutsummaryrefslogtreecommitdiff
path: root/javascript/imageviewerGamepad.js
diff options
context:
space:
mode:
authorunknown <mcgpapu@gmail.com>2023-03-13 03:39:02 -0500
committerunknown <mcgpapu@gmail.com>2023-03-13 03:39:02 -0500
commit40dc0132df0aae62078b29384600570688e3eb79 (patch)
tree778f12e94465b303d2e7a476a2af6fc61c702c45 /javascript/imageviewerGamepad.js
parentbfa14db2cb0e266121317e3624b93708b29f2e88 (diff)
modularize
Diffstat (limited to 'javascript/imageviewerGamepad.js')
-rw-r--r--javascript/imageviewerGamepad.js36
1 files changed, 36 insertions, 0 deletions
diff --git a/javascript/imageviewerGamepad.js b/javascript/imageviewerGamepad.js
new file mode 100644
index 00000000..29bd7140
--- /dev/null
+++ b/javascript/imageviewerGamepad.js
@@ -0,0 +1,36 @@
+ let delay = 350//ms
+ window.addEventListener('gamepadconnected', (e) => {
+ console.log("Gamepad connected!")
+ const gamepad = e.gamepad;
+ setInterval(() => {
+ const xValue = gamepad.axes[0].toFixed(2);
+ 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);
+ } else if (e.deltaX >= 0.6) {
+ modalNextImage(e);
+ }
+
+ setTimeout(() => {
+ isScrolling = false;
+ }, delay);
+ }); \ No newline at end of file