From b4187f089127be80324b3e65f0a5642ca541cc84 Mon Sep 17 00:00:00 2001 From: Daniel Scharrer Date: Wed, 17 Jan 2018 22:59:20 +0100 Subject: [PATCH] Config: Extract function --- src/core/Config.cpp | 40 +++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/src/core/Config.cpp b/src/core/Config.cpp index 92a4c5d3c2..fd1289c7c4 100644 --- a/src/core/Config.cpp +++ b/src/core/Config.cpp @@ -297,6 +297,9 @@ const std::string class ConfigReader : public IniReader { public: + + void getActionKey(const std::string & section, const std::string & key, InputKeyId & binding) const; + ActionKey getActionKey(const std::string & section, ControlAction index) const; }; @@ -320,30 +323,29 @@ void ConfigWriter::writeActionKey(ControlAction index, const ActionKey & actionK writeKey(Key::actions[index] + "_k1", v2); } -ActionKey ConfigReader::getActionKey(const std::string & section, ControlAction index) const { - - const std::string & key = Key::actions[index]; - ActionKey action_key = Default::actions[index]; +void ConfigReader::getActionKey(const std::string & section, const std::string & key, + InputKeyId & binding) const { - const IniKey * k0 = getKey(section, key + "_k0"); - if(k0) { - InputKeyId id = Input::getKeyId(k0->getValue()); - if(id == ActionKey::UNUSED && !k0->getValue().empty() && k0->getValue() != Input::KEY_NONE) { - LogWarning << "Error parsing key name for " << key << "_k0: \"" << k0->getValue() << "\", resetting to \"" << Input::getKeyName(action_key.key[0]) << "\""; + const IniKey * setting = getKey(section, key); + if(setting) { + InputKeyId id = Input::getKeyId(setting->getValue()); + if(id == ActionKey::UNUSED && !setting->getValue().empty() && setting->getValue() != Input::KEY_NONE) { + LogWarning << "Error parsing key name for " << key << ": \"" << setting->getValue() + << "\", resetting to \"" << Input::getKeyName(binding) << "\""; } else { - action_key.key[0] = id; + binding = id; } } - const IniKey * k1 = getKey(section, key + "_k1"); - if(k1) { - InputKeyId id = Input::getKeyId(k1->getValue()); - if(id == ActionKey::UNUSED && !k1->getValue().empty() && k1->getValue() != Input::KEY_NONE) { - LogWarning << "Error parsing key name for " << key << "_k1: \"" << k1->getValue() << "\", resetting to \"" << Input::getKeyName(action_key.key[1]) << "\""; - } else { - action_key.key[1] = id; - } - } +} + +ActionKey ConfigReader::getActionKey(const std::string & section, ControlAction index) const { + + const std::string & key = Key::actions[index]; + ActionKey action_key = Default::actions[index]; + + getActionKey(section, key + "_k0", action_key.key[0]); + getActionKey(section, key + "_k1", action_key.key[1]); LogDebug("[" << section << "] " << key << " = \"" << Input::getKeyName(action_key.key[0]) << "\", \"" << Input::getKeyName(action_key.key[1]) << "\"");