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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user