mirror of
https://github.com/appgurueu/modlib.git
synced 2024-11-21 23:03:44 +01:00
Add experimental minetest.media module
This commit is contained in:
parent
41ee5f57cb
commit
002d1e187b
@ -5,7 +5,8 @@ for _, value in pairs{
|
||||
"luon",
|
||||
"raycast",
|
||||
"schematic",
|
||||
"colorspec"
|
||||
"colorspec",
|
||||
"media"
|
||||
} do
|
||||
components[value] = value
|
||||
end
|
||||
|
56
minetest/media.lua
Normal file
56
minetest/media.lua
Normal file
@ -0,0 +1,56 @@
|
||||
local minetest, modlib, pairs, ipairs
|
||||
= minetest, modlib, pairs, ipairs
|
||||
|
||||
--! experimental
|
||||
|
||||
local _ENV = ...
|
||||
setfenv(1, _ENV)
|
||||
|
||||
-- TODO support for server texture packs (and possibly client TPs in singleplayer?)
|
||||
local media_foldernames = {"textures", "sounds", "media", "models", "locale"}
|
||||
local media_extensions = modlib.table.set{
|
||||
-- Textures
|
||||
"png", "jpg", "bmp", "tga", "pcx", "ppm", "psd", "wal", "rgb";
|
||||
-- Sounds
|
||||
"ogg";
|
||||
-- Models
|
||||
"x", "b3d", "md2", "obj";
|
||||
-- Translations
|
||||
"tr";
|
||||
}
|
||||
|
||||
local function collect_media(modname)
|
||||
local media = {}
|
||||
local function traverse(folder)
|
||||
local filenames = minetest.get_dir_list(folder, false)
|
||||
for _, filename in pairs(filenames) do
|
||||
local _, ext = modlib.file.splitext(filename)
|
||||
if media_extensions[ext] then
|
||||
media[filename] = folder .. "/" .. 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(folderpath)
|
||||
end
|
||||
end
|
||||
end
|
||||
-- Can't use foreach_value because order matters
|
||||
-- TODO foreach_ipairs?
|
||||
for _, foldername in ipairs(media_foldernames) do
|
||||
traverse(modlib.mod.get_resource(modname, foldername))
|
||||
end
|
||||
return media
|
||||
end
|
||||
|
||||
local paths = {}
|
||||
for _, mod in ipairs(modlib.minetest.get_mod_load_order()) do
|
||||
local mod_media = collect_media(mod.name)
|
||||
for medianame, path in pairs(mod_media) do
|
||||
paths[medianame] = path
|
||||
end
|
||||
end
|
||||
|
||||
media = {paths = paths}
|
Loading…
Reference in New Issue
Block a user