diff --git a/doc/en/scripting/user-input.md b/doc/en/scripting/user-input.md index 07070750..402f9e67 100644 --- a/doc/en/scripting/user-input.md +++ b/doc/en/scripting/user-input.md @@ -66,6 +66,18 @@ input.get_binding_text(bindname: str) -> str Returns text representation of button by binding name. +```python +input.is_active(bindname: str) -> bool +``` + +Checks if the binding is active. + +```python +input.set_enabled(bindname: str, flag: bool) +``` + +Enables/disables binding until leaving the world. + ```python input.is_pressed(code: str) -> bool ``` diff --git a/doc/ru/scripting/user-input.md b/doc/ru/scripting/user-input.md index 2b0c9f5c..686d962b 100644 --- a/doc/ru/scripting/user-input.md +++ b/doc/ru/scripting/user-input.md @@ -70,6 +70,12 @@ input.is_active(bindname: str) -> bool Проверяет активность привязки. +```python +input.set_enabled(bindname: str, flag: bool) +``` + +Включает/выключает привязку до выхода из мира. + ```python input.is_pressed(code: str) -> bool ``` diff --git a/src/engine.cpp b/src/engine.cpp index 177d327a..acff9542 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -403,6 +403,9 @@ double Engine::getDelta() const { } void Engine::setScreen(std::shared_ptr screen) { + // unblock all bindings + Events::enableBindings(); + // reset audio channels (stop all sources) audio::reset_channel(audio::get_channel_index("regular")); audio::reset_channel(audio::get_channel_index("ambient")); this->screen = std::move(screen); diff --git a/src/logic/scripting/lua/libs/libcore.cpp b/src/logic/scripting/lua/libs/libcore.cpp index 891cd791..ee611b63 100644 --- a/src/logic/scripting/lua/libs/libcore.cpp +++ b/src/logic/scripting/lua/libs/libcore.cpp @@ -60,8 +60,6 @@ static int l_close_world(lua::State* L) { if (save_world) { controller->saveWorld(); } - // unblock all bindings - Events::enableBindings(); // destroy LevelScreen and run quit callbacks engine->setScreen(nullptr); // create and go to menu screen diff --git a/src/logic/scripting/lua/libs/libinput.cpp b/src/logic/scripting/lua/libs/libinput.cpp index 2e869fe3..1866a433 100644 --- a/src/logic/scripting/lua/libs/libinput.cpp +++ b/src/logic/scripting/lua/libs/libinput.cpp @@ -133,7 +133,7 @@ static int l_reset_bindings(lua::State*) { return 0; } -static int l_enable_binding(lua::State* L) { +static int l_set_enabled(lua::State* L) { std::string bindname = lua::require_string(L, 1); bool enable = lua::toboolean(L, 2); const auto& bind = Events::bindings.find(bindname); @@ -154,5 +154,5 @@ const luaL_Reg inputlib[] = { {"is_active", lua::wrap}, {"is_pressed", lua::wrap}, {"reset_bindings", lua::wrap}, - {"enable_binding", lua::wrap}, + {"set_enabled", lua::wrap}, {NULL, NULL}};