diff --git a/Makefile b/Makefile index 12b81e8..9e259e1 100644 --- a/Makefile +++ b/Makefile @@ -80,7 +80,7 @@ clean: examples/*.txt examples/*.debug examples/*.log \ examples/*.pdf examples/*.out *~ examples/*~ *.pyc \ examples/*.dot examples/*.aux examples/*.toc $(png) \ - examples/*.map templates/*~ templates/*/*~ \ + $(map) templates/*~ templates/*/*~ \ $(examples:.gamebook=.png) readme.html \ examples/*.js examples/*.css diff --git a/examples/withmaps.gamebook b/examples/withmaps.gamebook new file mode 100644 index 0000000..26088d8 --- /dev/null +++ b/examples/withmaps.gamebook @@ -0,0 +1,9 @@ +title = Example Gamebook With Maps +author = Pelle Nilsson + +* start +This should have number 10, as specified in first map file. +The end, at [[end]], should be at 99. + +* end +Number 99, as specified in second map file. diff --git a/examples/withmaps.gamebook.options b/examples/withmaps.gamebook.options new file mode 100644 index 0000000..f73ae57 --- /dev/null +++ b/examples/withmaps.gamebook.options @@ -0,0 +1 @@ +-M -m examples/withmaps1.map -m examples/withmaps2.map \ No newline at end of file diff --git a/examples/withmaps.map b/examples/withmaps.map new file mode 100644 index 0000000..acb7d93 --- /dev/null +++ b/examples/withmaps.map @@ -0,0 +1 @@ +{"Dummy": 98, "end": 99, "start": 10} \ No newline at end of file diff --git a/examples/withmaps1.map b/examples/withmaps1.map new file mode 100644 index 0000000..017892d --- /dev/null +++ b/examples/withmaps1.map @@ -0,0 +1 @@ +{"start" : 10} \ No newline at end of file diff --git a/examples/withmaps2.map b/examples/withmaps2.map new file mode 100644 index 0000000..6e5103b --- /dev/null +++ b/examples/withmaps2.map @@ -0,0 +1 @@ +{"end" : 99} \ No newline at end of file diff --git a/expected/bgg.tex b/expected/bgg.tex index e8b291a..ee85fe9 100644 --- a/expected/bgg.tex +++ b/expected/bgg.tex @@ -27,12 +27,11 @@ \maketitle +\clearpage + \thispagestyle{empty} \pagestyle{empty} - -\clearpage - \subsection*{\begin{center} \textbf{Introduction} \end{center}} diff --git a/expected/codewords.tex b/expected/codewords.tex index e72a63c..75730eb 100644 --- a/expected/codewords.tex +++ b/expected/codewords.tex @@ -27,13 +27,12 @@ \maketitle +\clearpage + \thispagestyle{empty} \pagestyle{empty} -\clearpage - - Turn to 1 to begin. \phantomsection diff --git a/expected/counters.tex b/expected/counters.tex index 018b4ae..daaacf2 100644 --- a/expected/counters.tex +++ b/expected/counters.tex @@ -27,12 +27,11 @@ \maketitle +\clearpage + \thispagestyle{empty} \pagestyle{empty} - -\clearpage - \subsection*{\begin{center} \textbf{Introduction} \end{center}} diff --git a/expected/format.tex b/expected/format.tex index b1dc065..32c4119 100644 --- a/expected/format.tex +++ b/expected/format.tex @@ -27,12 +27,11 @@ \maketitle +\clearpage + \thispagestyle{empty} \pagestyle{empty} - -\clearpage - \subsection*{\begin{center} \textbf{Introduction} \end{center}} diff --git a/expected/items.tex b/expected/items.tex index ea96b0b..db769ce 100644 --- a/expected/items.tex +++ b/expected/items.tex @@ -27,13 +27,12 @@ \maketitle +\clearpage + \thispagestyle{empty} \pagestyle{empty} -\clearpage - - Turn to 1 to begin. \phantomsection diff --git a/expected/letter.tex b/expected/letter.tex index 277aed2..083b018 100644 --- a/expected/letter.tex +++ b/expected/letter.tex @@ -26,13 +26,12 @@ \maketitle +\clearpage + \thispagestyle{empty} \pagestyle{empty} -\clearpage - - Turn to 1 to begin. \phantomsection diff --git a/expected/references.tex b/expected/references.tex index 0f3b24f..8ec54cb 100644 --- a/expected/references.tex +++ b/expected/references.tex @@ -27,12 +27,11 @@ \maketitle +\clearpage + \thispagestyle{empty} \pagestyle{empty} - -\clearpage - \subsection*{\begin{center} \textbf{Introduction} \end{center}} diff --git a/expected/trade.tex b/expected/trade.tex index ece7f65..b7a0f10 100644 --- a/expected/trade.tex +++ b/expected/trade.tex @@ -27,12 +27,11 @@ \maketitle +\clearpage + \thispagestyle{empty} \pagestyle{empty} - -\clearpage - \subsection*{\begin{center} \textbf{Introduction} \end{center}} diff --git a/expected/unreachable.tex b/expected/unreachable.tex index 657d30f..d12e636 100644 --- a/expected/unreachable.tex +++ b/expected/unreachable.tex @@ -27,13 +27,12 @@ \maketitle +\clearpage + \thispagestyle{empty} \pagestyle{empty} -\clearpage - - Turn to 1 to begin. \phantomsection diff --git a/expected/withdemo.tex b/expected/withdemo.tex index b6a81c8..1b5d962 100644 --- a/expected/withdemo.tex +++ b/expected/withdemo.tex @@ -27,13 +27,12 @@ \maketitle +\clearpage + \thispagestyle{empty} \pagestyle{empty} -\clearpage - - Turn to 1 to begin. \phantomsection diff --git a/expected/withmaps.debug b/expected/withmaps.debug new file mode 100644 index 0000000..d11db93 --- /dev/null +++ b/expected/withmaps.debug @@ -0,0 +1,106 @@ +BEGIN DEBUG OUTPUT +Book title: Example Gamebook With Maps +Number of sections: 99 + + +Turn to 1 to begin. +1 () - (EMPTY) +2 () - (EMPTY) +3 () - (EMPTY) +4 () - (EMPTY) +5 () - (EMPTY) +6 () - (EMPTY) +7 () - (EMPTY) +8 () - (EMPTY) +9 () - (EMPTY) +10 (start) - This should have number 10, as specified in first map file. The end, at 99, should be at 99. +11 () - (EMPTY) +12 () - (EMPTY) +13 () - (EMPTY) +14 () - (EMPTY) +15 () - (EMPTY) +16 () - (EMPTY) +17 () - (EMPTY) +18 () - (EMPTY) +19 () - (EMPTY) +20 () - (EMPTY) +21 () - (EMPTY) +22 () - (EMPTY) +23 () - (EMPTY) +24 () - (EMPTY) +25 () - (EMPTY) +26 () - (EMPTY) +27 () - (EMPTY) +28 () - (EMPTY) +29 () - (EMPTY) +30 () - (EMPTY) +31 () - (EMPTY) +32 () - (EMPTY) +33 () - (EMPTY) +34 () - (EMPTY) +35 () - (EMPTY) +36 () - (EMPTY) +37 () - (EMPTY) +38 () - (EMPTY) +39 () - (EMPTY) +40 () - (EMPTY) +41 () - (EMPTY) +42 () - (EMPTY) +43 () - (EMPTY) +44 () - (EMPTY) +45 () - (EMPTY) +46 () - (EMPTY) +47 () - (EMPTY) +48 () - (EMPTY) +49 () - (EMPTY) +50 () - (EMPTY) +51 () - (EMPTY) +52 () - (EMPTY) +53 () - (EMPTY) +54 () - (EMPTY) +55 () - (EMPTY) +56 () - (EMPTY) +57 () - (EMPTY) +58 () - (EMPTY) +59 () - (EMPTY) +60 () - (EMPTY) +61 () - (EMPTY) +62 () - (EMPTY) +63 () - (EMPTY) +64 () - (EMPTY) +65 () - (EMPTY) +66 () - (EMPTY) +67 () - (EMPTY) +68 () - (EMPTY) +69 () - (EMPTY) +70 () - (EMPTY) +71 () - (EMPTY) +72 () - (EMPTY) +73 () - (EMPTY) +74 () - (EMPTY) +75 () - (EMPTY) +76 () - (EMPTY) +77 () - (EMPTY) +78 () - (EMPTY) +79 () - (EMPTY) +80 () - (EMPTY) +81 () - (EMPTY) +82 () - (EMPTY) +83 () - (EMPTY) +84 () - (EMPTY) +85 () - (EMPTY) +86 () - (EMPTY) +87 () - (EMPTY) +88 () - (EMPTY) +89 () - (EMPTY) +90 () - (EMPTY) +91 () - (EMPTY) +92 () - (EMPTY) +93 () - (EMPTY) +94 () - (EMPTY) +95 () - (EMPTY) +96 () - (EMPTY) +97 () - (EMPTY) +98 () - (EMPTY) +99 (end) - Number 99, as specified in second map file. +END DEBUG OUTPUT diff --git a/expected/withmaps.dot b/expected/withmaps.dot new file mode 100644 index 0000000..63d564e --- /dev/null +++ b/expected/withmaps.dot @@ -0,0 +1,4 @@ +digraph gamebook { + + 10->99 +} diff --git a/expected/withmaps.html b/expected/withmaps.html new file mode 100644 index 0000000..e237d0d --- /dev/null +++ b/expected/withmaps.html @@ -0,0 +1,79 @@ + + + + + + Example Gamebook With Maps + + + + + + +
+ + + + + +
+
10
+
+ This should have number 10, as specified in first map file. The end, at 99, should be at 99. +
+
+
+
99
+
+ Number 99, as specified in second map file. +
+
+
+
+
+ + +
+
+
+
+
+ + +
+ + + + + + diff --git a/expected/withmaps.rtf b/expected/withmaps.rtf new file mode 100644 index 0000000..5e500b6 --- /dev/null +++ b/expected/withmaps.rtf @@ -0,0 +1,27 @@ +{\rtf1\ansi\ansicpg1252\cocoartf1038\cocoasubrtf360 +{\fonttbl\f0\fswiss\fcharset0 Helvetica;} +{\colortbl;\red255\green255\blue255;} +\paperw11900\paperh16840\margl1440\margr1440\vieww14140\viewh14860\viewkind0 +\pard\tx566\tx1133\tx1700\tx2267\tx2834\tx3401\tx3968\tx4535\tx5102\tx5669\tx6236\tx6803\ql\qnatural\pardirnatural + +\f0\b\fs24 \cf0 + +\b \qc Example Gamebook With Maps +\b0\ + +\b Turn to 1 to begin. +\b0\ +\ +\b \qc 10 +\b0\ +\ql This should have number 10, as specified in first map file. The end, at \b 99 +\b0 +, should be at 99. \ +\ + +\b \qc 99 +\b0\ +\ql Number 99, as specified in second map file. \ +\ + +} diff --git a/expected/withmaps.tex b/expected/withmaps.tex new file mode 100644 index 0000000..6806e52 --- /dev/null +++ b/expected/withmaps.tex @@ -0,0 +1,151 @@ +\documentclass[a5paper,onecolumn]{book} + +\usepackage[utf8]{inputenc} +\usepackage[T1]{fontenc} +\usepackage[hidelinks]{hyperref} +\usepackage{graphicx} + +\usepackage[top=3.3cm, bottom=3.3cm, left=2cm, right=2cm]{geometry} +\newif\ifpdf +\ifx\pdfoutput\undefined + \pdffalse +\else + \ifnum\pdfoutput=1 + \pdftrue + \else + \pdffalse + \fi +\fi + +\title{Example Gamebook With Maps} +\author{Pelle Nilsson} +\date{} + +\newcounter{sectionnr} + +\begin{document} + +\maketitle + +\clearpage + +\thispagestyle{empty} + +\pagestyle{empty} + + +Turn to 1 to begin. +\refstepcounter{sectionnr} +\refstepcounter{sectionnr} +\refstepcounter{sectionnr} +\refstepcounter{sectionnr} +\refstepcounter{sectionnr} +\refstepcounter{sectionnr} +\refstepcounter{sectionnr} +\refstepcounter{sectionnr} +\refstepcounter{sectionnr} +\phantomsection +\refstepcounter{sectionnr} +\label{section10} +\subsection*{\begin{center} \textbf{10} \end{center}} + + \noindent + This should have number 10, as specified in first map file. The end, at \textbf{\autoref{section99}}, should be at 99. +\vspace{1em} +\refstepcounter{sectionnr} +\refstepcounter{sectionnr} +\refstepcounter{sectionnr} +\refstepcounter{sectionnr} +\refstepcounter{sectionnr} +\refstepcounter{sectionnr} +\refstepcounter{sectionnr} +\refstepcounter{sectionnr} +\refstepcounter{sectionnr} +\refstepcounter{sectionnr} +\refstepcounter{sectionnr} +\refstepcounter{sectionnr} +\refstepcounter{sectionnr} +\refstepcounter{sectionnr} +\refstepcounter{sectionnr} +\refstepcounter{sectionnr} +\refstepcounter{sectionnr} +\refstepcounter{sectionnr} +\refstepcounter{sectionnr} +\refstepcounter{sectionnr} +\refstepcounter{sectionnr} +\refstepcounter{sectionnr} +\refstepcounter{sectionnr} +\refstepcounter{sectionnr} +\refstepcounter{sectionnr} +\refstepcounter{sectionnr} +\refstepcounter{sectionnr} +\refstepcounter{sectionnr} +\refstepcounter{sectionnr} +\refstepcounter{sectionnr} +\refstepcounter{sectionnr} +\refstepcounter{sectionnr} +\refstepcounter{sectionnr} +\refstepcounter{sectionnr} +\refstepcounter{sectionnr} +\refstepcounter{sectionnr} +\refstepcounter{sectionnr} +\refstepcounter{sectionnr} +\refstepcounter{sectionnr} +\refstepcounter{sectionnr} +\refstepcounter{sectionnr} +\refstepcounter{sectionnr} +\refstepcounter{sectionnr} +\refstepcounter{sectionnr} +\refstepcounter{sectionnr} +\refstepcounter{sectionnr} +\refstepcounter{sectionnr} +\refstepcounter{sectionnr} +\refstepcounter{sectionnr} +\refstepcounter{sectionnr} +\refstepcounter{sectionnr} +\refstepcounter{sectionnr} +\refstepcounter{sectionnr} +\refstepcounter{sectionnr} +\refstepcounter{sectionnr} +\refstepcounter{sectionnr} +\refstepcounter{sectionnr} +\refstepcounter{sectionnr} +\refstepcounter{sectionnr} +\refstepcounter{sectionnr} +\refstepcounter{sectionnr} +\refstepcounter{sectionnr} +\refstepcounter{sectionnr} +\refstepcounter{sectionnr} +\refstepcounter{sectionnr} +\refstepcounter{sectionnr} +\refstepcounter{sectionnr} +\refstepcounter{sectionnr} +\refstepcounter{sectionnr} +\refstepcounter{sectionnr} +\refstepcounter{sectionnr} +\refstepcounter{sectionnr} +\refstepcounter{sectionnr} +\refstepcounter{sectionnr} +\refstepcounter{sectionnr} +\refstepcounter{sectionnr} +\refstepcounter{sectionnr} +\refstepcounter{sectionnr} +\refstepcounter{sectionnr} +\refstepcounter{sectionnr} +\refstepcounter{sectionnr} +\refstepcounter{sectionnr} +\refstepcounter{sectionnr} +\refstepcounter{sectionnr} +\refstepcounter{sectionnr} +\refstepcounter{sectionnr} +\refstepcounter{sectionnr} +\refstepcounter{sectionnr} +\phantomsection +\refstepcounter{sectionnr} +\label{section99} +\subsection*{\begin{center} \textbf{99} \end{center}} + + \noindent + Number 99, as specified in second map file. +\vspace{1em} +\end{document} diff --git a/expected/withmaps.txt b/expected/withmaps.txt new file mode 100644 index 0000000..7586d5c --- /dev/null +++ b/expected/withmaps.txt @@ -0,0 +1,11 @@ + Example Gamebook With Maps + + + +Turn to 1 to begin. +10 + This should have number 10, as specified in first map file. The end, at 99, should be at 99. + +99 + Number 99, as specified in second map file. + diff --git a/expected/withoutdemo.tex b/expected/withoutdemo.tex index fd7f3c0..5923f99 100644 --- a/expected/withoutdemo.tex +++ b/expected/withoutdemo.tex @@ -27,13 +27,12 @@ \maketitle +\clearpage + \thispagestyle{empty} \pagestyle{empty} -\clearpage - - Turn to 1 to begin. \phantomsection diff --git a/formatgamebook.py b/formatgamebook.py index 0e03e3c..1841476 100755 --- a/formatgamebook.py +++ b/formatgamebook.py @@ -68,13 +68,15 @@ def format_gamebook(inputfilenames, import_default_map_file, templatedirs, shuffle, - includetag): + includetag, + mapfilenames): output_format = make_output(outputfilename, templatedirs) book = sections.Book(make_bookid(outputfilename), includetag) for inputfilename in inputfilenames: parse_file_to_book(open(inputfilename, 'r'), book) if import_default_map_file: import_default_nr_map(outputfilename, book) + import_nr_maps(mapfilenames, book) write_book(book, shuffle, output_format, outputfilename) def make_bookid(filename): @@ -162,7 +164,13 @@ def write_book(book, shuffle, output_format, outputfilename): save_section_mapping(shuffled_sections, outputfilename) def import_default_nr_map(outputfilename, book): - mapfilename = make_default_map_filename(outputfilename) + import_nr_map(make_default_map_filename(outputfilename), book) + +def import_nr_maps(mapfilenames, book): + for m in mapfilenames: + import_nr_map(m, book) + +def import_nr_map(mapfilename, book): if os.path.exists(mapfilename): #FIXME better check for name,nr in json.load(open(mapfilename)).iteritems(): book.force_section_nr(name, nr) @@ -198,6 +206,8 @@ if __name__ == '__main__': ap.add_argument('-S', '--no-shuffle', action='store_false', dest='shuffle', help='do not shuffle sections') + ap.add_argument('-m', '--map-file', metavar='F', dest='mapfiles', + action='append', help='number map file') args = ap.parse_args() templatedirs = ['templates', os.path.join(os.path.dirname(sys.argv[0]), 'templates')] @@ -213,4 +223,5 @@ if __name__ == '__main__': args.import_default_map_file, templatedirs, args.shuffle, - args.includetag) + args.includetag, + args.mapfiles or []) diff --git a/readme.org b/readme.org index 8bcaf10..3f22af1 100644 --- a/readme.org +++ b/readme.org @@ -17,7 +17,7 @@ gamebook on paper or a screen (or for debugging it). : -t D, --template D add custom template dir : -o D, --option D add template override options dir : -S, --no-shuffle do not shuffle sections - +: -m F, --map-file F number map file ** Supported Output Formats | Name | Extension | Description | @@ -49,6 +49,23 @@ produce LaTeX files in Letter size rather than the default A5 size. | letter | tex | Letter paper size documents (PDF). | | static | html | Remove script link from HTML output. | +** Number Map Files +Whenever formatgamebook.py runs it looks for a file with the same +name as the output file, but with a .map suffix (eg output.map if +the output file is output.html). That file is expected to contain +a JSON object mapping section names to numbers, and all sections +included in that file are given those numbers rather than being +randomly shuffled like other paragraphs. You can also add more +map files using the --map-file (or -m) option on the command-line. +The -M flag disables the default map file. Unless it has been +disabled a default map file is also written, containing all +the sections output. This way if you generate the same output +file (or files with the same name but different types) they +always get the same section numbers assigned. The generated +map file can also be used from other scripts to easily read +what numbers were assigned to sections, if you need to +use the number of some section for something outside of +the gamebook itself. ** Gamebook Format The input file expected by the formatgamebook.py script must be in a