even more navigation refinements
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user