From 1723129c244b6cf1a6986d39b0e33ce7f103bdff Mon Sep 17 00:00:00 2001 From: Justin Oros Date: Thu, 14 May 2026 15:07:19 -0700 Subject: [PATCH] =?UTF-8?q?Fix=20gamepad=20on=20title/continue=20screens?= =?UTF-8?q?=20=E2=80=94=20poll=20from=20startup,=20handle=20A/Start=20on?= =?UTF-8?q?=20all=20screens?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- game.js | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/game.js b/game.js index 9284c02..e3ede91 100644 --- a/game.js +++ b/game.js @@ -600,20 +600,16 @@ class Game { Button 9 = Start (confirm) ══════════════════════════════════════════════════════════ */ _bindGamepad() { - /* Track previous button state to detect press edges */ - this._gpPrev = {}; + this._gpPrev = {}; this._gpActive = false; window.addEventListener('gamepadconnected', (e) => { console.log('Gamepad connected:', e.gamepad.id); - this._gpActive = true; - if (!this._gpLoop) this._startGpLoop(); }); - window.addEventListener('gamepaddisconnected', () => { - const gamepads = navigator.getGamepads ? navigator.getGamepads() : []; - this._gpActive = [...gamepads].some(g => g); - }); + /* Start polling immediately — don't wait for the event. + The poll function checks if any gamepad is present each frame. */ + this._startGpLoop(); } _startGpLoop() { @@ -665,14 +661,22 @@ class Game { const wasPressed = (i) => !!this._gpPrev[`btn_${i}`]; const justPressed = (i) => pressedNow(i) && !wasPressed(i); - /* A button (0) or Start (9) = confirm / talk */ + /* A button (0) or Start (9) — works on every screen */ if (justPressed(0) || justPressed(9)) { - this._pressA(); + if (s === 'title') { document.getElementById('screen-title')?.click(); } + else if (s === 'continue') { document.getElementById('btn-continue-save')?.click(); } + else if (s === 'intro') { this.advanceIntro(); } + else if (s === 'result') { document.getElementById('btn-result-cont')?.click(); } + else if (s === 'levelup') { document.getElementById('btn-lu-cont')?.click(); } + else if (s === 'complete') { document.getElementById('btn-play-again')?.click(); } + else { this._pressA(); } } - /* B button (1) = back / talk */ + /* B button (1) */ if (justPressed(1)) { - this._pressB(); + if (s === 'intro') { this.advanceIntro(); } + else if (s === 'result') { document.getElementById('btn-result-cont')?.click(); } + else { this._pressB(); } } /* Quick-pick answers with X=2, Y=3, LB=4, RB=5 on battle screen */