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

Added trade tag.

Also documented a couple of bugs related to cost
and trade. Seems like that system needs some rethinking.
This commit is contained in:
Pelle Nilsson 2014-03-07 21:22:10 +01:00
parent dbc1dd6a8e
commit be2bc017bc
10 changed files with 123 additions and 22 deletions

View file

@ -15,10 +15,19 @@ You can go on to the end at [[theend]].
* other :HTML:
Hopefully you now have 50 less gold than you just had.
You can go back to [[start]].
You can also go to [[someotherplace]] but an angry troll
is blocking your path and will only allow you to go there
if you give it a [trade item]gold ring[/trade].
* other :TXT:DEBUG:TEX:DOT:RTF:
Now you have 50 less gold than you just had.
You can go back to [[start]].
* someotherplace
This is somewhere else. Congratulations you have found [inc gold]100[/inc] gold!
Go back to [[start]].
* theend
It ends here.
It ends here. There is a [found item]crown[/found] here that you can trade for
some [trade item]spiderweb[/trade].

View file

@ -1,11 +1,12 @@
BEGIN DEBUG OUTPUT
Book title: Gamebook
Number of sections: 3
Number of sections: 4
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 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) - Now you have 50 less gold than you just had. You can go back to 1.
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 4 at a cost of 50. You can go on to the end at 2.
2 (theend) - It ends here. There is a [FOUND item]crown[/FOUND] here that you can trade for some spiderweb.
3 (someotherplace) - This is somewhere else. Congratulations you have found [INC gold]100[/INC] gold! Go back to 1.
4 (other) - Now you have 50 less gold than you just had. You can go back to 1.
END DEBUG OUTPUT

View file

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

View file

@ -65,8 +65,8 @@
. You can pick up some <span class="found enabledlink" data-type="item"
data-what="spiderweb"
>spiderweb</span>
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"
for free. You can go to <a class="sectionref enabledlink" data-ref="4"
href="#section4">4</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"
@ -80,7 +80,13 @@ if (typeof gamebook !== 'undefined') {
</script><div class="section" id="section2">
<div class="sectionnumber" id="para2">2</div>
<div class="sectiontext">
It ends here.
It ends here. There is a <span class="found enabledlink" data-type="item"
data-what="crown"
>crown</span>
here that you can trade for some <span class="trade" data-type="item"
data-what="spiderweb"
>spiderweb</span>
.
</div>
</div>
<script>
@ -90,7 +96,8 @@ if (typeof gamebook !== 'undefined') {
</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"
This is somewhere else. Congratulations you have found <span class="inc counterChange" data-type="gold"
data-amount="100">100</span> gold! Go back to <a class="sectionref enabledlink" data-ref="1"
href="#section1">1</a>.
</div>
</div>
@ -98,6 +105,21 @@ href="#section1">1</a>.
if (typeof gamebook !== 'undefined') {
gamebook.addSection(3, document.getElementById('section3'));
}
</script><div class="section" id="section4">
<div class="sectionnumber" id="para4">4</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>. You can also go to <a class="sectionref enabledlink" data-ref="3"
href="#section3">3</a> but an angry troll is blocking your path and will only allow you to go there if you give it a <span class="trade" data-type="item"
data-what="gold ring"
>gold ring</span>
.
</div>
</div>
<script>
if (typeof gamebook !== 'undefined') {
gamebook.addSection(4, document.getElementById('section4'));
}
</script> <div id="counters" class="counters">
</div>
<div id="counterTemplate" class="counterTemplate">

View file

@ -21,7 +21,7 @@
\
\b \qc 1
\b0\
\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
\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 4
\b0
at a cost of 50. You can go on to the end at \b 2
\b0
@ -30,11 +30,18 @@
\b \qc 2
\b0\
\ql It ends here. \
\ql It ends here. There is a crown here that you can trade for some spiderweb. \
\
\b \qc 3
\b0\
\ql This is somewhere else. Congratulations you have found 100 gold! Go back to \b 1
\b0
. \
\
\b \qc 4
\b0\
\ql Now you 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 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}}.
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{section4}} at a cost of 50. You can go on to the end at \textbf{\autoref{section2}}.
\vspace{1em}
\phantomsection
\refstepcounter{sectionnr}
@ -54,13 +54,21 @@ Turn to 1 to begin.
\subsection*{\begin{center} \textbf{2} \end{center}}
\noindent
It ends here.
It ends here. There is a \textbf{crown} here that you can trade for some spiderweb.
\vspace{1em}
\phantomsection
\refstepcounter{sectionnr}
\label{section3}
\subsection*{\begin{center} \textbf{3} \end{center}}
\noindent
This is somewhere else. Congratulations you have found 100 gold! Go back to \textbf{\autoref{section1}}.
\vspace{1em}
\phantomsection
\refstepcounter{sectionnr}
\label{section4}
\subsection*{\begin{center} \textbf{4} \end{center}}
\noindent
Now you have 50 less gold than you just had. You can go back to \textbf{\autoref{section1}}.
\vspace{1em}

