config.ld 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  1. -- place this file in mod ".ldoc" directory
  2. local print, type, string, table, tostring, tonumber, error, pairs, ipairs
  3. if import then
  4. print = import("print")
  5. type = import("type")
  6. string = import("string")
  7. table = import("table")
  8. tostring = import("tostring")
  9. tonumber = import("tonumber")
  10. error = import("error")
  11. pairs = import("pairs")
  12. ipairs = import("ipairs")
  13. end
  14. project = "3d_armor"
  15. title = "3D Armor"
  16. format = "markdown"
  17. not_luadoc = true
  18. boilerplate = false
  19. wrap = false
  20. style = true
  21. favicon = "https://www.minetest.net/media/icon.svg"
  22. file = {
  23. "3d_armor/api.lua",
  24. ".ldoc/settings.luadoc",
  25. --".ldoc/armors.luadoc",
  26. ".ldoc/helmets.luadoc",
  27. ".ldoc/chestplates.luadoc",
  28. ".ldoc/leggings.luadoc",
  29. ".ldoc/boots.luadoc",
  30. --".ldoc/shields.luadoc",
  31. "shields/init.lua",
  32. ".ldoc/crafting.luadoc",
  33. }
  34. new_type("setting", "Settings")
  35. new_type("armor", "Armors")
  36. new_type("craft", "Craft Recipes")
  37. alias("helmet", "armor")
  38. alias("chestplate", "armor")
  39. alias("leggings", "armor")
  40. alias("boots", "armor")
  41. alias("shield", "armor")
  42. alias("grp", "group")
  43. -- function declarations
  44. local format_text
  45. local format_group
  46. custom_tags = {
  47. -- settings
  48. {
  49. "settype",
  50. title = "Type",
  51. hidden = true,
  52. },
  53. {
  54. "min",
  55. title = "Minimum Value",
  56. hidden = true,
  57. },
  58. {
  59. "max",
  60. title = "Maximum Value",
  61. hidden = true,
  62. },
  63. {
  64. "default",
  65. title = "Default Value",
  66. hidden = true,
  67. },
  68. -- craft items/tools
  69. {
  70. -- specify image basename only
  71. "img",
  72. title = "Inventory Image",
  73. format = function(value)
  74. return "<img src=\"../data/" .. value .. "\" style=\"width:32px; height:32px;\" />"
  75. end,
  76. },
  77. {
  78. -- specify full (relative or absolute) image path
  79. "image",
  80. title = "Image",
  81. format = function(value)
  82. return "<img src=\"" .. value .. "\" style=\"width:32px; height:32px;\" />"
  83. end,
  84. },
  85. {
  86. "group",
  87. title = "Groups",
  88. format = function(value)
  89. return format_group(value)
  90. end,
  91. },
  92. {
  93. "armorgrp",
  94. title = "Armor Groups",
  95. format = function(value)
  96. return format_group(value)
  97. end,
  98. },
  99. {
  100. "damagegrp",
  101. title = "Damage Groups",
  102. format = function(value)
  103. return format_group(value)
  104. end,
  105. },
  106. }
  107. if string then
  108. string.trim = function(st, delim)
  109. if not delim then
  110. delim = " "
  111. end
  112. while string.find(st, delim) == 1 do
  113. st = st:sub(2)
  114. end
  115. while string.sub(st, string.len(st)) == delim do
  116. st = st:sub(1, string.len(st)-1)
  117. end
  118. return st
  119. end
  120. string.split = function(st, delim)
  121. local list = {}
  122. local idx = string.find(st, delim)
  123. while idx do
  124. table.insert(list, st:sub(1, idx-1))
  125. st = st:sub(idx+1)
  126. idx = string.find(st, delim)
  127. end
  128. -- add remaining item
  129. table.insert(list, st)
  130. return list
  131. end
  132. end
  133. if table then
  134. if not table.copy then
  135. table.copy = function(orig_table)
  136. local new_table = {}
  137. for k, v in pairs(orig_table) do
  138. new_table[k] = v
  139. end
  140. return new_table
  141. end
  142. end
  143. end
  144. format_text = function(text, flags)
  145. local ret = "<"
  146. local ttype = "span"
  147. if flags.code then
  148. ttype = "code"
  149. end
  150. ret = ret .. ttype .. " style=\""
  151. if flags.size then
  152. ret = ret .. "font-size:" .. flags.size .. ";"
  153. end
  154. if flags.mono then
  155. ret = ret .. "font-family:monospace;"
  156. end
  157. if flags.italic then
  158. ret = ret .. "font-style:italic;"
  159. end
  160. if flags.bold then
  161. ret = ret .. "font-weight:bold;"
  162. end
  163. if flags.color then
  164. ret = ret .. "color:" .. flags.color .. ";"
  165. end
  166. if flags.bgcolor then
  167. ret = ret .. "background-color:" .. flags.bgcolor .. ";"
  168. end
  169. ret = ret .. "\">" .. text .. "</" .. ttype .. ">"
  170. return ret
  171. end
  172. format_group = function(text)
  173. if string then
  174. local idx, k, v = string.find(text, " ")
  175. if idx then
  176. text = format_text(string.sub(text, 1, idx-1) .. ": ", {mono=true, color="darkgreen"})
  177. .. string.sub(text, idx)
  178. end
  179. end
  180. return text
  181. end
  182. local function format_setting_tag(desc, value)
  183. return "\n- <span style=\"font-size:80%;\">`" .. desc .. ":`</span> `" .. value .. "`"
  184. end
  185. local registered = {
  186. settings = {},
  187. }
  188. local function setting_handler(item)
  189. -- avoid parsing again
  190. if registered.settings[item.name] then
  191. return item
  192. end
  193. if not ipairs or not type then
  194. return item
  195. end
  196. local tags = {
  197. {"settype", "type"},
  198. {"default"},
  199. {"min", "minimum value"},
  200. {"max", "maximum value"},
  201. }
  202. local def = {
  203. ["settype"] = format_setting_tag("type", "string"),
  204. }
  205. for _, t in ipairs(tags) do
  206. local name = t[1]
  207. local desc = t[2]
  208. if not desc then desc = name end
  209. local value = item.tags[name]
  210. if type(value) == "table" then
  211. if #value > 1 then
  212. local msg = item.file.filename .. " (line " .. item.lineno
  213. .. "): multiple instances of tag \"" .. name .. "\" found"
  214. if error then
  215. error(msg)
  216. elseif print then
  217. print("WARNING: " .. msg)
  218. end
  219. end
  220. if value[1] then
  221. def[name] = format_setting_tag(desc, value[1])
  222. end
  223. end
  224. end
  225. item.description = item.description .. "\n\n**Definition:**\n" .. def.settype
  226. for _, t in ipairs({def.default, def.min, def.max}) do
  227. if t then
  228. item.description = item.description .. t
  229. end
  230. end
  231. registered.settings[item.name] = true
  232. return item
  233. end
  234. function custom_display_name_handler(item, default_handler)
  235. if item.type == "setting" then
  236. item = setting_handler(item)
  237. end
  238. if item then
  239. return default_handler(item)
  240. end
  241. end
  242. local custom_see_links = {
  243. ["ObjectRef"] = "https://minetest.gitlab.io/minetest/class-reference/#objectref",
  244. ["PlayerMetaRef"] = "https://minetest.gitlab.io/minetest/class-reference/#playermetaref",
  245. ["ItemDef"] = "https://minetest.gitlab.io/minetest/definition-tables/#item-definition",
  246. ["ItemStack"] = "https://minetest.gitlab.io/minetest/class-reference/#itemstack",
  247. ["groups"] = "https://minetest.gitlab.io/minetest/groups/",
  248. ["entity_damage_mechanism"] = "https://minetest.gitlab.io/minetest/entity-damage-mechanism/",
  249. ["vector"] = "https://minetest.gitlab.io/minetest/representations-of-simple-things/#positionvector",
  250. }
  251. local function format_custom_see(name, section)
  252. local url = custom_see_links[name]
  253. if not url then
  254. url = ""
  255. end
  256. if not name then
  257. name = ""
  258. end
  259. return name, url
  260. end
  261. custom_see_handler("^(ObjectRef)$", function(name, section)
  262. return format_custom_see(name, section)
  263. end)
  264. custom_see_handler("^(PlayerMetaRef)$", function(name, section)
  265. return format_custom_see(name, section)
  266. end)
  267. custom_see_handler("^(ItemDef)$", function(name, section)
  268. return format_custom_see(name, section)
  269. end)
  270. custom_see_handler("^(groups)$", function(name, section)
  271. return format_custom_see(name, section)
  272. end)
  273. custom_see_handler("^(entity_damage_mechanism)$", function(name, section)
  274. return format_custom_see(name, section)
  275. end)
  276. custom_see_handler("^(ItemStack)$", function(name, section)
  277. return format_custom_see(name, section)
  278. end)
  279. custom_see_handler("^(vector)$", function(name, section)
  280. return name, "https://minetest.gitlab.io/minetest/representations-of-simple-things/#positionvector"
  281. end)