add 'assets' library docs

This commit is contained in:
MihailRis 2025-08-13 23:59:05 +03:00
parent bef8e4b9d6
commit 2cdcebf9d9
7 changed files with 61 additions and 2 deletions

View File

@ -10,6 +10,7 @@ Subsections:
- [Entities and components](scripting/ecs.md)
- [Libraries](#)
- [app](scripting/builtins/libapp.md)
- [assets](scripting/builtins/libassets.md)
- [base64](scripting/builtins/libbase64.md)
- [bjson, json, toml, yaml](scripting/filesystem.md)
- [block](scripting/builtins/libblock.md)

View File

@ -0,0 +1,28 @@
# *assets* library
A library for working with audio/visual assets.
## Functions
```lua
-- Loads a texture
assets.load_texture(
-- Array of bytes of an image file
data: table | Bytearray,
-- Texture name after loading
name: str,
-- Image file format (only png is supported)
[optional]
format: str = "png"
)
-- Parses and loads a 3D model
assets.parse_model(
-- Model file format (xml / vcm)
format: str,
-- Contents of the model file
content: str,
-- Model name after loading
name: str
)
```

View File

@ -10,6 +10,7 @@
- [Сущности и компоненты](scripting/ecs.md)
- [Библиотеки](#)
- [app](scripting/builtins/libapp.md)
- [assets](scripting/builtins/libassets.md)
- [base64](scripting/builtins/libbase64.md)
- [bjson, json, toml, yaml](scripting/filesystem.md)
- [block](scripting/builtins/libblock.md)

View File

@ -0,0 +1,28 @@
# Библиотека *assets*
Библиотека для работы с аудио/визуальными загружаемыми ресурсами.
## Функции
```lua
-- Загружает текстуру
assets.load_texture(
-- Массив байт файла изображения
data: table | Bytearray,
-- Имя текстуры после загрузки
name: str,
-- Формат файла изображения (поддерживается только png)
[опционально]
format: str = "png"
)
-- Парсит и загружает 3D модель
assets.parse_model(
-- Формат файла модели (xml / vcm)
format: str,
-- Содержимое файла модели
content: str,
-- Имя модели после загрузки
name: str
)
```

View File

@ -123,7 +123,6 @@ function run_current_file()
local unit = info and info.unit
if script_type == "model" then
print(current_file.filename)
clear_output()
local _, err = pcall(reload_model, current_file.filename, unit)
if err then

View File

@ -174,7 +174,6 @@ std::unique_ptr<model::Model> vcm::parse(
"'model' tag expected as root, got '" + root.getTag() + "'"
);
}
std::cout << xml::stringify(*doc) << std::endl;
return load_model(root);
} catch (const parsing_error& err) {
throw std::runtime_error(err.errorLog());

View File

@ -23,6 +23,9 @@ static void load_texture(
}
static int l_load_texture(lua::State* L) {
if (lua::isstring(L, 3) && lua::require_lstring(L, 3) != "png") {
throw std::runtime_error("unsupportd image format");
}
if (lua::istable(L, 1)) {
lua::pushvalue(L, 1);
size_t size = lua::objlen(L, 1);