1
0
Fork 0
mirror of https://github.com/Oreolek/gamebookformat.git synced 2024-05-14 15:08:19 +03:00

Option to only include sections with specific tag.

This commit is contained in:
Pelle Nilsson 2013-06-16 23:43:45 +02:00
parent bce260d073
commit fcf41b9869
16 changed files with 67 additions and 63 deletions

View file

@ -6,12 +6,17 @@ You can get here. Congratulations!
* nothere
You can not get here. Verification
should warn you about that, if enabled (with the --verify option).
should warn you about that.
* nothereeither :fake:
* notevenincluded :dummy:
This section is not even included in the output. Definitely
ignored when verifying. The section numbering is affected though.
That might be a bug.
* nothereeither :fake:
You can not get here either, but because it is tagged as
fake there will be no warning generated.
* seconddummy :fake:
* secondfake :fake:
Another fake section that is also ignored.

View file

@ -11,5 +11,5 @@ Adventure begins in section 1.
1 (start) - This examples tests gamebook formatting, not so much game mechanics or references. Currently there is nothing here really. This section contains some tricky characters to quote, like } and { and " and ' and \. HTML will probably not like <div> or &boom;. There should be an image below as well. If something broke, turn to 2, otherwise turn to 3. [IMG]testimage.png[/IMG]
2 (bad) - Bad.
3 (good) - Good!
4 (dum) - Sections tagged as dummy will not be visible in output at all.
4 () - (EMPTY)
END DEBUG OUTPUT

View file

@ -72,16 +72,6 @@ if (this.gamebook) {
if (this.gamebook) {
gamebook.addSection(3, document.getElementById('section3'));
}
</script><div class="section" id="section4">
<div class="sectionnumber" id="para4">4</div>
<div class="sectiontext">
Sections tagged as dummy will not be visible in output at all.
</div>
</div>
<script>
if (this.gamebook) {
gamebook.addSection(4, document.getElementById('section4'));
}
</script> <div id="collections" class="collections">
</div>
<div id="collectionTemplate" class="collectionTemplate">

View file

@ -45,9 +45,4 @@
\ql Good! \
\
\b \qc 4
\b0\
\ql Sections tagged as dummy will not be visible in output at all. \
\
}

View file

@ -76,12 +76,5 @@ Adventure begins in section 1.
\noindent
Good!
\vspace{1em}
\phantomsection
\refstepcounter{sectionnr}
\label{section4}
\subsection*{\begin{center} \textbf{4} \end{center}}
\noindent
Sections tagged as dummy will not be visible in output at all.
\vspace{1em}
\end{document}

View file

@ -18,6 +18,3 @@ Adventure begins in section 1.
3
Good!
4
Sections tagged as dummy will not be visible in output at all.

View file

@ -1,12 +1,13 @@
BEGIN DEBUG OUTPUT
Book title: Gamebook
Number of sections: 5
Number of sections: 6
Turn to 1 to begin.
1 (start) - It starts here. You can get to 5.
2 (seconddummy) - Another fake section that is also ignored.
1 (start) - It starts here. You can get to 6.
2 (secondfake) - Another fake section that is also ignored.
3 (nothereeither) - You can not get here either, but because it is tagged as fake there will be no warning generated.
4 (nothere) - You can not get here. Verification should warn you about that, if enabled (with the --verify option).
5 (here) - You can get here. Congratulations!
4 () - (EMPTY)
5 (nothere) - You can not get here. Verification should warn you about that.
6 (here) - You can get here. Congratulations!
END DEBUG OUTPUT

View file

@ -1,4 +1,4 @@
digraph gamebook {
1->5
1->6
}

View file

@ -33,7 +33,7 @@
<div class="section" id="section1">
<div class="sectionnumber" id="para1">1</div>
<div class="sectiontext">
It starts here. You can get to <a class="sectionref enabledlink" data-ref="5">5</a>.
It starts here. You can get to <a class="sectionref enabledlink" data-ref="6">6</a>.
</div>
</div>
<script>
@ -60,25 +60,25 @@ if (this.gamebook) {
if (this.gamebook) {
gamebook.addSection(3, document.getElementById('section3'));
}
</script><div class="section" id="section4">
<div class="sectionnumber" id="para4">4</div>
</script><div class="section" id="section5">
<div class="sectionnumber" id="para5">5</div>
<div class="sectiontext">
You can not get here. Verification should warn you about that, if enabled (with the --verify option).
You can not get here. Verification should warn you about that.
</div>
</div>
<script>
if (this.gamebook) {
gamebook.addSection(4, document.getElementById('section4'));
gamebook.addSection(5, document.getElementById('section5'));
}
</script><div class="section" id="section5">
<div class="sectionnumber" id="para5">5</div>
</script><div class="section" id="section6">
<div class="sectionnumber" id="para6">6</div>
<div class="sectiontext">
You can get here. Congratulations!
</div>
</div>
<script>
if (this.gamebook) {
gamebook.addSection(5, document.getElementById('section5'));
gamebook.addSection(6, document.getElementById('section6'));
}
</script> <div id="collections" class="collections">
</div>

View file

@ -14,7 +14,7 @@
\
\b \qc 1
\b0\
\ql It starts here. You can get to \b 5
\ql It starts here. You can get to \b 6
\b0
. \
\
@ -29,12 +29,12 @@
\ql You can not get here either, but because it is tagged as fake there will be no warning generated. \
\
\b \qc 4
\b \qc 5
\b0\
\ql You can not get here. Verification should warn you about that, if enabled (with the --verify option). \
\ql You can not get here. Verification should warn you about that. \
\
\b \qc 5
\b \qc 6
\b0\
\ql You can get here. Congratulations! \
\

View file

@ -42,7 +42,7 @@ Turn to 1 to begin.
\subsection*{\begin{center} \textbf{1} \end{center}}
\noindent
It starts here. You can get to \textbf{\autoref{section5}}.
It starts here. You can get to \textbf{\autoref{section6}}.
\vspace{1em}
\phantomsection
\refstepcounter{sectionnr}
@ -60,19 +60,20 @@ Turn to 1 to begin.
\noindent
You can not get here either, but because it is tagged as fake there will be no warning generated.
\vspace{1em}
\phantomsection
\refstepcounter{sectionnr}
\label{section4}
\subsection*{\begin{center} \textbf{4} \end{center}}
\noindent
You can not get here. Verification should warn you about that, if enabled (with the --verify option).
\vspace{1em}
\phantomsection
\refstepcounter{sectionnr}
\label{section5}
\subsection*{\begin{center} \textbf{5} \end{center}}
\noindent
You can not get here. Verification should warn you about that.
\vspace{1em}
\phantomsection
\refstepcounter{sectionnr}
\label{section6}
\subsection*{\begin{center} \textbf{6} \end{center}}
\noindent
You can get here. Congratulations!
\vspace{1em}

View file

@ -4,7 +4,7 @@
Turn to 1 to begin.
1
It starts here. You can get to 5.
It starts here. You can get to 6.
2
Another fake section that is also ignored.
@ -12,9 +12,9 @@ Turn to 1 to begin.
3
You can not get here either, but because it is tagged as fake there will be no warning generated.
4
You can not get here. Verification should warn you about that, if enabled (with the --verify option).
5
You can not get here. Verification should warn you about that.
6
You can get here. Congratulations!

View file

@ -67,9 +67,10 @@ def format_gamebook(inputfilenames,
outputfilename,
import_default_map_file,
templatedirs,
shuffle):
shuffle,
includetag):
output_format = make_output(outputfilename, templatedirs)
book = sections.Book(make_bookid(outputfilename))
book = sections.Book(make_bookid(outputfilename), includetag)
for inputfilename in inputfilenames:
parse_file_to_book(open(inputfilename, 'r'), book)
if import_default_map_file:
@ -185,6 +186,8 @@ if __name__ == '__main__':
help='input gamebook file (eg test.gamebook)')
ap.add_argument('outputfile', metavar='outputfile',
help='output file (eg test.tex or test.rtf)')
ap.add_argument('-i', '--include', action='store', metavar='T',
dest='includetag', help='only include sections with tag')
ap.add_argument('-M', '--no-default-map', action='store_false',
dest='import_default_map_file',
help='ignore default map file')
@ -203,4 +206,5 @@ if __name__ == '__main__':
args.outputfile,
args.import_default_map_file,
templatedirs,
args.shuffle)
args.shuffle,
args.includetag)

