mirror of
https://github.com/Oreolek/gamebookformat.git
synced 2024-06-30 21:55:10 +03:00
Default templates. Added plain text output.
Made default section template constisting of sectionheader and sectionbody. Improved Makefile with more dependencies to rebuild examples when needed.
This commit is contained in:
parent
116ca6fad1
commit
54e03105e7
14
Makefile
14
Makefile
|
@ -7,20 +7,24 @@ pdf: $(examples:.gamebook=.pdf)
|
||||||
html: $(examples:.gamebook=.html)
|
html: $(examples:.gamebook=.html)
|
||||||
debug: $(examples:.gamebook=.debug)
|
debug: $(examples:.gamebook=.debug)
|
||||||
png: $(examples:.gamebook=.png)
|
png: $(examples:.gamebook=.png)
|
||||||
|
txt: $(examples:.gamebook=.txt)
|
||||||
|
|
||||||
%.rtf: %.gamebook formatgamebook.py
|
%.rtf: %.gamebook *.py templates/rtf/*.rtf
|
||||||
./formatgamebook.py --verify $< $@
|
./formatgamebook.py --verify $< $@
|
||||||
|
|
||||||
%.html: %.gamebook formatgamebook.py
|
%.html: %.gamebook *.py templates/html/*.html
|
||||||
./formatgamebook.py --verify $< $@
|
./formatgamebook.py --verify $< $@
|
||||||
|
|
||||||
%.tex: %.gamebook formatgamebook.py
|
%.tex: %.gamebook *.py templates/tex/*.tex
|
||||||
./formatgamebook.py --verify $< $@
|
./formatgamebook.py --verify $< $@
|
||||||
|
|
||||||
%.dot: %.gamebook formatgamebook.py
|
%.dot: %.gamebook *.py templates/dot/*.dot
|
||||||
./formatgamebook.py --verify $< $@
|
./formatgamebook.py --verify $< $@
|
||||||
|
|
||||||
%.debug: %.gamebook formatgamebook.py
|
%.debug: %.gamebook *.py templates/debug/*.debug
|
||||||
|
./formatgamebook.py --verify $< $@
|
||||||
|
|
||||||
|
%.txt: %.gamebook *.py templates/txt/*.txt
|
||||||
./formatgamebook.py --verify $< $@
|
./formatgamebook.py --verify $< $@
|
||||||
|
|
||||||
%.pdf: %.tex
|
%.pdf: %.tex
|
||||||
|
|
3
examples/format.gamebook
Normal file
3
examples/format.gamebook
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
* 1 start
|
||||||
|
This examples tests gamebook formatting, not so much game mechanics or
|
||||||
|
references. Currently there is nothing here really.
|
|
@ -50,6 +50,7 @@ OUTPUT_FORMATS = [
|
||||||
of('rtf', 'Rich Text Format'),
|
of('rtf', 'Rich Text Format'),
|
||||||
of('dot', 'Graphviz section flowchart'),
|
of('dot', 'Graphviz section flowchart'),
|
||||||
of('html', 'HTML+JS playable in browser'),
|
of('html', 'HTML+JS playable in browser'),
|
||||||
|
of('txt', 'Plain text'),
|
||||||
of('debug', 'Gamebook Debug Output'),
|
of('debug', 'Gamebook Debug Output'),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,7 @@ gamebook on paper or a screen (or for debugging it).
|
||||||
| Rich Text Format | .rtf | Supported because the Windhammer Prize requires it. |
|
| Rich Text Format | .rtf | Supported because the Windhammer Prize requires it. |
|
||||||
| Graphviz DOT | .dot | Use with the Graphviz dot tool to generate a flowchart graph of all sections in the gamebook. |
|
| Graphviz DOT | .dot | Use with the Graphviz dot tool to generate a flowchart graph of all sections in the gamebook. |
|
||||||
| HTML | .html | Play gamebook in browser. |
|
| HTML | .html | Play gamebook in browser. |
|
||||||
|
| Plain Text | .txt | Raw plain text without formatting. |
|
||||||
| Debug Plain Text | .debug | Plain text debug output of gamebook contents. |
|
| Debug Plain Text | .debug | Plain text debug output of gamebook contents. |
|
||||||
|
|
||||||
More to be added.
|
More to be added.
|
||||||
|
|
22
templates.py
22
templates.py
|
@ -18,14 +18,18 @@ class Templates (object):
|
||||||
for templatedir in self.templatedirs:
|
for templatedir in self.templatedirs:
|
||||||
if self.has_template_in(templatedir, name):
|
if self.has_template_in(templatedir, name):
|
||||||
return self.get_in(templatedir, name)
|
return self.get_in(templatedir, name)
|
||||||
|
elif self.has_template_in(templatedir, name, 'DEFAULT', 'txt'):
|
||||||
|
return self.get_in(templatedir, name, 'DEFAULT', 'txt')
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
def has_template_in(self, templatedir, name):
|
def has_template_in(self, templatedir, name, subdir=None, extension=None):
|
||||||
# FIXME better test
|
# FIXME better test
|
||||||
return os.path.exists(self.get_template_filename(templatedir, name))
|
return os.path.exists(self.get_template_filename(templatedir, name,
|
||||||
|
subdir,
|
||||||
|
extension))
|
||||||
|
|
||||||
def get_in(self, templatedir, name):
|
def get_in(self, templatedir, name, subdir=None, extension=None):
|
||||||
filename = self.get_template_filename(templatedir, name)
|
filename = self.get_template_filename(templatedir, name, subdir, extension)
|
||||||
f = open(filename, "r")
|
f = open(filename, "r")
|
||||||
template = self.read_template(f);
|
template = self.read_template(f);
|
||||||
f.close()
|
f.close()
|
||||||
|
@ -48,7 +52,9 @@ class Templates (object):
|
||||||
else:
|
else:
|
||||||
raise Exception("Bad preprocessor line '%s' in template." % line)
|
raise Exception("Bad preprocessor line '%s' in template." % line)
|
||||||
|
|
||||||
def get_template_filename(self, templatedir, name):
|
def get_template_filename(self, templatedir, name, subdir=None, extension=None):
|
||||||
return os.path.join(templatedir,
|
if not subdir:
|
||||||
self.extension,
|
subdir = self.extension
|
||||||
name + "." + self.extension)
|
if not extension:
|
||||||
|
extension = self.extension
|
||||||
|
return os.path.join(templatedir, subdir, name + "." + extension)
|
||||||
|
|
2
templates/DEFAULT/section.txt
Normal file
2
templates/DEFAULT/section.txt
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
#include "sectionheading"
|
||||||
|
#include "sectionbody"
|
2
templates/rtf/sectionbody.rtf
Normal file
2
templates/rtf/sectionbody.rtf
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
\ql %(text)s \
|
||||||
|
\
|
2
templates/rtf/sectionheading.rtf
Normal file
2
templates/rtf/sectionheading.rtf
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
\b \qc %(nr)d
|
||||||
|
\b0\
|
|
@ -1,9 +1,5 @@
|
||||||
\phantomsection
|
|
||||||
\refstepcounter{sectionnr}
|
|
||||||
\label{section%(nr)d}
|
|
||||||
\subsection*{\begin{center} \textbf{%(nr)d} \end{center}}
|
\subsection*{\begin{center} \textbf{%(nr)d} \end{center}}
|
||||||
|
|
||||||
\noindent
|
\noindent
|
||||||
%(text)s
|
%(text)s
|
||||||
\newline
|
\newline
|
||||||
|
|
3
templates/tex/sectionheading.tex
Normal file
3
templates/tex/sectionheading.tex
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
\phantomsection
|
||||||
|
\refstepcounter{sectionnr}
|
||||||
|
\label{section%(nr)d}
|
1
templates/txt/section_ref.txt
Normal file
1
templates/txt/section_ref.txt
Normal file
|
@ -0,0 +1 @@
|
||||||
|
%(nr)d
|
2
templates/txt/sectionbody.txt
Normal file
2
templates/txt/sectionbody.txt
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
%(text)s
|
||||||
|
|
2
templates/txt/sectionheading.txt
Normal file
2
templates/txt/sectionheading.txt
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
%(nr)
|
||||||
|
|
Loading…
Reference in a new issue