mirror of
https://github.com/appgurueu/modlib.git
synced 2024-11-22 07:13:45 +01:00
Add experimental modlib.minetest.get_mod_info()
This commit is contained in:
parent
a792aa2e31
commit
01309a5b79
@ -26,7 +26,8 @@ for filename, comps in pairs{
|
||||
"nodename_matcher",
|
||||
"playerdata",
|
||||
"connected_players",
|
||||
"register_on_leaveplayer"
|
||||
"register_on_leaveplayer",
|
||||
"get_mod_info"
|
||||
},
|
||||
liquid = {
|
||||
"liquid_level_max",
|
||||
|
@ -252,3 +252,46 @@ end
|
||||
function register_on_leaveplayer(func)
|
||||
return minetest["register_on_" .. (minetest.is_singleplayer() and "shutdown" or "leaveplayer")](func)
|
||||
end
|
||||
|
||||
--! experimental
|
||||
function get_mod_info()
|
||||
-- TODO validate modnames
|
||||
local modnames = minetest.get_modnames()
|
||||
local mod_info = {}
|
||||
for _, mod in pairs(modnames) do
|
||||
local info
|
||||
local function read_file(filename)
|
||||
return modlib.file.read(modlib.mod.get_resource(mod, filename))
|
||||
end
|
||||
local mod_conf = Settings(modlib.mod.get_resource(mod, "mod.conf"))
|
||||
if mod_conf then
|
||||
info = {}
|
||||
mod_conf = mod_conf:to_table()
|
||||
local function read_depends(field)
|
||||
local depends = {}
|
||||
for depend in (mod_conf[field] or ""):gmatch"[^,]+" do
|
||||
depends[depend:match"^%s*(.-)%s*$"] = true
|
||||
end
|
||||
info[field] = depends
|
||||
end
|
||||
read_depends"depends"
|
||||
read_depends"optional_depends"
|
||||
else
|
||||
info = {
|
||||
description = read_file"description.txt",
|
||||
depends = {},
|
||||
optional_depends = {}
|
||||
}
|
||||
local depends_txt = read_file"depends.txt"
|
||||
if depends_txt then
|
||||
for _, dependency in ipairs(modlib.table.map(modlib.text.split(depends_txt or "", "\n"), modlib.text.trim_spacing)) do
|
||||
local modname, is_optional = dependency:match"(.+)(%??)"
|
||||
table.insert(is_optional == "" and info.depends or info.optional_depends, modname)
|
||||
end
|
||||
end
|
||||
end
|
||||
mod_info[mod] = info
|
||||
end
|
||||
return mod_info
|
||||
end
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user