mirror of
https://github.com/Oreolek/gamebookformat.git
synced 2024-06-26 03:41:04 +03:00
Option to only include sections with specific tag.
This commit is contained in:
parent
bce260d073
commit
fcf41b9869
|
@ -6,12 +6,17 @@ You can get here. Congratulations!
|
||||||
|
|
||||||
* nothere
|
* nothere
|
||||||
You can not get here. Verification
|
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
|
You can not get here either, but because it is tagged as
|
||||||
fake there will be no warning generated.
|
fake there will be no warning generated.
|
||||||
|
|
||||||
* seconddummy :fake:
|
* secondfake :fake:
|
||||||
Another fake section that is also ignored.
|
Another fake section that is also ignored.
|
||||||
|
|
||||||
|
|
|
@ -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]
|
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.
|
2 (bad) - Bad.
|
||||||
3 (good) - Good!
|
3 (good) - Good!
|
||||||
4 (dum) - Sections tagged as dummy will not be visible in output at all.
|
4 () - (EMPTY)
|
||||||
END DEBUG OUTPUT
|
END DEBUG OUTPUT
|
||||||
|
|
|
@ -72,16 +72,6 @@ if (this.gamebook) {
|
||||||
if (this.gamebook) {
|
if (this.gamebook) {
|
||||||
gamebook.addSection(3, document.getElementById('section3'));
|
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">
|
</script> <div id="collections" class="collections">
|
||||||
</div>
|
</div>
|
||||||
<div id="collectionTemplate" class="collectionTemplate">
|
<div id="collectionTemplate" class="collectionTemplate">
|
||||||
|
|
|
@ -45,9 +45,4 @@
|
||||||
\ql Good! \
|
\ql Good! \
|
||||||
\
|
\
|
||||||
|
|
||||||
\b \qc 4
|
|
||||||
\b0\
|
|
||||||
\ql Sections tagged as dummy will not be visible in output at all. \
|
|
||||||
\
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -76,12 +76,5 @@ Adventure begins in section 1.
|
||||||
\noindent
|
\noindent
|
||||||
Good!
|
Good!
|
||||||
\vspace{1em}
|
\vspace{1em}
|
||||||
\phantomsection
|
|
||||||
\refstepcounter{sectionnr}
|
\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}
|
\end{document}
|
||||||
|
|
|
@ -18,6 +18,3 @@ Adventure begins in section 1.
|
||||||
3
|
3
|
||||||
Good!
|
Good!
|
||||||
|
|
||||||
4
|
|
||||||
Sections tagged as dummy will not be visible in output at all.
|
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,13 @@
|
||||||
BEGIN DEBUG OUTPUT
|
BEGIN DEBUG OUTPUT
|
||||||
Book title: Gamebook
|
Book title: Gamebook
|
||||||
Number of sections: 5
|
Number of sections: 6
|
||||||
|
|
||||||
|
|
||||||
Turn to 1 to begin.
|
Turn to 1 to begin.
|
||||||
1 (start) - It starts here. You can get to 5.
|
1 (start) - It starts here. You can get to 6.
|
||||||
2 (seconddummy) - Another fake section that is also ignored.
|
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.
|
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).
|
4 () - (EMPTY)
|
||||||
5 (here) - You can get here. Congratulations!
|
5 (nothere) - You can not get here. Verification should warn you about that.
|
||||||
|
6 (here) - You can get here. Congratulations!
|
||||||
END DEBUG OUTPUT
|
END DEBUG OUTPUT
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
digraph gamebook {
|
digraph gamebook {
|
||||||
|
|
||||||
1->5
|
1->6
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,7 +33,7 @@
|
||||||
<div class="section" id="section1">
|
<div class="section" id="section1">
|
||||||
<div class="sectionnumber" id="para1">1</div>
|
<div class="sectionnumber" id="para1">1</div>
|
||||||
<div class="sectiontext">
|
<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>
|
||||||
</div>
|
</div>
|
||||||
<script>
|
<script>
|
||||||
|
@ -60,25 +60,25 @@ if (this.gamebook) {
|
||||||
if (this.gamebook) {
|
if (this.gamebook) {
|
||||||
gamebook.addSection(3, document.getElementById('section3'));
|
gamebook.addSection(3, document.getElementById('section3'));
|
||||||
}
|
}
|
||||||
</script><div class="section" id="section4">
|
</script><div class="section" id="section5">
|
||||||
<div class="sectionnumber" id="para4">4</div>
|
<div class="sectionnumber" id="para5">5</div>
|
||||||
<div class="sectiontext">
|
<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>
|
||||||
</div>
|
</div>
|
||||||
<script>
|
<script>
|
||||||
if (this.gamebook) {
|
if (this.gamebook) {
|
||||||
gamebook.addSection(4, document.getElementById('section4'));
|
gamebook.addSection(5, document.getElementById('section5'));
|
||||||
}
|
}
|
||||||
</script><div class="section" id="section5">
|
</script><div class="section" id="section6">
|
||||||
<div class="sectionnumber" id="para5">5</div>
|
<div class="sectionnumber" id="para6">6</div>
|
||||||
<div class="sectiontext">
|
<div class="sectiontext">
|
||||||
You can get here. Congratulations!
|
You can get here. Congratulations!
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<script>
|
<script>
|
||||||
if (this.gamebook) {
|
if (this.gamebook) {
|
||||||
gamebook.addSection(5, document.getElementById('section5'));
|
gamebook.addSection(6, document.getElementById('section6'));
|
||||||
}
|
}
|
||||||
</script> <div id="collections" class="collections">
|
</script> <div id="collections" class="collections">
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
\
|
\
|
||||||
\b \qc 1
|
\b \qc 1
|
||||||
\b0\
|
\b0\
|
||||||
\ql It starts here. You can get to \b 5
|
\ql It starts here. You can get to \b 6
|
||||||
\b0
|
\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. \
|
\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\
|
\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\
|
\b0\
|
||||||
\ql You can get here. Congratulations! \
|
\ql You can get here. Congratulations! \
|
||||||
\
|
\
|
||||||
|
|
|
@ -42,7 +42,7 @@ Turn to 1 to begin.
|
||||||
\subsection*{\begin{center} \textbf{1} \end{center}}
|
\subsection*{\begin{center} \textbf{1} \end{center}}
|
||||||
|
|
||||||
\noindent
|
\noindent
|
||||||
It starts here. You can get to \textbf{\autoref{section5}}.
|
It starts here. You can get to \textbf{\autoref{section6}}.
|
||||||
\vspace{1em}
|
\vspace{1em}
|
||||||
\phantomsection
|
\phantomsection
|
||||||
\refstepcounter{sectionnr}
|
\refstepcounter{sectionnr}
|
||||||
|
@ -60,19 +60,20 @@ Turn to 1 to begin.
|
||||||
\noindent
|
\noindent
|
||||||
You can not get here either, but because it is tagged as fake there will be no warning generated.
|
You can not get here either, but because it is tagged as fake there will be no warning generated.
|
||||||
\vspace{1em}
|
\vspace{1em}
|
||||||
\phantomsection
|
|
||||||
\refstepcounter{sectionnr}
|
\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
|
\phantomsection
|
||||||
\refstepcounter{sectionnr}
|
\refstepcounter{sectionnr}
|
||||||
\label{section5}
|
\label{section5}
|
||||||
\subsection*{\begin{center} \textbf{5} \end{center}}
|
\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
|
\noindent
|
||||||
You can get here. Congratulations!
|
You can get here. Congratulations!
|
||||||
\vspace{1em}
|
\vspace{1em}
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
Turn to 1 to begin.
|
Turn to 1 to begin.
|
||||||
1
|
1
|
||||||
It starts here. You can get to 5.
|
It starts here. You can get to 6.
|
||||||
|
|
||||||
2
|
2
|
||||||
Another fake section that is also ignored.
|
Another fake section that is also ignored.
|
||||||
|
@ -12,9 +12,9 @@ Turn to 1 to begin.
|
||||||
3
|
3
|
||||||
You can not get here either, but because it is tagged as fake there will be no warning generated.
|
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
|
5
|
||||||
|
You can not get here. Verification should warn you about that.
|
||||||
|
|
||||||
|
6
|
||||||
You can get here. Congratulations!
|
You can get here. Congratulations!
|
||||||
|
|
||||||
|
|
|
@ -67,9 +67,10 @@ def format_gamebook(inputfilenames,
|
||||||
outputfilename,
|
outputfilename,
|
||||||
import_default_map_file,
|
import_default_map_file,
|
||||||
templatedirs,
|
templatedirs,
|
||||||
shuffle):
|
shuffle,
|
||||||
|
includetag):
|
||||||
output_format = make_output(outputfilename, templatedirs)
|
output_format = make_output(outputfilename, templatedirs)
|
||||||
book = sections.Book(make_bookid(outputfilename))
|
book = sections.Book(make_bookid(outputfilename), includetag)
|
||||||
for inputfilename in inputfilenames:
|
for inputfilename in inputfilenames:
|
||||||
parse_file_to_book(open(inputfilename, 'r'), book)
|
parse_file_to_book(open(inputfilename, 'r'), book)
|
||||||
if import_default_map_file:
|
if import_default_map_file:
|
||||||
|
@ -185,6 +186,8 @@ if __name__ == '__main__':
|
||||||
help='input gamebook file (eg test.gamebook)')
|
help='input gamebook file (eg test.gamebook)')
|
||||||
ap.add_argument('outputfile', metavar='outputfile',
|
ap.add_argument('outputfile', metavar='outputfile',
|
||||||
help='output file (eg test.tex or test.rtf)')
|
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',
|
ap.add_argument('-M', '--no-default-map', action='store_false',
|
||||||
dest='import_default_map_file',
|
dest='import_default_map_file',
|
||||||
help='ignore default map file')
|
help='ignore default map file')
|
||||||
|
@ -203,4 +206,5 @@ if __name__ == '__main__':
|
||||||
args.outputfile,
|
args.outputfile,
|
||||||
args.import_default_map_file,
|
args.import_default_map_file,
|
||||||
templatedirs,
|
templatedirs,
|
||||||
args.shuffle)
|
args.shuffle,
|
||||||
|
args.includetag)
|
||||||
|
|
|
@ -12,6 +12,7 @@ gamebook on paper or a screen (or for debugging it).
|
||||||
:
|
:
|
||||||
: optional arguments:
|
: optional arguments:
|
||||||
: -h, --help show this help message and exit
|
: -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
|
: -M, --no-default-map ignore default map file
|
||||||
: -t D, --template D add custom template dir
|
: -t D, --template D add custom template dir
|
||||||
: -S, --no-shuffle do not shuffle sections
|
: -S, --no-shuffle do not shuffle sections
|
||||||
|
|
|
@ -58,12 +58,13 @@ STR_BOOK_CONFIG = set(['id', 'title', 'author', 'starttext', 'hideintrotext',
|
||||||
INT_BOOK_CONFIG = set(['max'])
|
INT_BOOK_CONFIG = set(['max'])
|
||||||
|
|
||||||
class Book:
|
class Book:
|
||||||
def __init__(self, bookid="gamebook"):
|
def __init__(self, bookid='gamebook', includetag=None):
|
||||||
self.sections = []
|
self.sections = []
|
||||||
self.introsections = []
|
self.introsections = []
|
||||||
self.from_name = {}
|
self.from_name = {}
|
||||||
self.nr_sections = {}
|
self.nr_sections = {}
|
||||||
self.codewords = set()
|
self.codewords = set()
|
||||||
|
self.includetag = includetag
|
||||||
self.config = {'max' : 0,
|
self.config = {'max' : 0,
|
||||||
'title' : 'Gamebook',
|
'title' : 'Gamebook',
|
||||||
'author' : '',
|
'author' : '',
|
||||||
|
@ -82,6 +83,8 @@ class Book:
|
||||||
raise Exception("Unknown book option '%s'." % name)
|
raise Exception("Unknown book option '%s'." % name)
|
||||||
|
|
||||||
def add(self, section):
|
def add(self, section):
|
||||||
|
if self.includetag and not section.hastag(self.includetag):
|
||||||
|
return
|
||||||
if section.name in self.from_name:
|
if section.name in self.from_name:
|
||||||
raise Exception('Duplicate section names (%s) not allowed.' %
|
raise Exception('Duplicate section names (%s) not allowed.' %
|
||||||
section.name)
|
section.name)
|
||||||
|
|
|
@ -35,5 +35,19 @@ class TestBook(TestCase):
|
||||||
self.assertEqual(b.nr_sections, {})
|
self.assertEqual(b.nr_sections, {})
|
||||||
self.assertEqual(b.config['max'], 0)
|
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__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
Loading…
Reference in a new issue