1
0
Fork 0
mirror of https://github.com/Oreolek/gamebookformat.git synced 2024-06-17 07:30:43 +03:00

Codewords set in HTML.

Feel bad about how copy-pasted codewords are from items.
Ideally the same code would handle both. Not now though.
This commit is contained in:
Pelle Nilsson 2013-06-07 22:03:28 +02:00
parent ac0b806c73
commit ddf6ed3046
6 changed files with 49 additions and 14 deletions

View file

@ -15,11 +15,21 @@
if (this.inventory.indexOf(item) == -1) {
this.inventory.push(item);
}
this.inventory.sort();
gamebook.updateInventory();
},
'carries' : function(item) {
return gamebook.player.inventory.indexOf(item) >= 0;
return this.inventory.indexOf(item) >= 0;
},
'set' : function(codeword) {
this.codewords[codeword] = true;
gamebook.updateCodewords();
},
'has' : function(codeword) {
return codeword in this.codewords;
}
};
gamebook.sections = {};
@ -31,7 +41,6 @@
} else {
this.autoRun[nr] = [f];
}
console.log("autoRun " + nr + " " + this.autoRun[nr].length);
};
gamebook.runAutoRuns = function(nr) {
@ -53,6 +62,12 @@
});
};
gamebook.setCodeword = function(nr, codeword) {
this.addAutoRun(nr, function() {
gamebook.player.set(codeword);
});
};
gamebook.turnTo = function(nr) {
console.log("Turning to " + nr + ".");
if (!nr in this.sections) {
@ -69,25 +84,33 @@
gamebook.updateInventory = function() {
// FIXME obviously, this should be better written and do more
console.log("update inventory");
var e = document.getElementById('inventoryitems');
if (gamebook.player.inventory.length > 0) {
e.innerHTML = gamebook.player.inventory.join(', ');
} else {
e.innerHTML = "(nothing)";
}
e.innerHTML = gamebook.player.inventory.join(', ');
};
gamebook.updateCodewords = function() {
// FIXME obviously, this should be better written and do more
var e = document.getElementById('codewordslist');
e.innerHTML = Object.keys(gamebook.player.codewords).sort().join(', ');
};
</script>
<style>
.sectionref {font-weight: bold; cursor: pointer;}
.itemfound {font-weight: bold; cursor: pointer;}
.sectionnumber {font-weight: bolder; align: center;}
.sectionnumber {font-weight: bolder;
margin-left: 50%%;
margin-right: 50%%;}
.section {display: none;}
.sectiontext {margin-top: 0.5em;}
.gamebook {max-width: 40em; border: solid 1px; padding: 1em;}
.inventory {background: #ccc; margin-top: 5em;}
.inventory {background: #cfc; margin-top: 5em;}
.inventoryheading {}
.inventoryitems {}
.codewords {background: #fcc; margin-top: 0.5em;}
.codewordsheading {}
.codewordslist {}
.setcodeword {color: #f55;}
</style>
</head>
<body>

View file

@ -2,6 +2,10 @@
<span class="inventoryheading">Carrying: </span>
<span class="inventoryitems" id="inventoryitems"></span>
</div>
<div class="codewords">
<span class="codewordsheading">Codewords: </span>
<span class="codewordslist" id="codewordslist"></span>
</div>
</div>
<script>
if (this.gamebook) {

View file

@ -1,8 +1,9 @@
<div class="section" id="section%(nr)d">
<span class="sectionnumber" id="para%(nr)d">%(nr)d</span>
<br>
<div class="sectiontext">
%(text)s
</div>
</div>
<script>
if (this.gamebook) {
gamebook.addSection(%(nr)d, document.getElementById('section%(nr)d'));

7
templates/html/set.html Normal file
View file

@ -0,0 +1,7 @@
<div class="setcodeword">codeword %(inner)s</div>
<script>
if (this.gamebook) {
console.log("set %(nr)d %(inner)s");
gamebook.setCodeword(%(nr)d, "%(inner)s");
}
</script>

View file

@ -1,7 +1,6 @@
<span class="itemtake">%(inner)s</span>
<script>
if (this.gamebook) {
console.log("take %(nr)d %(inner)s");
gamebook.takeItem(%(nr)d, "%(inner)s");
}
</script>

View file

@ -1,4 +1,4 @@
* TODO [14/44] [31%]
* TODO [15/45] [33%]
- [X] Debug output
- [X] DOT output
- [X] LaTeX output
@ -15,10 +15,11 @@
- [X] Parse wiki-style tags used to mark up sections
- [X] New text formatting style for section references
- [X] Inventory pick up items
- [ ] Codewords set
- [X] Codewords set
- [ ] Check if has inventory item
- [ ] Check if has codeword
- [ ] Remove item from inventory (forced by instructions)
- [ ] Make sure removed items can not be picked up again.
- [ ] Optionally remove inventory item to make a choice
- [ ] Fix problem with map file from other book sometimes crashing formatter
- [ ] Keys from formatted book should be added to map file, not replace it