diff --git a/src/controller/controldevice/controller/Controller.cpp b/src/controller/controldevice/controller/Controller.cpp index 77bfec8ba..b47188174 100644 --- a/src/controller/controldevice/controller/Controller.cpp +++ b/src/controller/controldevice/controller/Controller.cpp @@ -107,6 +107,7 @@ void Controller::AddDefaultMappings(PhysicalDeviceType physicalDeviceType) { button->AddDefaultMappings(physicalDeviceType); } GetLeftStick()->AddDefaultMappings(physicalDeviceType); + GetRightStick()->AddDefaultMappings(physicalDeviceType); GetRumble()->AddDefaultMappings(physicalDeviceType); const std::string hasConfigCvarKey = diff --git a/src/controller/controldevice/controller/mapping/ControllerDefaultMappings.cpp b/src/controller/controldevice/controller/mapping/ControllerDefaultMappings.cpp index 568b55acb..64a8a7225 100644 --- a/src/controller/controldevice/controller/mapping/ControllerDefaultMappings.cpp +++ b/src/controller/controldevice/controller/mapping/ControllerDefaultMappings.cpp @@ -4,11 +4,14 @@ namespace Ship { ControllerDefaultMappings::ControllerDefaultMappings( std::unordered_map> defaultKeyboardKeyToButtonMappings, + std::unordered_map>> + defaultKeyboardKeyToAxisDirectionMappings, std::unordered_map> defaultSDLButtonToButtonMappings, std::unordered_map>> defaultSDLAxisDirectionToButtonMappings) { SetDefaultKeyboardKeyToButtonMappings(defaultKeyboardKeyToButtonMappings); + SetDefaultKeyboardKeyToAxisDirectionMappings(defaultKeyboardKeyToAxisDirectionMappings); SetDefaultSDLButtonToButtonMappings(defaultSDLButtonToButtonMappings); SetDefaultSDLAxisDirectionToButtonMappings(defaultSDLAxisDirectionToButtonMappings); } @@ -16,6 +19,7 @@ ControllerDefaultMappings::ControllerDefaultMappings( ControllerDefaultMappings::ControllerDefaultMappings() : ControllerDefaultMappings( std::unordered_map>(), + std::unordered_map>>(), std::unordered_map>(), std::unordered_map>>()) { } @@ -51,6 +55,25 @@ void ControllerDefaultMappings::SetDefaultKeyboardKeyToButtonMappings( mDefaultKeyboardKeyToButtonMappings[BTN_DRIGHT] = { KbScancode::LUS_KB_H }; } +std::unordered_map>> +ControllerDefaultMappings::GetDefaultKeyboardKeyToAxisDirectionMappings() { + return mDefaultKeyboardKeyToAxisDirectionMappings; +} + +void ControllerDefaultMappings::SetDefaultKeyboardKeyToAxisDirectionMappings( + std::unordered_map>> + defaultKeyboardKeyToAxisDirectionMappings) { + if (!defaultKeyboardKeyToAxisDirectionMappings.empty()) { + mDefaultKeyboardKeyToAxisDirectionMappings = defaultKeyboardKeyToAxisDirectionMappings; + return; + } + + mDefaultKeyboardKeyToAxisDirectionMappings[LEFT_STICK] = { { LEFT, KbScancode::LUS_KB_A }, + { RIGHT, KbScancode::LUS_KB_D }, + { UP, KbScancode::LUS_KB_W }, + { DOWN, KbScancode::LUS_KB_S } }; +} + std::unordered_map> ControllerDefaultMappings::GetDefaultSDLButtonToButtonMappings() { return mDefaultSDLButtonToButtonMappings; diff --git a/src/controller/controldevice/controller/mapping/ControllerDefaultMappings.h b/src/controller/controldevice/controller/mapping/ControllerDefaultMappings.h index 56a4b2dc8..5e0008e9d 100644 --- a/src/controller/controldevice/controller/mapping/ControllerDefaultMappings.h +++ b/src/controller/controldevice/controller/mapping/ControllerDefaultMappings.h @@ -5,6 +5,7 @@ #include #include #include +#include "ControllerAxisDirectionMapping.h" #ifndef CONTROLLERBUTTONS_T #define CONTROLLERBUTTONS_T uint16_t @@ -18,6 +19,8 @@ class ControllerDefaultMappings { public: ControllerDefaultMappings( std::unordered_map> defaultKeyboardKeyToButtonMappings, + std::unordered_map>> + defaultKeyboardKeyToAxisDirectionMappings, std::unordered_map> defaultSDLButtonToButtonMappings, std::unordered_map>> @@ -26,6 +29,8 @@ class ControllerDefaultMappings { ~ControllerDefaultMappings(); std::unordered_map> GetDefaultKeyboardKeyToButtonMappings(); + std::unordered_map>> + GetDefaultKeyboardKeyToAxisDirectionMappings(); std::unordered_map> GetDefaultSDLButtonToButtonMappings(); std::unordered_map>> @@ -36,6 +41,12 @@ class ControllerDefaultMappings { std::unordered_map> defaultKeyboardKeyToButtonMappings); std::unordered_map> mDefaultKeyboardKeyToButtonMappings; + void SetDefaultKeyboardKeyToAxisDirectionMappings( + std::unordered_map>> + defaultKeyboardKeyToAxisDirectionMappings); + std::unordered_map>> + mDefaultKeyboardKeyToAxisDirectionMappings; + void SetDefaultSDLButtonToButtonMappings( std::unordered_map> defaultSDLButtonToButtonMappings); diff --git a/src/controller/controldevice/controller/mapping/factories/AxisDirectionMappingFactory.cpp b/src/controller/controldevice/controller/mapping/factories/AxisDirectionMappingFactory.cpp index c274b9856..ae6ec2d8e 100644 --- a/src/controller/controldevice/controller/mapping/factories/AxisDirectionMappingFactory.cpp +++ b/src/controller/controldevice/controller/mapping/factories/AxisDirectionMappingFactory.cpp @@ -109,15 +109,17 @@ AxisDirectionMappingFactory::CreateAxisDirectionMappingFromConfig(uint8_t portIn std::vector> AxisDirectionMappingFactory::CreateDefaultKeyboardAxisDirectionMappings(uint8_t portIndex, StickIndex stickIndex) { - std::vector> mappings = { - std::make_shared(portIndex, stickIndex, LEFT, - LUS_DEFAULT_KB_MAPPING_STICKLEFT), - std::make_shared(portIndex, stickIndex, RIGHT, - LUS_DEFAULT_KB_MAPPING_STICKRIGHT), - std::make_shared(portIndex, stickIndex, UP, LUS_DEFAULT_KB_MAPPING_STICKUP), - std::make_shared(portIndex, stickIndex, DOWN, - LUS_DEFAULT_KB_MAPPING_STICKDOWN) - }; + std::vector> mappings; + + auto defaultsForStick = Context::GetInstance() + ->GetControlDeck() + ->GetControllerDefaultMappings() + ->GetDefaultKeyboardKeyToAxisDirectionMappings()[stickIndex]; + + for (const auto& [direction, scancode] : defaultsForStick) { + mappings.push_back( + std::make_shared(portIndex, stickIndex, direction, scancode)); + } return mappings; }