MCPcopy Create free account
hub / github.com/PCSX2/pcsx2 / AddBindings

Method AddBindings

pcsx2/Input/InputManager.cpp:606–665  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

604}
605
606void 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 }

Callers

nothing calls this directly

Calls 7

GetLayerMethod · 0.80
push_backMethod · 0.45
reserveMethod · 0.45
sizeMethod · 0.45
SetStringListMethod · 0.45
SaveMethod · 0.45
GetStringListMethod · 0.45

Tested by

no test coverage detected