mirror of
https://github.com/Oreolek/gamebookformat.git
synced 2024-05-16 16:08:20 +03:00
Can pick up items in HTML version. First stubs for HTML Javascript.
Ugly hack warning. Too tired to design.
This commit is contained in:
parent
1bf91169c5
commit
ac0b806c73
|
@ -103,7 +103,7 @@ class ReferenceFormatter (object):
|
|||
self.shuffled_sections = shuffled_sections
|
||||
self.found = set()
|
||||
self.ref_template = ref_template
|
||||
self.items = {}
|
||||
self.items = {'nr' : shuffled_sections.to_nr[section]}
|
||||
|
||||
def __getitem__(self, key):
|
||||
if key in self.items:
|
||||
|
|
|
@ -1,11 +1,95 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset='utf-8'>
|
||||
<title>Gamebook Title Here</title>
|
||||
<script>
|
||||
// inline js to make it easier to distribute book?
|
||||
var gamebook = {};
|
||||
gamebook.player = {
|
||||
'currentSection' : null,
|
||||
'inventory' : [],
|
||||
'codewords' : {},
|
||||
|
||||
'take' : function(item) {
|
||||
console.log("player take " + item);
|
||||
if (this.inventory.indexOf(item) == -1) {
|
||||
this.inventory.push(item);
|
||||
}
|
||||
gamebook.updateInventory();
|
||||
},
|
||||
|
||||
'carries' : function(item) {
|
||||
return gamebook.player.inventory.indexOf(item) >= 0;
|
||||
}
|
||||
};
|
||||
gamebook.sections = {};
|
||||
gamebook.autoRun = {};
|
||||
|
||||
gamebook.addAutoRun = function(nr, f) {
|
||||
if (nr in this.autoRun) {
|
||||
this.autoRun[nr].push(f);
|
||||
} else {
|
||||
this.autoRun[nr] = [f];
|
||||
}
|
||||
console.log("autoRun " + nr + " " + this.autoRun[nr].length);
|
||||
};
|
||||
|
||||
gamebook.runAutoRuns = function(nr) {
|
||||
if (nr in gamebook.autoRun) {
|
||||
gamebook.autoRun[nr].forEach(function (f) {
|
||||
f();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
gamebook.addSection = function(nr, element) {
|
||||
var section = {'element' : element, 'nr' : nr};
|
||||
this.sections[nr] = section;
|
||||
};
|
||||
|
||||
gamebook.takeItem = function(nr, item) {
|
||||
this.addAutoRun(nr, function() {
|
||||
gamebook.player.take(item);
|
||||
});
|
||||
};
|
||||
|
||||
gamebook.turnTo = function(nr) {
|
||||
console.log("Turning to " + nr + ".");
|
||||
if (!nr in this.sections) {
|
||||
throw new Exception("Can not turn to non-existing section "
|
||||
+ nr + ".");
|
||||
}
|
||||
if (this.player.currentSection) {
|
||||
this.player.currentSection.element.style.display = 'none';
|
||||
}
|
||||
this.sections[nr].element.style.display = 'block';
|
||||
this.player.currentSection = gamebook.sections[nr];
|
||||
gamebook.runAutoRuns(nr);
|
||||
};
|
||||
|
||||
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)";
|
||||
}
|
||||
};
|
||||
|
||||
</script>
|
||||
<style>
|
||||
.sectionref {font-weight: bold; cursor: pointer;}
|
||||
.itemfound {font-weight: bold; cursor: pointer;}
|
||||
.sectionnumber {font-weight: bolder; align: center;}
|
||||
.section {display: none;}
|
||||
.gamebook {max-width: 40em; border: solid 1px; padding: 1em;}
|
||||
.inventory {background: #ccc; margin-top: 5em;}
|
||||
.inventoryheading {}
|
||||
.inventoryitems {}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<!-- TODO definitely need to add content here, but mostly book specific? -->
|
||||
|
||||
<div class="gamebook">
|
||||
|
|
|
@ -1,2 +1,13 @@
|
|||
<div class="inventory">
|
||||
<span class="inventoryheading">Carrying: </span>
|
||||
<span class="inventoryitems" id="inventoryitems"></span>
|
||||
</div>
|
||||
</div>
|
||||
<script>
|
||||
if (this.gamebook) {
|
||||
gamebook.updateInventory();
|
||||
gamebook.turnTo(1);
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
||||
|
|
3
templates/html/found.html
Normal file
3
templates/html/found.html
Normal file
|
@ -0,0 +1,3 @@
|
|||
<span class="itemfound"
|
||||
onclick="gamebook.player.take('%(inner)s')"
|
||||
>%(inner)s</span>
|
|
@ -1,5 +1,10 @@
|
|||
<div class="paragraph">
|
||||
<span class="paragraphnumber" id="para%(nr)d">%(nr)d</span>
|
||||
-
|
||||
<div class="section" id="section%(nr)d">
|
||||
<span class="sectionnumber" id="para%(nr)d">%(nr)d</span>
|
||||
<br>
|
||||
%(text)s
|
||||
</div>
|
||||
</div>
|
||||
<script>
|
||||
if (this.gamebook) {
|
||||
gamebook.addSection(%(nr)d, document.getElementById('section%(nr)d'));
|
||||
}
|
||||
</script>
|
|
@ -1 +1,2 @@
|
|||
<a href="#para%(nr)d">%(nr)d</a>
|
||||
<a class="sectionref"
|
||||
onclick="gamebook.turnTo(%(nr)d)">%(nr)d</a>
|
7
templates/html/take.html
Normal file
7
templates/html/take.html
Normal file
|
@ -0,0 +1,7 @@
|
|||
<span class="itemtake">%(inner)s</span>
|
||||
<script>
|
||||
if (this.gamebook) {
|
||||
console.log("take %(nr)d %(inner)s");
|
||||
gamebook.takeItem(%(nr)d, "%(inner)s");
|
||||
}
|
||||
</script>
|
7
todo.org
7
todo.org
|
@ -1,4 +1,4 @@
|
|||
* TODO [13/43] [30%]
|
||||
* TODO [14/44] [31%]
|
||||
- [X] Debug output
|
||||
- [X] DOT output
|
||||
- [X] LaTeX output
|
||||
|
@ -14,7 +14,7 @@
|
|||
Look at how some existing gamebooks are formatted.
|
||||
- [X] Parse wiki-style tags used to mark up sections
|
||||
- [X] New text formatting style for section references
|
||||
- [ ] Inventory pick up items
|
||||
- [X] Inventory pick up items
|
||||
- [ ] Codewords set
|
||||
- [ ] Check if has inventory item
|
||||
- [ ] Check if has codeword
|
||||
|
@ -29,6 +29,7 @@
|
|||
- [ ] Book option to set title
|
||||
- [ ] Book option to set author
|
||||
- [ ] Book option to set date
|
||||
- [ ] Quote strings to not break formatting.
|
||||
- [ ] Template for book introduction (including rules etc)
|
||||
- [ ] Some way to insert character sheet in book introduction
|
||||
- [ ] Some way to insert dice at bottom of pages for LaTeX
|
||||
|
@ -43,5 +44,5 @@
|
|||
- [ ] Counters increase/decrease
|
||||
- [ ] Counters check
|
||||
- [ ] Document Gamebook format
|
||||
- [ ] Playable HTML (javascript) output
|
||||
- [ ] HTML CSS
|
||||
- [ ] Higher level text-language for Gamebooks
|
||||
|
|
Loading…
Reference in a new issue