From e26b87e7e5d37d5e0f4195072b8e2eff306126fa Mon Sep 17 00:00:00 2001 From: MihailRis Date: Fri, 3 May 2024 23:32:52 +0300 Subject: [PATCH] pack.get_info: dependencies list included --- src/logic/scripting/lua/libpack.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/logic/scripting/lua/libpack.cpp b/src/logic/scripting/lua/libpack.cpp index 3b72e145..6ac3e060 100644 --- a/src/logic/scripting/lua/libpack.cpp +++ b/src/logic/scripting/lua/libpack.cpp @@ -9,6 +9,7 @@ #include "../../../world/World.h" #include +#include #include static int l_pack_get_folder(lua_State* L) { @@ -85,6 +86,23 @@ static int l_pack_get_info(lua_State* L, const ContentPack& pack, const Content* lua_pushstring(L, icon.c_str()); lua_setfield(L, -2, "icon"); + if (!pack.dependencies.empty()) { + lua_createtable(L, pack.dependencies.size(), 0); + for (size_t i = 0; i < pack.dependencies.size(); i++) { + auto& dpack = pack.dependencies.at(i); + std::string prefix; + switch (dpack.level) { + case DependencyLevel::required: prefix = "!"; break; + case DependencyLevel::optional: prefix = "?"; break; + case DependencyLevel::weak: prefix = "~"; break; + default: throw std::runtime_error(""); + } + lua_pushfstring(L, "%s%s", prefix.c_str(), dpack.id.c_str()); + lua_rawseti(L, -2, i+1); + } + lua_setfield(L, -2, "dependencies"); + } + auto runtime = content ? content->getPackRuntime(pack.id) : nullptr; if (runtime) { lua_pushboolean(L, runtime->getStats().hasSavingContent());