From dabd45997eb681ea216957834a8debf4cf9d928d Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Wed, 9 Aug 2023 11:25:37 -0700 Subject: [PATCH] Back out change supporting multiple names for binding elements testcontroller expects to be able to call SDL_GetGamepadStringForButton() and find that name in the binding string We can revisit this later if it becomes important to use new names in bindings. @smcv --- src/joystick/SDL_gamepad.c | 52 ++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 27 deletions(-) diff --git a/src/joystick/SDL_gamepad.c b/src/joystick/SDL_gamepad.c index fdc662fb9..00b6e9287 100644 --- a/src/joystick/SDL_gamepad.c +++ b/src/joystick/SDL_gamepad.c @@ -1105,31 +1105,29 @@ const char *SDL_GetGamepadStringForAxis(SDL_GamepadAxis axis) } static const char *map_StringForGamepadButton[] = { - "a", NULL, - "b", NULL, - "x", NULL, - "y", NULL, - "back", NULL, - "guide", NULL, - "start", NULL, - "leftstick", NULL, - "rightstick", NULL, - "leftshoulder", NULL, - "rightshoulder", NULL, - "dpup", NULL, - "dpdown", NULL, - "dpleft", NULL, - "dpright", NULL, - "misc1", NULL, - /* Keep using paddle1-4 when we generate mapping strings so that they - * can be reused with SDL2, but accept rightpaddle1 etc. as input */ - "paddle1", "rightpaddle1", - "paddle2", "leftpaddle1", - "paddle3", "rightpaddle2", - "paddle4", "leftpaddle2", - "touchpad", NULL + "a", + "b", + "x", + "y", + "back", + "guide", + "start", + "leftstick", + "rightstick", + "leftshoulder", + "rightshoulder", + "dpup", + "dpdown", + "dpleft", + "dpright", + "misc1", + "paddle1", + "paddle2", + "paddle3", + "paddle4", + "touchpad" }; -SDL_COMPILE_TIME_ASSERT(map_StringForGamepadButton, SDL_arraysize(map_StringForGamepadButton) == 2 * SDL_GAMEPAD_BUTTON_MAX); +SDL_COMPILE_TIME_ASSERT(map_StringForGamepadButton, SDL_arraysize(map_StringForGamepadButton) == SDL_GAMEPAD_BUTTON_MAX); /* * convert a string to its enum equivalent @@ -1143,8 +1141,8 @@ SDL_GamepadButton SDL_GetGamepadButtonFromString(const char *str) } for (i = 0; i < SDL_arraysize(map_StringForGamepadButton); ++i) { - if (map_StringForGamepadButton[i] && SDL_strcasecmp(str, map_StringForGamepadButton[i]) == 0) { - return (SDL_GamepadButton) (i / 2); + if (SDL_strcasecmp(str, map_StringForGamepadButton[i]) == 0) { + return (SDL_GamepadButton)i; } } return SDL_GAMEPAD_BUTTON_INVALID; @@ -1156,7 +1154,7 @@ SDL_GamepadButton SDL_GetGamepadButtonFromString(const char *str) const char *SDL_GetGamepadStringForButton(SDL_GamepadButton button) { if (button > SDL_GAMEPAD_BUTTON_INVALID && button < SDL_GAMEPAD_BUTTON_MAX) { - return map_StringForGamepadButton[button * 2]; + return map_StringForGamepadButton[button]; } return NULL; }