relocated input parser to the new namespace

This commit is contained in:
kalaposfos13 2024-10-18 17:41:19 +02:00
parent e0b288ac68
commit 942c1d8471
2 changed files with 35 additions and 36 deletions

View File

@ -308,40 +308,7 @@ SDL_Keymod KeyBinding::getCustomModState() {
return state; return state;
} }
} // namespace KBMConfig void parseInputConfig() {
namespace Frontend {
using Libraries::Pad::OrbisPadButtonDataOffset;
using namespace KBMConfig;
using KBMConfig::AxisMapping;
using KBMConfig::KeyBinding;
// modifiers are bitwise or-d together, so we need to check if ours is in that
template <typename T>
typename std::map<KeyBinding, T>::const_iterator FindKeyAllowingPartialModifiers(
const std::map<KeyBinding, T>& map, KeyBinding binding) {
for (typename std::map<KeyBinding, T>::const_iterator it = map.cbegin(); it != map.cend();
it++) {
if ((it->first.key == binding.key) && (it->first.modifier & binding.modifier) != 0) {
return it;
}
}
return map.end(); // Return end if no match is found
}
template <typename T>
typename std::map<KeyBinding, T>::const_iterator FindKeyAllowingOnlyNoModifiers(
const std::map<KeyBinding, T>& map, KeyBinding binding) {
for (typename std::map<KeyBinding, T>::const_iterator it = map.cbegin(); it != map.cend();
it++) {
if (it->first.key == binding.key && it->first.modifier == SDL_KMOD_NONE) {
return it;
}
}
return map.end(); // Return end if no match is found
}
void WindowSDL::parseInputConfig() {
// Read configuration file of the game, and if it doesn't exist, generate it from default // Read configuration file of the game, and if it doesn't exist, generate it from default
// If that doesn't exist either, generate that from getDefaultConfig() and try again // If that doesn't exist either, generate that from getDefaultConfig() and try again
// If even the folder is missing, we start with that. // If even the folder is missing, we start with that.
@ -500,6 +467,39 @@ void WindowSDL::parseInputConfig() {
file.close(); file.close();
} }
} // namespace KBMConfig
namespace Frontend {
using Libraries::Pad::OrbisPadButtonDataOffset;
using namespace KBMConfig;
using KBMConfig::AxisMapping;
using KBMConfig::KeyBinding;
// modifiers are bitwise or-d together, so we need to check if ours is in that
template <typename T>
typename std::map<KeyBinding, T>::const_iterator FindKeyAllowingPartialModifiers(
const std::map<KeyBinding, T>& map, KeyBinding binding) {
for (typename std::map<KeyBinding, T>::const_iterator it = map.cbegin(); it != map.cend();
it++) {
if ((it->first.key == binding.key) && (it->first.modifier & binding.modifier) != 0) {
return it;
}
}
return map.end(); // Return end if no match is found
}
template <typename T>
typename std::map<KeyBinding, T>::const_iterator FindKeyAllowingOnlyNoModifiers(
const std::map<KeyBinding, T>& map, KeyBinding binding) {
for (typename std::map<KeyBinding, T>::const_iterator it = map.cbegin(); it != map.cend();
it++) {
if (it->first.key == binding.key && it->first.modifier == SDL_KMOD_NONE) {
return it;
}
}
return map.end(); // Return end if no match is found
}
Uint32 WindowSDL::keyRepeatCallback(void* param, Uint32 id, Uint32 interval) { Uint32 WindowSDL::keyRepeatCallback(void* param, Uint32 id, Uint32 interval) {
auto* data = (std::pair<WindowSDL*, SDL_Event*>*)param; auto* data = (std::pair<WindowSDL*, SDL_Event*>*)param;
KeyBinding binding(data->second); KeyBinding binding(data->second);

View File

@ -19,6 +19,7 @@ class GameController;
namespace KBMConfig { namespace KBMConfig {
std::string getDefaultKeyboardConfig(); std::string getDefaultKeyboardConfig();
void parseInputConfig();
class KeyBinding { class KeyBinding {
public: public:
@ -103,8 +104,6 @@ private:
static Uint32 keyRepeatCallback(void* param, Uint32 id, Uint32 interval); static Uint32 keyRepeatCallback(void* param, Uint32 id, Uint32 interval);
static Uint32 mousePolling(void* param, Uint32 id, Uint32 interval); static Uint32 mousePolling(void* param, Uint32 id, Uint32 interval);
void parseInputConfig();
private: private:
s32 width; s32 width;
s32 height; s32 height;