2021-07-30 16:15:21 -07:00
|
|
|
|
|
|
|
local print, error, type, ipairs
|
|
|
|
if import then
|
|
|
|
print = import("print")
|
|
|
|
error = import("error")
|
|
|
|
type = import("type")
|
|
|
|
ipairs = import("ipairs")
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2021-07-12 08:58:55 -07:00
|
|
|
project = "Cleaner"
|
|
|
|
title = "Cleaner mod for Minetest"
|
|
|
|
format = "markdown"
|
2021-07-30 16:15:21 -07:00
|
|
|
not_luadoc=true
|
2021-07-12 08:58:55 -07:00
|
|
|
boilerplate = false
|
2021-07-29 12:48:35 -07:00
|
|
|
style = true
|
2021-07-12 15:46:33 -07:00
|
|
|
|
|
|
|
file = {
|
|
|
|
"settings.lua",
|
|
|
|
"api.lua",
|
|
|
|
"chat.lua",
|
2021-07-29 13:38:10 -07:00
|
|
|
"tools.lua",
|
2021-07-30 17:54:33 -07:00
|
|
|
".ldoc/config.luadoc",
|
2021-07-12 15:46:33 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
new_type("chatcmd", "Chat Commands")
|
|
|
|
new_type("setting", "Settings")
|
2021-07-28 01:41:15 -07:00
|
|
|
new_type("tool", "Tools")
|
2021-07-30 16:15:21 -07:00
|
|
|
new_type("json", "JSON Configurations")
|
2021-07-12 15:46:33 -07:00
|
|
|
|
2021-07-31 04:17:50 -07:00
|
|
|
|
|
|
|
local function video_frame(src)
|
|
|
|
return '<iframe width="560" height="315" src="' .. src
|
|
|
|
.. '" title="Video Player" frameborder="0"'
|
|
|
|
.. ' allow="fullscreen;"></iframe>'
|
|
|
|
end
|
|
|
|
|
2021-07-12 15:46:33 -07:00
|
|
|
custom_tags = {
|
2021-07-28 01:41:15 -07:00
|
|
|
{
|
|
|
|
"privs",
|
|
|
|
title = "Required Privileges",
|
|
|
|
},
|
2021-07-31 04:17:50 -07:00
|
|
|
{
|
|
|
|
"video",
|
|
|
|
title = "Video",
|
|
|
|
format = video_frame,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"youtube",
|
|
|
|
title = "Video",
|
|
|
|
format = function(value)
|
|
|
|
return video_frame("https://www.youtube.com/embed/" .. value)
|
|
|
|
end,
|
|
|
|
},
|
2021-07-28 01:41:15 -07:00
|
|
|
-- settings
|
2021-07-12 15:46:33 -07:00
|
|
|
{
|
|
|
|
"settype",
|
|
|
|
title = "Setting Type",
|
2021-07-30 16:15:21 -07:00
|
|
|
hidden = true,
|
2021-07-12 15:46:33 -07:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"default",
|
|
|
|
title = "Default Value",
|
2021-07-30 16:15:21 -07:00
|
|
|
hidden = true,
|
2021-07-12 15:46:33 -07:00
|
|
|
},
|
2021-07-28 01:41:15 -07:00
|
|
|
-- craft items/tools
|
|
|
|
{
|
|
|
|
"img",
|
|
|
|
title = "Image",
|
|
|
|
format = function(value)
|
2021-07-30 17:54:33 -07:00
|
|
|
return "<img src=\"../data/" .. value .. "\" style=\"width:32px; height:32px;\" />"
|
2021-07-28 01:41:15 -07:00
|
|
|
end,
|
|
|
|
},
|
2021-07-12 15:46:33 -07:00
|
|
|
}
|
2021-07-30 16:15:21 -07:00
|
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
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
|