mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-05 11:01:49 +00:00
add controls reset
This commit is contained in:
parent
d46afee063
commit
0733ddb38e
6 changed files with 40 additions and 8 deletions
|
|
@ -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
|
||||
);
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue