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 = {} local modutils = {}
-- class methods
function modutils.get_modname_by_itemname(itemname) function modutils.get_modname_by_itemname(itemname)
local def = minetest.registered_items[itemname] local def = minetest.registered_items[itemname]
if def then if def then
@ -13,40 +12,36 @@ function modutils.get_modname_by_itemname(itemname)
return nil return nil
end end
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 end
function modutils.get_depend_checker(modname) function modutils.get_depend_checker(modname)
-- Definition of returning object attributes local self = {
local this = { } modname = modname,
this.modname = modname depends = {} -- depends.txt parsed
this.depends = {} -- depends.txt parsed }
this.check_depend = check_depend
this.check_depend_by_itemname = check_depend_by_itemname
-- 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 -- get module path
local modpath = minetest.get_modpath(modname) local modpath = minetest.get_modpath(modname)
@ -64,13 +59,13 @@ function modutils.get_depend_checker(modname)
for line in dependsfile:lines() do for line in dependsfile:lines() do
if line:sub(-1) == "?" then if line:sub(-1) == "?" then
line = line:sub(1, -2) line = line:sub(1, -2)
this.depends[line] = "optional" self.depends[line] = "optional"
else else
this.depends[line] = "required" self.depends[line] = "required"
end end
end end
dependsfile:close()
return this return self
end end
return modutils return modutils