1
0
mirror of https://github.com/luanti-org/luanti.git synced 2025-11-21 00:45:23 +01:00

Main menu: Fix mod detection within nested modpacks

* Re-use the C++ implementation of mod detection
* Correctly show up nested modpacks in the main menu
This commit is contained in:
SmallJoker
2025-10-29 22:56:30 +01:00
committed by sfan5
parent bf01cdf823
commit 392c054be9
9 changed files with 106 additions and 106 deletions

View File

@@ -94,77 +94,25 @@ pkgmgr = {}
-- @param path Absolute directory path to scan recursively
-- @param virtual_path Prettified unique path (e.g. "mods", "mods/mt_modpack")
-- @param listing Input. Flat array to insert located mods and modpacks
-- @param modpack Currently processing modpack or nil/"" if none (recursion)
function pkgmgr.get_mods(path, virtual_path, listing, modpack)
local mods = core.get_dir_list(path, true)
local added = {}
for _, name in ipairs(mods) do
if name:sub(1, 1) ~= "." then
local mod_path = path .. DIR_DELIM .. name
local mod_virtual_path = virtual_path .. "/" .. name
local toadd = {
dir_name = name,
parent_dir = path,
}
listing[#listing + 1] = toadd
added[#added + 1] = toadd
function pkgmgr.get_mods(path, virtual_path, listing)
local mods = core.get_mod_list(path, virtual_path)
local parent = {}
for i, toadd in ipairs(mods) do
listing[#listing + 1] = toadd
-- Get config file
local mod_conf
local modpack_conf = io.open(mod_path .. DIR_DELIM .. "modpack.conf")
if modpack_conf then
toadd.is_modpack = true
modpack_conf:close()
mod_conf = Settings(mod_path .. DIR_DELIM .. "modpack.conf"):to_table()
if mod_conf.name then
name = mod_conf.name
toadd.is_name_explicit = true
end
else
mod_conf = Settings(mod_path .. DIR_DELIM .. "mod.conf"):to_table()
if mod_conf.name then
name = mod_conf.name
toadd.is_name_explicit = true
end
end
-- Read from config
toadd.name = name
toadd.title = mod_conf.title
toadd.author = mod_conf.author
toadd.release = tonumber(mod_conf.release) or 0
toadd.path = mod_path
toadd.virtual_path = mod_virtual_path
toadd.type = "mod"
-- Check modpack.txt
-- Note: modpack.conf is already checked above
local modpackfile = io.open(mod_path .. DIR_DELIM .. "modpack.txt")
if modpackfile then
modpackfile:close()
toadd.is_modpack = true
end
-- Deal with modpack contents
if modpack and modpack ~= "" then
toadd.modpack = modpack
elseif toadd.is_modpack then
toadd.type = "modpack"
toadd.is_modpack = true
pkgmgr.get_mods(mod_path, mod_virtual_path, listing, name)
end
if toadd.is_modpack then
parent[toadd.modpack_depth + 1] = toadd
elseif parent[toadd.modpack_depth] then
toadd.modpack = parent[toadd.modpack_depth].name
end
local parent_dir, dir_name = toadd.path:match("^(.+)[/\\]([^/\\]+)$")
toadd.dir_name = dir_name
toadd.parent_dir = parent_dir
toadd.type = toadd.is_modpack and "modpack" or "mod"
end
pkgmgr.update_translations(added)
if not modpack then
-- Sort all when the recursion is done
table.sort(listing, function(a, b)
return a.virtual_path:lower() < b.virtual_path:lower()
end)
end
pkgmgr.update_translations(mods)
end
--------------------------------------------------------------------------------
@@ -346,11 +294,8 @@ function pkgmgr.render_packagelist(render_list, use_technical_names, with_icon)
end
retval[#retval + 1] = color
if v.modpack ~= nil or v.loc == "game" then
retval[#retval + 1] = "1"
else
retval[#retval + 1] = "0"
end
-- `v.modpack_depth` is `nil` for the selected game (treated as level 0)
retval[#retval + 1] = (v.modpack_depth or 0) + (v.loc == "game" and 1 or 0)
if with_icon then
retval[#retval + 1] = icon