1
0
Fork 0
mirror of https://github.com/Oreolek/gamebookformat.git synced 2024-06-26 03:41:04 +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:
Pelle Nilsson 2013-06-10 22:15:54 +02:00
parent 116ca6fad1
commit 54e03105e7
13 changed files with 42 additions and 17 deletions

View file

@ -7,20 +7,24 @@ pdf: $(examples:.gamebook=.pdf)
html: $(examples:.gamebook=.html)
debug: $(examples:.gamebook=.debug)
png: $(examples:.gamebook=.png)
txt: $(examples:.gamebook=.txt)
%.rtf: %.gamebook formatgamebook.py
%.rtf: %.gamebook *.py templates/rtf/*.rtf
./formatgamebook.py --verify $< $@
%.html: %.gamebook formatgamebook.py
%.html: %.gamebook *.py templates/html/*.html
./formatgamebook.py --verify $< $@
%.tex: %.gamebook formatgamebook.py
%.tex: %.gamebook *.py templates/tex/*.tex
./formatgamebook.py --verify $< $@
%.dot: %.gamebook formatgamebook.py
%.dot: %.gamebook *.py templates/dot/*.dot
./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 $< $@
%.pdf: %.tex

3
examples/format.gamebook Normal file
View 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.

View file

@ -50,6 +50,7 @@ OUTPUT_FORMATS = [
of('rtf', 'Rich Text Format'),
of('dot', 'Graphviz section flowchart'),
of('html', 'HTML+JS playable in browser'),
of('txt', 'Plain text'),
of('debug', 'Gamebook Debug Output'),
]

View file

@ -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. |
| 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. |
| Plain Text | .txt | Raw plain text without formatting. |
| Debug Plain Text | .debug | Plain text debug output of gamebook contents. |
More to be added.

View file

@ -18,14 +18,18 @@ class Templates (object):
for templatedir in self.templatedirs:
if self.has_template_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 ""
def has_template_in(self, templatedir, name):
def has_template_in(self, templatedir, name, subdir=None, extension=None):
# 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):
filename = self.get_template_filename(templatedir, name)
def get_in(self, templatedir, name, subdir=None, extension=None):
filename = self.get_template_filename(templatedir, name, subdir, extension)
f = open(filename, "r")
template = self.read_template(f);
f.close()
@ -48,7 +52,9 @@ class Templates (object):
else:
raise Exception("Bad preprocessor line '%s' in template." % line)
def get_template_filename(self, templatedir, name):
return os.path.join(templatedir,
self.extension,
name + "." + self.extension)
def get_template_filename(self, templatedir, name, subdir=None, extension=None):
if not subdir:
subdir = self.extension
if not extension:
extension = self.extension
return os.path.join(templatedir, subdir, name + "." + extension)

View file

@ -0,0 +1,2 @@
#include "sectionheading"
#include "sectionbody"

View file

@ -0,0 +1,2 @@
\ql %(text)s \
\

View file

@ -0,0 +1,2 @@
\b \qc %(nr)d
\b0\

View file

@ -1,9 +1,5 @@
\phantomsection
\refstepcounter{sectionnr}
\label{section%(nr)d}
\subsection*{\begin{center} \textbf{%(nr)d} \end{center}}
\noindent
%(text)s
\newline

View file

@ -0,0 +1,3 @@
\phantomsection
\refstepcounter{sectionnr}
\label{section%(nr)d}

View file

@ -0,0 +1 @@
%(nr)d

View file

@ -0,0 +1,2 @@
%(text)s

View file

@ -0,0 +1,2 @@
%(nr)