Skip to content

M5.3 C3: Gamepad support - #39

Merged
hynding merged 1 commit into
mainfrom
claude/m5.3-c3-gamepad
Nov 21, 2026
Merged

hynding merged 1 commit into
mainfrom
claude/m5.3-c3-gamepad

Conversation

@hynding

@hynding hynding commented Nov 21, 2026

Copy link
Copy Markdown
Owner

Requested by Steve · project thread

Third PR of the extended controls plan (docs/plans/extended-controls.md, C3). With this, you can play a level and use the menus with only a controller.

What changed

  • Reading pads:
    • The first pad to press something is player 1. It's polled every animation frame, even while frozen, so Start unpauses.
    • Pure code (src/sim/gamepad.ts) handles the rest:
      • standard-mapping button names and stick directions;
      • a trigger pulled past halfway counts as a press;
      • non-standard pads give raw b7 / axis2+ plus a best guess by position, so the defaults still work;
      • choosing player 1, and button edges.
  • Analog movement:
    • The left stick, with a radial dead zone and rescaling, walks at its tilt.
    • Pushed past input.analog.runThreshold, it runs. The double-tap still works too.
    • Keys and the d-pad override the stick, and the stick's own digital directions don't snap it to full speed.
  • Schema v5 adds input.analog (deadZone, runThreshold) and feel.rumble. Migration 4 → 5 fills in the defaults.
  • Rumble:
    • Hits the player takes rumble in proportion to damage. Hits the player lands rumble softer, and a KO kicks harder.
    • It's tuned in feel.rumble and can be turned off by the player.
    • It only plays where the pad has a vibration actuator.
  • Pause on disconnect: if the pad in use goes away mid-fight, the game pauses.
  • Held through a pause: inputs held when the scene freezes are ignored until they're released (suppressHeld), so pressing A on RESUME doesn't also jump.
  • Prompts follow the last used device:
    • New store fields inputDevice and padLabels drive this.
    • The HUD, start menu and pause hint show Xbox, PlayStation (✕ ○ □ △), Nintendo or generic names.
  • Menu navigation (MenuPad):
    • The d-pad or stick moves focus spatially between visible buttons (nextFocus), with auto-repeat. A clicks, B resumes from pause or goes back.
    • It's off in the Forge and while a fight is running.
    • A focus ring shows the selected button.
  • CONTROLS panel, controller tab: says "Press any button…" until a pad is seen. It has "+ press a button" capture, a dead-zone slider and a vibration toggle, and reset clears the dead zone too.
  • Forge: the controller tab has "+ press" capture.

Testing

  • npm test passes: 391 tests.
    • New tests cover the fake-pad readers (standard, triggers, non-standard), the stick dead zone, player-1 choice and edges, label sets and controller help.
    • Also new: rumble strength, analog vs digital movement in the sampler, suppressHeld, spatial menu nav and auto-repeat, and the v4 → v5 migration.
    • The DEFAULT_CONFIG snapshot was updated deliberately (input.analog, feel.rumble).
  • npm run lint and npm run build are clean.
  • Headless Chromium smoke run with a stubbed navigator.getGamepads (a DualSense id with a fake vibration actuator):
    • The d-pad focuses START GAME, then FORGE, then START GAME again. A starts the run.
    • The HUD shows PlayStation names.
    • Half tilt walks and full tilt runs.
    • X attacks. Start pauses, and the hint says "Press OPTIONS". B resumes.
    • In the pause menu, the d-pad focuses RESUME and A resumes.
    • Rumble effects fired during a fight.
    • Disconnecting the pad paused the game.
  • The repo has no Playwright suite, so this smoke run isn't in CI.

Generated by Claude Code

Player 1's controller (the first pad to press something) is polled every
frame: standard-mapping buttons and stick directions, raw names for
other pads. The left stick moves with its tilt (radial dead zone) and
runs past a threshold; keys and the d-pad override it. Schema v5 adds
input.analog and feel.rumble (migration 4 -> 5). Rumble on hits the
player takes or lands; pause when the pad in use disconnects; inputs
held through a freeze wait to be released.

Prompts follow the last used device, with Xbox, PlayStation, Nintendo
or generic button names. Menus can be driven with the d-pad or stick,
A and B (MenuPad). The CONTROLS panel's controller tab shows whether a
pad is seen, captures a pressed button, and has a dead zone slider and
a vibration toggle; the Forge's controller tab captures too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017AxU91KfohopVBJiiV9gwj
@hynding hynding self-assigned this Nov 21, 2026
@hynding
hynding merged commit 25c69ac into main Nov 21, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants