bindings.toml, config/bindings.toml file
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
#include "Events.hpp"
|
||||
#include "Window.hpp"
|
||||
#include "../debug/Logger.hpp"
|
||||
#include "../util/stringutil.hpp"
|
||||
|
||||
#include <GL/glew.h>
|
||||
#include <GLFW/glfw3.h>
|
||||
@@ -148,6 +149,7 @@ void Events::setPosition(float xpos, float ypos) {
|
||||
|
||||
#include "../data/dynamic.hpp"
|
||||
#include "../coders/json.hpp"
|
||||
#include "../coders/toml.hpp"
|
||||
|
||||
std::string Events::writeBindings() {
|
||||
dynamic::Map obj;
|
||||
@@ -189,3 +191,28 @@ void Events::loadBindings(const std::string& filename, const std::string& source
|
||||
jentry->num("code", binding.code);
|
||||
}
|
||||
}
|
||||
|
||||
void Events::loadBindingsToml(const std::string& filename, const std::string& source) {
|
||||
auto map = toml::parse(filename, source);
|
||||
for (auto& entry : map->values) {
|
||||
if (auto value = std::get_if<std::string>(&entry.second)) {
|
||||
auto [prefix, codename] = util::split_at(*value, ':');
|
||||
inputtype type;
|
||||
int code;
|
||||
if (prefix == "key") {
|
||||
type = inputtype::keyboard;
|
||||
code = static_cast<int>(input_util::keycode_from(codename));
|
||||
} else if (prefix == "mouse") {
|
||||
type = inputtype::mouse;
|
||||
code = static_cast<int>(input_util::mousecode_from(codename));
|
||||
} else {
|
||||
logger.error() << "unknown input type: " << prefix
|
||||
<< " (binding " << util::quote(entry.first) << ")";
|
||||
continue;
|
||||
}
|
||||
Events::bind(entry.first, type, code);
|
||||
} else {
|
||||
logger.error() << "invalid binding entry: " << entry.first;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,11 +2,11 @@
|
||||
#define WINDOW_EVENTS_HPP_
|
||||
|
||||
#include "input.hpp"
|
||||
#include "../typedefs.hpp"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <unordered_map>
|
||||
#include "../typedefs.hpp"
|
||||
|
||||
inline constexpr short KEYS_BUFFER_SIZE = 1036;
|
||||
|
||||
@@ -51,6 +51,7 @@ public:
|
||||
|
||||
static std::string writeBindings();
|
||||
static void loadBindings(const std::string& filename, const std::string& source);
|
||||
static void loadBindingsToml(const std::string& filename, const std::string& source);
|
||||
};
|
||||
|
||||
#endif // WINDOW_EVENTS_HPP_
|
||||
|
||||
@@ -15,6 +15,7 @@ static std::unordered_map<std::string, int> keycodes {
|
||||
{"delete", GLFW_KEY_DELETE},
|
||||
{"home", GLFW_KEY_HOME},
|
||||
{"end", GLFW_KEY_END},
|
||||
{"tab", GLFW_KEY_TAB},
|
||||
{"insert", GLFW_KEY_INSERT},
|
||||
{"page-down", GLFW_KEY_PAGE_DOWN},
|
||||
{"page-up", GLFW_KEY_PAGE_UP},
|
||||
@@ -26,6 +27,7 @@ static std::unordered_map<std::string, int> keycodes {
|
||||
{"right-alt", GLFW_KEY_RIGHT_ALT},
|
||||
{"left-super", GLFW_KEY_LEFT_SUPER},
|
||||
{"right-super", GLFW_KEY_RIGHT_SUPER},
|
||||
{"grave-accent", GLFW_KEY_GRAVE_ACCENT},
|
||||
{"left", GLFW_KEY_LEFT},
|
||||
{"right", GLFW_KEY_RIGHT},
|
||||
{"down", GLFW_KEY_DOWN},
|
||||
@@ -59,7 +61,7 @@ void input_util::initialize() {
|
||||
keycodes["f"+std::to_string(i)] = GLFW_KEY_F1+i;
|
||||
}
|
||||
for (char i = 'a'; i <= 'z'; i++) {
|
||||
keycodes[std::to_string(i)] = GLFW_KEY_A-'a'+i;
|
||||
keycodes[std::string({i})] = GLFW_KEY_A-'a'+i;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user