Schema fixes

This commit is contained in:
Lars Mueller 2020-12-22 13:36:39 +01:00
parent 43612117c9
commit ff3d8c8805

@ -29,17 +29,13 @@ function generate_settingtypes(self)
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 typ == "table" then elseif typ == "table" then
local handled = {}
local settings = {} local settings = {}
if self._level > 0 then if self._level > 0 then
-- HACK: Minetest automatically adds the modname -- HACK: Minetest automatically adds the modname
return {"[" .. table.concat(modlib.table.repetition("*", self._level)) .. self.name .. "]"} -- TODO simple names (not modname.field.other_field)
settings = {"[" .. table.concat(modlib.table.repetition("*", self._level)) .. self.name .. "]"}
end end
local function setting(key, value_scheme) local function setting(key, value_scheme)
if handled[key] then
return
end
handled[key] = true
assert(not key:find("[=%.%s]")) assert(not key:find("[=%.%s]"))
value_scheme.name = self.name .. "." .. key value_scheme.name = self.name .. "." .. key
value_scheme.title = value_scheme.title or self.title .. " " .. field_name_to_title(key) value_scheme.title = value_scheme.title or self.title .. " " .. field_name_to_title(key)
@ -79,13 +75,8 @@ function generate_markdown(self)
self.title = self.title or field_name_to_title(self._md_name) self.title = self.title or field_name_to_title(self._md_name)
self._md_level = self._md_level or 1 self._md_level = self._md_level or 1
if typ == "table" then if typ == "table" then
local handled = {}
local settings = {} local settings = {}
local function setting(key, value_scheme) local function setting(key, value_scheme)
if handled[key] then
return
end
handled[key] = true
value_scheme._md_name = key value_scheme._md_name = key
value_scheme.title = value_scheme.title or self.title .. " " .. field_name_to_title(key) value_scheme.title = value_scheme.title or self.title .. " " .. field_name_to_title(key)
value_scheme._md_level = self._md_level + 1 value_scheme._md_level = self._md_level + 1
@ -112,7 +103,11 @@ function generate_markdown(self)
end end
local description = self.description local description = self.description
if description then if description then
modlib.table.append(lines, type(description) == "table" and description or {description}) if type(description) ~= "table" then
table.insert(lines, description)
else
modlib.table.append(lines, description)
end
end end
table.insert(lines, "") table.insert(lines, "")
line("Type: " .. self.type) line("Type: " .. self.type)
@ -180,11 +175,11 @@ function load(self, override, params)
end end
end end
local _error = error local _error = error
local function format_error(type, ...) local function format_error(typ, ...)
if type == "type" then if typ == "type" then
return "mismatched type: expected " .. self.type ..", got " .. type(override) .. (converted and " (converted)" or "") return "mismatched type: expected " .. self.type ..", got " .. type(override) .. (converted and " (converted)" or "")
end end
if type == "range" then if typ == "range" then
local conditions = {} local conditions = {}
local function push(condition, bound) local function push(condition, bound)
if self.range[bound] then if self.range[bound] then
@ -197,27 +192,27 @@ function load(self, override, params)
push("<=", "max") push("<=", "max")
return "out of range: expected value " .. table.concat(conditions, "and") return "out of range: expected value " .. table.concat(conditions, "and")
end end
if type == "int" then if typ == "int" then
return "expected integer" return "expected integer"
end end
if type == "infinity" then if typ == "infinity" then
return "expected no infinity" return "expected no infinity"
end end
if type == "nan" then if typ == "nan" then
return "expected no nan" return "expected no nan"
end end
if type == "required" then if typ == "required" then
local key = ... local key = ...
return "required field " .. minetest.write_json(key) .. " missing" return "required field " .. minetest.write_json(key) .. " missing"
end end
if type == "additional" then if typ == "additional" then
local key = ... local key = ...
return "superfluous field " .. minetest.write_json(key) return "superfluous field " .. minetest.write_json(key)
end end
if type == "list" then if typ == "list" then
return "not a list" return "not a list"
end end
if type == "values" then if typ == "values" then
return "expected one of " .. minetest.write_json(modlib.table.keys(self.values)) .. ", got " .. minetest.write_json(override) return "expected one of " .. minetest.write_json(modlib.table.keys(self.values)) .. ", got " .. minetest.write_json(override)
end end
_error("unknown error type") _error("unknown error type")