1 -- This file adds a command for generating the schemedit usage help readme
2 -- file, in Markdown format. The text is extracted from the metadata of
3 -- the items. This is only used for development purposes, after the
4 -- help text of any of the items was changed.
6 -- How to use: Temporarily set MAKE_README to true in init.lua, then
7 -- start the game as admin and run “/make_schemedit_readme”. Copy the
8 -- generated file back to the mod directory (USAGE.md).
10 -- Everything here is intentionally NOT translated because it is for text
14 -- Extract text from item definition
15 local get_text
= function(item
, field
)
16 local text
= minetest
.registered_items
[item
][field
]
18 -- Remove translation escapes
19 text
= string.gsub(text
, "\x1BE", "")
20 text
= string.gsub(text
, "\x1B%(T@schemedit%)", "")
22 -- Fix Markdown syntax error
23 text
= string.gsub(text
, "schematic_override", "`schematic_override`")
28 -- Schemedit items to generate the readme from
29 local items
= { "creator", "probtool", "void" }
31 minetest
.register_chatcommand("make_schemedit_readme", {
32 description
= "Generate the schemedit usage help readme file",
33 privs
= {server
=true},
34 func
= function(name
, param
)
36 local readme
= "## Usage help".."\n"
37 readme
= readme
.. "In this section you'll learn how to use the items of this mod.".."\n"
38 readme
= readme
.. "Note: If you have the `doc` and `doc_items` mods installed, you can also access the same help texts in-game (possibly translated).".."\n\n"
43 local desc
= get_text("schemedit:"..item
, "description")
44 local longdesc
= get_text("schemedit:"..item
, "_doc_items_longdesc")
45 local usagehelp
= get_text("schemedit:"..item
, "_doc_items_usagehelp")
47 readme
= readme
.. "### "..desc
.."\n"
48 readme
= readme
.. longdesc
.."\n\n"
49 readme
= readme
.. "#### Usage\n"
50 readme
= readme
.. usagehelp
52 readme
= readme
.. "\n\n\n"
56 local path
= minetest
.get_worldpath().."/schemedit_readme.md"
57 local file
= io
.open(path
, "w")
59 return false, "Failed to open file!"
61 local ok
= file
:write(readme
)
64 return true, "File written to: "..path
66 return false, "Failed to write file!"