| 286 | } |
| 287 | |
| 288 | std::optional<InputBindingKey> XInputSource::ParseKeyString(const std::string_view device, const std::string_view binding) |
| 289 | { |
| 290 | if (!device.starts_with("XInput-") || binding.empty()) |
| 291 | return std::nullopt; |
| 292 | |
| 293 | const std::optional<s32> player_id = StringUtil::FromChars<s32>(device.substr(7)); |
| 294 | if (!player_id.has_value() || player_id.value() < 0) |
| 295 | return std::nullopt; |
| 296 | |
| 297 | InputBindingKey key = {}; |
| 298 | key.source_type = InputSourceType::XInput; |
| 299 | key.source_index = static_cast<u32>(player_id.value()); |
| 300 | |
| 301 | if (binding.ends_with("Motor")) |
| 302 | { |
| 303 | key.source_subtype = InputSubclass::ControllerMotor; |
| 304 | if (binding == "LargeMotor") |
| 305 | { |
| 306 | key.data = 0; |
| 307 | return key; |
| 308 | } |
| 309 | else if (binding == "SmallMotor") |
| 310 | { |
| 311 | key.data = 1; |
| 312 | return key; |
| 313 | } |
| 314 | else |
| 315 | { |
| 316 | return std::nullopt; |
| 317 | } |
| 318 | } |
| 319 | else if (binding[0] == '+' || binding[0] == '-') |
| 320 | { |
| 321 | // likely an axis |
| 322 | const std::string_view axis_name(binding.substr(1)); |
| 323 | for (u32 i = 0; i < std::size(s_axis_setting_names); i++) |
| 324 | { |
| 325 | if (axis_name == s_axis_setting_names[i]) |
| 326 | { |
| 327 | // found an axis! |
| 328 | key.source_subtype = InputSubclass::ControllerAxis; |
| 329 | key.data = i; |
| 330 | key.modifier = binding[0] == '-' ? InputModifier::Negate : InputModifier::None; |
| 331 | return key; |
| 332 | } |
| 333 | } |
| 334 | } |
| 335 | else |
| 336 | { |
| 337 | // must be a button |
| 338 | for (u32 i = 0; i < std::size(s_button_setting_names); i++) |
| 339 | { |
| 340 | if (binding == s_button_setting_names[i]) |
| 341 | { |
| 342 | key.source_subtype = InputSubclass::ControllerButton; |
| 343 | key.data = i; |
| 344 | return key; |
| 345 | } |