add controls reset
This commit is contained in:
+12
-2
@@ -126,6 +126,10 @@ void Events::bind(const std::string& name, inputtype type, int code) {
|
||||
}
|
||||
|
||||
void Events::rebind(const std::string& name, inputtype type, int code) {
|
||||
auto& found = bindings.find(name);
|
||||
if (found == bindings.end()) {
|
||||
throw std::runtime_error("binding '" + name + "' does not exists");
|
||||
}
|
||||
bindings[name] = Binding(type, code);
|
||||
}
|
||||
|
||||
@@ -193,7 +197,8 @@ std::string Events::writeBindings() {
|
||||
}
|
||||
|
||||
void Events::loadBindings(
|
||||
const std::string& filename, const std::string& source
|
||||
const std::string& filename, const std::string& source,
|
||||
BindType bindType
|
||||
) {
|
||||
auto map = toml::parse(filename, source);
|
||||
for (auto& [sectionName, section] : map.asObject()) {
|
||||
@@ -214,7 +219,12 @@ void Events::loadBindings(
|
||||
<< util::quote(key) << ")";
|
||||
continue;
|
||||
}
|
||||
Events::bind(key, type, code);
|
||||
if (bindType == BindType::BIND) {
|
||||
Events::bind(key, type, code);
|
||||
} else if (bindType == BindType::REBIND) {
|
||||
Events::rebind(key, type, code);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,11 @@
|
||||
|
||||
inline constexpr short KEYS_BUFFER_SIZE = 1036;
|
||||
|
||||
enum class BindType {
|
||||
BIND = 0,
|
||||
REBIND = 1
|
||||
};
|
||||
|
||||
class Events {
|
||||
static bool keys[KEYS_BUFFER_SIZE];
|
||||
static uint frames[KEYS_BUFFER_SIZE];
|
||||
@@ -52,6 +57,7 @@ public:
|
||||
|
||||
static std::string writeBindings();
|
||||
static void loadBindings(
|
||||
const std::string& filename, const std::string& source
|
||||
const std::string& filename, const std::string& source,
|
||||
BindType bindType
|
||||
);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user