Test techage ingame docu API
This commit is contained in:
parent
754f4cf354
commit
62a5ed049d
4
init.lua
4
init.lua
@ -525,3 +525,7 @@ minetest.register_craft({
|
||||
{"basic_materials:plastic_sheet", "basic_materials:plastic_sheet", "basic_materials:plastic_sheet"}
|
||||
},
|
||||
})
|
||||
|
||||
dofile(minetest.get_modpath("ta4_jetpack") .. "/manual.lua")
|
||||
techage.add_manual_items({ta4_jetpack = "ta4_jetpack.png"})
|
||||
|
||||
|
31
manual.lua
Normal file
31
manual.lua
Normal file
@ -0,0 +1,31 @@
|
||||
techage.add_to_manual('EN', {
|
||||
"1,TA4 Jetpack",
|
||||
"2,Instructions",
|
||||
"2,Important to know",
|
||||
}, {
|
||||
"The Jetpack is inspired by the jetpack from spirit689 (https://github.com/spirit689/jetpack)\n"..
|
||||
"and by the historical game Lunar Lander.\n"..
|
||||
"\n"..
|
||||
"\n"..
|
||||
"\n",
|
||||
" - Craft TA4 Jetpack\\, Jetpack Controller and Training Mat\n"..
|
||||
" - Use the armor extension (3d_armor) of the player menu to strap the Jetpack on your back\n"..
|
||||
" - You can refuel the jetpack by left-clicking with the controller on a hydrogen tank\n"..
|
||||
" - Turn the controller on by right-click and check the fuel tank level (the small colored bar below the controller icon)\n"..
|
||||
" - Use the space bar to activate the Jetpack and the WASD keys to control the direction\n"..
|
||||
" - Before your first flight you should do some training starts and landings on the Training Mat \n(The Jetpack is a bit stubborn\\, it takes some practice to keep the JetPack in the air)\n"..
|
||||
"\n",
|
||||
" - 12 units of hydrogen are sufficient for a flight of 6 minutes\n"..
|
||||
" - Maximum 5 items stacks in your inventory are allowed including the controller.\nOtherwise you would be too heavy :-)\n"..
|
||||
" - The Jetpack also wears out and can be used for approximately 10 flights\n"..
|
||||
" - Always hold the controller tight during the flight\\, otherwise it will switch off :)\n"..
|
||||
"\n",
|
||||
}, {
|
||||
"ta4_jetpack",
|
||||
"",
|
||||
"",
|
||||
}, {
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
})
|
27
manual.md
Normal file
27
manual.md
Normal file
@ -0,0 +1,27 @@
|
||||
# TA4 Jetpack
|
||||
|
||||
The Jetpack is inspired by the jetpack from spirit689 (https://github.com/spirit689/jetpack)
|
||||
and by the historical game Lunar Lander.
|
||||
|
||||
[ta4_jetpack|image]
|
||||
|
||||
|
||||
## Instructions
|
||||
|
||||
- Craft TA4 Jetpack, Jetpack Controller and Training Mat
|
||||
- Use the armor extension (3d_armor) of the player menu to strap the Jetpack on your back
|
||||
- You can refuel the jetpack by left-clicking with the controller on a hydrogen tank
|
||||
- Turn the controller on by right-click and check the fuel tank level (the small colored bar below the controller icon)
|
||||
- Use the space bar to activate the Jetpack and the WASD keys to control the direction
|
||||
- Before your first flight you should do some training starts and landings on the Training Mat
|
||||
(The Jetpack is a bit stubborn, it takes some practice to keep the JetPack in the air)
|
||||
|
||||
|
||||
## Important to know
|
||||
|
||||
- 12 units of hydrogen are sufficient for a flight of 6 minutes
|
||||
- Maximum 5 items stacks in your inventory are allowed including the controller.
|
||||
Otherwise you would be too heavy :-)
|
||||
- The Jetpack also wears out and can be used for approximately 10 flights
|
||||
- Always hold the controller tight during the flight, otherwise it will switch off :)
|
||||
|
194
markdown2lua.py
Normal file
194
markdown2lua.py
Normal file
@ -0,0 +1,194 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
|
||||
import re
|
||||
import mistune
|
||||
|
||||
class WikiLinkInlineLexer(mistune.InlineLexer):
|
||||
def enable_wiki_link(self):
|
||||
# add wiki_link rules
|
||||
self.rules.wiki_link = re.compile(
|
||||
r'\[' # [
|
||||
r'([\s\S]+?\|[\s\S]+?)' # name| img-type
|
||||
r'\](?!\])' # ]
|
||||
)
|
||||
|
||||
# Add wiki_link parser to default rules
|
||||
# you can insert it some place you like
|
||||
# but place matters, maybe 3 is not good
|
||||
self.default_rules.insert(3, 'wiki_link')
|
||||
|
||||
def output_wiki_link(self, m):
|
||||
text = m.group(1)
|
||||
name, itype = text.split('|')
|
||||
# you can create an custom render
|
||||
# you can also return the html if you like
|
||||
return self.renderer.wiki_link(name, itype)
|
||||
|
||||
class MarkdownToLua(mistune.Renderer):
|
||||
def __init__(self, mod_name, dst_file_name, *args, **kwargs):
|
||||
mistune.Renderer.__init__(self, *args, **kwargs)
|
||||
self.mod_name = mod_name
|
||||
self.dst_file_name = dst_file_name
|
||||
self.item_name = ""
|
||||
self.plan_table = ""
|
||||
self.is_first_header = True
|
||||
self.text_chunck = []
|
||||
self.lTitle = []
|
||||
self.lText = []
|
||||
self.lItemName = []
|
||||
self.lPlanTable = []
|
||||
|
||||
def m2l_formspec_escape(self, text):
|
||||
text = text.replace("\\", "")
|
||||
text = text.replace("[", "\\\\[")
|
||||
text = text.replace("]", "\\\\]")
|
||||
text = text.replace(";", "\\\\;")
|
||||
text = text.replace(",", "\\\\,")
|
||||
text = text.replace('"', '\\"')
|
||||
text = text.replace('\n', '\\n')
|
||||
return text
|
||||
|
||||
def m2l_add_last_paragraph(self):
|
||||
"""
|
||||
Used to add a text block before the next header or at the end of the document
|
||||
"""
|
||||
self.lText.append(self.text_chunck)
|
||||
self.text_chunck = []
|
||||
self.lItemName.append(self.item_name)
|
||||
self.item_name = ""
|
||||
self.lPlanTable.append(self.plan_table)
|
||||
self.plan_table = ""
|
||||
##
|
||||
## Block Level
|
||||
##
|
||||
def block_code(self, code, lang):
|
||||
text = self.m2l_formspec_escape(code.strip())
|
||||
lines = text.split("\n")
|
||||
lines = [" " + item for item in lines]
|
||||
self.text_chunck.extend(lines)
|
||||
self.text_chunck.append("")
|
||||
return ""
|
||||
|
||||
def header(self, text, level, raw=None):
|
||||
if not self.is_first_header:
|
||||
self.m2l_add_last_paragraph()
|
||||
self.is_first_header = False
|
||||
self.lTitle.append("%u,%s" % (level, self.m2l_formspec_escape(text)))
|
||||
return ""
|
||||
|
||||
def hrule(self):
|
||||
self.text_chunck.append("\n----------------------------------------------------\n")
|
||||
return ""
|
||||
|
||||
def paragraph(self, text):
|
||||
lines = text.split("\\n") + [""]
|
||||
self.text_chunck.extend(lines)
|
||||
return ""
|
||||
|
||||
def list(self, body, ordered=True):
|
||||
lines = body.split("\n")
|
||||
self.text_chunck.extend(lines)
|
||||
return ""
|
||||
|
||||
def list_item(self, text):
|
||||
return " - %s\n" % text.strip()
|
||||
##
|
||||
## Span Level
|
||||
##
|
||||
def emphasis(self, text):
|
||||
return "*%s*" % self.m2l_formspec_escape(text)
|
||||
|
||||
def double_emphasis(self, text):
|
||||
return "*%s*" % self.m2l_formspec_escape(text)
|
||||
|
||||
def codespan(self, text):
|
||||
return "'%s'" % self.m2l_formspec_escape(text)
|
||||
|
||||
def text(self, text):
|
||||
return self.m2l_formspec_escape(text)
|
||||
|
||||
def link(self, link, title, content):
|
||||
"""
|
||||
Used for plans and images:
|
||||
[myimage](/image/)
|
||||
[myplan](/plan/)
|
||||
"""
|
||||
if link == "/image/":
|
||||
self.item_name = content
|
||||
elif link == "/plan/":
|
||||
self.plan_table = content
|
||||
return ""
|
||||
|
||||
def wiki_link(self, name, itype):
|
||||
"""
|
||||
Used for plans and images:
|
||||
[myimage|image]
|
||||
[myplan|plan]
|
||||
"""
|
||||
if itype == "image":
|
||||
self.item_name = name
|
||||
elif itype == "plan":
|
||||
self.plan_table = name
|
||||
return ""
|
||||
|
||||
def autolink(self, link, is_email=False):
|
||||
return link
|
||||
|
||||
def linebreak(self):
|
||||
return "\\n"
|
||||
|
||||
def newline(self):
|
||||
return "\\n"
|
||||
|
||||
def inline_html(self, text):
|
||||
#print(text)
|
||||
pass
|
||||
|
||||
def parse_md_file(self, src_name):
|
||||
print("Read Lua file '%s'" % src_name)
|
||||
inline = WikiLinkInlineLexer(self)
|
||||
# enable the feature
|
||||
inline.enable_wiki_link()
|
||||
md = mistune.Markdown(renderer=self, inline=inline)
|
||||
md.renderer.src_name = src_name
|
||||
md.render(open(src_name, 'r').read())
|
||||
md.renderer.m2l_add_last_paragraph()
|
||||
|
||||
def lua_table(self, lData):
|
||||
lOut = []
|
||||
lOut.append("{")
|
||||
for line in lData:
|
||||
lOut.append(' "%s",' % line)
|
||||
lOut.append("}")
|
||||
return "\n".join(lOut)
|
||||
|
||||
def lua_text_table(self, lData):
|
||||
lOut = []
|
||||
lOut.append("{")
|
||||
for lines in lData:
|
||||
for line in lines[:-1]:
|
||||
line = line.replace('<br>', '\\n')
|
||||
lOut.append(' "%s\\n"..' % line)
|
||||
if len(lines) > 0:
|
||||
lOut.append(' "%s\\n",' % lines[-1])
|
||||
else:
|
||||
lOut.append(' "",')
|
||||
lOut.append("}")
|
||||
return "\n".join(lOut)
|
||||
|
||||
def gen_lua_file(self, dest_name):
|
||||
print("Write Lua file '%s'" % dest_name)
|
||||
lOut = []
|
||||
s = ", ".join([self.lua_table(self.lTitle),
|
||||
self.lua_text_table(self.lText),
|
||||
self.lua_table(self.lItemName),
|
||||
self.lua_table(self.lPlanTable)])
|
||||
open(dest_name, "w").write("techage.add_to_manual('EN', %s)\n" % s)
|
||||
|
||||
|
||||
m2l = MarkdownToLua("ta4_jetpack", "manual")
|
||||
m2l.parse_md_file("./manual.md")
|
||||
m2l.gen_lua_file("./manual.lua")
|
||||
|
BIN
textures/ta4_jetpack.png
Normal file
BIN
textures/ta4_jetpack.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.3 KiB |
Loading…
x
Reference in New Issue
Block a user