diff --git a/output.py b/output.py index faa70dd..7555669 100644 --- a/output.py +++ b/output.py @@ -8,31 +8,43 @@ class OutputFormat (object): self.templates = templates def write_begin(self, book, output): - print >> output, self.load_template("begin") % { + print >> output, self.format_with_template("begin", { 'max' : book.max - }, + }), def write_shuffled_sections(self, shuffled_sections, output): - for p in shuffled_sections.as_list[1:]: + for i, p in enumerate(shuffled_sections.as_list): if p: self.write_section(p, shuffled_sections, output) + elif i > 0: + self.write_empty_section(i, output) def write_section(self, section, shuffled_sections, output): refs = [] refsdict = ReferenceFormatter(section, shuffled_sections, - self.load_template("section_ref")) + self.format_with_template("section_ref")) formatted_text = section.format(refsdict) - print >> output, self.load_template("section") % { + print >> output, self.format_with_template("section", { 'nr' : shuffled_sections.to_nr[section], + 'name' : section.name, 'text' : formatted_text, 'refs' : '\n'.join(refsdict.getfound()) # hack for DOT output - }, + }), + + def write_empty_section(self, nr, output): + print >> output, self.format_with_template("empty_section", { + 'nr' : nr, + }), def write_end(self, book, output): - print >> output, self.load_template("end") % {}, + print >> output, self.format_with_template("end"), - def load_template(self, name): - return self.templates.get(name) + def format_with_template(self, name, values=None): + template = self.templates.get(name) + if values: + return template % values + else: + return template class ReferenceFormatter (object): "There is probably a better way, but this hack seems to work." diff --git a/templates.py b/templates.py index 79025ad..7f2abfb 100644 --- a/templates.py +++ b/templates.py @@ -14,8 +14,7 @@ class Templates (object): for templatedir in self.templatedirs: if self.has_template_in(templatedir, name): return self.get_in(templatedir, name) - raise Exception("Found no template " + name + " for " - + self.extension + ".") + return "" def has_template_in(self, templatedir, name): # FIXME better test diff --git a/templates/debug/empty_section.debug b/templates/debug/empty_section.debug new file mode 100644 index 0000000..ac7001d --- /dev/null +++ b/templates/debug/empty_section.debug @@ -0,0 +1 @@ +%(nr)d () - (EMPTY) diff --git a/templates/debug/section.debug b/templates/debug/section.debug index cc4bf3f..fafdc4f 100644 --- a/templates/debug/section.debug +++ b/templates/debug/section.debug @@ -1 +1 @@ -%(nr)d - %(text)s +%(nr)d (%(name)s) - %(text)s diff --git a/templates/tex/empty_section.tex b/templates/tex/empty_section.tex new file mode 100644 index 0000000..54314e4 --- /dev/null +++ b/templates/tex/empty_section.tex @@ -0,0 +1 @@ +\refstepcounter{sectionnr} diff --git a/templates/tex/section.tex b/templates/tex/section.tex index 5fc4b65..fd91d5a 100644 --- a/templates/tex/section.tex +++ b/templates/tex/section.tex @@ -1,6 +1,7 @@ -\subsection*{\begin{center} \textbf{%(nr)d} \end{center}} +\phantomsection \refstepcounter{sectionnr} \label{section%(nr)d} +\subsection*{\begin{center} \textbf{%(nr)d} \end{center}} \noindent %(text)s diff --git a/test.gamebook b/test.gamebook deleted file mode 100644 index 4599d83..0000000 --- a/test.gamebook +++ /dev/null @@ -1,14 +0,0 @@ -*1 start -This is where the adventure begins. You can go on to the -next section, see %(next)s or try the other instead, see %(other)s. - -*next -This is the next section. Go on to the end at %(end)s. - -*other -This is another section. You can try the next section now, -see %(next)s, or go on to the end, see %(end)s. - -*end -The end. - diff --git a/todo.org b/todo.org index a8eb823..78844c8 100644 --- a/todo.org +++ b/todo.org @@ -1,4 +1,4 @@ -* TODO [10/26] [38%] +* TODO [11/26] [42%] - [X] Debug output - [X] DOT output - [X] LaTeX output @@ -10,7 +10,8 @@ - [X] Add support for custom document templates. Fixed names and/or command-line options. - [X] Add section links in LaTeX output. -- [ ] Debug HTML output +- [X] Prettier LaTeX output + Look at how some existing gamebooks are formatted. - [ ] Inventory pick up items - [ ] Codewords set - [ ] Check if has inventory item @@ -19,12 +20,11 @@ - [ ] Optionally remove inventory item to make a choice - [ ] More formatting possibilities in sections Look at existing gamebooks to get ideas. -- [ ] Prettier LaTeX output - Look at how some existing gamebooks are formatted. - [ ] Command-line flag to set max section number to use - [ ] Dummy sections - [ ] Counters (life, money, whatever) create and set - [ ] Counters increase/decrease - [ ] Counters check - [ ] Document Gamebook format +- [ ] Debug HTML output - [ ] Higher level text-language for Gamebooks