From 5f748d37d84b0a12896b0c386fd5cf5c0d6f709d Mon Sep 17 00:00:00 2001 From: Lars Mueller Date: Tue, 22 Dec 2020 11:43:50 +0100 Subject: [PATCH] Add & fix settingtypes.txt generation --- mod.lua | 1 + schema.lua | 18 +++++++++++------- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/mod.lua b/mod.lua index ea542be..fcaf1e7 100644 --- a/mod.lua +++ b/mod.lua @@ -99,6 +99,7 @@ function configuration(modname) overrides = modlib.table.deep_add_all(overrides, minetest_conf) conf = schema:load(overrides, {convert_strings = true, error_message = true}) end + modlib.file.ensure_content(get_resource(modname, "settingtypes.txt"), schema:generate_settingtypes()) if conf == nil then return schema:load({}, {error_message = true}) end diff --git a/schema.lua b/schema.lua index 8a93cad..0f9eafb 100644 --- a/schema.lua +++ b/schema.lua @@ -12,25 +12,29 @@ local function field_name_to_title(name) end function generate_settingtypes(self) - local type = self.type + local typ = self.type local settingtype, type_args self.title = self.title or field_name_to_title(self.name) self._level = self._level or 0 local default = self.default - if type == "boolean" then + if typ == "boolean" then settingtype = "bool" default = default and "true" or "false" - elseif type == "string" then + elseif typ == "string" then settingtype = "string" - elseif type == "number" then + elseif typ == "number" then settingtype = self.int and "int" or "float" if self.min or self.max then -- 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)) end - elseif type == "table" then + elseif typ == "table" then 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) if handled[key] then return @@ -52,7 +56,7 @@ function generate_settingtypes(self) end return table.concat(settings, "\n") end - if not type then + if not typ then return "" end local description = self.description