diff --git a/cyberpnk.txt b/cyberpnk.txt
index 8b2633f..376c058 100644
--- a/cyberpnk.txt
+++ b/cyberpnk.txt
@@ -1,4 +1,13 @@
-@ Section
-# Sub section
-: Competence 1
-: Competence 2
+@ Compétences
++ Sub section
+- Competence 1
+- Competence 2
+. Repeating 1
++ Sub section 2
++ Sub section 3
++ Sub section 4
+@ Magie
++ Subsection 2
+@ Combat
++ Subsection 2
+- Competence2
diff --git a/generator.py b/generator.py
index cb2041d..4a2db07 100644
--- a/generator.py
+++ b/generator.py
@@ -1,37 +1,121 @@
-# Generate skills sections and others from a file, on the long run, it should be able to generate the whole sheet
+#ENCODING UTF-8
+
+# content skills sections and others from a file, on the long run, it should be able to content the whole sheet
import argparse, sys, os
-#
-#
-#
-def printable(name):
- return name.replace(" ","").lower()
+class Node(object):
+ """Generic Node."""
+ def __init__(self, name,nb):
+ self.name = name.strip(" ")
+ self.number=nb
+ self.children=[]
+ self.checked=""
+ self.parent=None
+ self.pname=name.replace(" ","").lower()
+ if nb==1:
+ self.checked='checked="checked"'
-def checked(b):
- if b==1:
- return 'checked="checked"'
- return ""
+ def content(self):
+ return ""
-def gen_tab(name,tab_nb):
- return ''.format(name=name,nb=tab_nb,checked=checked(tab_nb))
+ def header(self):
+ return ""
+ def css(self):
+ return ""
-#
-#
-#
-#
-#
+ def addchild(self,child):
+ self.children+=[child]
+
+ # def printable(self,name):
+ # return
+
+class Root(Node):
+ """docstring for Root."""
+ def __init__(self):
+ super(Root,self).__init__("",0)
+
+ def generate(self):
+ "Return the whole tree, printable"
+ return self.content()
+
+ def content(self):
+ ret=""
+ for child in self.children:
+ ret+=child.header() # Ligne de chaque tab direct, puis tout
+ for child in self.children:
+ ret+=child.content()
+ ret+="
\n"
+ return ret
+
+ def css(self):
+ "Return the whole css, printable"
+ ret="""div.sheet-tab-content { display: none; }"""
+ for child in self.children:
+ ret+="input.sheet-tab{}:checked ~ div.sheet-tab{},\n".format(child.number)
+ ret=ret[:-1]
+ ret+="{display: block;}"
+ return ret
+
+class Tab(Node):
+ """Tab node, contains"""
+
+ def __init__(self, name,nb):
+ super(Tab, self).__init__(name,nb)
+
+ def header(self): # Comes first
+ return '
\n'.format(self=self)
+
+ def content(self):
+ ret='
\n
\n'.format(self=self) # And add all content
+ for child in self.children:
+ ret+=child.header()
+ ret+="
\n"
+ for child in self.children:
+ ret+=child.content()
+ return ret
+
+class SubTab(Node):
+ def __init__(self,name,nb):
+ super(SubTab,self).__init__(name,nb)
+
+ def header(self):
+ return """
\n""".format(self=self)
+
+ def content(self):
+ ret= '
\n'.format(self=self)
+ ret+=" \n
{self.name}
\n".format(self=self)
+ for child in self.children:
+ ret+=child.content()
+ ret+=" \n"
+ return ret
+
+class Skill(Node):
+ """Print a skill."""
+ def __init__(self, name,nb):
+ super(Skill, self).__init__(name,nb)
+
+ def content(self):
+ ret="""
+
+
+
+
+
+
""".format(self=self)
-def gen_subtab(name,secname,tab_nb,subtab_nb):
- if subtab_nb==1:
- intro="""
-
""".format(tab_nb)
- else:
- intro=""
- line="""""".format(name=name,nb=subtab_nb,check=checked(subtab_nb))
- return intro+line
#
#
Compétences Intellectuelles
@@ -54,65 +138,34 @@ def gen_subtab(name,secname,tab_nb,subtab_nb):
#
#
-def gen_repeating(name):
- pass
-
-#
-#
-#
-#
-#
-#
-#
-#
-#
-
-#
-def gen_technique(name,tab_name,tab_nb,first_technique):
-
- if first_technique:
- intro="""
""".format(name)
- else:
- intro=""
- pass
-
if __name__ == '__main__':
# filen=sys.argv[1]
filen="cyberpnk.txt"
def parse(filen):
- tab,subtab="",""
- tab_nb,subtab_nb=0,0
- first_technique=True
+ root=Root()
+ active_tab,active_subtab=None,None
+ tab_nb,subtab_nb,skill_nb=1,1,1
try:
with open(filen) as f:
for line in f.readlines():
- if line[0]=="#": # section
- first_technique=True
- subtab_content=gen_tab(line[1:],tab_nb)
- tab=printable(line[1:])
- print(tab,subtab_content)
+ if line[0]=="@": # Tab
+ active_tab=Tab(line[1:-1],tab_nb)
+ root.addchild(active_tab)
tab_nb+=1
- elif line[0]=="@":
- # first_technique=True
- subtab_content=gen_subtab(line[1:],tab,tab_nb,subtab_nb)
- subtab=printable(line[1:])
- print(subtab,subtab_content)
- elif line[0]==":":
- tech_content=gen_technique(line[1:],tab,tab_nb,first_technique)
- # tech=printable()
+ subtab_nb=1
+ elif line[0]=="+":
+ active_subtab=SubTab(line[1:-1],subtab_nb)
+ active_tab.addchild(active_subtab)
+ subtab_nb+=1
+ skill_nb=1
+ elif line[0]=="-":
+ tech_content=Skill(line[1:-1],skill_nb)
+ active_subtab.addchild(tech_content)
+ skill_nb+=1
except FileNotFoundError:
print(filen,"was not found")
-
- parse(filen)
+ return root
+ root=parse(filen)
+ print(root.content())