mirror of
https://github.com/Oreolek/gamebookformat.git
synced 2024-06-26 03:41:04 +03:00
Cost tag that sets a price on something found.
This commit is contained in:
parent
17257b7970
commit
f1d2f933ba
14
examples/trade.gamebook
Normal file
14
examples/trade.gamebook
Normal file
|
@ -0,0 +1,14 @@
|
|||
= 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[/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.
|
||||
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 on to the end at [[theend]].
|
||||
|
||||
* theend
|
||||
It ends here.
|
|
@ -99,8 +99,8 @@ if (this.gamebook) {
|
|||
</script><div class="section" id="section6">
|
||||
<div class="sectionnumber" id="para6">6</div>
|
||||
<div class="sectiontext">
|
||||
You found <span class="found enabledlink"
|
||||
onclick="gamebook.player.add('item', 'something valuable')"
|
||||
You found <span class="found enabledlink" data-type="item"
|
||||
data-what="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>.
|
||||
|
@ -139,8 +139,8 @@ if (this.gamebook) {
|
|||
</script><div class="section" id="section9">
|
||||
<div class="sectionnumber" id="para9">9</div>
|
||||
<div class="sectiontext">
|
||||
There is a <span class="found enabledlink"
|
||||
onclick="gamebook.player.add('item', 'cursed bracelet')"
|
||||
There is a <span class="found enabledlink" data-type="item"
|
||||
data-what="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"
|
||||
|
@ -180,11 +180,11 @@ if (this.gamebook) {
|
|||
</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')"
|
||||
You have reached a t-junction. Here you find a <span class="found enabledlink" data-type="item"
|
||||
data-what="key"
|
||||
>key</span>
|
||||
and a <span class="found enabledlink"
|
||||
onclick="gamebook.player.add('item', 'stick')"
|
||||
and a <span class="found enabledlink" data-type="item"
|
||||
data-what="stick"
|
||||
>stick</span>
|
||||
. 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"
|
||||
|
|
11
expected/trade.debug
Normal file
11
expected/trade.debug
Normal file
|
@ -0,0 +1,11 @@
|
|||
BEGIN DEBUG OUTPUT
|
||||
Book title: Gamebook
|
||||
Number of sections: 2
|
||||
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.
|
||||
2 (theend) - It ends here.
|
||||
END DEBUG OUTPUT
|
4
expected/trade.dot
Normal file
4
expected/trade.dot
Normal file
|
@ -0,0 +1,4 @@
|
|||
digraph gamebook {
|
||||
|
||||
1->2
|
||||
}
|
104
expected/trade.html
Normal file
104
expected/trade.html
Normal file
|
@ -0,0 +1,104 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset='utf-8'>
|
||||
<meta name="viewport"
|
||||
content="width=device-width, initial-scale=1, maximum-scale=1">
|
||||
<title>Gamebook</title>
|
||||
<script type="text/javascript" src="gamebookformatplay.js"></script>
|
||||
<link rel="stylesheet" href="gamebookformat.css"
|
||||
type="text/css" />
|
||||
<script>
|
||||
if (typeof gamebook !== 'undefined') {
|
||||
gamebook.id = 'trade';
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<div class="hideintrolink nodisplay"
|
||||
onclick="gamebook.hideIntroSections()">(hide instructions)</div>
|
||||
<div class="gamebook">
|
||||
<div class="introsection">
|
||||
<div class="introsectionheading">Introduction</div>
|
||||
<div class="introsectionbody">
|
||||
Testing trade of things. You can buy things using <span class="count counterChange" data-type="gold"
|
||||
data-name="Gold">Gold</span> of which you start with <span class="set counterChange" data-type="gold"
|
||||
data-amount="100">100</span>. You also have an <span class="collect" data-type="item"
|
||||
data-name="Inventory">Inventory</span>. At start you carry a <span class="add" data-type="item"
|
||||
data-what="sword">sword</span>.
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="resumelink nodisplay"
|
||||
onclick="gamebook.loadGame()">Resume saved game.</div>
|
||||
|
||||
<div class="startlink"
|
||||
onclick="gamebook.turnTo(1)">Turn to 1 to begin.</div>
|
||||
<script>
|
||||
if (typeof gamebook !== 'undefined' && gamebook.hasSavedGame()) {
|
||||
var resumeLinks = document.getElementsByClassName('resumelink');
|
||||
Array.prototype.forEach.call(resumeLinks, function(e) {
|
||||
e.classList.remove('nodisplay');
|
||||
});
|
||||
}
|
||||
</script>
|
||||
<div class="section" id="section1">
|
||||
<div class="sectionnumber" id="para1">1</div>
|
||||
<div class="sectiontext">
|
||||
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"
|
||||
data-amount="50"
|
||||
>50</span>
|
||||
Gold. 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"
|
||||
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"
|
||||
href="#section2">2</a>.
|
||||
</div>
|
||||
</div>
|
||||
<script>
|
||||
if (this.gamebook) {
|
||||
gamebook.addSection(1, document.getElementById('section1'));
|
||||
}
|
||||
</script><div class="section" id="section2">
|
||||
<div class="sectionnumber" id="para2">2</div>
|
||||
<div class="sectiontext">
|
||||
It ends here.
|
||||
</div>
|
||||
</div>
|
||||
<script>
|
||||
if (this.gamebook) {
|
||||
gamebook.addSection(2, document.getElementById('section2'));
|
||||
}
|
||||
</script> <div id="counters" class="counters">
|
||||
</div>
|
||||
<div id="counterTemplate" class="counterTemplate">
|
||||
<span class="counterheading"></span>
|
||||
<span class="countercontents"></span>
|
||||
</div>
|
||||
</div>
|
||||
<div id="collections" class="collections">
|
||||
</div>
|
||||
<div id="collectionTemplate" class="collectionTemplate">
|
||||
<span class="collectionheading"></span>
|
||||
<span class="collectioncontents"></span>
|
||||
</div>
|
||||
</div>
|
||||
<script>
|
||||
if (typeof gamebook !== 'undefined') {
|
||||
gamebook.prepare();
|
||||
}
|
||||
</script>
|
||||
<div class="displayintrolink nodisplay"
|
||||
onclick="gamebook.showIntroSections()">(show instructions)</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
35
expected/trade.rtf
Normal file
35
expected/trade.rtf
Normal file
|
@ -0,0 +1,35 @@
|
|||
{\rtf1\ansi\ansicpg1252\cocoartf1038\cocoasubrtf360
|
||||
{\fonttbl\f0\fswiss\fcharset0 Helvetica;}
|
||||
{\colortbl;\red255\green255\blue255;}
|
||||
\paperw11900\paperh16840\margl1440\margr1440\vieww14140\viewh14860\viewkind0
|
||||
\pard\tx566\tx1133\tx1700\tx2267\tx2834\tx3401\tx3968\tx4535\tx5102\tx5669\tx6236\tx6803\ql\qnatural\pardirnatural
|
||||
|
||||
\f0\b\fs24 \cf0
|
||||
|
||||
\b \qc Gamebook
|
||||
\b0\
|
||||
\
|
||||
\b \qc Introduction
|
||||
\b0\
|
||||
|
||||
|
||||
|
||||
\ql Testing trade of things. You can buy things using Gold of which you start with 100. You also have an Inventory. At start you carry a sword. \
|
||||
\
|
||||
|
||||
\b Turn to 1 to begin.
|
||||
\b0\
|
||||
\
|
||||
\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
|
||||
\b0
|
||||
. \
|
||||
\
|
||||
|
||||
\b \qc 2
|
||||
\b0\
|
||||
\ql It ends here. \
|
||||
\
|
||||
|
||||
}
|
61
expected/trade.tex
Normal file
61
expected/trade.tex
Normal file
|
@ -0,0 +1,61 @@
|
|||
\documentclass[a5paper,onecolumn]{book}
|
||||
|
||||
\usepackage[utf8]{inputenc}
|
||||
\usepackage[T1]{fontenc}
|
||||
\usepackage[hidelinks]{hyperref}
|
||||
\usepackage{graphicx}
|
||||
|
||||
\usepackage[top=3.3cm, bottom=3.3cm, left=2cm, right=2cm]{geometry}
|
||||
\newif\ifpdf
|
||||
\ifx\pdfoutput\undefined
|
||||
\pdffalse
|
||||
\else
|
||||
\ifnum\pdfoutput=1
|
||||
\pdftrue
|
||||
\else
|
||||
\pdffalse
|
||||
\fi
|
||||
\fi
|
||||
|
||||
\title{Gamebook}
|
||||
\author{}
|
||||
\date{}
|
||||
|
||||
\newcounter{sectionnr}
|
||||
|
||||
\begin{document}
|
||||
|
||||
\maketitle
|
||||
|
||||
\thispagestyle{empty}
|
||||
|
||||
\pagestyle{empty}
|
||||
|
||||
\clearpage
|
||||
|
||||
\subsection*{\begin{center} \textbf{Introduction} \end{center}}
|
||||
|
||||
|
||||
\noindent
|
||||
Testing trade of things. You can buy things using Gold of which you start with 100. You also have an Inventory. At start you carry a \textbf{sword}.
|
||||
\vspace{1em}
|
||||
|
||||
|
||||
Turn to 1 to begin.
|
||||
\phantomsection
|
||||
\refstepcounter{sectionnr}
|
||||
\label{section1}
|
||||
\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}}.
|
||||
\vspace{1em}
|
||||
\phantomsection
|
||||
\refstepcounter{sectionnr}
|
||||
\label{section2}
|
||||
\subsection*{\begin{center} \textbf{2} \end{center}}
|
||||
|
||||
\noindent
|
||||
It ends here.
|
||||
\vspace{1em}
|
||||
\end{document}
|
14
expected/trade.txt
Normal file
14
expected/trade.txt
Normal file
|
@ -0,0 +1,14 @@
|
|||
Gamebook
|
||||
|
||||
Introduction
|
||||
Testing trade of things. You can buy things using Gold of which you start with 100. You also have an Inventory. At start you carry a sword.
|
||||
|
||||
|
||||
|
||||
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.
|
||||
|
||||
2
|
||||
It ends here.
|
||||
|
|
@ -254,6 +254,7 @@ var gamebook = {
|
|||
var hasXorScope = false;
|
||||
var hasAutoScope = false;
|
||||
var xorEnableNext = false;
|
||||
var lastCanHaveCost = null;
|
||||
var autoDisableAllRemaining = (
|
||||
gamebook.player.started
|
||||
&& e.classList.contains('introsectionbody'));
|
||||
|
@ -261,6 +262,7 @@ var gamebook = {
|
|||
if (!c.classList) {
|
||||
return;
|
||||
}
|
||||
// FIXME yes, this must be split up
|
||||
if (c.classList.contains('sectionref')) {
|
||||
if (enableNextLink && !autoDisableAllRemaining) {
|
||||
gamebook.enableLink(c);
|
||||
|
@ -321,10 +323,29 @@ var gamebook = {
|
|||
c.classList.add("enabledlink");
|
||||
c.classList.remove("disabledlink");
|
||||
autoDisableAllRemaining = true;
|
||||
} else if (c.classList.contains('found')) {
|
||||
lastCanHaveCost = c;
|
||||
c.addEventListener('click', gamebook.takeFound);
|
||||
} else if (c.classList.contains('cost')) {
|
||||
gamebook.addCost(c, lastCanHaveCost);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
addCost : function(c, e) {
|
||||
var cost = parseInt(c.dataset.amount);
|
||||
var counter = gamebook.player.counters[c.dataset.type];
|
||||
if (counter.value - cost >= counter.minValue) {
|
||||
e.classList.add("enabledlink");
|
||||
e.classList.remove("disabledlink");
|
||||
e.dataset.cost = c.dataset.amount;
|
||||
e.dataset.costtype = c.dataset.type;
|
||||
} else {
|
||||
e.classList.add("disabledlink");
|
||||
e.classList.remove("enabledlink");
|
||||
}
|
||||
},
|
||||
|
||||
'enableLink' : function(e) {
|
||||
e.addEventListener('click',
|
||||
gamebook.getTurnToFunction(e.dataset.ref));
|
||||
|
@ -411,6 +432,25 @@ var gamebook = {
|
|||
this.turnToFunctions[nr] = f;
|
||||
return f;
|
||||
}
|
||||
},
|
||||
|
||||
'takeFound' : function(evt) {
|
||||
evt.preventDefault();
|
||||
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];
|
||||
if (counter.value - cost < counter.minValue) {
|
||||
// this should not happen, link should be disabled
|
||||
return;
|
||||
}
|
||||
counter.dec(cost);
|
||||
gamebook.updateCountersView();
|
||||
}
|
||||
gamebook.player.add(type, what);
|
||||
}
|
||||
|
||||
};
|
||||
|
|
3
templates/html/cost.html
Normal file
3
templates/html/cost.html
Normal file
|
@ -0,0 +1,3 @@
|
|||
<span class="cost enabledlink" data-type="%(arg1)s"
|
||||
data-amount="%(inner)s"
|
||||
>%(inner)s</span>
|
|
@ -1,3 +1,3 @@
|
|||
<span class="found enabledlink"
|
||||
onclick="gamebook.player.add('%(arg1)s', '%(inner)s')"
|
||||
<span class="found enabledlink" data-type="%(arg1)s"
|
||||
data-what="%(inner)s"
|
||||
>%(inner)s</span>
|
||||
|
|
8
todo.org
8
todo.org
|
@ -1,4 +1,4 @@
|
|||
* TODO [51/75] [68%]
|
||||
* TODO [52/75] [69%]
|
||||
- [X] Debug output
|
||||
- [X] DOT output
|
||||
- [X] LaTeX output
|
||||
|
@ -63,12 +63,16 @@
|
|||
and in inferior browsers
|
||||
- [X] Make sure counters start at 0 (not 1).
|
||||
- [X] Remove the counter names from counter-tags output (and templates).
|
||||
- [ ] Buy (optionally decrease a counter to add something to a collection)
|
||||
- [X] Buy (optionally decrease a counter to add something to a collection)
|
||||
buy tag to specify what can be bought, eg [buy item]sword[/buy]
|
||||
followed by cost tag to specify what it will cost, eg [cost gold]3[/cost]
|
||||
Implemented by adding cost to the old found tag (put cost tag after it).
|
||||
Might reconsider and make explicit buy tag for clarity?
|
||||
- [ ] Sell (optionally increase a counter to drop something from a collection)
|
||||
sell tag to specify what can be bought, eg [sell item]sword[/sell]
|
||||
followed by cost tag to specify what it will cost, eg [cost gold]2[/cost]
|
||||
Might want to wait with this and add normal drop function first?
|
||||
- [ ] Trade decrease on counter to increase another counter.
|
||||
- [ ] Pick a specific number of things from those found in a(n intro) section
|
||||
Used to pick up one or more of something found, or before starting.
|
||||
Create counter and set to how many are allowed to be picked.
|
||||
|
|
Loading…
Reference in a new issue