mirror of
https://github.com/appgurueu/modlib.git
synced 2024-08-20 13:24:11 +02:00
Add & fix settingtypes.txt generation
This commit is contained in:
parent
f4ee51e543
commit
5f748d37d8
1
mod.lua
1
mod.lua
@ -99,6 +99,7 @@ function configuration(modname)
|
|||||||
overrides = modlib.table.deep_add_all(overrides, minetest_conf)
|
overrides = modlib.table.deep_add_all(overrides, minetest_conf)
|
||||||
conf = schema:load(overrides, {convert_strings = true, error_message = true})
|
conf = schema:load(overrides, {convert_strings = true, error_message = true})
|
||||||
end
|
end
|
||||||
|
modlib.file.ensure_content(get_resource(modname, "settingtypes.txt"), schema:generate_settingtypes())
|
||||||
if conf == nil then
|
if conf == nil then
|
||||||
return schema:load({}, {error_message = true})
|
return schema:load({}, {error_message = true})
|
||||||
end
|
end
|
||||||
|
18
schema.lua
18
schema.lua
@ -12,25 +12,29 @@ local function field_name_to_title(name)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function generate_settingtypes(self)
|
function generate_settingtypes(self)
|
||||||
local type = self.type
|
local typ = self.type
|
||||||
local settingtype, type_args
|
local settingtype, type_args
|
||||||
self.title = self.title or field_name_to_title(self.name)
|
self.title = self.title or field_name_to_title(self.name)
|
||||||
self._level = self._level or 0
|
self._level = self._level or 0
|
||||||
local default = self.default
|
local default = self.default
|
||||||
if type == "boolean" then
|
if typ == "boolean" then
|
||||||
settingtype = "bool"
|
settingtype = "bool"
|
||||||
default = default and "true" or "false"
|
default = default and "true" or "false"
|
||||||
elseif type == "string" then
|
elseif typ == "string" then
|
||||||
settingtype = "string"
|
settingtype = "string"
|
||||||
elseif type == "number" then
|
elseif typ == "number" then
|
||||||
settingtype = self.int and "int" or "float"
|
settingtype = self.int and "int" or "float"
|
||||||
if self.min or self.max then
|
if self.min or self.max then
|
||||||
-- TODO handle exclusive min/max
|
-- TODO handle exclusive min/max
|
||||||
type_args = (self.int and "%d %d" or "%f %f"):format(self.min or (2 ^ -30), self.max or (2 ^ 30))
|
type_args = (self.int and "%d %d" or "%f %f"):format(self.min or (2 ^ -30), self.max or (2 ^ 30))
|
||||||
end
|
end
|
||||||
elseif type == "table" then
|
elseif typ == "table" then
|
||||||
local handled = {}
|
local handled = {}
|
||||||
local settings = {"[" .. table.concat(modlib.table.repetition("*", self._level)) .. self.name .. "]"}
|
local settings = {}
|
||||||
|
if self._level > 0 then
|
||||||
|
-- HACK: Minetest automatically adds the modname
|
||||||
|
return {"[" .. table.concat(modlib.table.repetition("*", self._level)) .. self.name .. "]"}
|
||||||
|
end
|
||||||
local function setting(key, value_scheme)
|
local function setting(key, value_scheme)
|
||||||
if handled[key] then
|
if handled[key] then
|
||||||
return
|
return
|
||||||
@ -52,7 +56,7 @@ function generate_settingtypes(self)
|
|||||||
end
|
end
|
||||||
return table.concat(settings, "\n")
|
return table.concat(settings, "\n")
|
||||||
end
|
end
|
||||||
if not type then
|
if not typ then
|
||||||
return ""
|
return ""
|
||||||
end
|
end
|
||||||
local description = self.description
|
local description = self.description
|
||||||
|
Loading…
Reference in New Issue
Block a user