From f4f479d3897f0472119cea4c940b699cd374fd0b Mon Sep 17 00:00:00 2001 From: MihailRis Date: Wed, 20 Nov 2024 12:15:09 +0300 Subject: [PATCH] move 'devtools:console' binding handler to __vc_on_hud_open --- res/scripts/stdlib.lua | 10 +++++++++- src/core_defs.hpp | 1 - src/frontend/hud.cpp | 8 -------- src/logic/scripting/scripting_hud.cpp | 2 +- 4 files changed, 10 insertions(+), 11 deletions(-) diff --git a/res/scripts/stdlib.lua b/res/scripts/stdlib.lua index 7fc726f8..2c48bdfc 100644 --- a/res/scripts/stdlib.lua +++ b/res/scripts/stdlib.lua @@ -269,7 +269,7 @@ function _rules.clear() _rules.create("allow-cheats", true) end -function __vc_create_hud_rules() +function __vc_on_hud_open() _rules.create("allow-content-access", hud._is_content_access(), function(value) hud._set_content_access(value) input.set_enabled("player.pick", value) @@ -295,6 +295,14 @@ function __vc_create_hud_rules() _rules.create("allow-debug-cheats", true, function(value) hud._set_debug_cheats(value) end) + input.add_callback("devtools.console", function() + if hud.is_paused() then + return + end + time.post_runnable(function() + hud.show_overlay("core:console", false, {"console"}) + end) + end) end local RULES_FILE = "world:rules.toml" diff --git a/src/core_defs.hpp b/src/core_defs.hpp index 4a02cac9..9f26b1c8 100644 --- a/src/core_defs.hpp +++ b/src/core_defs.hpp @@ -10,7 +10,6 @@ inline const std::string CORE_STRUCT_AIR = "core:struct_air"; inline const std::string TEXTURE_NOTFOUND = "notfound"; // built-in bindings -inline const std::string BIND_DEVTOOLS_CONSOLE = "devtools.console"; inline const std::string BIND_CHUNKS_RELOAD = "chunks.reload"; inline const std::string BIND_MOVE_FORWARD = "movement.forward"; inline const std::string BIND_MOVE_BACK = "movement.back"; diff --git a/src/frontend/hud.cpp b/src/frontend/hud.cpp index f81a4c26..cc9c54d0 100644 --- a/src/frontend/hud.cpp +++ b/src/frontend/hud.cpp @@ -229,17 +229,9 @@ void Hud::processInput(bool visible) { setPause(true); } } - if (!pause && Events::jactive(BIND_DEVTOOLS_CONSOLE)) { - showOverlay( - assets->get("core:console"), - false, - dv::list({std::string("console")}) - ); - } if (!Window::isFocused() && !pause && !isInventoryOpen()) { setPause(true); } - if (!pause && visible && Events::jactive(BIND_HUD_INVENTORY)) { if (inventoryOpen) { closeInventory(); diff --git a/src/logic/scripting/scripting_hud.cpp b/src/logic/scripting/scripting_hud.cpp index a7be1892..146fe817 100644 --- a/src/logic/scripting/scripting_hud.cpp +++ b/src/logic/scripting/scripting_hud.cpp @@ -37,7 +37,7 @@ void scripting::on_frontend_init(Hud* hud, WorldRenderer* renderer) { load_script("hud_classes.lua"); - if (lua::getglobal(L, "__vc_create_hud_rules")) { + if (lua::getglobal(L, "__vc_on_hud_open")) { lua::call_nothrow(L, 0, 0); }