mirror of
https://github.com/appgurueu/modlib.git
synced 2024-11-25 16:53:46 +01:00
Fix collecting media from subfolders
This commit is contained in:
parent
2f4ed5b857
commit
cc49af0ae6
@ -16,25 +16,24 @@ local media_extensions = modlib.table.set{
|
|||||||
|
|
||||||
local function collect_media(modname)
|
local function collect_media(modname)
|
||||||
local media = {}
|
local media = {}
|
||||||
local function traverse(folder)
|
local function traverse(folderpath)
|
||||||
local filenames = minetest.get_dir_list(folder, false)
|
-- Traverse files (collect media)
|
||||||
|
local filenames = minetest.get_dir_list(folderpath, false)
|
||||||
for _, filename in pairs(filenames) do
|
for _, filename in pairs(filenames) do
|
||||||
local _, ext = modlib.file.get_extension(filename)
|
local _, ext = modlib.file.get_extension(filename)
|
||||||
if media_extensions[ext] then
|
if media_extensions[ext] then
|
||||||
media[filename] = folder .. "/" .. filename
|
media[filename] = modlib.file.concat_path{folderpath, filename}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
local folderpaths = minetest.get_dir_list(folder, true)
|
-- Traverse subfolders
|
||||||
for _, folderpath in pairs(folderpaths) do
|
local foldernames = minetest.get_dir_list(folderpath, true)
|
||||||
local first = folderpath:sub(1, 1)
|
for _, foldername in pairs(foldernames) do
|
||||||
if first ~= "_" and first ~= "." then
|
if not foldername:match"^[_%.]" then -- ignore hidden subfolders / subfolders starting with `_`
|
||||||
traverse(modlib.mod.get_resource(modname, folderpath))
|
traverse(modlib.file.concat_path{folderpath, foldername})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
-- Can't use foreach_value because order matters
|
for _, foldername in ipairs(media_foldernames) do -- order matters!
|
||||||
-- TODO foreach_ipairs?
|
|
||||||
for _, foldername in ipairs(media_foldernames) do
|
|
||||||
traverse(modlib.mod.get_resource(modname, foldername))
|
traverse(modlib.mod.get_resource(modname, foldername))
|
||||||
end
|
end
|
||||||
return media
|
return media
|
||||||
|
Loading…
Reference in New Issue
Block a user