From 13d13e89cf3075381f6dfd5cd2cf432301113531 Mon Sep 17 00:00:00 2001 From: MihailRis Date: Wed, 7 Jan 2026 02:03:33 +0300 Subject: [PATCH] move open_folder, open_url from core to app --- res/layouts/pages/content.xml | 4 ++-- res/layouts/pages/content_menu.xml | 2 +- res/layouts/pages/settings.xml | 2 +- res/layouts/pages/worlds.xml | 2 +- src/logic/scripting/lua/libs/libapp.cpp | 30 ++++++++++++++++++++++++ src/logic/scripting/lua/libs/libcore.cpp | 30 ------------------------ 6 files changed, 35 insertions(+), 35 deletions(-) diff --git a/res/layouts/pages/content.xml b/res/layouts/pages/content.xml index dfa7b6546..63474effd 100644 --- a/res/layouts/pages/content.xml +++ b/res/layouts/pages/content.xml @@ -15,7 +15,7 @@ - @@ -38,4 +38,4 @@ - \ No newline at end of file + diff --git a/res/layouts/pages/content_menu.xml b/res/layouts/pages/content_menu.xml index 85dd54d0d..6718a3028 100644 --- a/res/layouts/pages/content_menu.xml +++ b/res/layouts/pages/content_menu.xml @@ -9,7 +9,7 @@ - diff --git a/res/layouts/pages/settings.xml b/res/layouts/pages/settings.xml index 00437e68b..68a71aa04 100644 --- a/res/layouts/pages/settings.xml +++ b/res/layouts/pages/settings.xml @@ -10,7 +10,7 @@ - + diff --git a/res/layouts/pages/worlds.xml b/res/layouts/pages/worlds.xml index a8a536a21..34fe3400c 100644 --- a/res/layouts/pages/worlds.xml +++ b/res/layouts/pages/worlds.xml @@ -3,6 +3,6 @@ - + diff --git a/src/logic/scripting/lua/libs/libapp.cpp b/src/logic/scripting/lua/libs/libapp.cpp index 6d975af31..1f0a45610 100644 --- a/src/logic/scripting/lua/libs/libapp.cpp +++ b/src/logic/scripting/lua/libs/libapp.cpp @@ -9,7 +9,12 @@ #include "devtools/Project.hpp" #include "network/Network.hpp" #include "util/platform.hpp" +#include "util/stringutil.hpp" #include "window/Window.hpp" +#include "frontend/locale.hpp" +#include "graphics/ui/GUI.hpp" +#include "graphics/ui/gui_util.hpp" +#include "graphics/ui/elements/Menu.hpp" using namespace scripting; @@ -102,6 +107,29 @@ static int l_set_title(lua::State* L) { return 0; } +static int l_open_folder(lua::State* L) { + platform::open_folder(io::resolve(lua::require_string(L, 1))); + return 0; +} + +static int l_open_url(lua::State* L) { + auto url = lua::require_string(L, 1); + + std::wstring msg = langs::get(L"Are you sure you want to open the link:") + + L"\n" + util::str2wstr_utf8(url) + + std::wstring(L"?"); + + auto menu = engine->getGUI().getMenu(); + + guiutil::confirm(*engine, msg, [url, menu]() { + platform::open_url(url); + if (!menu->back()) { + menu->reset(); + } + }); + return 0; +} + const luaL_Reg applib[] = { {"start_debug_instance", lua::wrap}, {"focus", lua::wrap}, @@ -110,6 +138,8 @@ const luaL_Reg applib[] = { {"set_content_sources", lua::wrap}, {"reset_content_sources", lua::wrap}, {"set_title", lua::wrap}, + {"open_folder", lua::wrap}, + {"open_url", lua::wrap}, // for other functions see libcore.cpp and stdlib.lua {nullptr, nullptr} }; diff --git a/src/logic/scripting/lua/libs/libcore.cpp b/src/logic/scripting/lua/libs/libcore.cpp index a3e0f5687..922298a58 100644 --- a/src/logic/scripting/lua/libs/libcore.cpp +++ b/src/logic/scripting/lua/libs/libcore.cpp @@ -20,11 +20,6 @@ #include "util/platform.hpp" #include "world/Level.hpp" #include "world/generator/WorldGenerator.hpp" -#include "util/platform.hpp" -#include "frontend/locale.hpp" -#include "graphics/ui/gui_util.hpp" -#include "graphics/ui/GUI.hpp" -#include "graphics/ui/elements/Menu.hpp" #include "window/Window.hpp" using namespace scripting; @@ -240,29 +235,6 @@ static int l_get_setting_info(lua::State* L) { throw std::runtime_error("unsupported setting type"); } -static int l_open_folder(lua::State* L) { - platform::open_folder(io::resolve(lua::require_string(L, 1))); - return 0; -} - -static int l_open_url(lua::State* L) { - auto url = lua::require_string(L, 1); - - std::wstring msg = langs::get(L"Are you sure you want to open the link:") + - L"\n" + util::str2wstr_utf8(url) + - std::wstring(L"?"); - - auto menu = engine->getGUI().getMenu(); - - guiutil::confirm(*engine, msg, [url, menu]() { - platform::open_url(url); - if (!menu->back()) { - menu->reset(); - } - }); - return 0; -} - /// @brief Quit the game static int l_quit(lua::State*) { engine->quit(); @@ -317,8 +289,6 @@ const luaL_Reg corelib[] = { {"set_setting", lua::wrap}, {"str_setting", lua::wrap}, {"get_setting_info", lua::wrap}, - {"open_folder", lua::wrap}, - {"open_url", lua::wrap}, {"quit", lua::wrap}, {"capture_output", lua::wrap}, {nullptr, nullptr}