Controls: which button and key press each Switch button, from the options file #335

Merged
gab9281 merged 1 commit from input/bindings into main 2026-11-07 23:47:54 +00:00
gab9281 commented 2026-11-07 21:24:55 +00:00 (Migrated from github.com)

Part of splitting #83 into small PRs. This is the first of three. The next two, which build on it, let the Insert menu be driven from a controller and add a Controls page to rebind from inside the game.

The gamepad buttons and the keys were fixed tables in nn_hid.c and pad_sdl.c. They are now one table: each Switch button has a gamepad input (by position) and up to two keys.

  • hookshot_options.ini can set them with pad_<button>=<position> and key_<button>=<key code>,<key code>. A button it leaves out keeps today's default, so nothing changes without those lines.
  • The pads (SDL and XInput) now report their inputs by position (HOS_PAD_*, SDL's order). The table turns them into the Switch's buttons.
  • The Insert menu's save keeps the pad_ and key_ lines. Before, it rewrote the whole file.
  • The readme says how to write the lines.

Tested on Linux (game built from this branch, a copy of real saves):

  • With key_a=71 (G) in hookshot_options.ini, the log says hid: 1 controls from hookshot_options.ini. On the title screen, E (A's default key) does nothing and G opens the Load screen.
  • Changing FPS counter in the Insert menu rewrote the options and kept key_a=71.
  • I could not press a controller's buttons in this test. The default table maps each gamepad position to the same Switch button as the old fixed tables did (bottom face button → B, right → A, and so on).
  • tests/ gives the same result as on main (the 4 test_cpp_preflight checks need Visual Studio).

Merge notes: #324 moves hookshot_options.ini next to the saves; whichever lands second changes binds_load to use hos_options_path(). #328 rewrites pad_sdl.c for the SDL stubs, and the loop that reads the buttons conflicts in a small way.

🤖 Generated with Claude Code

Part of splitting #83 into small PRs. This is the first of three. The next two, which build on it, let the Insert menu be driven from a controller and add a Controls page to rebind from inside the game. The gamepad buttons and the keys were fixed tables in `nn_hid.c` and `pad_sdl.c`. They are now one table: each Switch button has a gamepad input (by position) and up to two keys. - `hookshot_options.ini` can set them with `pad_<button>=<position>` and `key_<button>=<key code>,<key code>`. A button it leaves out keeps today's default, so nothing changes without those lines. - The pads (SDL and XInput) now report their inputs by position (`HOS_PAD_*`, SDL's order). The table turns them into the Switch's buttons. - The Insert menu's save keeps the `pad_` and `key_` lines. Before, it rewrote the whole file. - The readme says how to write the lines. **Tested on Linux** (game built from this branch, a copy of real saves): - With `key_a=71` (G) in `hookshot_options.ini`, the log says `hid: 1 controls from hookshot_options.ini`. On the title screen, E (A's default key) does nothing and G opens the Load screen. - Changing FPS counter in the Insert menu rewrote the options and kept `key_a=71`. - I could not press a controller's buttons in this test. The default table maps each gamepad position to the same Switch button as the old fixed tables did (bottom face button → B, right → A, and so on). - `tests/` gives the same result as on main (the 4 `test_cpp_preflight` checks need Visual Studio). Merge notes: #324 moves `hookshot_options.ini` next to the saves; whichever lands second changes `binds_load` to use `hos_options_path()`. #328 rewrites `pad_sdl.c` for the SDL stubs, and the loop that reads the buttons conflicts in a small way. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
gab9281 commented 2026-11-07 23:26:31 +00:00 (Migrated from github.com)

@NotRexed rebased on current main (9e8fb5b).

@NotRexed rebased on current main (9e8fb5b).
Commenting is not possible because the repository is archived.
No description provided.