Skip to content

Commit

Permalink
add app.is_content_loaded()
Browse files Browse the repository at this point in the history
  • Loading branch information
MihailRis committed Jan 9, 2025
1 parent 7bbd8ba commit 653d1d2
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 0 deletions.
2 changes: 2 additions & 0 deletions dev/tests/world.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ 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())

-- Close
app.close_world(true)
assert(not world.is_open())
assert(not app.is_content_loaded())

-- Reopen
app.open_world("demo")
Expand Down
6 changes: 6 additions & 0 deletions doc/en/scripting/builtins/libapp.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions doc/ru/scripting/builtins/libapp.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ app.config_packs(
Обновляет конфигурацию паков, автоматически удаляя лишние, добавляя отсутствующие в прошлой конфигурации.
Использует app.reconfig_packs.

```lua
app.is_content_loaded() -> bool
```

Проверяет, загружен ли контент.

```lua
app.new_world(
-- название мира
Expand Down
1 change: 1 addition & 0 deletions res/scripts/stdlib.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions src/logic/scripting/lua/libs/libcore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -258,6 +262,7 @@ const luaL_Reg corelib[] = {
{"get_version", lua::wrap<l_get_version>},
{"load_content", lua::wrap<l_load_content>},
{"reset_content", lua::wrap<l_reset_content>},
{"is_content_loaded", lua::wrap<l_is_content_loaded>},
{"new_world", lua::wrap<l_new_world>},
{"open_world", lua::wrap<l_open_world>},
{"reopen_world", lua::wrap<l_reopen_world>},
Expand Down

0 comments on commit 653d1d2

Please sign in to comment.