refactor: replace references to Events with Input
This commit is contained in:
@@ -184,71 +184,6 @@ observer_handler Events::addKeyCallback(keycode key, KeyCallback callback) {
|
||||
return ::key_callbacks[key].add(std::move(callback));
|
||||
}
|
||||
|
||||
#include "coders/json.hpp"
|
||||
#include "coders/toml.hpp"
|
||||
|
||||
std::string Events::writeBindings() {
|
||||
auto obj = dv::object();
|
||||
for (auto& entry : bindings.getAll()) {
|
||||
const auto& binding = entry.second;
|
||||
std::string value;
|
||||
switch (binding.type) {
|
||||
case inputtype::keyboard:
|
||||
value =
|
||||
"key:" +
|
||||
input_util::get_name(static_cast<keycode>(binding.code));
|
||||
break;
|
||||
case inputtype::mouse:
|
||||
value =
|
||||
"mouse:" +
|
||||
input_util::get_name(static_cast<mousecode>(binding.code));
|
||||
break;
|
||||
default:
|
||||
throw std::runtime_error("unsupported control type");
|
||||
}
|
||||
obj[entry.first] = std::move(value);
|
||||
}
|
||||
return toml::stringify(obj);
|
||||
}
|
||||
|
||||
void Events::loadBindings(
|
||||
const std::string& filename, const std::string& source,
|
||||
BindType bindType
|
||||
) {
|
||||
auto map = toml::parse(filename, source);
|
||||
for (auto& [sectionName, section] : map.asObject()) {
|
||||
for (auto& [name, value] : section.asObject()) {
|
||||
auto key = sectionName + "." + name;
|
||||
auto [prefix, codename] = util::split_at(value.asString(), ':');
|
||||
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(key) << ")";
|
||||
continue;
|
||||
}
|
||||
if (bindType == BindType::BIND) {
|
||||
Events::bind(key, type, code);
|
||||
} else if (bindType == BindType::REBIND) {
|
||||
Events::rebind(key, type, code);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Events::enableBindings() {
|
||||
for (auto& entry : bindings.getAll()) {
|
||||
entry.second.enabled = true;
|
||||
}
|
||||
}
|
||||
|
||||
bool Events::isCursorLocked() {
|
||||
return cursor_locked;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user