| 604 | } |
| 605 | |
| 606 | void InputManager::AddBindings(const std::vector<std::string>& bindings, const InputEventHandler& handler, |
| 607 | InputBindingInfo::Type binding_type, SettingsInterface& si, const char* section, const char* key, bool is_profile) |
| 608 | { |
| 609 | std::vector<std::shared_ptr<InputBinding>> ibindings; |
| 610 | |
| 611 | bool migrate = false; |
| 612 | for (const std::string& binding : bindings) |
| 613 | { |
| 614 | std::shared_ptr<InputBinding> ibinding = AddBinding(binding, handler); |
| 615 | ibindings.push_back(ibinding); |
| 616 | |
| 617 | if (ibinding) |
| 618 | { |
| 619 | // Check for SDL2-3 migrations |
| 620 | for (u32 i = 0; i < ibinding->num_keys; i++) |
| 621 | { |
| 622 | if (ibinding->keys[i].needs_migration) |
| 623 | migrate = true; |
| 624 | } |
| 625 | } |
| 626 | } |
| 627 | |
| 628 | // Save migrations |
| 629 | if (migrate) |
| 630 | { |
| 631 | std::vector<std::string> new_bindings; |
| 632 | new_bindings.reserve(bindings.size()); |
| 633 | |
| 634 | for (size_t i = 0; i < bindings.size(); i++) |
| 635 | { |
| 636 | if (ibindings[i]) |
| 637 | new_bindings.push_back(ConvertInputBindingKeysToString(binding_type, ibindings[i]->keys, ibindings[i]->num_keys, true)); |
| 638 | else |
| 639 | // Retain invalid bindings as is |
| 640 | new_bindings.push_back(bindings[i]); |
| 641 | } |
| 642 | |
| 643 | if (is_profile) |
| 644 | { |
| 645 | // INISettingsInterface, can just update directly |
| 646 | si.SetStringList(section, key, new_bindings); |
| 647 | si.Save(); |
| 648 | } |
| 649 | else |
| 650 | { |
| 651 | // LayeredSettingsInterface, Need to find which layer our binding came from |
| 652 | LayeredSettingsInterface& lsi = static_cast<LayeredSettingsInterface&>(si); |
| 653 | for (u32 i = 0; i < LayeredSettingsInterface::NUM_LAYERS; i++) |
| 654 | { |
| 655 | SettingsInterface* layer = lsi.GetLayer(static_cast<LayeredSettingsInterface::Layer>(i)); |
| 656 | if (layer && layer->GetStringList(section, key) == bindings) |
| 657 | { |
| 658 | // Layer found, update settings |
| 659 | layer->SetStringList(section, key, new_bindings); |
| 660 | layer->Save(); |
| 661 | } |
| 662 | } |
| 663 | } |
nothing calls this directly
no test coverage detected