add lua function block/unbloc bindings
This commit is contained in:
parent
e762cf9b23
commit
63304712f3
@ -133,6 +133,26 @@ static int l_reset_bindings(lua::State*) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void enableBinding(std::string& bindname, bool enable) {
|
||||||
|
const auto& bind = Events::bindings.find(bindname);
|
||||||
|
if (bind == Events::bindings.end()) {
|
||||||
|
throw std::runtime_error("unknown binding " + util::quote(bindname));
|
||||||
|
}
|
||||||
|
Events::bindings[bindname].enable = enable;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int l_enable_binding(lua::State* L) {
|
||||||
|
std::string bindname = lua::require_string(L, 1);
|
||||||
|
enableBinding(bindname, true);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int l_disable_binding(lua::State* L) {
|
||||||
|
std::string bindname = lua::require_string(L, 1);
|
||||||
|
enableBinding(bindname, false);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
const luaL_Reg inputlib[] = {
|
const luaL_Reg inputlib[] = {
|
||||||
{"keycode", lua::wrap<l_keycode>},
|
{"keycode", lua::wrap<l_keycode>},
|
||||||
{"mousecode", lua::wrap<l_mousecode>},
|
{"mousecode", lua::wrap<l_mousecode>},
|
||||||
@ -143,4 +163,6 @@ const luaL_Reg inputlib[] = {
|
|||||||
{"is_active", lua::wrap<l_is_active>},
|
{"is_active", lua::wrap<l_is_active>},
|
||||||
{"is_pressed", lua::wrap<l_is_pressed>},
|
{"is_pressed", lua::wrap<l_is_pressed>},
|
||||||
{"reset_bindings", lua::wrap<l_reset_bindings>},
|
{"reset_bindings", lua::wrap<l_reset_bindings>},
|
||||||
|
{"enable_binding", lua::wrap<l_enable_binding>},
|
||||||
|
{"disable_binding", lua::wrap<l_disable_binding>},
|
||||||
{NULL, NULL}};
|
{NULL, NULL}};
|
||||||
|
|||||||
@ -78,6 +78,9 @@ void Events::pollEvents() {
|
|||||||
|
|
||||||
for (auto& entry : bindings) {
|
for (auto& entry : bindings) {
|
||||||
auto& binding = entry.second;
|
auto& binding = entry.second;
|
||||||
|
if (!binding.enable) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
binding.justChange = false;
|
binding.justChange = false;
|
||||||
|
|
||||||
bool newstate = false;
|
bool newstate = false;
|
||||||
|
|||||||
@ -137,6 +137,7 @@ struct Binding {
|
|||||||
int code;
|
int code;
|
||||||
bool state = false;
|
bool state = false;
|
||||||
bool justChange = false;
|
bool justChange = false;
|
||||||
|
bool enable = true;
|
||||||
|
|
||||||
Binding() = default;
|
Binding() = default;
|
||||||
Binding(inputtype type, int code) : type(type), code(code) {
|
Binding(inputtype type, int code) : type(type), code(code) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user