Skip to content

feat(input): weapon selection via number keys (1-8 -> impulse) - #23

Merged
tannevaled merged 1 commit into
mainfrom
weapon-switching
Jul 6, 2026
Merged

feat(input): weapon selection via number keys (1-8 -> impulse)#23
tannevaled merged 1 commit into
mainfrom
weapon-switching

Conversation

@tannevaled

Copy link
Copy Markdown
Contributor

The number keys were never decoded, so the player was stuck on whatever weapon spawned (the shotgun in lq_e0m1). Wire the full path:

  • backend: add Key1..Key8 KeyCodes + ImpulseForKey (Key1..Key8 -> 1..8).
  • backend/wasm + backend/wasmbox keymaps: map DOM "Digit1".."Digit8".
  • runloop: a Key1..Key8 down-edge queues a one-shot PendingImpulse, fed into client.TickInput.Impulse and cleared after the tic (edge-triggered — a held key doesn't re-switch every frame). Gated off while the menu/console has focus. The impulse rides clc_move → the QC ImpulseCommands runs W_ChangeWeapon (the host already writes self.impulse to the edict).

Verification (Firefox/Playwright, lq_e0m1)

  • Digit1weapon=4096 (IT_AXE, 0 ammo)
  • Digit2weapon=1 (IT_SHOTGUN, 25 shells)

Switches both ways. 100% coverage held on backend / backend/wasm / backend/wasmbox (new ImpulseForKey test + Digit rows in both keymap tables).

🤖 Generated with Claude Code

The number keys were never decoded, so the player was stuck on whatever
weapon spawned. Wire the full path:

- backend: add Key1..Key8 KeyCodes + ImpulseForKey (Key1..Key8 -> 1..8).
- backend/wasm + backend/wasmbox keymaps: map DOM "Digit1".."Digit8".
- runloop: a Key1..Key8 down-edge queues a one-shot PendingImpulse, fed into
  client.TickInput.Impulse and cleared after the tic (edge-triggered, so a
  held key doesn't re-switch every frame). Gated off while the menu or console
  has focus. The impulse rides clc_move -> the QC ImpulseCommands runs it as
  W_ChangeWeapon (host already writes self.impulse to the edict).

Verified in-browser (Firefox/Playwright, lq_e0m1): Digit1 -> weapon=4096
(IT_AXE, 0 ammo), Digit2 -> weapon=1 (IT_SHOTGUN, 25 shells), switching both
ways. 100% coverage held on backend / backend/wasm / backend/wasmbox (new
ImpulseForKey test + Digit rows in both keymap tables).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@tannevaled
tannevaled merged commit f9d13ca into main Jul 6, 2026
7 checks passed
@tannevaled
tannevaled deleted the weapon-switching branch July 6, 2026 09:56
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.

1 participant