update doc/*/scripting/user-input.md

This commit is contained in:
MihailRis 2024-11-02 13:15:17 +03:00
parent 47c6c98b4a
commit 839211a310
5 changed files with 23 additions and 4 deletions

View File

@ -66,6 +66,18 @@ input.get_binding_text(bindname: str) -> str
Returns text representation of button by binding name. 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 ```python
input.is_pressed(code: str) -> bool input.is_pressed(code: str) -> bool
``` ```

View File

@ -70,6 +70,12 @@ input.is_active(bindname: str) -> bool
Проверяет активность привязки. Проверяет активность привязки.
```python
input.set_enabled(bindname: str, flag: bool)
```
Включает/выключает привязку до выхода из мира.
```python ```python
input.is_pressed(code: str) -> bool input.is_pressed(code: str) -> bool
``` ```

View File

@ -403,6 +403,9 @@ double Engine::getDelta() const {
} }
void Engine::setScreen(std::shared_ptr<Screen> screen) { void Engine::setScreen(std::shared_ptr<Screen> 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("regular"));
audio::reset_channel(audio::get_channel_index("ambient")); audio::reset_channel(audio::get_channel_index("ambient"));
this->screen = std::move(screen); this->screen = std::move(screen);

View File

@ -60,8 +60,6 @@ static int l_close_world(lua::State* L) {
if (save_world) { if (save_world) {
controller->saveWorld(); controller->saveWorld();
} }
// unblock all bindings
Events::enableBindings();
// destroy LevelScreen and run quit callbacks // destroy LevelScreen and run quit callbacks
engine->setScreen(nullptr); engine->setScreen(nullptr);
// create and go to menu screen // create and go to menu screen

View File

@ -133,7 +133,7 @@ static int l_reset_bindings(lua::State*) {
return 0; 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); std::string bindname = lua::require_string(L, 1);
bool enable = lua::toboolean(L, 2); bool enable = lua::toboolean(L, 2);
const auto& bind = Events::bindings.find(bindname); const auto& bind = Events::bindings.find(bindname);
@ -154,5 +154,5 @@ 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>}, {"set_enabled", lua::wrap<l_set_enabled>},
{NULL, NULL}}; {NULL, NULL}};