1
0
Fork 0
mirror of https://github.com/Oreolek/gamebookformat.git synced 2024-06-26 03:41:04 +03:00

Fixed problem with section used for missing.

It was handled at parse time, but must be done at
output time to be sure the section to use has been parsed.
This commit is contained in:
Pelle Nilsson 2013-06-20 22:59:25 +02:00
parent b9025d92a5
commit 431357a85c
24 changed files with 484 additions and 237 deletions

View file

@ -9,7 +9,9 @@
<link rel="stylesheet" href="gamebookformat.css"
type="text/css" />
<script>
gamebook.id = 'codewords';
if (typeof gamebook !== 'undefined') {
gamebook.id = 'codewords';
}
</script>
</head>
<body>
@ -23,7 +25,7 @@
<div class="startlink"
onclick="gamebook.turnTo(1)">Turn to 1 to begin.</div>
<script>
if (gamebook.hasSavedGame()) {
if (typeof gamebook !== 'undefined' && gamebook.hasSavedGame()) {
var resumeLinks = document.getElementsByClassName('resumelink');
Array.prototype.forEach.call(resumeLinks, function(e) {
e.classList.remove('nodisplay');
@ -34,7 +36,8 @@
<div class="sectionnumber" id="para1">1</div>
<div class="sectiontext">
Demonstrating how <span class="collect" data-type="code"
data-name="Codewords">Codewords</span> (AKA sightings) can be used. Go to <a class="sectionref enabledlink" data-ref="2">2</a>.
data-name="Codewords">Codewords</span> (AKA sightings) can be used. Go to <a class="sectionref enabledlink" data-ref="2"
href="#section2">2</a>.
</div>
</div>
<script>
@ -45,7 +48,8 @@ if (this.gamebook) {
<div class="sectionnumber" id="para2">2</div>
<div class="sectiontext">
Got codeword <span class="add" data-type="code"
data-what="warrior">warrior</span>. Simple enough to set a codeword. Turn to <a class="sectionref enabledlink" data-ref="9">9</a>.
data-what="warrior">warrior</span>. Simple enough to set a codeword. Turn to <a class="sectionref enabledlink" data-ref="9"
href="#section9">9</a>.
</div>
</div>
<script>
@ -65,7 +69,11 @@ if (this.gamebook) {
</script><div class="section" id="section4">
<div class="sectionnumber" id="para4">4</div>
<div class="sectiontext">
OK, if you have the codeword <span class="has" data-type="code" data-what="warrior">warrior</span>, you may turn to <span class="xor"></span><a class="sectionref enabledlink" data-ref="3">3</a> otherwise you may go back to <a class="sectionref enabledlink" data-ref="2">2</a>. Although we both know you have that codeword. If you have the codeword <span class="has" data-type="code" data-what="fun">fun</span> you may turn to <span class="xor"></span><a class="sectionref enabledlink" data-ref="5">5</a>, without it you can go to <a class="sectionref enabledlink" data-ref="8">8</a>.
OK, if you have the codeword <span class="has" data-type="code" data-what="warrior">warrior</span>, you may turn to <span class="xor"></span><a class="sectionref enabledlink" data-ref="3"
href="#section3">3</a> otherwise you may go back to <a class="sectionref enabledlink" data-ref="2"
href="#section2">2</a>. Although we both know you have that codeword. If you have the codeword <span class="has" data-type="code" data-what="fun">fun</span> you may turn to <span class="xor"></span><a class="sectionref enabledlink" data-ref="5"
href="#section5">5</a>, without it you can go to <a class="sectionref enabledlink" data-ref="8"
href="#section8">8</a>.
</div>
</div>
<script>
@ -85,7 +93,10 @@ if (this.gamebook) {
</script><div class="section" id="section6">
<div class="sectionnumber" id="para6">6</div>
<div class="sectiontext">
If you have the codeword <span class="has" data-type="code" data-what="fun">fun</span> turn to <span class="auto"></span><a class="sectionref enabledlink" data-ref="5">5</a>. Otherwise you can go to the end at <a class="sectionref enabledlink" data-ref="3">3</a> or to the xortest at <a class="sectionref enabledlink" data-ref="4">4</a>.
If you have the codeword <span class="has" data-type="code" data-what="fun">fun</span> turn to <span class="auto"></span><a class="sectionref enabledlink" data-ref="5"
href="#section5">5</a>. Otherwise you can go to the end at <a class="sectionref enabledlink" data-ref="3"
href="#section3">3</a> or to the xortest at <a class="sectionref enabledlink" data-ref="4"
href="#section4">4</a>.
</div>
</div>
<script>
@ -95,7 +106,10 @@ if (this.gamebook) {
</script><div class="section" id="section7">
<div class="sectionnumber" id="para7">7</div>
<div class="sectiontext">
If you have codeword <span class="has" data-type="code" data-what="warrior">warrior</span> turn to <span class="auto"></span><a class="sectionref enabledlink" data-ref="6">6</a>. Otherwise you can go to the end at <a class="sectionref enabledlink" data-ref="3">3</a> or back to <a class="sectionref enabledlink" data-ref="1">1</a>.
If you have codeword <span class="has" data-type="code" data-what="warrior">warrior</span> turn to <span class="auto"></span><a class="sectionref enabledlink" data-ref="6"
href="#section6">6</a>. Otherwise you can go to the end at <a class="sectionref enabledlink" data-ref="3"
href="#section3">3</a> or back to <a class="sectionref enabledlink" data-ref="1"
href="#section1">1</a>.
</div>
</div>
<script>
@ -105,7 +119,9 @@ if (this.gamebook) {
</script><div class="section" id="section8">
<div class="sectionnumber" id="para8">8</div>
<div class="sectiontext">
This is just to demonstrate choices allowed when not having a codeword. Now go on to <a class="sectionref enabledlink" data-ref="7">7</a> (autotest) or <a class="sectionref enabledlink" data-ref="4">4</a> (xor test).
This is just to demonstrate choices allowed when not having a codeword. Now go on to <a class="sectionref enabledlink" data-ref="7"
href="#section7">7</a> (autotest) or <a class="sectionref enabledlink" data-ref="4"
href="#section4">4</a> (xor test).
</div>
</div>
<script>
@ -115,8 +131,12 @@ if (this.gamebook) {
</script><div class="section" id="section9">
<div class="sectionnumber" id="para9">9</div>
<div class="sectiontext">
If you have the codeword <span class="has" data-type="code" data-what="warrior">warrior</span> you may turn to <a class="sectionref enabledlink" data-ref="3">3</a>. If you do not have the codeword <span class="hasnot" data-type="code"
data-what="fun">fun</span>, you may turn to <a class="sectionref enabledlink" data-ref="8">8</a>. If you have the codeword <span class="has" data-type="code" data-what="fun">fun</span>, you may instead turn to <a class="sectionref enabledlink" data-ref="5">5</a>. Otherwise see <a class="sectionref enabledlink" data-ref="4">4</a>.
If you have the codeword <span class="has" data-type="code" data-what="warrior">warrior</span> you may turn to <a class="sectionref enabledlink" data-ref="3"
href="#section3">3</a>. If you do not have the codeword <span class="hasnot" data-type="code"
data-what="fun">fun</span>, you may turn to <a class="sectionref enabledlink" data-ref="8"
href="#section8">8</a>. If you have the codeword <span class="has" data-type="code" data-what="fun">fun</span>, you may instead turn to <a class="sectionref enabledlink" data-ref="5"
href="#section5">5</a>. Otherwise see <a class="sectionref enabledlink" data-ref="4"
href="#section4">4</a>.
</div>
</div>
<script>
@ -138,8 +158,8 @@ if (this.gamebook) {
</div>
</div>
<script>
if (this.gamebook) {
gamebook.runActionsInIntroSections();
if (typeof gamebook !== 'undefined') {
gamebook.prepare();
}
</script>
<div class="displayintrolink nodisplay"

View file

@ -1,19 +1,16 @@
BEGIN DEBUG OUTPUT
Book title: Counters Example
Number of sections: 4
Number of sections: 7
Introduction
This example gamebook shows how to use counters.
Turn to 1 to begin.
1 (start) - This is where the gamebook starts. We have counters for Life Points and for Gold. You start the adventure with 10 Life Points
and 12 Gold
. You can never have less than 0 Gold
. FIXME need to figure out best syntax for death when life points go below 1. Go to 4 to get more Gold or 3 to lose some Life Points.
2 (losegold) - You drop 5 Gold
. It should not be possible to go below 0. Then go on to get gold at 4 or lose life at 3.
3 (dangerous) - You lose 1 Life Points
. You can go to 4 to get some Gold.
4 (getgold) - Congratulations, you found 2 Gold
. You can go to 3 to lose some life or to 2 to drop some gold.
1 (start) - This is where the gamebook starts. We have counters for [COUNT life]Life Points[/COUNT] and for [COUNT gold]Gold[/COUNT]. You start the adventure with [SET life]10[/SET] and [SET gold]12[/SET]. You can never have less than [MIN gold]0[/MIN]. FIXME need to figure out best syntax for death when life points go below 1. Go to 7 to get more Gold or 6 to lose some Life Points.
2 (death) - Less than 1 Life Point means the adventure ends now.
3 (hurrah) - You have at least 16 gold. Go back to get some more at 7.
4 (rich) - You have more than 16 Gold. How nice. Go back to get some more at 7.
5 (losegold) - You drop [DEC gold]5[/DEC]. It should not be possible to go below 0. Then go on to get gold at 7 or lose life at 6.
6 (dangerous) - You lose [DEC life]1[/DEC]. You can go to 7 to get some Gold.
7 (getgold) - Congratulations, you found [INC gold]2[/INC]. If you have less than 1, turn to ((automatic))2. You can go to 6 to lose some life or to 5 to drop some gold. If you have at least 16 you can turn to 3. If you have even more than 16 you can turn to 4.
END DEBUG OUTPUT

View file

@ -1,13 +1,21 @@
digraph gamebook {
1->3
1->6
1->4
2->4
1->7
3->7
4->7
5->7
2->3
3->4
4->2
5->6
6->7
7->5
4->3
7->6
7->3
7->4
7->2
}

View file

@ -9,7 +9,9 @@
<link rel="stylesheet" href="gamebookformat.css"
type="text/css" />
<script>
gamebook.id = 'counters';
if (typeof gamebook !== 'undefined') {
gamebook.id = 'counters';
}
</script>
</head>
<body>
@ -29,7 +31,7 @@
<div class="startlink"
onclick="gamebook.turnTo(1)">Turn to 1 to begin.</div>
<script>
if (gamebook.hasSavedGame()) {
if (typeof gamebook !== 'undefined' && gamebook.hasSavedGame()) {
var resumeLinks = document.getElementsByClassName('resumelink');
Array.prototype.forEach.call(resumeLinks, function(e) {
e.classList.remove('nodisplay');
@ -45,7 +47,9 @@
data-amount="10">10 Life Points</span> and <span class="set counterChange" data-type="gold"
data-amount="12">12 Gold</span>. You can never have less than <span class="min counterChange" data-type="gold"
data-limit="0">0 Gold</span>
. FIXME need to figure out best syntax for death when life points go below 1. Go to <a class="sectionref enabledlink" data-ref="4">4</a> to get more Gold or <a class="sectionref enabledlink" data-ref="3">3</a> to lose some Life Points.
. FIXME need to figure out best syntax for death when life points go below 1. Go to <a class="sectionref enabledlink" data-ref="7"
href="#section7">7</a> to get more Gold or <a class="sectionref enabledlink" data-ref="6"
href="#section6">6</a> to lose some Life Points.
</div>
</div>
<script>
@ -55,8 +59,7 @@ if (this.gamebook) {
</script><div class="section" id="section2">
<div class="sectionnumber" id="para2">2</div>
<div class="sectiontext">
You drop <span class="dec counterChange" data-type="gold"
data-amount="5">5 Gold</span>. It should not be possible to go below 0. Then go on to get gold at <a class="sectionref enabledlink" data-ref="4">4</a> or lose life at <a class="sectionref enabledlink" data-ref="3">3</a>.
Less than 1 Life Point means the adventure ends now.
</div>
</div>
<script>
@ -66,8 +69,8 @@ if (this.gamebook) {
</script><div class="section" id="section3">
<div class="sectionnumber" id="para3">3</div>
<div class="sectiontext">
You lose <span class="dec counterChange" data-type="life"
data-amount="1">1 Life Points</span>. You can go to <a class="sectionref enabledlink" data-ref="4">4</a> to get some Gold.
You have at least 16 gold. Go back to get some more at <a class="sectionref enabledlink" data-ref="7"
href="#section7">7</a>.
</div>
</div>
<script>
@ -77,14 +80,58 @@ if (this.gamebook) {
</script><div class="section" id="section4">
<div class="sectionnumber" id="para4">4</div>
<div class="sectiontext">
Congratulations, you found <span class="inc counterChange" data-type="gold"
data-amount="2">2 Gold</span>. You can go to <a class="sectionref enabledlink" data-ref="3">3</a> to lose some life or to <a class="sectionref enabledlink" data-ref="2">2</a> to drop some gold.
You have more than 16 Gold. How nice. Go back to get some more at <a class="sectionref enabledlink" data-ref="7"
href="#section7">7</a>.
</div>
</div>
<script>
if (this.gamebook) {
gamebook.addSection(4, document.getElementById('section4'));
}
</script><div class="section" id="section5">
<div class="sectionnumber" id="para5">5</div>
<div class="sectiontext">
You drop <span class="dec counterChange" data-type="gold"
data-amount="5">5 Gold</span>. It should not be possible to go below 0. Then go on to get gold at <a class="sectionref enabledlink" data-ref="7"
href="#section7">7</a> or lose life at <a class="sectionref enabledlink" data-ref="6"
href="#section6">6</a>.
</div>
</div>
<script>
if (this.gamebook) {
gamebook.addSection(5, document.getElementById('section5'));
}
</script><div class="section" id="section6">
<div class="sectionnumber" id="para6">6</div>
<div class="sectiontext">
You lose <span class="dec counterChange" data-type="life"
data-amount="1">1 Life Points</span>. You can go to <a class="sectionref enabledlink" data-ref="7"
href="#section7">7</a> to get some Gold.
</div>
</div>
<script>
if (this.gamebook) {
gamebook.addSection(6, document.getElementById('section6'));
}
</script><div class="section" id="section7">
<div class="sectionnumber" id="para7">7</div>
<div class="sectiontext">
Congratulations, you found <span class="inc counterChange" data-type="gold"
data-amount="2">2 Gold</span>. If you have less than <span class="lessthan" data-type="life" data-amount="1"
>1 Life Points</span>, turn to <span class="auto"></span><a class="sectionref enabledlink" data-ref="2"
href="#section2">2</a>. You can go to <a class="sectionref enabledlink" data-ref="6"
href="#section6">6</a> to lose some life or to <a class="sectionref enabledlink" data-ref="5"
href="#section5">5</a> to drop some gold. If you have at least <span class="atleast" data-type="gold" data-amount="16"
>16 Gold</span> you can turn to <a class="sectionref enabledlink" data-ref="3"
href="#section3">3</a>. If you have even more than <span class="morethan" data-type="gold" data-amount="16"
>16 Gold</span> you can turn to <a class="sectionref enabledlink" data-ref="4"
href="#section4">4</a>.
</div>
</div>
<script>
if (this.gamebook) {
gamebook.addSection(7, document.getElementById('section7'));
}
</script> <div id="counters" class="counters">
</div>
<div id="counterTemplate" class="counterTemplate">
@ -100,8 +147,8 @@ if (this.gamebook) {
</div>
</div>
<script>
if (this.gamebook) {
gamebook.runActionsInIntroSections();
if (typeof gamebook !== 'undefined') {
gamebook.prepare();
}
</script>
<div class="displayintrolink nodisplay"

View file

@ -8,6 +8,7 @@
\b \qc Counters Example
\b0\
\
\b \qc Introduction
\b0\
@ -24,39 +25,64 @@
\ql This is where the gamebook starts. We have counters for Life Points and for Gold. You start the adventure with 10 Life Points
and 12 Gold
. You can never have less than 0 Gold
. FIXME need to figure out best syntax for death when life points go below 1. Go to \b 4
. FIXME need to figure out best syntax for death when life points go below 1. Go to \b 7
\b0
to get more Gold or \b 3
to get more Gold or \b 6
\b0
to lose some Life Points. \
\
\b \qc 2
\b0\
\ql You drop 5 Gold
. It should not be possible to go below 0. Then go on to get gold at \b 4
\b0
or lose life at \b 3
\b0
. \
\ql Less than 1 Life Point means the adventure ends now. \
\
\b \qc 3
\b0\
\ql You lose 1 Life Points
. You can go to \b 4
\ql You have at least 16 gold. Go back to get some more at \b 7
\b0
to get some Gold. \
. \
\
\b \qc 4
\b0\
\ql You have more than 16 Gold. How nice. Go back to get some more at \b 7
\b0
. \
\
\b \qc 5
\b0\
\ql You drop 5 Gold
. It should not be possible to go below 0. Then go on to get gold at \b 7
\b0
or lose life at \b 6
\b0
. \
\
\b \qc 6
\b0\
\ql You lose 1 Life Points
. You can go to \b 7
\b0
to get some Gold. \
\
\b \qc 7
\b0\
\ql Congratulations, you found 2 Gold
. You can go to \b 3
. If you have less than 1, turn to \b 2
\b0
to lose some life or to \b 2
. You can go to \b 6
\b0
to drop some gold. \
to lose some life or to \b 5
\b0
to drop some gold. If you have at least 16 you can turn to \b 3
\b0
. If you have even more than 16 you can turn to \b 4
\b0
. \
\
}

View file

@ -51,7 +51,7 @@ Turn to 1 to begin.
This is where the gamebook starts. We have counters for Life Points and for Gold. You start the adventure with 10 Life Points
and 12 Gold
. You can never have less than 0 Gold
. FIXME need to figure out best syntax for death when life points go below 1. Go to \textbf{\autoref{section4}} to get more Gold or \textbf{\autoref{section3}} to lose some Life Points.
. FIXME need to figure out best syntax for death when life points go below 1. Go to \textbf{\autoref{section7}} to get more Gold or \textbf{\autoref{section6}} to lose some Life Points.
\vspace{1em}
\phantomsection
\refstepcounter{sectionnr}
@ -59,8 +59,7 @@ Turn to 1 to begin.
\subsection*{\begin{center} \textbf{2} \end{center}}
\noindent
You drop 5 Gold
. It should not be possible to go below 0. Then go on to get gold at \textbf{\autoref{section4}} or lose life at \textbf{\autoref{section3}}.
Less than 1 Life Point means the adventure ends now.
\vspace{1em}
\phantomsection
\refstepcounter{sectionnr}
@ -68,16 +67,41 @@ Turn to 1 to begin.
\subsection*{\begin{center} \textbf{3} \end{center}}
\noindent
You lose 1 Life Points
. You can go to \textbf{\autoref{section4}} to get some Gold.
You have at least 16 gold. Go back to get some more at \textbf{\autoref{section7}}.
\vspace{1em}
\phantomsection
\refstepcounter{sectionnr}
\label{section4}
\subsection*{\begin{center} \textbf{4} \end{center}}
\noindent
You have more than 16 Gold. How nice. Go back to get some more at \textbf{\autoref{section7}}.
\vspace{1em}
\phantomsection
\refstepcounter{sectionnr}
\label{section5}
\subsection*{\begin{center} \textbf{5} \end{center}}
\noindent
You drop 5 Gold
. It should not be possible to go below 0. Then go on to get gold at \textbf{\autoref{section7}} or lose life at \textbf{\autoref{section6}}.
\vspace{1em}
\phantomsection
\refstepcounter{sectionnr}
\label{section6}
\subsection*{\begin{center} \textbf{6} \end{center}}
\noindent
You lose 1 Life Points
. You can go to \textbf{\autoref{section7}} to get some Gold.
\vspace{1em}
\phantomsection
\refstepcounter{sectionnr}
\label{section7}
\subsection*{\begin{center} \textbf{7} \end{center}}
\noindent
Congratulations, you found 2 Gold
. You can go to \textbf{\autoref{section3}} to lose some life or to \textbf{\autoref{section2}} to drop some gold.
. If you have less than 1, turn to \textbf{\autoref{section2}}. You can go to \textbf{\autoref{section6}} to lose some life or to \textbf{\autoref{section5}} to drop some gold. If you have at least 16 you can turn to \textbf{\autoref{section3}}. If you have even more than 16 you can turn to \textbf{\autoref{section4}}.
\vspace{1em}
\end{document}

View file

@ -10,17 +10,26 @@ Turn to 1 to begin.
This is where the gamebook starts. We have counters for Life Points and for Gold. You start the adventure with 10 Life Points
and 12 Gold
. You can never have less than 0 Gold
. FIXME need to figure out best syntax for death when life points go below 1. Go to 4 to get more Gold or 3 to lose some Life Points.
. FIXME need to figure out best syntax for death when life points go below 1. Go to 7 to get more Gold or 6 to lose some Life Points.
2
You drop 5 Gold
. It should not be possible to go below 0. Then go on to get gold at 4 or lose life at 3.
Less than 1 Life Point means the adventure ends now.
3
You lose 1 Life Points
. You can go to 4 to get some Gold.
You have at least 16 gold. Go back to get some more at 7.
4
Congratulations, you found 2 Gold
. You can go to 3 to lose some life or to 2 to drop some gold.
You have more than 16 Gold. How nice. Go back to get some more at 7.
5
You drop 5 Gold
. It should not be possible to go below 0. Then go on to get gold at 7 or lose life at 6.
6
You lose 1 Life Points
. You can go to 7 to get some Gold.
7
Congratulations, you found 2 Gold
. If you have less than 1, turn to 2. You can go to 6 to lose some life or to 5 to drop some gold. If you have at least 16 you can turn to 3. If you have even more than 16 you can turn to 4.

View file

@ -9,7 +9,9 @@
<link rel="stylesheet" href="gamebookformat.css"
type="text/css" />
<script>
gamebook.id = 'format2';
if (typeof gamebook !== 'undefined') {
gamebook.id = 'format2';
}
</script>
</head>
<body>
@ -35,7 +37,7 @@
<div class="startlink"
onclick="gamebook.turnTo(1)">Adventure begins in section 1.</div>
<script>
if (gamebook.hasSavedGame()) {
if (typeof gamebook !== 'undefined' && gamebook.hasSavedGame()) {
var resumeLinks = document.getElementsByClassName('resumelink');
Array.prototype.forEach.call(resumeLinks, function(e) {
e.classList.remove('nodisplay');
@ -45,7 +47,9 @@
<div class="section" id="section1">
<div class="sectionnumber" id="para1">1</div>
<div class="sectiontext">
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 &lt;div&gt; or &amp;boom;. There should be an image below as well. If something broke, turn to <a class="sectionref enabledlink" data-ref="2">2</a>, otherwise turn to <a class="sectionref enabledlink" data-ref="3">3</a>. <img src="testimage.png" class="sectionimage"></img>
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 &lt;div&gt; or &amp;boom;. There should be an image below as well. If something broke, turn to <a class="sectionref enabledlink" data-ref="2"
href="#section2">2</a>, otherwise turn to <a class="sectionref enabledlink" data-ref="3"
href="#section3">3</a>. <img src="testimage.png" class="sectionimage"></img>
</div>
</div>
<script>
@ -87,8 +91,8 @@ if (this.gamebook) {
</div>
</div>
<script>
if (this.gamebook) {
gamebook.runActionsInIntroSections();
if (typeof gamebook !== 'undefined') {
gamebook.prepare();
}
</script>
<div class="displayintrolink nodisplay"

View file

@ -8,6 +8,7 @@
\b \qc Format
\b0\
\
\b \qc Introduction
\b0\
@ -15,6 +16,7 @@
\ql Adding an introduction to the gamebook here. This will create a section, but it will not be shuffled nor numbered with the gamebook sections below. \
\
\
\b \qc Another Heading
\b0\

View file

@ -1,18 +1,19 @@
BEGIN DEBUG OUTPUT
Book title: Items
Number of sections: 11
Number of sections: 12
Turn to 1 to begin.
1 (start) - Demonstrating how to manage player [COLLECT item]Inventory[/COLLECT]. You start the book carrying a [ADD item]sword[/ADD] and a [ADD item]shield[/ADD]. Turn to 11.
2 (won) - Congratulations, you won.
3 (cut_rope) - OK. That was fun. Turn to 2.
4 (inside) - There is a rope here that can be cut using a [HAS item]sword[/HAS]. If you have one and want to do that, see 3. Otherwise turn to 2.
5 (treasure) - You found [FOUND item]something valuable[/FOUND], but there is no way forward, so you head back to 11.
6 (portal) - A magic portal ahead will only allow you to pass if you did not pick up the [HAS NOT item]cursed bracelet[/HAS NOT], leading you to 5. If you have the [HAS item]cursed bracelet[/HAS] you have to go back to 11 instead. Actually feel free to head back to 11 either way.
7 (drop_stick) - OK [DROP item]stick[/DROP] dropped. Turn back to 11 to confirm stick can not be picked up again even if the text says it is there (books work that way, although ideally this dynamic version should provide some hints that it is no longer there).
8 (curse) - There is a [FOUND item]cursed bracelet[/FOUND] here. You can go on to 6 or go back to 11. You can also drop the [HAS item]stick[/HAS] for no particular reason if you have it, see 7.
9 (attempt_break_door_with_sword) - OK. The door is broken, but so is the [DROP item]sword[/DROP]. Turn to 4.
10 (door) - There is a locked door here. If you have a [HAS item]key[/HAS] you can use that to open the door, see 4. Being right before the link should be enough for the formatter to figure out that the key is required to be allowed to follow the link. Else you can try to open with the [HAS item]sword[/HAS], if you have it, see 9. Hopefully the magic is good enough to pair pre-conditions to links, or more markup must be added later. You could also try to go back to pick up the key, see 11.
11 (tjunction) - You have reached a t-junction. Here you find a [FOUND item]key[/FOUND] and a [FOUND item]stick[/FOUND]. You can go west to 10, or east to 8.
1 (start) - Demonstrating how to manage player [COLLECT item]Inventory[/COLLECT]. You start the book carrying a [ADD item]sword[/ADD] and a [ADD item]shield[/ADD]. Turn to 12 or go to the autotest at 2.
2 (autotest) - If you have the [HAS item]stick[/HAS] then you must turn immediately to ((automatic))12, and everything else in this section is ignored. You find a [ADD item]book[/ADD] here. If you have the [HAS item]sword[/HAS] you must turn immediately to ((automatic))5, again ignoring everything that follows. You drop the [DROP item]something valuable[/DROP] here if you have it, then go on to 7.
3 (won) - Congratulations, you won.
4 (cut_rope) - OK. That was fun. Turn to 3.
5 (inside) - There is a rope here that can be cut using a [HAS item]sword[/HAS]. If you have one and want to do that, see 4. You can also run to the autotest at 2. Otherwise turn to 3.
6 (treasure) - You found [FOUND item]something valuable[/FOUND], but there is no way forward, so you head back to 12.
7 (portal) - A magic portal ahead will only allow you to pass if you did not pick up the [HAS NOT item]cursed bracelet[/HAS NOT], leading you to 6. If you have the [HAS item]cursed bracelet[/HAS] you have to go back to 12 instead. Actually feel free to head back to 12 either way.
8 (drop_stick) - OK [DROP item]stick[/DROP] dropped. Turn back to 12 to confirm stick can not be picked up again even if the text says it is there (books work that way, although ideally this dynamic version should provide some hints that it is no longer there).
9 (curse) - There is a [FOUND item]cursed bracelet[/FOUND] here. You can go on to 7 or go back to 12. You can also drop the [HAS item]stick[/HAS] for no particular reason if you have it, see 8.
10 (attempt_break_door_with_sword) - OK. The door is broken, but so is the [DROP item]sword[/DROP]. Turn to 5.
11 (door) - There is a locked door here. If you have a [HAS item]key[/HAS] you can use that to open the door, see 5. Being right before the link should be enough for the formatter to figure out that the key is required to be allowed to follow the link. Else you can try to open with the [HAS item]sword[/HAS], if you have it, see 10. Hopefully the magic is good enough to pair pre-conditions to links, or more markup must be added later. You could also try to go back to pick up the key, see 12.
12 (tjunction) - You have reached a t-junction. Here you find a [FOUND item]key[/FOUND] and a [FOUND item]stick[/FOUND]. You can go west to 11, or east to 9.
END DEBUG OUTPUT

View file

@ -1,27 +1,36 @@
digraph gamebook {
1->11
3->2
4->2
1->12
1->2
2->7
2->12
2->5
4->3
5->11
6->5
5->2
6->11
7->11
8->6
5->4
8->11
5->3
6->12
7->6
8->7
9->4
10->9
7->12
8->12
9->12
10->4
9->7
10->11
9->8
10->5
11->10
11->8
11->5
11->12
12->9
12->11
}

View file

@ -9,7 +9,9 @@
<link rel="stylesheet" href="gamebookformat.css"
type="text/css" />
<script>
gamebook.id = 'items';
if (typeof gamebook !== 'undefined') {
gamebook.id = 'items';
}
</script>
</head>
<body>
@ -23,7 +25,7 @@
<div class="startlink"
onclick="gamebook.turnTo(1)">Turn to 1 to begin.</div>
<script>
if (gamebook.hasSavedGame()) {
if (typeof gamebook !== 'undefined' && gamebook.hasSavedGame()) {
var resumeLinks = document.getElementsByClassName('resumelink');
Array.prototype.forEach.call(resumeLinks, function(e) {
e.classList.remove('nodisplay');
@ -36,7 +38,9 @@
Demonstrating how to manage player <span class="collect" data-type="item"
data-name="Inventory">Inventory</span>. You start the book carrying a <span class="add" data-type="item"
data-what="sword">sword</span> and a <span class="add" data-type="item"
data-what="shield">shield</span>. Turn to <a class="sectionref enabledlink" data-ref="11">11</a>.
data-what="shield">shield</span>. Turn to <a class="sectionref enabledlink" data-ref="12"
href="#section12">12</a> or go to the autotest at <a class="sectionref enabledlink" data-ref="2"
href="#section2">2</a>.
</div>
</div>
<script>
@ -46,7 +50,12 @@ if (this.gamebook) {
</script><div class="section" id="section2">
<div class="sectionnumber" id="para2">2</div>
<div class="sectiontext">
Congratulations, you won.
If you have the <span class="has" data-type="item" data-what="stick">stick</span> then you must turn immediately to <span class="auto"></span><a class="sectionref enabledlink" data-ref="12"
href="#section12">12</a>, and everything else in this section is ignored. You find a <span class="add" data-type="item"
data-what="book">book</span> here. If you have the <span class="has" data-type="item" data-what="sword">sword</span> you must turn immediately to <span class="auto"></span><a class="sectionref enabledlink" data-ref="5"
href="#section5">5</a>, again ignoring everything that follows. You drop the <span class="drop" data-type="item"
data-what="something valuable">something valuable</span> here if you have it, then go on to <a class="sectionref enabledlink" data-ref="7"
href="#section7">7</a>.
</div>
</div>
<script>
@ -56,7 +65,7 @@ if (this.gamebook) {
</script><div class="section" id="section3">
<div class="sectionnumber" id="para3">3</div>
<div class="sectiontext">
OK. That was fun. Turn to <a class="sectionref enabledlink" data-ref="2">2</a>.
Congratulations, you won.
</div>
</div>
<script>
@ -66,7 +75,8 @@ if (this.gamebook) {
</script><div class="section" id="section4">
<div class="sectionnumber" id="para4">4</div>
<div class="sectiontext">
There is a rope here that can be cut using a <span class="has" data-type="item" data-what="sword">sword</span>. If you have one and want to do that, see <a class="sectionref enabledlink" data-ref="3">3</a>. Otherwise turn to <a class="sectionref enabledlink" data-ref="2">2</a>.
OK. That was fun. Turn to <a class="sectionref enabledlink" data-ref="3"
href="#section3">3</a>.
</div>
</div>
<script>
@ -76,10 +86,10 @@ if (this.gamebook) {
</script><div class="section" id="section5">
<div class="sectionnumber" id="para5">5</div>
<div class="sectiontext">
You found <span class="found enabledlink"
onclick="gamebook.player.add('item', 'something valuable')"
>something valuable</span>
, but there is no way forward, so you head back to <a class="sectionref enabledlink" data-ref="11">11</a>.
There is a rope here that can be cut using a <span class="has" data-type="item" data-what="sword">sword</span>. If you have one and want to do that, see <a class="sectionref enabledlink" data-ref="4"
href="#section4">4</a>. You can also run to the autotest at <a class="sectionref enabledlink" data-ref="2"
href="#section2">2</a>. Otherwise turn to <a class="sectionref enabledlink" data-ref="3"
href="#section3">3</a>.
</div>
</div>
<script>
@ -89,8 +99,11 @@ if (this.gamebook) {
</script><div class="section" id="section6">
<div class="sectionnumber" id="para6">6</div>
<div class="sectiontext">
A magic portal ahead will only allow you to pass if you did not pick up the <span class="hasnot" data-type="item"
data-what="cursed bracelet">cursed bracelet</span>, leading you to <a class="sectionref enabledlink" data-ref="5">5</a>. If you have the <span class="has" data-type="item" data-what="cursed bracelet">cursed bracelet</span> you have to go back to <a class="sectionref enabledlink" data-ref="11">11</a> instead. Actually feel free to head back to <a class="sectionref enabledlink" data-ref="11">11</a> either way.
You found <span class="found enabledlink"
onclick="gamebook.player.add('item', 'something valuable')"
>something valuable</span>
, but there is no way forward, so you head back to <a class="sectionref enabledlink" data-ref="12"
href="#section12">12</a>.
</div>
</div>
<script>
@ -100,8 +113,11 @@ if (this.gamebook) {
</script><div class="section" id="section7">
<div class="sectionnumber" id="para7">7</div>
<div class="sectiontext">
OK <span class="drop" data-type="item"
data-what="stick">stick</span> dropped. Turn back to <a class="sectionref enabledlink" data-ref="11">11</a> to confirm stick can not be picked up again even if the text says it is there (books work that way, although ideally this dynamic version should provide some hints that it is no longer there).
A magic portal ahead will only allow you to pass if you did not pick up the <span class="hasnot" data-type="item"
data-what="cursed bracelet">cursed bracelet</span>, leading you to <a class="sectionref enabledlink" data-ref="6"
href="#section6">6</a>. If you have the <span class="has" data-type="item" data-what="cursed bracelet">cursed bracelet</span> you have to go back to <a class="sectionref enabledlink" data-ref="12"
href="#section12">12</a> instead. Actually feel free to head back to <a class="sectionref enabledlink" data-ref="12"
href="#section12">12</a> either way.
</div>
</div>
<script>
@ -111,10 +127,9 @@ if (this.gamebook) {
</script><div class="section" id="section8">
<div class="sectionnumber" id="para8">8</div>
<div class="sectiontext">
There is a <span class="found enabledlink"
onclick="gamebook.player.add('item', 'cursed bracelet')"
>cursed bracelet</span>
here. You can go on to <a class="sectionref enabledlink" data-ref="6">6</a> or go back to <a class="sectionref enabledlink" data-ref="11">11</a>. You can also drop the <span class="has" data-type="item" data-what="stick">stick</span> for no particular reason if you have it, see <a class="sectionref enabledlink" data-ref="7">7</a>.
OK <span class="drop" data-type="item"
data-what="stick">stick</span> dropped. Turn back to <a class="sectionref enabledlink" data-ref="12"
href="#section12">12</a> to confirm stick can not be picked up again even if the text says it is there (books work that way, although ideally this dynamic version should provide some hints that it is no longer there).
</div>
</div>
<script>
@ -124,8 +139,13 @@ if (this.gamebook) {
</script><div class="section" id="section9">
<div class="sectionnumber" id="para9">9</div>
<div class="sectiontext">
OK. The door is broken, but so is the <span class="drop" data-type="item"
data-what="sword">sword</span>. Turn to <a class="sectionref enabledlink" data-ref="4">4</a>.
There is a <span class="found enabledlink"
onclick="gamebook.player.add('item', 'cursed bracelet')"
>cursed bracelet</span>
here. You can go on to <a class="sectionref enabledlink" data-ref="7"
href="#section7">7</a> or go back to <a class="sectionref enabledlink" data-ref="12"
href="#section12">12</a>. You can also drop the <span class="has" data-type="item" data-what="stick">stick</span> for no particular reason if you have it, see <a class="sectionref enabledlink" data-ref="8"
href="#section8">8</a>.
</div>
</div>
<script>
@ -135,7 +155,9 @@ if (this.gamebook) {
</script><div class="section" id="section10">
<div class="sectionnumber" id="para10">10</div>
<div class="sectiontext">
There is a locked door here. If you have a <span class="has" data-type="item" data-what="key">key</span> you can use that to open the door, see <a class="sectionref enabledlink" data-ref="4">4</a>. Being right before the link should be enough for the formatter to figure out that the key is required to be allowed to follow the link. Else you can try to open with the <span class="has" data-type="item" data-what="sword">sword</span>, if you have it, see <a class="sectionref enabledlink" data-ref="9">9</a>. Hopefully the magic is good enough to pair pre-conditions to links, or more markup must be added later. You could also try to go back to pick up the key, see <a class="sectionref enabledlink" data-ref="11">11</a>.
OK. The door is broken, but so is the <span class="drop" data-type="item"
data-what="sword">sword</span>. Turn to <a class="sectionref enabledlink" data-ref="5"
href="#section5">5</a>.
</div>
</div>
<script>
@ -144,6 +166,19 @@ if (this.gamebook) {
}
</script><div class="section" id="section11">
<div class="sectionnumber" id="para11">11</div>
<div class="sectiontext">
There is a locked door here. If you have a <span class="has" data-type="item" data-what="key">key</span> you can use that to open the door, see <a class="sectionref enabledlink" data-ref="5"
href="#section5">5</a>. Being right before the link should be enough for the formatter to figure out that the key is required to be allowed to follow the link. Else you can try to open with the <span class="has" data-type="item" data-what="sword">sword</span>, if you have it, see <a class="sectionref enabledlink" data-ref="10"
href="#section10">10</a>. Hopefully the magic is good enough to pair pre-conditions to links, or more markup must be added later. You could also try to go back to pick up the key, see <a class="sectionref enabledlink" data-ref="12"
href="#section12">12</a>.
</div>
</div>
<script>
if (this.gamebook) {
gamebook.addSection(11, document.getElementById('section11'));
}
</script><div class="section" id="section12">
<div class="sectionnumber" id="para12">12</div>
<div class="sectiontext">
You have reached a t-junction. Here you find a <span class="found enabledlink"
onclick="gamebook.player.add('item', 'key')"
@ -151,12 +186,14 @@ if (this.gamebook) {
and a <span class="found enabledlink"
onclick="gamebook.player.add('item', 'stick')"
>stick</span>
. You can go west to <a class="sectionref enabledlink" data-ref="10">10</a>, or east to <a class="sectionref enabledlink" data-ref="8">8</a>.
. You can go west to <a class="sectionref enabledlink" data-ref="11"
href="#section11">11</a>, or east to <a class="sectionref enabledlink" data-ref="9"
href="#section9">9</a>.
</div>
</div>
<script>
if (this.gamebook) {
gamebook.addSection(11, document.getElementById('section11'));
gamebook.addSection(12, document.getElementById('section12'));
}
</script> <div id="counters" class="counters">
</div>
@ -173,8 +210,8 @@ if (this.gamebook) {
</div>
</div>
<script>
if (this.gamebook) {
gamebook.runActionsInIntroSections();
if (typeof gamebook !== 'undefined') {
gamebook.prepare();
}
</script>
<div class="displayintrolink nodisplay"

View file

@ -14,91 +14,106 @@
\
\b \qc 1
\b0\
\ql Demonstrating how to manage player Inventory. You start the book carrying a sword and a shield. Turn to \b 11
\ql Demonstrating how to manage player Inventory. You start the book carrying a sword and a shield. Turn to \b 12
\b0
or go to the autotest at \b 2
\b0
. \
\
\b \qc 2
\b0\
\ql Congratulations, you won. \
\ql If you have the stick then you must turn immediately to \b 12
\b0
, and everything else in this section is ignored. You find a book here. If you have the sword you must turn immediately to \b 5
\b0
, again ignoring everything that follows. You drop the something valuable here if you have it, then go on to \b 7
\b0
. \
\
\b \qc 3
\b0\
\ql OK. That was fun. Turn to \b 2
\b0
. \
\ql Congratulations, you won. \
\
\b \qc 4
\b0\
\ql There is a rope here that can be cut using a sword. If you have one and want to do that, see \b 3
\b0
. Otherwise turn to \b 2
\ql OK. That was fun. Turn to \b 3
\b0
. \
\
\b \qc 5
\b0\
\ql You found something valuable, but there is no way forward, so you head back to \b 11
\ql There is a rope here that can be cut using a sword. If you have one and want to do that, see \b 4
\b0
. You can also run to the autotest at \b 2
\b0
. Otherwise turn to \b 3
\b0
. \
\
\b \qc 6
\b0\
\ql A magic portal ahead will only allow you to pass if you did not pick up the cursed bracelet, leading you to \b 5
\b0
. If you have the cursed bracelet you have to go back to \b 11
\b0
instead. Actually feel free to head back to \b 11
\b0
either way. \
\
\b \qc 7
\b0\
\ql OK stick dropped. Turn back to \b 11
\b0
to confirm stick can not be picked up again even if the text says it is there (books work that way, although ideally this dynamic version should provide some hints that it is no longer there). \
\
\b \qc 8
\b0\
\ql There is a cursed bracelet here. You can go on to \b 6
\b0
or go back to \b 11
\b0
. You can also drop the stick for no particular reason if you have it, see \b 7
\ql You found something valuable, but there is no way forward, so you head back to \b 12
\b0
. \
\
\b \qc 7
\b0\
\ql A magic portal ahead will only allow you to pass if you did not pick up the cursed bracelet, leading you to \b 6
\b0
. If you have the cursed bracelet you have to go back to \b 12
\b0
instead. Actually feel free to head back to \b 12
\b0
either way. \
\
\b \qc 8
\b0\
\ql OK stick dropped. Turn back to \b 12
\b0
to confirm stick can not be picked up again even if the text says it is there (books work that way, although ideally this dynamic version should provide some hints that it is no longer there). \
\
\b \qc 9
\b0\
\ql OK. The door is broken, but so is the sword. Turn to \b 4
\ql There is a cursed bracelet here. You can go on to \b 7
\b0
or go back to \b 12
\b0
. You can also drop the stick for no particular reason if you have it, see \b 8
\b0
. \
\
\b \qc 10
\b0\
\ql There is a locked door here. If you have a key you can use that to open the door, see \b 4
\b0
. Being right before the link should be enough for the formatter to figure out that the key is required to be allowed to follow the link. Else you can try to open with the sword, if you have it, see \b 9
\b0
. Hopefully the magic is good enough to pair pre-conditions to links, or more markup must be added later. You could also try to go back to pick up the key, see \b 11
\ql OK. The door is broken, but so is the sword. Turn to \b 5
\b0
. \
\
\b \qc 11
\b0\
\ql You have reached a t-junction. Here you find a key and a stick. You can go west to \b 10
\ql There is a locked door here. If you have a key you can use that to open the door, see \b 5
\b0
, or east to \b 8
. Being right before the link should be enough for the formatter to figure out that the key is required to be allowed to follow the link. Else you can try to open with the sword, if you have it, see \b 10
\b0
. Hopefully the magic is good enough to pair pre-conditions to links, or more markup must be added later. You could also try to go back to pick up the key, see \b 12
\b0
. \
\
\b \qc 12
\b0\
\ql You have reached a t-junction. Here you find a key and a stick. You can go west to \b 11
\b0
, or east to \b 9
\b0
. \
\

View file

@ -42,7 +42,7 @@ Turn to 1 to begin.
\subsection*{\begin{center} \textbf{1} \end{center}}
\noindent
Demonstrating how to manage player Inventory. You start the book carrying a \textbf{sword} and a \textbf{shield}. Turn to \textbf{\autoref{section11}}.
Demonstrating how to manage player Inventory. You start the book carrying a \textbf{sword} and a \textbf{shield}. Turn to \textbf{\autoref{section12}} or go to the autotest at \textbf{\autoref{section2}}.
\vspace{1em}
\phantomsection
\refstepcounter{sectionnr}
@ -50,7 +50,8 @@ Turn to 1 to begin.
\subsection*{\begin{center} \textbf{2} \end{center}}
\noindent
Congratulations, you won.
If you have the \textit{stick} then you must turn immediately to \textbf{\autoref{section12}}, and everything else in this section is ignored. You find a \textbf{book} here. If you have the \textit{sword} you must turn immediately to \textbf{\autoref{section5}}, again ignoring everything that follows. You drop the \textit{something valuable}
here if you have it, then go on to \textbf{\autoref{section7}}.
\vspace{1em}
\phantomsection
\refstepcounter{sectionnr}
@ -58,7 +59,7 @@ Turn to 1 to begin.
\subsection*{\begin{center} \textbf{3} \end{center}}
\noindent
OK. That was fun. Turn to \textbf{\autoref{section2}}.
Congratulations, you won.
\vspace{1em}
\phantomsection
\refstepcounter{sectionnr}
@ -66,7 +67,7 @@ Turn to 1 to begin.
\subsection*{\begin{center} \textbf{4} \end{center}}
\noindent
There is a rope here that can be cut using a \textit{sword}. If you have one and want to do that, see \textbf{\autoref{section3}}. Otherwise turn to \textbf{\autoref{section2}}.
OK. That was fun. Turn to \textbf{\autoref{section3}}.
\vspace{1em}
\phantomsection
\refstepcounter{sectionnr}
@ -74,7 +75,7 @@ Turn to 1 to begin.
\subsection*{\begin{center} \textbf{5} \end{center}}
\noindent
You found \textbf{something valuable}, but there is no way forward, so you head back to \textbf{\autoref{section11}}.
There is a rope here that can be cut using a \textit{sword}. If you have one and want to do that, see \textbf{\autoref{section4}}. You can also run to the autotest at \textbf{\autoref{section2}}. Otherwise turn to \textbf{\autoref{section3}}.
\vspace{1em}
\phantomsection
\refstepcounter{sectionnr}
@ -82,7 +83,7 @@ Turn to 1 to begin.
\subsection*{\begin{center} \textbf{6} \end{center}}
\noindent
A magic portal ahead will only allow you to pass if you did not pick up the \textit{cursed bracelet}, leading you to \textbf{\autoref{section5}}. If you have the \textit{cursed bracelet} you have to go back to \textbf{\autoref{section11}} instead. Actually feel free to head back to \textbf{\autoref{section11}} either way.
You found \textbf{something valuable}, but there is no way forward, so you head back to \textbf{\autoref{section12}}.
\vspace{1em}
\phantomsection
\refstepcounter{sectionnr}
@ -90,8 +91,7 @@ Turn to 1 to begin.
\subsection*{\begin{center} \textbf{7} \end{center}}
\noindent
OK \textit{stick}
dropped. Turn back to \textbf{\autoref{section11}} to confirm stick can not be picked up again even if the text says it is there (books work that way, although ideally this dynamic version should provide some hints that it is no longer there).
A magic portal ahead will only allow you to pass if you did not pick up the \textit{cursed bracelet}, leading you to \textbf{\autoref{section6}}. If you have the \textit{cursed bracelet} you have to go back to \textbf{\autoref{section12}} instead. Actually feel free to head back to \textbf{\autoref{section12}} either way.
\vspace{1em}
\phantomsection
\refstepcounter{sectionnr}
@ -99,7 +99,8 @@ Turn to 1 to begin.
\subsection*{\begin{center} \textbf{8} \end{center}}
\noindent
There is a \textbf{cursed bracelet} here. You can go on to \textbf{\autoref{section6}} or go back to \textbf{\autoref{section11}}. You can also drop the \textit{stick} for no particular reason if you have it, see \textbf{\autoref{section7}}.
OK \textit{stick}
dropped. Turn back to \textbf{\autoref{section12}} to confirm stick can not be picked up again even if the text says it is there (books work that way, although ideally this dynamic version should provide some hints that it is no longer there).
\vspace{1em}
\phantomsection
\refstepcounter{sectionnr}
@ -107,8 +108,7 @@ Turn to 1 to begin.
\subsection*{\begin{center} \textbf{9} \end{center}}
\noindent
OK. The door is broken, but so is the \textit{sword}
. Turn to \textbf{\autoref{section4}}.
There is a \textbf{cursed bracelet} here. You can go on to \textbf{\autoref{section7}} or go back to \textbf{\autoref{section12}}. You can also drop the \textit{stick} for no particular reason if you have it, see \textbf{\autoref{section8}}.
\vspace{1em}
\phantomsection
\refstepcounter{sectionnr}
@ -116,7 +116,8 @@ Turn to 1 to begin.
\subsection*{\begin{center} \textbf{10} \end{center}}
\noindent
There is a locked door here. If you have a \textit{key} you can use that to open the door, see \textbf{\autoref{section4}}. Being right before the link should be enough for the formatter to figure out that the key is required to be allowed to follow the link. Else you can try to open with the \textit{sword}, if you have it, see \textbf{\autoref{section9}}. Hopefully the magic is good enough to pair pre-conditions to links, or more markup must be added later. You could also try to go back to pick up the key, see \textbf{\autoref{section11}}.
OK. The door is broken, but so is the \textit{sword}
. Turn to \textbf{\autoref{section5}}.
\vspace{1em}
\phantomsection
\refstepcounter{sectionnr}
@ -124,6 +125,14 @@ Turn to 1 to begin.
\subsection*{\begin{center} \textbf{11} \end{center}}
\noindent
You have reached a t-junction. Here you find a \textbf{key} and a \textbf{stick}. You can go west to \textbf{\autoref{section10}}, or east to \textbf{\autoref{section8}}.
There is a locked door here. If you have a \textit{key} you can use that to open the door, see \textbf{\autoref{section5}}. Being right before the link should be enough for the formatter to figure out that the key is required to be allowed to follow the link. Else you can try to open with the \textit{sword}, if you have it, see \textbf{\autoref{section10}}. Hopefully the magic is good enough to pair pre-conditions to links, or more markup must be added later. You could also try to go back to pick up the key, see \textbf{\autoref{section12}}.
\vspace{1em}
\phantomsection
\refstepcounter{sectionnr}
\label{section12}
\subsection*{\begin{center} \textbf{12} \end{center}}
\noindent
You have reached a t-junction. Here you find a \textbf{key} and a \textbf{stick}. You can go west to \textbf{\autoref{section11}}, or east to \textbf{\autoref{section9}}.
\vspace{1em}
\end{document}

View file

@ -4,35 +4,38 @@
Turn to 1 to begin.
1
Demonstrating how to manage player Inventory. You start the book carrying a sword and a shield. Turn to 11.
Demonstrating how to manage player Inventory. You start the book carrying a sword and a shield. Turn to 12 or go to the autotest at 2.
2
Congratulations, you won.
If you have the stick then you must turn immediately to 12, and everything else in this section is ignored. You find a book here. If you have the sword you must turn immediately to 5, again ignoring everything that follows. You drop the something valuable here if you have it, then go on to 7.
3
OK. That was fun. Turn to 2.
Congratulations, you won.
4
There is a rope here that can be cut using a sword. If you have one and want to do that, see 3. Otherwise turn to 2.
OK. That was fun. Turn to 3.
5
You found something valuable, but there is no way forward, so you head back to 11.
There is a rope here that can be cut using a sword. If you have one and want to do that, see 4. You can also run to the autotest at 2. Otherwise turn to 3.
6
A magic portal ahead will only allow you to pass if you did not pick up the cursed bracelet, leading you to 5. If you have the cursed bracelet you have to go back to 11 instead. Actually feel free to head back to 11 either way.
You found something valuable, but there is no way forward, so you head back to 12.
7
OK stick dropped. Turn back to 11 to confirm stick can not be picked up again even if the text says it is there (books work that way, although ideally this dynamic version should provide some hints that it is no longer there).
A magic portal ahead will only allow you to pass if you did not pick up the cursed bracelet, leading you to 6. If you have the cursed bracelet you have to go back to 12 instead. Actually feel free to head back to 12 either way.
8
There is a cursed bracelet here. You can go on to 6 or go back to 11. You can also drop the stick for no particular reason if you have it, see 7.
OK stick dropped. Turn back to 12 to confirm stick can not be picked up again even if the text says it is there (books work that way, although ideally this dynamic version should provide some hints that it is no longer there).
9
OK. The door is broken, but so is the sword. Turn to 4.
There is a cursed bracelet here. You can go on to 7 or go back to 12. You can also drop the stick for no particular reason if you have it, see 8.
10
There is a locked door here. If you have a key you can use that to open the door, see 4. Being right before the link should be enough for the formatter to figure out that the key is required to be allowed to follow the link. Else you can try to open with the sword, if you have it, see 9. Hopefully the magic is good enough to pair pre-conditions to links, or more markup must be added later. You could also try to go back to pick up the key, see 11.
OK. The door is broken, but so is the sword. Turn to 5.
11
You have reached a t-junction. Here you find a key and a stick. You can go west to 10, or east to 8.
There is a locked door here. If you have a key you can use that to open the door, see 5. Being right before the link should be enough for the formatter to figure out that the key is required to be allowed to follow the link. Else you can try to open with the sword, if you have it, see 10. Hopefully the magic is good enough to pair pre-conditions to links, or more markup must be added later. You could also try to go back to pick up the key, see 12.
12
You have reached a t-junction. Here you find a key and a stick. You can go west to 11, or east to 9.

View file

@ -9,7 +9,9 @@
<link rel="stylesheet" href="gamebookformat.css"
type="text/css" />
<script>
gamebook.id = 'references';
if (typeof gamebook !== 'undefined') {
gamebook.id = 'references';
}
</script>
</head>
<body>
@ -19,7 +21,9 @@
<div class="introsection">
<div class="introsectionheading">Introduction</div>
<div class="introsectionbody">
This gamebook demonstrates simple references between sections. Also notice that an intro section like this one can reference sections, like the start at <a class="sectionref enabledlink" data-ref="1">1</a> or the next section at <a class="sectionref enabledlink" data-ref="400">400</a>.
This gamebook demonstrates simple references between sections. Also notice that an intro section like this one can reference sections, like the start at <a class="sectionref enabledlink" data-ref="1"
href="#section1">1</a> or the next section at <a class="sectionref enabledlink" data-ref="400"
href="#section400">400</a>.
</div>
</div>
@ -29,7 +33,7 @@
<div class="startlink"
onclick="gamebook.turnTo(1)">Turn to 1 to begin.</div>
<script>
if (gamebook.hasSavedGame()) {
if (typeof gamebook !== 'undefined' && gamebook.hasSavedGame()) {
var resumeLinks = document.getElementsByClassName('resumelink');
Array.prototype.forEach.call(resumeLinks, function(e) {
e.classList.remove('nodisplay');
@ -39,7 +43,9 @@
<div class="section" id="section1">
<div class="sectionnumber" id="para1">1</div>
<div class="sectiontext">
This is where the adventure begins. You can go on to the next section, see <a class="sectionref enabledlink" data-ref="400">400</a> or try the random selection feature at <a class="sectionref enabledlink" data-ref="399">399</a>.
This is where the adventure begins. You can go on to the next section, see <a class="sectionref enabledlink" data-ref="400"
href="#section400">400</a> or try the random selection feature at <a class="sectionref enabledlink" data-ref="399"
href="#section399">399</a>.
</div>
</div>
<script>
@ -69,7 +75,10 @@ if (this.gamebook) {
</script><div class="section" id="section399">
<div class="sectionnumber" id="para399">399</div>
<div class="sectiontext">
<span class="random enabledlink">Pick a destination at random</span> from <a class="sectionref enabledlink" data-ref="400">400</a> or <a class="sectionref enabledlink" data-ref="397">397</a> or <a class="sectionref enabledlink" data-ref="398">398</a>.
<span class="random enabledlink">Pick a destination at random</span> from <a class="sectionref enabledlink" data-ref="400"
href="#section400">400</a> or <a class="sectionref enabledlink" data-ref="397"
href="#section397">397</a> or <a class="sectionref enabledlink" data-ref="398"
href="#section398">398</a>.
</div>
</div>
<script>
@ -79,7 +88,8 @@ if (this.gamebook) {
</script><div class="section" id="section400">
<div class="sectionnumber" id="para400">400</div>
<div class="sectiontext">
This is the next section. Go on to the end at <a class="sectionref enabledlink" data-ref="397">397</a>.
This is the next section. Go on to the end at <a class="sectionref enabledlink" data-ref="397"
href="#section397">397</a>.
</div>
</div>
<script>
@ -101,8 +111,8 @@ if (this.gamebook) {
</div>
</div>
<script>
if (this.gamebook) {
gamebook.runActionsInIntroSections();
if (typeof gamebook !== 'undefined') {
gamebook.prepare();
}
</script>
<div class="displayintrolink nodisplay"

View file

@ -8,6 +8,7 @@
\b \qc Gamebook
\b0\
\
\b \qc Introduction
\b0\

View file

@ -9,7 +9,9 @@
<link rel="stylesheet" href="gamebookformat.css"
type="text/css" />
<script>
gamebook.id = 'unreachable';
if (typeof gamebook !== 'undefined') {
gamebook.id = 'unreachable';
}
</script>
</head>
<body>
@ -23,7 +25,7 @@
<div class="startlink"
onclick="gamebook.turnTo(1)">Turn to 1 to begin.</div>
<script>
if (gamebook.hasSavedGame()) {
if (typeof gamebook !== 'undefined' && gamebook.hasSavedGame()) {
var resumeLinks = document.getElementsByClassName('resumelink');
Array.prototype.forEach.call(resumeLinks, function(e) {
e.classList.remove('nodisplay');
@ -33,7 +35,8 @@
<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="6">6</a>.
It starts here. You can get to <a class="sectionref enabledlink" data-ref="6"
href="#section6">6</a>.
</div>
</div>
<script>
@ -95,8 +98,8 @@ if (this.gamebook) {
</div>
</div>
<script>
if (this.gamebook) {
gamebook.runActionsInIntroSections();
if (typeof gamebook !== 'undefined') {
gamebook.prepare();
}
</script>
<div class="displayintrolink nodisplay"

View file

@ -2,12 +2,8 @@ digraph gamebook {
1->5
1->2
1->4
2->4
4->2
4->3
5->3
}

View file

@ -9,7 +9,9 @@
<link rel="stylesheet" href="gamebookformat.css"
type="text/css" />
<script>
gamebook.id = 'withdemo';
if (typeof gamebook !== 'undefined') {
gamebook.id = 'withdemo';
}
</script>
</head>
<body>
@ -23,7 +25,7 @@
<div class="startlink"
onclick="gamebook.turnTo(1)">Turn to 1 to begin.</div>
<script>
if (gamebook.hasSavedGame()) {
if (typeof gamebook !== 'undefined' && gamebook.hasSavedGame()) {
var resumeLinks = document.getElementsByClassName('resumelink');
Array.prototype.forEach.call(resumeLinks, function(e) {
e.classList.remove('nodisplay');
@ -33,7 +35,10 @@
<div class="section" id="section1">
<div class="sectionnumber" id="para1">1</div>
<div class="sectiontext">
This gamebook contains a few sections tagged as demo, that will be included when building the example (see withdemo.gamebook.options file). There are also some sections without the demo tag that will be ignored. Go on to <a class="sectionref enabledlink" data-ref="5">5</a> or <a class="sectionref enabledlink" data-ref="4">4</a> or <a class="sectionref enabledlink" data-ref="2">2</a>.
This gamebook contains a few sections tagged as demo, that will be included when building the example (see withdemo.gamebook.options file). There are also some sections without the demo tag that will be ignored. Go on to <a class="sectionref enabledlink" data-ref="5"
href="#section5">5</a> or <a class="sectionref enabledlink" data-ref="4"
href="#section4">4</a> or <a class="sectionref enabledlink" data-ref="2"
href="#section2">2</a>.
</div>
</div>
<script>
@ -43,7 +48,8 @@ if (this.gamebook) {
</script><div class="section" id="section2">
<div class="sectionnumber" id="para2">2</div>
<div class="sectiontext">
This is where references to non-demo sections will lead you. It is configured at the top of the gamebook file. Remember to tag this section correctly to be included. Go on to <a class="sectionref enabledlink" data-ref="4">4</a>.
This is where references to non-demo sections will lead you. It is configured at the top of the gamebook file. Remember to tag this section correctly to be included. Go on to <a class="sectionref enabledlink" data-ref="4"
href="#section4">4</a>.
</div>
</div>
<script>
@ -63,7 +69,9 @@ if (this.gamebook) {
</script><div class="section" id="section4">
<div class="sectionnumber" id="para4">4</div>
<div class="sectiontext">
This is the second demo section. You can go on to the end at <a class="sectionref enabledlink" data-ref="3">3</a> or alternative (not in demo) end at <a class="sectionref enabledlink" data-ref="2">2</a>.
This is the second demo section. You can go on to the end at <a class="sectionref enabledlink" data-ref="3"
href="#section3">3</a> or alternative (not in demo) end at <a class="sectionref enabledlink" data-ref="2"
href="#section2">2</a>.
</div>
</div>
<script>
@ -73,7 +81,8 @@ if (this.gamebook) {
</script><div class="section" id="section5">
<div class="sectionnumber" id="para5">5</div>
<div class="sectiontext">
This is the first demo section (not counting the start section). You can go on to the end at <a class="sectionref enabledlink" data-ref="3">3</a>.
This is the first demo section (not counting the start section). You can go on to the end at <a class="sectionref enabledlink" data-ref="3"
href="#section3">3</a>.
</div>
</div>
<script>
@ -95,8 +104,8 @@ if (this.gamebook) {
</div>
</div>
<script>
if (this.gamebook) {
gamebook.runActionsInIntroSections();
if (typeof gamebook !== 'undefined') {
gamebook.prepare();
}
</script>
<div class="displayintrolink nodisplay"

View file

@ -9,7 +9,9 @@
<link rel="stylesheet" href="gamebookformat.css"
type="text/css" />
<script>
gamebook.id = 'withoutdemo';
if (typeof gamebook !== 'undefined') {
gamebook.id = 'withoutdemo';
}
</script>
</head>
<body>
@ -23,7 +25,7 @@
<div class="startlink"
onclick="gamebook.turnTo(1)">Turn to 1 to begin.</div>
<script>
if (gamebook.hasSavedGame()) {
if (typeof gamebook !== 'undefined' && gamebook.hasSavedGame()) {
var resumeLinks = document.getElementsByClassName('resumelink');
Array.prototype.forEach.call(resumeLinks, function(e) {
e.classList.remove('nodisplay');
@ -33,7 +35,10 @@
<div class="section" id="section1">
<div class="sectionnumber" id="para1">1</div>
<div class="sectiontext">
This gamebook contains a few sections tagged as demo, that will be included when building the example as withdemo.gamebook (see withdemo.gamebook.options file). There are also some sections without the demo tag that will be ignored. This version is built without options and includes all sections. Go on to <a class="sectionref enabledlink" data-ref="7">7</a> or <a class="sectionref enabledlink" data-ref="5">5</a> or <a class="sectionref enabledlink" data-ref="8">8</a>.
This gamebook contains a few sections tagged as demo, that will be included when building the example as withdemo.gamebook (see withdemo.gamebook.options file). There are also some sections without the demo tag that will be ignored. This version is built without options and includes all sections. Go on to <a class="sectionref enabledlink" data-ref="7"
href="#section7">7</a> or <a class="sectionref enabledlink" data-ref="5"
href="#section5">5</a> or <a class="sectionref enabledlink" data-ref="8"
href="#section8">8</a>.
</div>
</div>
<script>
@ -53,7 +58,8 @@ if (this.gamebook) {
</script><div class="section" id="section3">
<div class="sectionnumber" id="para3">3</div>
<div class="sectiontext">
This is where references to non-demo sections will lead you. It is configured at the top of the gamebook file. Remember to tag this section correctly to be included. Nothing should lead to this section when building without the demo tag option. Go on to <a class="sectionref enabledlink" data-ref="5">5</a>.
This is where references to non-demo sections will lead you. It is configured at the top of the gamebook file. Remember to tag this section correctly to be included. Nothing should lead to this section when building without the demo tag option. Go on to <a class="sectionref enabledlink" data-ref="5"
href="#section5">5</a>.
</div>
</div>
<script>
@ -73,7 +79,9 @@ if (this.gamebook) {
</script><div class="section" id="section5">
<div class="sectionnumber" id="para5">5</div>
<div class="sectiontext">
This is the second demo section. You can go on to the end at <a class="sectionref enabledlink" data-ref="4">4</a> or alternative (not in demo) end at <a class="sectionref enabledlink" data-ref="2">2</a>.
This is the second demo section. You can go on to the end at <a class="sectionref enabledlink" data-ref="4"
href="#section4">4</a> or alternative (not in demo) end at <a class="sectionref enabledlink" data-ref="2"
href="#section2">2</a>.
</div>
</div>
<script>
@ -83,7 +91,10 @@ if (this.gamebook) {
</script><div class="section" id="section6">
<div class="sectionnumber" id="para6">6</div>
<div class="sectiontext">
This section is not included in the demo. You can go on to <a class="sectionref enabledlink" data-ref="5">5</a> or <a class="sectionref enabledlink" data-ref="4">4</a> or <a class="sectionref enabledlink" data-ref="2">2</a>.
This section is not included in the demo. You can go on to <a class="sectionref enabledlink" data-ref="5"
href="#section5">5</a> or <a class="sectionref enabledlink" data-ref="4"
href="#section4">4</a> or <a class="sectionref enabledlink" data-ref="2"
href="#section2">2</a>.
</div>
</div>
<script>
@ -93,7 +104,8 @@ if (this.gamebook) {
</script><div class="section" id="section7">
<div class="sectionnumber" id="para7">7</div>
<div class="sectiontext">
This is the first demo section (not counting the start section). You can go on to the end at <a class="sectionref enabledlink" data-ref="4">4</a>.
This is the first demo section (not counting the start section). You can go on to the end at <a class="sectionref enabledlink" data-ref="4"
href="#section4">4</a>.
</div>
</div>
<script>
@ -103,7 +115,8 @@ if (this.gamebook) {
</script><div class="section" id="section8">
<div class="sectionnumber" id="para8">8</div>
<div class="sectiontext">
This section is not included in the demo. Turn to <a class="sectionref enabledlink" data-ref="6">6</a>.
This section is not included in the demo. Turn to <a class="sectionref enabledlink" data-ref="6"
href="#section6">6</a>.
</div>
</div>
<script>
@ -125,8 +138,8 @@ if (this.gamebook) {
</div>
</div>
<script>
if (this.gamebook) {
gamebook.runActionsInIntroSections();
if (typeof gamebook !== 'undefined') {
gamebook.prepare();
}
</script>
<div class="displayintrolink nodisplay"

View file

@ -29,6 +29,7 @@ class OutputFormat (object):
refs = []
refsdict = ReferenceFormatter(section.nr,
shuffled_sections.name_to_nr,
shuffled_sections.missingto,
self.format_with_template("section_ref"),
self.quote)
formatted_text = self.format_section_body(section, refsdict)
@ -55,6 +56,7 @@ class OutputFormat (object):
refs = []
refsdict = ReferenceFormatter(section.nr,
shuffled_sections.name_to_nr,
shuffled_sections.missingto,
self.format_with_template("section_ref"),
self.quote)
formatted_text = self.format_section_body(section, refsdict)
@ -142,18 +144,22 @@ class OutputFormat (object):
class ReferenceFormatter (object):
"There is probably a better way, but this hack seems to work."
def __init__(self, from_nr, name_to_nr, ref_template, quote):
def __init__(self, from_nr, name_to_nr, missingto, ref_template, quote):
self.from_nr = from_nr
self.name_to_nr = name_to_nr
self.found = set()
self.ref_template = ref_template
self.items = {'nr' : from_nr}
self.quote = quote
self.missingto = missingto
def __getitem__(self, key):
if key in self.items:
return self.quote(self.items[key])
to_nr = self.name_to_nr[key]
if key in self.name_to_nr:
to_nr = self.name_to_nr[key]
else:
to_nr = self.name_to_nr[self.missingto]
res = self.ref_template % {
'nr' : to_nr,
'from_nr' : self.from_nr

View file

@ -43,8 +43,7 @@ class IntroSection (Section):
repr(self.tags))
class ShuffledSections:
def __init__(self, as_list, from_nr, from_name, nr_sections,
skipped_names, missingto):
def __init__(self, as_list, from_nr, from_name, nr_sections, missingto):
self.as_list = as_list
self.from_nr = from_nr
self.from_name = from_name
@ -53,8 +52,7 @@ class ShuffledSections:
self.name_to_nr[n] = from_name[n].nr
for nr in nr_sections:
self.name_to_nr[nr_sections[nr]] = nr
for name in skipped_names:
self.name_to_nr[name] = self.name_to_nr[missingto]
self.missingto = missingto
STR_BOOK_CONFIG = set(['id', 'title', 'author', 'starttext', 'hideintrotext',
'showintrotext', 'resumetext', 'missingto'])
@ -68,7 +66,6 @@ class Book:
self.nr_sections = {}
self.codewords = set()
self.includetag = includetag
self.skipped_names = set()
self.config = {'max' : 0,
'title' : 'Gamebook',
'author' : '',
@ -89,7 +86,6 @@ class Book:
def add(self, section):
if self.includetag and not section.hastag(self.includetag):
self.skipped_names.add(section.name)
return
if section.name in self.from_name:
raise Exception('Duplicate section names (%s) not allowed.' %
@ -138,5 +134,5 @@ class Book:
if section:
shuffled_from_name[section.name] = section
return ShuffledSections(as_list, from_nr, shuffled_from_name,
self.nr_sections, self.skipped_names,
self.nr_sections,
self.config['missingto'])

View file

@ -31,18 +31,20 @@ class TestReferenceFormatter(TestCase):
pass
def test_create(self):
rf = output.ReferenceFormatter(1, {}, "", str)
rf = output.ReferenceFormatter(1, {}, None, "", str)
def test_get_item(self):
rf = output.ReferenceFormatter(1, {'a' : 1, 'b' : 2}, "%(nr)d", int)
rf = output.ReferenceFormatter(1, {'a' : 1, 'b' : 2}, None,
"%(nr)d", int)
self.assertEqual(rf['nr'], 1)
def test_get_quoted_item(self):
rf = output.ReferenceFormatter(1, {'a' : 1, 'b' : 2}, "%(nr)d", str)
rf = output.ReferenceFormatter(1, {'a' : 1, 'b' : 2}, None,
"%(nr)d", str)
self.assertEqual(rf['nr'], '1')
def test_get_reference(self):
rf = output.ReferenceFormatter(1, {'a' : 1, 'b' : 2},
rf = output.ReferenceFormatter(1, {'a' : 1, 'b' : 2}, None,
"%(from_nr)d to %(nr)d", None)
self.assertEqual(rf['b'], '1 to 2')
self.assertEquals(rf.found, set(['1 to 2']))