Fix collecting media from subfolders

This commit is contained in:
Lars Mueller 2023-03-04 15:00:09 +01:00
parent 2f4ed5b857
commit cc49af0ae6

@ -16,25 +16,24 @@ local media_extensions = modlib.table.set{
local function collect_media(modname)
local media = {}
local function traverse(folder)
local filenames = minetest.get_dir_list(folder, false)
local function traverse(folderpath)
-- Traverse files (collect media)
local filenames = minetest.get_dir_list(folderpath, false)
for _, filename in pairs(filenames) do
local _, ext = modlib.file.get_extension(filename)
if media_extensions[ext] then
media[filename] = folder .. "/" .. filename
media[filename] = modlib.file.concat_path{folderpath, filename}
end
end
local folderpaths = minetest.get_dir_list(folder, true)
for _, folderpath in pairs(folderpaths) do
local first = folderpath:sub(1, 1)
if first ~= "_" and first ~= "." then
traverse(modlib.mod.get_resource(modname, folderpath))
-- Traverse subfolders
local foldernames = minetest.get_dir_list(folderpath, true)
for _, foldername in pairs(foldernames) do
if not foldername:match"^[_%.]" then -- ignore hidden subfolders / subfolders starting with `_`
traverse(modlib.file.concat_path{folderpath, foldername})
end
end
end
-- Can't use foreach_value because order matters
-- TODO foreach_ipairs?
for _, foldername in ipairs(media_foldernames) do
for _, foldername in ipairs(media_foldernames) do -- order matters!
traverse(modlib.mod.get_resource(modname, foldername))
end
return media