mirror of
https://codeberg.org/AntumLuanti/mod-cleaner.git
synced 2025-03-15 04:41:22 +00:00
LDoc: Add some functionality to config.ld
This commit is contained in:
parent
c5ae889ee5
commit
64f31da3f2
2 changed files with 87 additions and 1 deletions
|
@ -1,6 +1,17 @@
|
|||
|
||||
local print, error, type, ipairs
|
||||
if import then
|
||||
print = import("print")
|
||||
error = import("error")
|
||||
type = import("type")
|
||||
ipairs = import("ipairs")
|
||||
end
|
||||
|
||||
|
||||
project = "Cleaner"
|
||||
title = "Cleaner mod for Minetest"
|
||||
format = "markdown"
|
||||
not_luadoc=true
|
||||
boilerplate = false
|
||||
style = true
|
||||
|
||||
|
@ -14,6 +25,7 @@ file = {
|
|||
new_type("chatcmd", "Chat Commands")
|
||||
new_type("setting", "Settings")
|
||||
new_type("tool", "Tools")
|
||||
new_type("json", "JSON Configurations")
|
||||
|
||||
custom_tags = {
|
||||
{
|
||||
|
@ -24,10 +36,12 @@ custom_tags = {
|
|||
{
|
||||
"settype",
|
||||
title = "Setting Type",
|
||||
hidden = true,
|
||||
},
|
||||
{
|
||||
"default",
|
||||
title = "Default Value",
|
||||
hidden = true,
|
||||
},
|
||||
-- craft items/tools
|
||||
{
|
||||
|
@ -38,3 +52,75 @@ custom_tags = {
|
|||
end,
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
local registered = {
|
||||
settings = {},
|
||||
}
|
||||
|
||||
local function format_setting_tag(desc, value)
|
||||
return "\n- <span style=\"font-size:80%;\">`" .. desc .. ":`</span> `" .. value .. "`"
|
||||
end
|
||||
|
||||
local function setting_handler(item)
|
||||
print("\nsetting_handler: " .. item.name)
|
||||
|
||||
if not ipairs or not type then
|
||||
return item
|
||||
end
|
||||
|
||||
local tags = {
|
||||
{"settype", "type"},
|
||||
{"default"},
|
||||
{"min", "minimum value"},
|
||||
{"max", "maximum value"},
|
||||
}
|
||||
|
||||
local def = {
|
||||
["settype"] = format_setting_tag("type", "string"),
|
||||
}
|
||||
|
||||
for _, t in ipairs(tags) do
|
||||
local name = t[1]
|
||||
local desc = t[2]
|
||||
if not desc then desc = name end
|
||||
|
||||
local value = item.tags[name]
|
||||
if type(value) == "table" then
|
||||
if #value > 1 then
|
||||
local msg = item.file.filename .. " (line " .. item.lineno
|
||||
.. "): multiple instances of tag \"" .. name .. "\" found"
|
||||
if error then
|
||||
error(msg)
|
||||
elseif print then
|
||||
print("WARNING: " .. msg)
|
||||
end
|
||||
end
|
||||
|
||||
if value[1] then
|
||||
def[name] = format_setting_tag(desc, value[1])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
item.description = item.description .. "\n\n**Definition:**\n" .. def.settype
|
||||
for _, t in ipairs({def.default, def.min, def.max}) do
|
||||
if t then
|
||||
item.description = item.description .. t
|
||||
end
|
||||
end
|
||||
|
||||
registered.settings[item.name] = true
|
||||
|
||||
return item
|
||||
end
|
||||
|
||||
function custom_display_name_handler(item, default_handler)
|
||||
if item.type == "setting" and not registered.settings[item.name] then
|
||||
item = setting_handler(item)
|
||||
end
|
||||
|
||||
if item then
|
||||
return default_handler(item)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -10,4 +10,4 @@ cd "${root}"
|
|||
rm -rf "${docs}/reference"
|
||||
|
||||
# Create new files
|
||||
ldoc -c "${config}" -d "${docs}/reference" "${root}"
|
||||
ldoc --UNSAFE_NO_SANDBOX -c "${config}" -d "${docs}/reference" "${root}"
|
||||
|
|
Loading…
Add table
Reference in a new issue