Repository navigation
Declare movement as a vector action, bound per device and merged by Controls - #65
Merged
Merged
Conversation
…ontrols
Controls.actions({ buttons, vectors }) declares vector actions next to
buttons. Keyboard.vector and Gamepad.vector bind one to keys, a stick, or
the d-pad, and a Touch layout's stick names the vector it drives; every
snapshot reports vectors with length at most 1. Controls merges the longest
and checks kinds, gaps, and lacking for vectors like buttons. Keyboard
timelines name directions ("move.right"). Top-down drops normalizeMovement.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
Movement is the one input every game has, and the one input Controls didn't model. Games split it into four button actions and rebuilt the direction by hand (
normalizeMovementin top-down). That meant:What
Controls.actions({ buttons, vectors }). A name declared as both kinds doesn't compile.Keyboard.vector({ up, down, left, right }): opposite keys cancel, diagonals have length 1.Gamepad.vector({ stick, up, down, left, right }): a stick, the d-pad, or both; the longer wins.stick.vectornames the vector the stick drives.vectors; Pointer's is empty.lacking,available,idleandlastUsed.rebindandparseRebindingtake vector bindings; Gamepad can swap sticks."move.right"). Gamepad and touch timelines are unchanged.Touch.idle({ buttons, vector? })andTouch.scripted({ buttons, vector? }, timeline).vectors.moveand dropsnormalizeMovement; a new test checks diagonals.Controls.actionsshape.Checks
pnpm run check(652 tests, with type tests for every error above)pnpm pack:checkpnpm --dir website build🤖 Generated with Claude Code