View file

@ -6,11 +6,14 @@ Introduction
Turn to 1 to begin.
1
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.
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 4 at a cost of 50. You can go on to the end at 2.
2
It ends here.
It ends here. There is a crown here that you can trade for some spiderweb.
3
This is somewhere else. Congratulations you have found 100 gold! Go back to 1.
4
Now you have 50 less gold than you just had. You can go back to 1.

View file

@ -349,7 +349,10 @@ var gamebook = {
c.addEventListener('click', gamebook.takeFound);
} else if (c.classList.contains('cost')) {
gamebook.addCost(c, lastCanHaveCost);
} else if (c.classList.contains('trade')) {
gamebook.addTrade(c, lastCanHaveCost);
}
});
},
@ -367,6 +370,20 @@ var gamebook = {
}
},
addTrade : function(c, e) {
var what = c.dataset.what;
var tradetype = c.dataset.type;
if (gamebook.player.has(tradetype, what)) {
e.classList.add("enabledlink");
e.classList.remove("disabledlink");
e.dataset.trade = what;
e.dataset.tradetype = tradetype;
} else {
e.classList.add("disabledlink");
e.classList.remove("enabledlink");
}
},
'enableLink' : function(e) {
e.addEventListener('click', gamebook.getTurnToFunction(e.dataset.ref));
e.classList.add("enabledlink");
@ -470,15 +487,28 @@ var gamebook = {
},
'payPrice' : function(e) {
var cost, counter, trade, tradetype;
if ('cost' in e.dataset && 'costtype' in e.dataset) {
var cost = parseInt(e.dataset.cost);
var counter = gamebook.player.counters[e.dataset.costtype];
cost = parseInt(e.dataset.cost);
counter = gamebook.player.counters[e.dataset.costtype];
if (counter.value - cost < counter.minValue) {
return false;
}
}
if ('trade' in e.dataset && 'tradetype' in e.dataset) {
trade = e.dataset.trade;
tradetype = e.dataset.tradetype;
if (!gamebook.player.has(tradetype, trade)) {
return false;
}
}
if (cost) {
counter.dec(cost);
gamebook.updateCountersView();
}
if (trade) {
gamebook.player.drop(tradetype, trade);
}
return true;
},

View file

@ -0,0 +1,3 @@
<span class="trade" data-type="%(arg1)s"
data-what="%(inner)s"
>%(inner)s</span>

View file

@ -1,4 +1,4 @@
* TODO [58/78] [74%]
* TODO [60/82] [73%]
** DONE Debug output
** DONE DOT output
** DONE LaTeX output
@ -89,10 +89,21 @@
This will also work for picking eg starting skills.
** DONE Subtract from counter when following link (implies has at least that)
This is the cost tag again, when it immediately follows a reference.
** TODO Add keyword when following link
** DONE Remove keyword (or item) when picking up something
Trade one thing from a collection to add something else to some collection.
** TODO Add keyword (or item) when following link
This is a new tag that follows a reference similar to a cost tag.
** TODO Remove keyword when following link
** DONE Remove keyword (or item) when following link
This is a new tag that follows a reference similar to a cost tag.
** TODO Fix bug in HTML with being able to click disabled things
It is possible sometimes to follow a disabled reference or
pick something up even when not having enough to pay its price.
Seems to only happen with things that do have a price, not those
disabled for other reasons.
** TODO When buying or trading for something, it can be receievd again
The js code to make sure that something you have had but later dropped
can not be picked up again seems to be broken for things that
have a price.
** TODO Use points to buy values for counters
Eg to buy starting values for some attributes in introsection.
** TODO Counter max values, not leaving a section too early
@ -127,6 +138,12 @@
- Dynamic (markup needed to make playable (HTML) version)
- Standard output formats reference
- Customization (make new output formats or override existing)
** TODO Make it possible for a modifier tag to refer to any other tag
Currently a modifier (eg cost) always applies to tag on its left or right,
and it can be a bit confusing to remember what direction, or awkward to
write the text in a good way to follow that rule. Make it possible to add
to a tag what it applies to (eg what item or reference the cost should apply to,
anywhere in the section).
** TODO HTML with javascript active, do not make new URLs (that break history)
** TODO Javascript GUI tests running in a browser
Preferably headless (in nodejs?). Run tests on gamebook html example(s).