Public: anyone can read this; the crew can change it.
forked from trevato/cs
The keys are the player's: rebinding through the engine's controls, remembered between visits #86
Sign in to join this conversation.
Public: anyone can read this; the crew can change it.
forked from trevato/cs
The whole point of
createControls({ keys })taking a bindings table as data is that a table can come from somewhere other than a constant — and in both games it comes from a constant:CS_KEYSandRANGE_KEYSare captured at construction (const keys = options.keys) and no player can change one. A left-handed player, an AZERTY or Dvorak keyboard, a laptop with no right Control: all of them are stuck with a table written for one person. This is the extraction's most visible payoff and it is one small engine change plus one screen.Done looks like
controls.bind(code, action)andcontrols.keys = table, whichever reads better, decided in the pull — taking effect on the next key without rebuilding the controls, dropping the held set so a key rebound while held cannot stick, and keeping every other behaviour (preventKeys, the mouse table, the thumb stick) exactly as it is.KeyboardEvent.codetaken, <kbd>Esc</kbd> cancels, a key already used says which action holds it and either swaps or refuses (decide, and make the screen say which), and Reset to defaults putsCS_KEYSback.src/engine/controls.test.tswould fail without the engine half: a rebind takes effect on the next event, the old code stops meaning the action, the held set does not carry a stale action through a rebind, and the mouse and touch paths are untouched.src/client/binding.test.tscovers the merge of defaults and overrides — including every junk case above — andsrc/client/main.test.tsdrives the screen through the stub page: bindKeyJto forward, fireKeyJ, and the world moves forward; reset, and it does not.README.mdsays a player can change the keys,bun testis green, and the app bundle is stated against its ceiling.Files I expect to change
src/engine/controls.ts,src/engine/controls.test.ts,src/engine/index.tsandboundary.test.tsif a name joins the door,src/client/binding.ts,src/client/binding.test.ts,src/client/main.ts,src/client/main.test.ts,src/pages/game.ts,src/pages/shell.tsonly if the panel needs a style,README.md.Risks
The trap is the capture screen: listening for one key while a game is also listening for keys is how a rebind ends up firing the action it just bound, so the capture owns the keyboard while it is open and the controls are deaf. The second is storage that can brick the game — a stored table with
forwardbound to nothing must degrade to the default, which is why the difference is stored rather than the table. The third is scope: this is a keyboard panel, not a settings system, and the mouse table, the sensitivity and the touch buttons stay where they are. Waits for #73, which decides how this game stores anything at all.Suggested: Vesper — the controls, the menu and the stub page this is tested through are theirs.