pack.get_installed + pack docs

This commit is contained in:
MihailRis 2024-03-23 23:55:02 +03:00
parent 15b11d52ad
commit 86a2349863
3 changed files with 51 additions and 0 deletions

View File

@ -71,6 +71,26 @@ world.get_seed() -> int
Returns world seed.
## *pack* library
```python
pack.get_folder(packid: str) -> str
```
Returns installed content-pack folder
```python
pack.is_installed(packid: str) -> bool
```
Check if the world has specified pack installed
```python
pack.get_installed() -> array of strings
```
Returns all installed content-pack ids
## *gui* library
Library contains ui elements access functions. Library should not be directly used, because script *layouts/layout_name.xml.lua* already has a generated variable **document** (instance of **Document**)

View File

@ -66,6 +66,26 @@ world.get_seed() -> int
Возвращает зерно мира.
## Библиотека pack
```python
pack.get_folder(packid: str) -> str
```
Возвращает путь к папке установленного контент-пака
```python
pack.is_installed(packid: str) -> bool
```
Проверяет наличие контент-пака в мире
```python
pack.get_installed() -> массив строк
```
Возращает id всех установленных в мире контент-паков
## Библиотека gui
Библиотека содержит функции для доступа к свойствам UI элементов. Вместо gui следует использовать объектную обертку, предоставляющую доступ к свойствам через мета-методы __index, __newindex:

View File

@ -25,7 +25,18 @@ static int l_pack_get_folder(lua_State* L) {
return 1;
}
static int l_pack_get_installed(lua_State* L) {
auto& packs = scripting::engine->getContentPacks();
lua_createtable(L, packs.size(), 0);
for (size_t i = 0; i < packs.size(); i++) {
lua_pushstring(L, packs[i].id.c_str());
lua_rawseti(L, -2, i + 1);
}
return 1;
}
const luaL_Reg packlib [] = {
{"get_folder", lua_wrap_errors<l_pack_get_folder>},
{"get_installed", lua_wrap_errors<l_pack_get_installed>},
{NULL, NULL}
};