View file

@ -12,6 +12,7 @@ gamebook on paper or a screen (or for debugging it).
:
: optional arguments:
: -h, --help show this help message and exit
: -i T, --include T only include sections with tag
: -M, --no-default-map ignore default map file
: -t D, --template D add custom template dir
: -S, --no-shuffle do not shuffle sections

View file

@ -58,12 +58,13 @@ STR_BOOK_CONFIG = set(['id', 'title', 'author', 'starttext', 'hideintrotext',
INT_BOOK_CONFIG = set(['max'])
class Book:
def __init__(self, bookid="gamebook"):
def __init__(self, bookid='gamebook', includetag=None):
self.sections = []
self.introsections = []
self.from_name = {}
self.nr_sections = {}
self.codewords = set()
self.includetag = includetag
self.config = {'max' : 0,
'title' : 'Gamebook',
'author' : '',
@ -82,6 +83,8 @@ class Book:
raise Exception("Unknown book option '%s'." % name)
def add(self, section):
if self.includetag and not section.hastag(self.includetag):
return
if section.name in self.from_name:
raise Exception('Duplicate section names (%s) not allowed.' %
section.name)

View file

@ -35,5 +35,19 @@ class TestBook(TestCase):
self.assertEqual(b.nr_sections, {})
self.assertEqual(b.config['max'], 0)
def test_includetag(self):
b = sections.Book(includetag='test')
sec = sections.Section("nnn", "text")
sec.add_tags(['some', 'test', 'other'])
b.add(sec)
self.assertEqual(b.sections, [sec])
def test_excludetag(self):
b = sections.Book(includetag='test')
sec = sections.Section("nnn", "text")
sec.add_tags(['some', 'other'])
b.add(sec)
self.assertEqual(b.sections, [])
if __name__ == '__main__':
unittest.main()