From 5f4f0b424bc48f8afd3d63bb96c9965b2917ced0 Mon Sep 17 00:00:00 2001 From: Sasha Szpakowski Date: Sun, 18 Jun 2023 11:54:17 -0300 Subject: [PATCH] love.joystick: more fixes for duplicate platform fields in gamepad mapping strings. --- src/modules/joystick/sdl/JoystickModule.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/modules/joystick/sdl/JoystickModule.cpp b/src/modules/joystick/sdl/JoystickModule.cpp index d979fc02b..de45fe0ff 100644 --- a/src/modules/joystick/sdl/JoystickModule.cpp +++ b/src/modules/joystick/sdl/JoystickModule.cpp @@ -470,7 +470,9 @@ std::string JoystickModule::getGamepadMappingString(const std::string &guid) con // Matches SDL_GameControllerAddMappingsFromRW. if (mapping.find_last_of(',') != mapping.length() - 1) mapping += ","; - mapping += "platform:" + std::string(SDL_GetPlatform()); + + if (mapping.find("platform:") == std::string::npos) + mapping += "platform:" + std::string(SDL_GetPlatform()); return mapping; } @@ -494,8 +496,10 @@ std::string JoystickModule::saveGamepadMappings() mapping += ","; // Matches SDL_GameControllerAddMappingsFromRW. - mapping += "platform:" + std::string(SDL_GetPlatform()) + ",\n"; - mappings += mapping; + if (mapping.find("platform:") == std::string::npos) + mapping += "platform:" + std::string(SDL_GetPlatform()) + ","; + + mappings += mapping + "\n"; } return mappings;