migrate from dynamic::Value to dv::value & total erase namespace 'dynamic'
This commit is contained in:
+17
-22
@@ -167,10 +167,9 @@ void Events::setPosition(float xpos, float ypos) {
|
||||
|
||||
#include "coders/json.hpp"
|
||||
#include "coders/toml.hpp"
|
||||
#include "data/dynamic.hpp"
|
||||
|
||||
std::string Events::writeBindings() {
|
||||
dynamic::Map obj;
|
||||
auto obj = dv::object();
|
||||
for (auto& entry : Events::bindings) {
|
||||
const auto& binding = entry.second;
|
||||
std::string value;
|
||||
@@ -188,7 +187,7 @@ std::string Events::writeBindings() {
|
||||
default:
|
||||
throw std::runtime_error("unsupported control type");
|
||||
}
|
||||
obj.put(entry.first, value);
|
||||
obj[entry.first] = std::move(value);
|
||||
}
|
||||
return toml::stringify(obj);
|
||||
}
|
||||
@@ -197,26 +196,22 @@ void Events::loadBindings(
|
||||
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);
|
||||
for (auto& [key, value] : map.asObject()) {
|
||||
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() << "invalid binding entry: " << entry.first;
|
||||
logger.error()
|
||||
<< "unknown input type: " << prefix << " (binding "
|
||||
<< util::quote(key) << ")";
|
||||
continue;
|
||||
}
|
||||
Events::bind(key, type, code);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user