From 31bf1f3432dc2bd2b1e095c871501b874c86b253 Mon Sep 17 00:00:00 2001 From: MihailRis Date: Thu, 28 Nov 2024 12:10:13 +0300 Subject: [PATCH 1/3] update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 01bc864b..0b586d95 100644 --- a/README.md +++ b/README.md @@ -78,7 +78,7 @@ cmake --build . ### Install libraries ```sh -brew install glfw3 glew glm libpng libvorbis lua luajit openal-soft skypjack/entt/entt +brew install glfw3 glew glm libpng libvorbis lua luajit libcurl openal-soft skypjack/entt/entt ``` > [!TIP] From bf9f6bbe7915d6e952ec4ec436b55328ae225a53 Mon Sep 17 00:00:00 2001 From: MihailRis Date: Thu, 28 Nov 2024 13:41:59 +0300 Subject: [PATCH 2/3] make 'structures.toml' combined --- src/content/loading/GeneratorLoader.cpp | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/content/loading/GeneratorLoader.cpp b/src/content/loading/GeneratorLoader.cpp index 8aef7f7b..f9f06d80 100644 --- a/src/content/loading/GeneratorLoader.cpp +++ b/src/content/loading/GeneratorLoader.cpp @@ -132,14 +132,14 @@ static VoxelStructureMeta load_structure_meta( } static std::vector> load_structures( - const fs::path& structuresFile + const dv::value& map, const fs::path& filesFolder, const ResPaths& paths ) { - auto structuresDir = structuresFile.parent_path() / fs::path("fragments"); - auto map = files::read_object(structuresFile); + auto structuresDir = filesFolder / fs::path("fragments"); std::vector> structures; for (auto& [name, config] : map.asObject()) { auto structFile = structuresDir / fs::u8path(name + ".vox"); + structFile = paths.find(structFile.u8string()); logger.debug() << "loading voxel fragment " << structFile.u8string(); if (!fs::exists(structFile)) { throw std::runtime_error("structure file does not exist (" + @@ -159,8 +159,13 @@ static std::vector> load_structures( return structures; } -static void load_structures(GeneratorDef& def, const fs::path& structuresFile) { - auto rawStructures = load_structures(structuresFile); +static void load_structures( + GeneratorDef& def, + const dv::value& map, + const fs::path& filesFolder, + const ResPaths& paths +) { + auto rawStructures = load_structures(map, filesFolder, paths); def.structures.resize(rawStructures.size()); for (int i = 0; i < rawStructures.size(); i++) { @@ -231,10 +236,9 @@ void ContentLoader::loadGenerator( auto folder = generatorsDir / fs::u8path(name + ".files"); auto scriptFile = folder / fs::u8path("script.lua"); - auto structuresFile = folder / STRUCTURES_FILE; - if (fs::exists(structuresFile)) { - load_structures(def, structuresFile); - } + auto structuresFile = GENERATORS_DIR / fs::u8path(name + ".files") / STRUCTURES_FILE; + auto structuresMap = paths.readCombinedObject(structuresFile.u8string()); + load_structures(def, structuresMap, structuresFile.parent_path(), paths); auto biomesFile = GENERATORS_DIR / fs::u8path(name + ".files") / BIOMES_FILE; auto biomesMap = paths.readCombinedObject(biomesFile.u8string()); From 3f9701915c85208efe730173aba52e424625d5eb Mon Sep 17 00:00:00 2001 From: MihailRis Date: Thu, 28 Nov 2024 15:48:44 +0300 Subject: [PATCH 3/3] update hud.open(...) --- doc/en/scripting/builtins/libhud.md | 13 +++++++++++-- doc/ru/scripting/builtins/libhud.md | 14 ++++++++++++-- src/frontend/hud.cpp | 8 ++------ src/frontend/hud.hpp | 2 +- src/logic/scripting/lua/libs/libhud.cpp | 13 +++++-------- 5 files changed, 31 insertions(+), 19 deletions(-) diff --git a/doc/en/scripting/builtins/libhud.md b/doc/en/scripting/builtins/libhud.md index 963e428c..72b1a4ed 100644 --- a/doc/en/scripting/builtins/libhud.md +++ b/doc/en/scripting/builtins/libhud.md @@ -8,8 +8,17 @@ hud.open_inventory() hud.close_inventory() -- Open UI and inventory. --- Throws an exception if has no UI layout. -hud.open(invid: int, layoutid: str) +-- Throws an exception if has UI layout does not exists. +-- If invid is not specified, a virtual (temporary) inventory is created. +-- Returns the invid or id of the virtual inventory. +hud.open( + -- UI layout name + layoutid: str, + -- Don't open player inventory + [optional] disablePlayerInventory: bool, + -- Inventory that UI layout will be bound to + [optional] invid: int +) -> int -- Open block UI and inventory. -- Throws an exception if block has no UI layout. diff --git a/doc/ru/scripting/builtins/libhud.md b/doc/ru/scripting/builtins/libhud.md index 4bf14d99..d43867ac 100644 --- a/doc/ru/scripting/builtins/libhud.md +++ b/doc/ru/scripting/builtins/libhud.md @@ -8,8 +8,18 @@ hud.open_inventory() hud.close_inventory() -- Открывает инвентарь и UI. --- Если не имеет макета UI - бросается исключение. -hud.open(invid: int, layoutid: str) +-- Если макет UI не существует - бросается исключение. +-- Если invid не указан, создаётся виртуальный (временный) инвентарь. +-- Возвращает invid или id виртуального инвентаря. +hud.open( + -- Макет UI + layoutid: str, + -- Не открывать инвентарь игрока + [опционально] disablePlayerInventory: bool, + -- Инвентарь, к которому будет привязан UI макет + [опционально] invid: int +) -> int + -- Открывает инвентарь и UI блока. -- Если блок не имеет макета UI - бросается исключение. diff --git a/src/frontend/hud.cpp b/src/frontend/hud.cpp index cc9c54d0..30659969 100644 --- a/src/frontend/hud.cpp +++ b/src/frontend/hud.cpp @@ -382,16 +382,11 @@ void Hud::openInventory() { add(HudElement(hud_element_mode::inventory_bound, nullptr, exchangeSlot, false)); } -void Hud::openInventory( +std::shared_ptr Hud::openInventory( UiDocument* doc, std::shared_ptr inv, bool playerInventory ) { - if (inv == nullptr) { - // why try to open nox-existent inventory?? - return; - } - if (isInventoryOpen()) { closeInventory(); } @@ -413,6 +408,7 @@ void Hud::openInventory( } secondInvView->bind(inv, content); add(HudElement(hud_element_mode::inventory_bound, doc, secondUI, false)); + return inv; } void Hud::openInventory( diff --git a/src/frontend/hud.hpp b/src/frontend/hud.hpp index 4a2ecfd5..580ab54d 100644 --- a/src/frontend/hud.hpp +++ b/src/frontend/hud.hpp @@ -153,7 +153,7 @@ public: /// @param doc ui layout /// @param inv inventory /// @param playerInventory show player inventory too - void openInventory( + std::shared_ptr openInventory( UiDocument* doc, std::shared_ptr inv, bool playerInventory diff --git a/src/logic/scripting/lua/libs/libhud.cpp b/src/logic/scripting/lua/libs/libhud.cpp index 460cf66b..7f5ec46d 100644 --- a/src/logic/scripting/lua/libs/libhud.cpp +++ b/src/logic/scripting/lua/libs/libhud.cpp @@ -37,23 +37,20 @@ static int l_close_inventory(lua::State*) { } static int l_open(lua::State* L) { - auto invid = lua::tointeger(L, 1); - auto layoutid = lua::require_string(L, 2); - bool playerInventory = !lua::toboolean(L, 3); + auto layoutid = lua::require_string(L, 1); + bool playerInventory = !lua::toboolean(L, 2); + auto invid = lua::tointeger(L, 3); auto assets = engine->getAssets(); auto layout = assets->get(layoutid); if (layout == nullptr) { throw std::runtime_error("there is no ui layout " + util::quote(layoutid)); } - - hud->openInventory( + return lua::pushinteger(L, hud->openInventory( layout, level->inventories->get(invid), playerInventory - ); - - return 0; + )->getId()); } static int l_open_block(lua::State* L) {