Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Content-related funcs #436

Merged
merged 2 commits into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading