track-width fixes
This commit is contained in:
+48
-1
@@ -1,9 +1,12 @@
|
||||
#include <iostream>
|
||||
#include "Events.h"
|
||||
#include "../debug/Logger.hpp"
|
||||
|
||||
#include <GL/glew.h>
|
||||
#include <GLFW/glfw3.h>
|
||||
#include <string.h>
|
||||
|
||||
static debug::Logger logger("events");
|
||||
|
||||
inline constexpr short _MOUSE_KEYS_OFFSET = 1024;
|
||||
|
||||
bool Events::keys[KEYS_BUFFER_SIZE] = {};
|
||||
@@ -141,3 +144,47 @@ void Events::setPosition(float xpos, float ypos) {
|
||||
Events::cursor.x = xpos;
|
||||
Events::cursor.y = ypos;
|
||||
}
|
||||
|
||||
#include "../data/dynamic.h"
|
||||
#include "../coders/json.h"
|
||||
|
||||
std::string Events::writeBindings() {
|
||||
dynamic::Map obj;
|
||||
for (auto& entry : Events::bindings) {
|
||||
const auto& binding = entry.second;
|
||||
|
||||
auto& jentry = obj.putMap(entry.first);
|
||||
switch (binding.type) {
|
||||
case inputtype::keyboard: jentry.put("type", "keyboard"); break;
|
||||
case inputtype::mouse: jentry.put("type", "mouse"); break;
|
||||
default: throw std::runtime_error("unsupported control type");
|
||||
}
|
||||
jentry.put("code", binding.code);
|
||||
}
|
||||
return json::stringify(&obj, true, " ");
|
||||
}
|
||||
|
||||
void Events::loadBindings(const std::string& filename, const std::string& source) {
|
||||
auto obj = json::parse(filename, source);
|
||||
for (auto& entry : Events::bindings) {
|
||||
auto& binding = entry.second;
|
||||
|
||||
auto jentry = obj->map(entry.first);
|
||||
if (jentry == nullptr)
|
||||
continue;
|
||||
inputtype type;
|
||||
std::string typestr;
|
||||
jentry->str("type", typestr);
|
||||
|
||||
if (typestr == "keyboard") {
|
||||
type = inputtype::keyboard;
|
||||
} else if (typestr == "mouse") {
|
||||
type = inputtype::mouse;
|
||||
} else {
|
||||
logger.error() << "unknown input type '" << typestr << "'";
|
||||
continue;
|
||||
}
|
||||
binding.type = type;
|
||||
jentry->num("code", binding.code);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user