controls.json -> controls.toml
This commit is contained in:
+15
-8
@@ -110,6 +110,10 @@ void Events::bind(const std::string& name, inputtype type, int code) {
|
||||
bindings.emplace(name, Binding(type, code));
|
||||
}
|
||||
|
||||
void Events::rebind(const std::string& name, inputtype type, int code) {
|
||||
bindings[name] = Binding(type, code);
|
||||
}
|
||||
|
||||
bool Events::active(const std::string& name) {
|
||||
const auto& found = bindings.find(name);
|
||||
if (found == bindings.end()) {
|
||||
@@ -155,19 +159,22 @@ std::string Events::writeBindings() {
|
||||
dynamic::Map obj;
|
||||
for (auto& entry : Events::bindings) {
|
||||
const auto& binding = entry.second;
|
||||
|
||||
auto& jentry = obj.putMap(entry.first);
|
||||
std::string value;
|
||||
switch (binding.type) {
|
||||
case inputtype::keyboard: jentry.put("type", "keyboard"); break;
|
||||
case inputtype::mouse: jentry.put("type", "mouse"); break;
|
||||
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");
|
||||
}
|
||||
jentry.put("code", binding.code);
|
||||
obj.put(entry.first, value);
|
||||
}
|
||||
return json::stringify(&obj, true, " ");
|
||||
return toml::stringify(obj);
|
||||
}
|
||||
|
||||
void Events::loadBindings(const std::string& filename, const std::string& source) {
|
||||
void Events::loadBindingsOld(const std::string& filename, const std::string& source) {
|
||||
auto obj = json::parse(filename, source);
|
||||
for (auto& entry : Events::bindings) {
|
||||
auto& binding = entry.second;
|
||||
@@ -192,7 +199,7 @@ void Events::loadBindings(const std::string& filename, const std::string& source
|
||||
}
|
||||
}
|
||||
|
||||
void Events::loadBindingsToml(const std::string& filename, const std::string& source) {
|
||||
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)) {
|
||||
|
||||
Reference in New Issue
Block a user