1
0
Fork 0
mirror of https://github.com/Oreolek/gamebookformat.git synced 2024-05-17 08:28:20 +03:00

Pay something (a counter, eg gold) to follow a reference.

Also refactored old code to pay for item slightly.
This commit is contained in:
Pelle Nilsson 2014-03-04 23:02:51 +01:00
parent 23999c2373
commit 86667922ec
9 changed files with 95 additions and 21 deletions

View file

@ -5,10 +5,16 @@ You also have an [collect item]Inventory[/item]. At start you carry
a [add item]sword[/add].
* 1 start
You can buy a [found item]shield[/found] here for [cost gold]50[/cost] Gold.
You can buy a [found item]shield[/found] here for [cost gold]50[/cost] Gold
or a beautiful [found item]gold ring[/found] for only [cost gold]75[/cost].
There is also a [found item]chain mail[/found] costing [cost gold]150[/cost].
You can pick up some [found item]spiderweb[/found] for free.
You can go to [[other]] at a cost of [cost gold]50[/cost].
You can go on to the end at [[theend]].
* other
Hopefully you now have 50 less gold than you just had.
You can go back to [[start]].
* theend
It ends here.

View file

@ -1,10 +1,11 @@
BEGIN DEBUG OUTPUT
Book title: Gamebook
Number of sections: 2
Number of sections: 3
Introduction
Testing trade of things. You can buy things using [COUNT gold]Gold[/COUNT] of which you start with [SET gold]100[/SET]. You also have an [COLLECT item]Inventory[/COLLECT]. At start you carry a [ADD item]sword[/ADD].
Turn to 1 to begin.
1 (start) - You can buy a [FOUND item]shield[/FOUND] here for 50 Gold. There is also a [FOUND item]chain mail[/FOUND] costing 150. You can pick up some [FOUND item]spiderweb[/FOUND] for free. You can go on to the end at 2.
1 (start) - You can buy a [FOUND item]shield[/FOUND] here for 50 Gold or a beautiful [FOUND item]gold ring[/FOUND] for only 75. There is also a [FOUND item]chain mail[/FOUND] costing 150. You can pick up some [FOUND item]spiderweb[/FOUND] for free. You can go to 3 at a cost of 50. You can go on to the end at 2.
2 (theend) - It ends here.
3 (other) - Hopefully you now have 50 less gold than you just had. You can go back to 1.
END DEBUG OUTPUT

View file

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

View file

@ -47,19 +47,29 @@
You can buy a <span class="found enabledlink" data-type="item"
data-what="shield"
>shield</span>
here for <span class="cost enabledlink" data-type="gold"
here for <span class="cost" data-type="gold"
data-amount="50"
>50</span>
Gold. There is also a <span class="found enabledlink" data-type="item"
Gold or a beautiful <span class="found enabledlink" data-type="item"
data-what="gold ring"
>gold ring</span>
for only <span class="cost" data-type="gold"
data-amount="75"
>75</span>
. There is also a <span class="found enabledlink" data-type="item"
data-what="chain mail"
>chain mail</span>
costing <span class="cost enabledlink" data-type="gold"
costing <span class="cost" data-type="gold"
data-amount="150"
>150</span>
. You can pick up some <span class="found enabledlink" data-type="item"
data-what="spiderweb"
>spiderweb</span>
for free. You can go on to the end at <a class="sectionref enabledlink" data-ref="2"
for free. You can go to <a class="sectionref enabledlink" data-ref="3"
href="#section3">3</a> at a cost of <span class="cost" data-type="gold"
data-amount="50"
>50</span>
. You can go on to the end at <a class="sectionref enabledlink" data-ref="2"
href="#section2">2</a>.
</div>
</div>
@ -77,6 +87,17 @@ if (typeof gamebook !== 'undefined') {
if (typeof gamebook !== 'undefined') {
gamebook.addSection(2, document.getElementById('section2'));
}
</script><div class="section" id="section3">
<div class="sectionnumber" id="para3">3</div>
<div class="sectiontext">
Hopefully you now have 50 less gold than you just had. You can go back to <a class="sectionref enabledlink" data-ref="1"
href="#section1">1</a>.
</div>
</div>
<script>
if (typeof gamebook !== 'undefined') {
gamebook.addSection(3, document.getElementById('section3'));
}
</script> <div id="counters" class="counters">
</div>
<div id="counterTemplate" class="counterTemplate">

View file

@ -21,7 +21,9 @@
\
\b \qc 1
\b0\
\ql You can buy a shield here for 50 Gold. There is also a chain mail costing 150. You can pick up some spiderweb for free. You can go on to the end at \b 2
\ql You can buy a shield here for 50 Gold or a beautiful gold ring for only 75. There is also a chain mail costing 150. You can pick up some spiderweb for free. You can go to \b 3
\b0
at a cost of 50. You can go on to the end at \b 2
\b0
. \
\
@ -31,4 +33,11 @@
\ql It ends here. \
\
\b \qc 3
\b0\
\ql Hopefully you now have 50 less gold than you just had. You can go back to \b 1
\b0
. \
\
}

