Skip to content

Commit

Permalink
Config: Extract function
Browse files Browse the repository at this point in the history
  • Loading branch information
dscharrer committed Jan 17, 2018
1 parent 5e16509 commit b4187f0
Showing 1 changed file with 21 additions and 19 deletions.
40 changes: 21 additions & 19 deletions src/core/Config.cpp
Expand Up @@ -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;

};
Expand All @@ -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]) << "\"");

Expand Down

0 comments on commit b4187f0

Please sign in to comment.