Restore compatibility with older GameCube mappings

Restore the original button values for GameCube controllers, but swap labeled mappings to positional while loading mappings

Fixes https://github.com/libsdl-org/SDL/issues/12847
This commit is contained in:
Sam Lantinga
2025-04-30 15:21:34 -07:00
parent 3730128e33
commit 21a7bbbf14
6 changed files with 55 additions and 32 deletions

View File

@@ -2474,6 +2474,7 @@ static char *JoinMapping(MappingParts *parts)
sort_order[i].index = i;
}
SDL_qsort(sort_order, parts->num_elements, sizeof(*sort_order), SortMapping);
MoveSortedEntry("face", sort_order, parts->num_elements, true);
MoveSortedEntry("type", sort_order, parts->num_elements, true);
MoveSortedEntry("platform", sort_order, parts->num_elements, true);
MoveSortedEntry("crc", sort_order, parts->num_elements, true);
@@ -2809,6 +2810,8 @@ const char *GetGamepadTypeString(SDL_GamepadType type)
return "Joy-Con (R)";
case SDL_GAMEPAD_TYPE_NINTENDO_SWITCH_JOYCON_PAIR:
return "Joy-Con Pair";
case SDL_GAMEPAD_TYPE_GAMECUBE:
return "GameCube";
default:
return "";
}

View File

@@ -478,6 +478,17 @@ static void CommitBindingElement(const char *binding, bool force)
mapping = NULL;
}
if (mapping && SDL_GetGamepadType(controller->gamepad) == SDL_GAMEPAD_TYPE_GAMECUBE) {
if (SDL_strstr(mapping, "face:") == NULL) {
char *new_mapping = NULL;
SDL_asprintf(&new_mapping, "%sface:axby,", mapping);
if (new_mapping) {
SDL_free(mapping);
mapping = new_mapping;
}
}
}
/* If the controller generates multiple events for a single element, pick the best one */
if (!force && binding_advance_time) {
char *current = GetElementBinding(mapping, binding_element);