Skip to content

Commit

Permalink
Do not enable default keys in addition to player-defined keys (#1070)
Browse files Browse the repository at this point in the history
* Log invalid keymap setting to warning

Additional code style changes: change a comment, reduce indentation and move the warning to the else part because it is unlikely

* Do not enable default keys in addition to player-defined keys

I applied what christ2go commented.
Fixes #592
  • Loading branch information
HybridDog authored and tobbi committed Dec 9, 2019
1 parent 71cafdf commit f0209f6
Showing 1 changed file with 22 additions and 23 deletions.
45 changes: 22 additions & 23 deletions src/control/keyboard_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,35 +52,34 @@ KeyboardConfig::KeyboardConfig() :
void
KeyboardConfig::read(const ReaderMapping& keymap_mapping)
{
// backwards compatibility:
// keycode values changed between SDL1 and SDL2, so we skip old SDL1
// based values and use the defaults instead on the first read of
// the config file
bool config_is_sdl2 = false;
keymap_mapping.get("sdl2", config_is_sdl2);
if (config_is_sdl2)
{
keymap_mapping.get("jump-with-up", m_jump_with_up_kbd);
if (!config_is_sdl2)
return;

auto iter = keymap_mapping.get_iter();
while (iter.next())
{
if (iter.get_key() == "map")
{
int key = -1;
auto map = iter.as_mapping();
map.get("key", key);

std::string control_text;
map.get("control", control_text);

const boost::optional<Control> maybe_control = Control_from_string(control_text);
if (!maybe_control) {
log_info << "Invalid control '" << control_text << "' in keymap" << std::endl;
} else {
const Control control = *maybe_control;
m_keymap[static_cast<SDL_Keycode>(key)] = control;
}
}
keymap_mapping.get("jump-with-up", m_jump_with_up_kbd);

auto iter = keymap_mapping.get_iter();
while (iter.next())
{
if (iter.get_key() != "map")
continue;
int key = -1;
auto map = iter.as_mapping();
map.get("key", key);

std::string control_text;
map.get("control", control_text);

const boost::optional<Control> maybe_control = Control_from_string(control_text);
if (maybe_control) {
bind_key(static_cast<SDL_Keycode>(key), *maybe_control);
} else {
log_warning << "Invalid control '" << control_text << "' in keymap" << std::endl;
}
}
}
Expand Down

0 comments on commit f0209f6

Please sign in to comment.