View file

@ -46,7 +46,7 @@ Turn to 1 to begin.
\subsection*{\begin{center} \textbf{1} \end{center}}
\noindent
You can buy a \textbf{shield} here for 50 Gold. There is also a \textbf{chain mail} costing 150. You can pick up some \textbf{spiderweb} for free. You can go on to the end at \textbf{\autoref{section2}}.
You can buy a \textbf{shield} here for 50 Gold or a beautiful \textbf{gold ring} for only 75. There is also a \textbf{chain mail} costing 150. You can pick up some \textbf{spiderweb} for free. You can go to \textbf{\autoref{section3}} at a cost of 50. You can go on to the end at \textbf{\autoref{section2}}.
\vspace{1em}
\phantomsection
\refstepcounter{sectionnr}
@ -56,4 +56,12 @@ Turn to 1 to begin.
\noindent
It ends here.
\vspace{1em}
\phantomsection
\refstepcounter{sectionnr}
\label{section3}
\subsection*{\begin{center} \textbf{3} \end{center}}
\noindent
Hopefully you now have 50 less gold than you just had. You can go back to \textbf{\autoref{section1}}.
\vspace{1em}
\end{document}

View file

@ -6,8 +6,11 @@ Introduction
Turn to 1 to begin.
1
You can buy a shield here for 50 Gold. There is also a chain mail costing 150. You can pick up some spiderweb for free. You can go on to the end at 2.
You can buy a shield here for 50 Gold or a beautiful gold ring for only 75. There is also a chain mail costing 150. You can pick up some spiderweb for free. You can go to 3 at a cost of 50. You can go on to the end at 2.
2
It ends here.
3
Hopefully you now have 50 less gold than you just had. You can go back to 1.

View file

@ -289,6 +289,7 @@ var gamebook = {
} else {
gamebook.disableLink(c);
}
lastCanHaveCost = c;
enableNextLink = !(hasXorScope && !xorEnableNext);
hasAutoScope = false;
hasXorScope = false;
@ -367,8 +368,7 @@ var gamebook = {
},
'enableLink' : function(e) {
e.addEventListener('click',
gamebook.getTurnToFunction(e.dataset.ref));
e.addEventListener('click', gamebook.getTurnToFunction(e.dataset.ref));
e.classList.add("enabledlink");
e.classList.remove("disabledlink");
},
@ -447,7 +447,9 @@ var gamebook = {
return this.turnToFunctions[nr];
} else {
var f = function () {
gamebook.turnTo(nr);
if (gamebook.payPrice(this)) {
gamebook.turnTo(nr);
}
};
this.turnToFunctions[nr] = f;
return f;
@ -456,21 +458,43 @@ var gamebook = {
'takeFound' : function(evt) {
evt.preventDefault();
if (!gamebook.payPrice(this)) {
return false;
}
this.classList.remove("enabledlink");
this.classList.add("disabledlink");
var what = this.dataset.what;
var type = this.dataset.type;
if ('cost' in this.dataset && 'costtype' in this.dataset) {
var cost = parseInt(this.dataset.cost);
var counter = gamebook.player.counters[this.dataset.costtype];
gamebook.player.add(type, what);
gamebook.disableLinksNowTooExpensive();
},
'payPrice' : function(e) {
if ('cost' in e.dataset && 'costtype' in e.dataset) {
var cost = parseInt(e.dataset.cost);
var counter = gamebook.player.counters[e.dataset.costtype];
if (counter.value - cost < counter.minValue) {
// this should not happen, link should be disabled
return;
return false;
}
counter.dec(cost);
gamebook.updateCountersView();
}
gamebook.player.add(type, what);
return true;
},
'disableLinksNowTooExpensive' : function() {
var e = this.sections[this.player.currentSection].element;
var cs = e.getElementsByClassName('sectiontext')[0].childNodes;
Array.prototype.forEach.call(cs, function(c) {
if (c.dataset && 'cost' in c.dataset && 'costtype' in c.dataset) {
var cost = parseInt(c.dataset.cost);
var counter = gamebook.player.counters[c.dataset.costtype];
if (counter.value - cost < counter.minValue) {
c.classList.remove("enabledlink");
c.classList.add("disabledlink");
}
}
});
}
};

View file

@ -1,3 +1,3 @@
<span class="cost enabledlink" data-type="%(arg1)s"
<span class="cost" data-type="%(arg1)s"
data-amount="%(inner)s"
>%(inner)s</span>