even more navigation refinements

This commit is contained in:
roormonger
2026-03-24 14:38:18 -04:00
parent 76229465ca
commit 8f92bf33c3
3 changed files with 166 additions and 30 deletions

View File

@@ -8,6 +8,8 @@ const BUTTON_DPAD_UP = 12;
const BUTTON_DPAD_DOWN = 13;
const BUTTON_DPAD_LEFT = 14;
const BUTTON_DPAD_RIGHT = 15;
const BUTTON_LB = 4;
const BUTTON_RB = 5;
const AXIS_THRESHOLD = 0.5;
const INITIAL_DELAY_MS = 400;
const REPEAT_RATE_MS = 100;
@@ -86,6 +88,19 @@ export const useGamepad = () => {
handleInput(`gp${i}_right`, right, () => navigateByDirection('right', {}));
handleInput(`gp${i}_enter`, enter, () => dispatchEnter(), false);
handleInput(`gp${i}_back`, back, () => dispatchEscape(), false);
const lb = gp.buttons[BUTTON_LB]?.pressed;
const rb = gp.buttons[BUTTON_RB]?.pressed;
handleInput(`gp${i}_lb`, lb, () => window.dispatchEvent(new CustomEvent('previousplatform')));
handleInput(`gp${i}_rb`, rb, () => window.dispatchEvent(new CustomEvent('nextplatform')));
// Right analog stick — scroll the currently focused list
const rsX = gp.axes[2] ?? 0;
const rsY = gp.axes[3] ?? 0;
if (Math.abs(rsX) > AXIS_THRESHOLD || Math.abs(rsY) > AXIS_THRESHOLD) {
setMode('gamepad');
window.dispatchEvent(new CustomEvent('analogscroll', { detail: { dx: rsX, dy: rsY } }));
}
}
} catch (e) {
console.error("Gamepad Polling Error", e);