input: don't change mapper if file not found. sdl: fix default bindings

This commit is contained in:
Flyinghead 2021-07-05 09:59:46 +02:00
parent 7cd832e914
commit b40328e621
2 changed files with 10 additions and 16 deletions

View File

@ -350,8 +350,7 @@ void GamepadDevice::load_system_mappings(int system)
for (int i = 0; i < GetGamepadCount(); i++)
{
std::shared_ptr<GamepadDevice> gamepad = GetGamepad(i);
if (!gamepad->find_mapping(system))
gamepad->input_mapper = gamepad->getDefaultMapping();
gamepad->find_mapping(system);
}
}
@ -386,20 +385,12 @@ bool GamepadDevice::find_mapping(int system)
if (!file_exists(system_mapping_path))
mapping_file = make_mapping_filename(false);
input_mapper = InputMapping::LoadMapping(mapping_file.c_str());
std::shared_ptr<InputMapping> mapper = InputMapping::LoadMapping(mapping_file.c_str());
// fallback to default mapping filename for sdl inputs
if (!input_mapper && mapping_file.find("SDL") != std::string::npos)
{
mapping_file = make_mapping_filename(false);
std::string mapping_path = get_readonly_config_path(std::string("mappings/") + mapping_file);
// create default mapping filename if none exists
if (!file_exists(mapping_path))
std::ofstream file{ mapping_path.c_str() };
input_mapper = InputMapping::LoadMapping(mapping_file.c_str());
}
return !!input_mapper;
if (!mapper)
return false;
input_mapper = mapper;
return true;
}
bool GamepadDevice::find_mapping(const char *custom_mapping /* = nullptr */)

View File

@ -110,7 +110,10 @@ public:
_unique_id = "sdl_joystick_" + std::to_string(sdl_joystick_instance);
INFO_LOG(INPUT, "SDL: Opened joystick %d on port %d: '%s' unique_id=%s", sdl_joystick_instance, maple_port, _name.c_str(), _unique_id.c_str());
loadMapping();
if (!find_mapping())
input_mapper = std::make_shared<DefaultInputMapping>(joystick_idx);
else
INFO_LOG(INPUT, "using custom mapping '%s'", input_mapper->name.c_str());
sdl_haptic = SDL_HapticOpenFromJoystick(sdl_joystick);
if (SDL_HapticRumbleInit(sdl_haptic) != 0)
{