From 653d1d20d46a698ab4b78d0d7156f75d2572ae3a Mon Sep 17 00:00:00 2001 From: MihailRis Date: Thu, 9 Jan 2025 18:53:25 +0300 Subject: [PATCH] add app.is_content_loaded() --- dev/tests/world.lua | 2 ++ doc/en/scripting/builtins/libapp.md | 6 ++++++ doc/ru/scripting/builtins/libapp.md | 6 ++++++ res/scripts/stdlib.lua | 1 + src/logic/scripting/lua/libs/libcore.cpp | 5 +++++ 5 files changed, 20 insertions(+) diff --git a/dev/tests/world.lua b/dev/tests/world.lua index db1ffca53..cd9c21c36 100644 --- a/dev/tests/world.lua +++ b/dev/tests/world.lua @@ -5,6 +5,7 @@ app.reconfig_packs({"base"}, {}) app.new_world("demo", "2019", "core:default") assert(world.is_open()) assert(world.get_generator() == "core:default") +assert(app.is_content_loaded()) app.sleep(1) assert(world.get_total_time() > 0.0) print(world.get_total_time()) @@ -12,6 +13,7 @@ print(world.get_total_time()) -- Close app.close_world(true) assert(not world.is_open()) +assert(not app.is_content_loaded()) -- Reopen app.open_world("demo") diff --git a/doc/en/scripting/builtins/libapp.md b/doc/en/scripting/builtins/libapp.md index e3fed3d4b..ffc4d923e 100644 --- a/doc/en/scripting/builtins/libapp.md +++ b/doc/en/scripting/builtins/libapp.md @@ -69,6 +69,12 @@ app.config_packs( Updates the packs configuration, automatically removing unspecified ones, adding those missing in the previous configuration. Uses app.reconfig_packs. +```lua +app.is_content_loaded() -> bool +``` + +Checks if content is loaded. + ```lua app.new_world( -- world name diff --git a/doc/ru/scripting/builtins/libapp.md b/doc/ru/scripting/builtins/libapp.md index 7887bcdf6..c0f3b741c 100644 --- a/doc/ru/scripting/builtins/libapp.md +++ b/doc/ru/scripting/builtins/libapp.md @@ -69,6 +69,12 @@ app.config_packs( Обновляет конфигурацию паков, автоматически удаляя лишние, добавляя отсутствующие в прошлой конфигурации. Использует app.reconfig_packs. +```lua +app.is_content_loaded() -> bool +``` + +Проверяет, загружен ли контент. + ```lua app.new_world( -- название мира diff --git a/res/scripts/stdlib.lua b/res/scripts/stdlib.lua index f376e2106..ad36a221a 100644 --- a/res/scripts/stdlib.lua +++ b/res/scripts/stdlib.lua @@ -39,6 +39,7 @@ local function complete_app_lib(app) app.get_setting_info = core.get_setting_info app.load_content = core.load_content app.reset_content = core.reset_content + app.is_content_loaded = core.is_content_loaded function app.config_packs(packs_list) -- Check if packs are valid and add dependencies to the configuration diff --git a/src/logic/scripting/lua/libs/libcore.cpp b/src/logic/scripting/lua/libs/libcore.cpp index 80a924c5a..7946d301f 100644 --- a/src/logic/scripting/lua/libs/libcore.cpp +++ b/src/logic/scripting/lua/libs/libcore.cpp @@ -43,6 +43,10 @@ static int l_reset_content(lua::State* L) { return 0; } +static int l_is_content_loaded(lua::State* L) { + return lua::pushboolean(L, content != nullptr); +} + /// @brief Creating new world /// @param name Name world /// @param seed Seed world @@ -258,6 +262,7 @@ const luaL_Reg corelib[] = { {"get_version", lua::wrap}, {"load_content", lua::wrap}, {"reset_content", lua::wrap}, + {"is_content_loaded", lua::wrap}, {"new_world", lua::wrap}, {"open_world", lua::wrap}, {"reopen_world", lua::wrap},