modutils updated

This commit is contained in:
Alexander Weber 2017-03-09 00:39:07 +01:00
parent 12552ce92f
commit 384dbb964a

@ -1,6 +1,5 @@
local modutils = {}
-- class methods
function modutils.get_modname_by_itemname(itemname)
local def = minetest.registered_items[itemname]
if def then
@ -13,40 +12,36 @@ function modutils.get_modname_by_itemname(itemname)
return nil
end
end
end
-- object methods
local function check_depend(this, modname, deptype)
local depends = this.depends
if depends[modname] then
if not deptype then --"required" or "optional" only
return true
else
return (depends[modname] == deptype)
end
else
return false
end
end
local function check_depend_by_itemname(this, itemname, deptype)
local modname = modutils.get_modname_by_itemname(itemname)
if modname then
return this:check_depend(modname, deptype)
else
return false
end
end
function modutils.get_depend_checker(modname)
-- Definition of returning object attributes
local this = { }
this.modname = modname
this.depends = {} -- depends.txt parsed
this.check_depend = check_depend
this.check_depend_by_itemname = check_depend_by_itemname
local self = {
modname = modname,
depends = {} -- depends.txt parsed
}
-- Check if dependency exists to mod modname
function self:check_depend(modname, deptype)
if self.depends[modname] then
if not deptype then --"required" or "optional" only
return true
else
return (self.depends[modname] == deptype)
end
else
return false
end
end
--Check if dependency exists to item origin mod
function self:check_depend_by_itemname(itemname, deptype)
local modname = modutils.get_modname_by_itemname(itemname)
if modname then
return self:check_depend(modname, deptype)
else
return false
end
end
-- get module path
local modpath = minetest.get_modpath(modname)
@ -64,13 +59,13 @@ function modutils.get_depend_checker(modname)
for line in dependsfile:lines() do
if line:sub(-1) == "?" then
line = line:sub(1, -2)
this.depends[line] = "optional"
self.depends[line] = "optional"
else
this.depends[line] = "required"
self.depends[line] = "required"
end
end
return this
dependsfile:close()
return self
end
return modutils