Browse Source

Keymapper: remove now useless INI access functions

pull/2464/head
Jmgr 5 years ago committed by Anders Jenbo
parent
commit
84b8b5828d
  1. 15
      Source/controls/keymapper.cpp
  2. 12
      Source/controls/keymapper.hpp
  3. 13
      Source/diablo.cpp

15
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<char, 64> 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.

12
Source/controls/keymapper.hpp

@ -11,8 +11,6 @@ namespace devilution {
/** The Keymapper maps keys to actions. */
class Keymapper final {
public:
using SetConfigKeyFunction = std::function<void(const std::string &key, const std::string &value)>;
using GetConfigKeyFunction = std::function<std::string(const std::string &key)>;
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<int, std::reference_wrapper<Action>> keyIDToAction;
std::unordered_map<int, std::string> keyIDToKeyName;
std::unordered_map<std::string, int> keyNameToKeyID;
SetConfigKeyFunction setKeyFunction;
GetConfigKeyFunction getKeyFunction;
};
} // namespace devilution

13
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<char, 64> result;
if (!GetIniValue("Keymapping", key.c_str(), result.data(), result.size()))
return {};
return { result.data() };
}
};
Keymapper keymapper;
std::array<Keymapper::ActionIndex, 4> quickSpellActionIndexes;
bool gbForceWindowed = false;

Loading…
Cancel
Save