Skip to content

Save simple button mappings per port - #414

Merged
patchzyy merged 1 commit into
patchzyy:mainfrom
mitsa-ng:fix/issue-404-per-port-button-mappings
Nov 17, 2026
Merged

patchzyy merged 1 commit into
patchzyy:mainfrom
mitsa-ng:fix/issue-404-per-port-button-mappings

Conversation

@mitsa-ng

@mitsa-ng mitsa-ng commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #404.

What

The F10 controller tab's simple mapping UI now persists bindings per port, as [controller] <key>_<port+1> keys (a_1 .. right_4), matching how the expression system (expr_<port+1>_<control>) already works.

Every persistence site saves the port it edits:

  • rebind capture (CompleteRebind, already knew capture.port)
  • the trigger-threshold slider (writeBinding in DrawGamepadMapping)
  • the GameCube layout restore and the Classic Controller Pro / PlayStation presets

ApplyConfiguredMappings reads the port's own binding first via the new PortControllerButton(port, index).

The old shared keys ([controller] a, b, ...) remain as the fallback for ports that were never rebound individually, so an existing config keeps applying to every port exactly as before until a port is actually reconfigured on top of it. There is deliberately no migration: single-player setups are unchanged, and multiplayer setups converge port by port as each player rebinds.

Why

Reported in #404: two players (e.g. over Parsec), player 2 rebinds after player 1, and on next launch both ports use player 2's layout, because there was only one shared binding set and the last writer won.

Testing

  • New runtime_config_tests.cpp cases: per-port keys parse into the right slots; a_0, a_5, a_x, non-string values, and unknown button names are rejected; shared and per-port keys stay separate; PortControllerButtonKey layout (including out-of-range port/index returning empty).
  • static_assert(RuntimeConfigFile::kControllerPortCount == PAD_MAX_CONTROLLERS) keeps the config side honest against the pad layer.
  • Built and ran the full host-platform test suite (MKW_PLATFORM_TESTS_ONLY): 12/12 pass on macOS arm64.
  • Compiled mkw_macos_native_compile (covers settings_overlay.cpp) locally on macOS arm64.

I do not have a usable game dump on this machine, so runtime behavior is verified by the config-layer tests and code reading, not by an in-game run; happy to adjust if a reviewer sees something off in the overlay paths.

Summary by CodeRabbit

  • New Features
    • Controller button bindings can now be customized separately for each port. Ports without saved overrides continue to use the shared bindings.
  • Bug Fixes
    • Invalid or unsupported port-specific binding entries are ignored when loading settings.

The F10 bar's simple mapping UI persisted one shared [controller]
binding set: rebinding on any port overwrote it, and the next launch
applied the last writer's layout to every port (issue patchzyy#404). The
expression system (expr_<port+1>_<control>) was already per-port; the
simple mapping path now matches it.

Bindings now persist as [controller] "<key>_<port+1>" (a_1 .. right_4).
Every write site (rebind capture, threshold slider, GameCube restore,
layout presets) saves the port it edits, and ApplyConfiguredMappings
reads the port's own binding first. The old shared keys stay as the
fallback for ports never rebound, so existing configs keep behaving
exactly as before until a port is individually reconfigured.

Fixes patchzyy#404
@coderabbitai

coderabbitai Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Runtime configuration now supports per-port controller button overrides with fallback to shared bindings. The settings overlay applies and saves mappings for the selected port, and tests cover key parsing, storage separation, and bounds.

Changes: Per-port controller bindings

Layer / File(s) Summary
Configuration contract and persistence
runtime/include/runtime_config.h, runtime/tests/runtime_config_tests.cpp
Runtime configuration stores and parses button overrides for ports 1–4. Lookup uses the shared binding when no port override exists. Tests cover valid and invalid keys, storage separation, and bounds.
Port-specific settings actions
runtime/src/settings_overlay.cpp
The settings overlay applies, edits, and restores bindings for the current port. It checks the configured port count and states that ports without overrides use the shared mapping.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: patchzyy, javiomaster211

Merge Risk: Minimal · up to bc975

The change saves simple controller button mappings per port and falls back to the shared bindings for ports not yet rebound. No concrete merge-blocking problem was found. Moving a controller between ports and in-game behavior were not exercised, so they are worth a quick manual check.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title "Save simple button mappings per port" matches the main change. The PR stores simple controller button mappings under per-port [controller] keys (e.g., a_1 through right_4), adds parsing and…
Linked Issues check Passed [#404] The issue asks that controller button mappings save per port, so a later rebind by one player does not overwrite another port's bindings. At the reviewed head, runtime_config.h adds controllerP…
Out of Scope Changes check Passed All changed hunks serve #404. runtime_config.h adds the per-port storage, parsing, key helpers, and accessors. settings_overlay.cpp routes every shared-binding write site to a per-port write and reads…
Full details: Title check

Explanation

The title "Save simple button mappings per port" matches the main change. The PR stores simple controller button mappings under per-port [controller] keys (e.g., a_1 through right_4), adds parsing and helpers for those keys, and applies per-port bindings with fallback to shared keys. The title is short, specific, and free of file lists or vague terms.

Full details: Linked Issues check

Explanation

[#404] The issue asks that controller button mappings save per port, so a later rebind by one player does not overwrite another port's bindings. At the reviewed head, runtime_config.h adds controllerPortButtons (4 ports x 12 buttons). ParseConfigDocument reads keys in the form <button><1..4>. SetPortControllerButton writes the key <button><port+1>. PortControllerButton returns the port override and falls back to the shared binding. In settings_overlay.cpp, CompleteRebind, the trigger-threshold writeBinding, the GameCube layout restore, and the Classic Controller Pro and PlayStation presets all save with the port they edit. ApplyConfiguredMappings reads PortControllerButton(port, i). This covers the requested behavior in code. The PR also adds parsing tests in runtime_config_tests.cpp. I did not read the test diff directly. The in-game behavior was not run by the author and was not verified here. The verdict rests on the code path, not on a runtime test.

Full details: Out of Scope Changes check

Explanation

All changed hunks serve #404. runtime_config.h adds the per-port storage, parsing, key helpers, and accessors. settings_overlay.cpp routes every shared-binding write site to a per-port write and reads per-port bindings in ApplyConfiguredMappings. It also adds a static_assert tying kControllerPortCount to PAD_MAX_CONTROLLERS and an overlay help line that describes the fallback. The Wii U Pro exclusion is unchanged. The tests cover the new parsing and key layout. No unrelated change was found in the inspected hunks. One minor code note: PortControllerButton declares an unused local static 'empty'. This does not affect scope or requirements.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 02df3b57-e53d-4115-bad1-9c7c5fd9dbe2
Commits

Reviewing files that changed from the base of the PR and between ffbde83 and bc9751f.

Files selected for processing: 3

  • runtime/include/runtime_config.h
  • runtime/src/settings_overlay.cpp
  • runtime/tests/runtime_config_tests.cpp

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 2 remain after this review.

@patchzyy
patchzyy merged commit c987e2b into patchzyy:main Nov 17, 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.

[Feature] Save controller button mappings based on port number

2 participants