mirror of
https://github.com/Oreolek/gamebookformat.git
synced 2024-05-14 23:18:19 +03:00
Improved LaTeX references.
Includes some ugly hacks like the empty sections to increase counter.
This commit is contained in:
parent
ad1bbe65ae
commit
5e187d3252
30
output.py
30
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."
|
||||
|
|
|
@ -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
|
||||
|
|
1
templates/debug/empty_section.debug
Normal file
1
templates/debug/empty_section.debug
Normal file
|
@ -0,0 +1 @@
|
|||
%(nr)d () - (EMPTY)
|
|
@ -1 +1 @@
|
|||
%(nr)d - %(text)s
|
||||
%(nr)d (%(name)s) - %(text)s
|
||||
|
|
1
templates/tex/empty_section.tex
Normal file
1
templates/tex/empty_section.tex
Normal file
|
@ -0,0 +1 @@
|
|||
\refstepcounter{sectionnr}
|
|
@ -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
|
||||
|
|
|
@ -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.
|
||||
|
8
todo.org
8
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
|
||||
|
|
Loading…
Reference in a new issue