From 84b8b5828d8396274968160a7fd50844add015bd Mon Sep 17 00:00:00 2001 From: Jmgr Date: Tue, 27 Jul 2021 19:47:31 +0100 Subject: [PATCH] Keymapper: remove now useless INI access functions --- Source/controls/keymapper.cpp | 15 +++++++++------ Source/controls/keymapper.hpp | 12 +----------- Source/diablo.cpp | 13 +------------ 3 files changed, 11 insertions(+), 29 deletions(-) diff --git a/Source/controls/keymapper.cpp b/Source/controls/keymapper.cpp index c218f9349..8d86a2dd7 100644 --- a/Source/controls/keymapper.cpp +++ b/Source/controls/keymapper.cpp @@ -12,12 +12,11 @@ #include "control.h" #include "utils/log.hpp" +#include "options.h" namespace devilution { -Keymapper::Keymapper(SetConfigKeyFunction setKeyFunction, GetConfigKeyFunction getKeyFunction) - : setKeyFunction(std::move(setKeyFunction)) - , getKeyFunction(std::move(getKeyFunction)) +Keymapper::Keymapper() { // Insert all supported keys: a-z, 0-9 and F1-F12. keyIDToKeyName.reserve(('Z' - 'A' + 1) + ('9' - '0' + 1) + 12); @@ -75,7 +74,7 @@ void Keymapper::Save() const for (const auto &action : actions) { if (action.key == DVL_VK_INVALID) { // Just add an empty config entry if the action is unbound. - setKeyFunction(action.name, ""); + SetIniValue("Keymapping", action.name.c_str(), ""); continue; } @@ -84,7 +83,7 @@ void Keymapper::Save() const Log("Keymapper: no name found for key '{}'", action.key); continue; } - setKeyFunction(action.name, keyNameIt->second); + SetIniValue("Keymapping", action.name.c_str(), keyNameIt->second.c_str()); } } @@ -107,7 +106,11 @@ void Keymapper::Load() int Keymapper::GetActionKey(const Keymapper::Action &action) { - auto key = getKeyFunction(action.name); + std::array result; + if (!GetIniValue("Keymapping", action.name.c_str(), result.data(), result.size())) + return {}; + + std::string key = result.data(); if (key.empty()) return action.defaultKey; // Return the default key if no key has been set. diff --git a/Source/controls/keymapper.hpp b/Source/controls/keymapper.hpp index ac44354d0..758228f44 100644 --- a/Source/controls/keymapper.hpp +++ b/Source/controls/keymapper.hpp @@ -11,8 +11,6 @@ namespace devilution { /** The Keymapper maps keys to actions. */ class Keymapper final { public: - using SetConfigKeyFunction = std::function; - using GetConfigKeyFunction = std::function; using ActionIndex = std::size_t; /** @@ -51,13 +49,7 @@ public: friend class Keymapper; }; - /** - * Keymapper, for now, uses two function pointers to interact with the - * configuration. - * This is mostly a workaround and should be replaced later when another INI - * library will be used. - */ - Keymapper(SetConfigKeyFunction setKeyFunction, GetConfigKeyFunction getKeyFunction); + Keymapper(); ActionIndex AddAction(const Action &action); void KeyPressed(int key) const; @@ -72,8 +64,6 @@ private: std::unordered_map> keyIDToAction; std::unordered_map keyIDToKeyName; std::unordered_map keyNameToKeyID; - SetConfigKeyFunction setKeyFunction; - GetConfigKeyFunction getKeyFunction; }; } // namespace devilution diff --git a/Source/diablo.cpp b/Source/diablo.cpp index 9cafbf726..17b5555f8 100644 --- a/Source/diablo.cpp +++ b/Source/diablo.cpp @@ -92,18 +92,7 @@ bool gbQuietMode = false; clicktype sgbMouseDown; uint16_t gnTickDelay = 50; char gszProductName[64] = "DevilutionX vUnknown"; -Keymapper keymapper { - // Workaround: remove once the INI library has been replaced. - [](const std::string &key, const std::string &value) { - SetIniValue("Keymapping", key.c_str(), value.c_str()); - }, - [](const std::string &key) -> std::string { - std::array result; - if (!GetIniValue("Keymapping", key.c_str(), result.data(), result.size())) - return {}; - return { result.data() }; - } -}; +Keymapper keymapper; std::array quickSpellActionIndexes; bool gbForceWindowed = false;