mirror of
https://github.com/Oreolek/gamebookformat.git
synced 2024-06-26 03:41:04 +03:00
Random link selection. Stylesheet fixes for links. Some fixes with hiding/showing.
This commit is contained in:
parent
f60a650598
commit
df76c64e7f
|
@ -8,14 +8,18 @@ section at [[next]].
|
||||||
|
|
||||||
* 1 start
|
* 1 start
|
||||||
This is where the adventure begins. You can go on to the
|
This is where the adventure begins. You can go on to the
|
||||||
next section, see [[next]] or try the other instead, see [[other]].
|
next section, see [[next]] or try the random selection
|
||||||
|
feature at [[random]].
|
||||||
|
|
||||||
* next
|
* next
|
||||||
This is the next section. Go on to the end at [[end]].
|
This is the next section. Go on to the end at [[end]].
|
||||||
|
|
||||||
* other
|
* random
|
||||||
This is another section. You can try the next section now,
|
[random]Pick a destination at random[/random] from
|
||||||
see [[next]], or go on to the end, see [[end]].
|
[[next]] or [[end]] or [[altend]].
|
||||||
|
|
||||||
|
* altend
|
||||||
|
Alternative ending.
|
||||||
|
|
||||||
* end
|
* end
|
||||||
The end.
|
The end.
|
||||||
|
|
1
templates/debug/random.debug
Normal file
1
templates/debug/random.debug
Normal file
|
@ -0,0 +1 @@
|
||||||
|
[RANDOM]%(inner)s[/RANDOM]
|
|
@ -1,2 +1,3 @@
|
||||||
if (this.gamebook) {
|
if (this.gamebook) {
|
||||||
|
gamebook.runActionsInIntroSections();
|
||||||
}
|
}
|
||||||
|
|
1
templates/html/random.html
Normal file
1
templates/html/random.html
Normal file
|
@ -0,0 +1 @@
|
||||||
|
<span class="random enabledlink">%(inner)s</span>
|
|
@ -1,5 +1,6 @@
|
||||||
var gamebook = {
|
var gamebook = {
|
||||||
'player' : {
|
'player' : {
|
||||||
|
'started' : false,
|
||||||
'currentSection' : null,
|
'currentSection' : null,
|
||||||
'collections' : {},
|
'collections' : {},
|
||||||
|
|
||||||
|
@ -56,7 +57,9 @@
|
||||||
},
|
},
|
||||||
|
|
||||||
'turnTo' : function(nr) {
|
'turnTo' : function(nr) {
|
||||||
console.log("Turning to " + nr + ".");
|
if (!gamebook.player.started) {
|
||||||
|
gamebook.start();
|
||||||
|
}
|
||||||
if (!nr in this.sections) {
|
if (!nr in this.sections) {
|
||||||
throw new Exception("Can not turn to non-existing section "
|
throw new Exception("Can not turn to non-existing section "
|
||||||
+ nr + ".");
|
+ nr + ".");
|
||||||
|
@ -67,7 +70,7 @@
|
||||||
'start' : function() {
|
'start' : function() {
|
||||||
this.hideIntroSections();
|
this.hideIntroSections();
|
||||||
this.addClassToClass('startlink', 'nodisplay');
|
this.addClassToClass('startlink', 'nodisplay');
|
||||||
this.turnTo(1);
|
gamebook.player.started = true;
|
||||||
},
|
},
|
||||||
|
|
||||||
'displaySection' : function(nr) {
|
'displaySection' : function(nr) {
|
||||||
|
@ -87,12 +90,19 @@
|
||||||
},
|
},
|
||||||
|
|
||||||
'showIntroSections' : function() {
|
'showIntroSections' : function() {
|
||||||
|
this.runActionsInIntroSections();
|
||||||
this.removeClassFromClass('introsection', 'nodisplay');
|
this.removeClassFromClass('introsection', 'nodisplay');
|
||||||
this.addClassToClass('displayintrolink', 'nodisplay');
|
this.addClassToClass('displayintrolink', 'nodisplay');
|
||||||
this.removeClassFromClass('hideintrolink', 'nodisplay');
|
this.removeClassFromClass('hideintrolink', 'nodisplay');
|
||||||
document.body.scrollIntoView();
|
document.body.scrollIntoView();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
'runActionsInIntroSections' : function() {
|
||||||
|
Array.prototype.forEach.call(
|
||||||
|
document.getElementsByClassName('introsectionbody'),
|
||||||
|
gamebook.runActions);
|
||||||
|
},
|
||||||
|
|
||||||
'addClassToClass' : function(className, addClass) {
|
'addClassToClass' : function(className, addClass) {
|
||||||
Array.prototype.forEach.call(
|
Array.prototype.forEach.call(
|
||||||
document.getElementsByClassName(className),
|
document.getElementsByClassName(className),
|
||||||
|
@ -114,9 +124,13 @@
|
||||||
var hasXorScope = false;
|
var hasXorScope = false;
|
||||||
var hasAutoScope = false;
|
var hasAutoScope = false;
|
||||||
var xorEnableNext = false;
|
var xorEnableNext = false;
|
||||||
var autoDisableAllRemainingLinks = false;
|
var autoDisableAllRemainingLinks = (
|
||||||
|
gamebook.player.started && e.classList.contains('introsectionbody'));
|
||||||
Array.prototype.forEach.call(e.childNodes, function(c) {
|
Array.prototype.forEach.call(e.childNodes, function(c) {
|
||||||
if (/sectionref$/.test(c.className)) {
|
if (!c.classList) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (c.classList.contains('sectionref')) {
|
||||||
if (enableNextLink && !autoDisableAllRemainingLinks) {
|
if (enableNextLink && !autoDisableAllRemainingLinks) {
|
||||||
gamebook.enableLink(c);
|
gamebook.enableLink(c);
|
||||||
if (hasAutoScope) {
|
if (hasAutoScope) {
|
||||||
|
@ -137,18 +151,20 @@
|
||||||
} else if (c.className === 'has') {
|
} else if (c.className === 'has') {
|
||||||
enableNextLink = gamebook.player.has(c.dataset.type,
|
enableNextLink = gamebook.player.has(c.dataset.type,
|
||||||
c.dataset.what);
|
c.dataset.what);
|
||||||
console.log("has " + c.dataset.type +
|
|
||||||
" " + c.dataset.what + " " + enableNextLink);
|
|
||||||
} else if (c.className === 'hasnot') {
|
} else if (c.className === 'hasnot') {
|
||||||
enableNextLink = !gamebook.player.has(c.dataset.type,
|
enableNextLink = !gamebook.player.has(c.dataset.type,
|
||||||
c.dataset.what);
|
c.dataset.what);
|
||||||
console.log("has not " + c.dataset.type +
|
|
||||||
" " + c.dataset.what + " " + enableNextLink);
|
|
||||||
} else if (c.className === 'xor') {
|
} else if (c.className === 'xor') {
|
||||||
hasXorScope = true;
|
hasXorScope = true;
|
||||||
xorEnableNext = !enableNextLink;
|
xorEnableNext = !enableNextLink;
|
||||||
} else if (c.className === 'auto') {
|
} else if (c.className === 'auto') {
|
||||||
hasAutoScope = true;
|
hasAutoScope = true;
|
||||||
|
} else if (c.classList.contains('random')) {
|
||||||
|
c.addEventListener('click',
|
||||||
|
gamebook.enableRandomLinkAfter);
|
||||||
|
c.classList.add("enabledlink");
|
||||||
|
c.classList.remove("disabledlink");
|
||||||
|
autoDisableAllRemainingLinks = true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
@ -156,13 +172,35 @@
|
||||||
'enableLink' : function(e) {
|
'enableLink' : function(e) {
|
||||||
e.addEventListener('click',
|
e.addEventListener('click',
|
||||||
gamebook.getTurnToFunction(e.dataset.ref));
|
gamebook.getTurnToFunction(e.dataset.ref));
|
||||||
e.className = "enabledsectionref";
|
e.classList.add("enabledLink");
|
||||||
|
e.classList.remove("disabledlink");
|
||||||
},
|
},
|
||||||
|
|
||||||
'disableLink' : function(e) {
|
'disableLink' : function(e) {
|
||||||
e.removeEventListener('click',
|
e.removeEventListener('click',
|
||||||
gamebook.getTurnToFunction(e.dataset.ref));
|
gamebook.getTurnToFunction(e.dataset.ref));
|
||||||
e.className = "disabledsectionref";
|
e.classList.remove("enabledLink");
|
||||||
|
e.classList.add("disabledlink");
|
||||||
|
},
|
||||||
|
|
||||||
|
'enableRandomLinkAfter' : function(event) {
|
||||||
|
this.classList.remove("enabledlink");
|
||||||
|
this.classList.add("disabledlink");
|
||||||
|
var links = [];
|
||||||
|
var e = this.nextSibling;
|
||||||
|
while (e) {
|
||||||
|
if (e.classList && e.classList.contains('sectionref')) {
|
||||||
|
links.push(e);
|
||||||
|
}
|
||||||
|
e = e.nextSibling;
|
||||||
|
}
|
||||||
|
if (links.length > 0) {
|
||||||
|
var selected = links[Math.floor(Math.random()*links.length)]
|
||||||
|
gamebook.enableLink(selected);
|
||||||
|
} else {
|
||||||
|
console.log("Random with nothing to select?");
|
||||||
|
}
|
||||||
|
event.preventDefault();
|
||||||
},
|
},
|
||||||
|
|
||||||
'addCollectionView' : function(type, name) {
|
'addCollectionView' : function(type, name) {
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
<a class="sectionref" data-ref="%(nr)d">%(nr)d</a>
|
<a class="sectionref enabledlink" data-ref="%(nr)d">%(nr)d</a>
|
|
@ -1,2 +1,2 @@
|
||||||
<div class="startlink"
|
<div class="startlink"
|
||||||
onclick="gamebook.start()">%(starttext)s</div>
|
onclick="gamebook.turnTo(1)">%(starttext)s</div>
|
||||||
|
|
|
@ -1,2 +0,0 @@
|
||||||
<div class="startlink"
|
|
||||||
onclick="gamebook.start()">%(starttext)s</div>
|
|
|
@ -1,5 +1,17 @@
|
||||||
.enabledsectionref {font-weight: bold; cursor: pointer;}
|
.startlink,.sectionref,.displayintrolink,.hideintrolink {
|
||||||
.disabledsectionref {font-weight: bold; color: #aaa; cursor: not-allowed;}
|
font-weight: bold;
|
||||||
|
padding-left: 1.5em;
|
||||||
|
padding-right: 1.5em;
|
||||||
|
margin: 0.2em;
|
||||||
|
vertical-align: middle;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
.startlink,.enabledlink,.displayintrolink,.hideintrolink {cursor: pointer;
|
||||||
|
background: #eef;}
|
||||||
|
.startlink:hover,.enabledlink:hover,.displayintrolink:hover,
|
||||||
|
.hideintrolink:hover {background: #a9f;}
|
||||||
|
.disabledlink {color: #bbb; cursor: not-allowed; background: #fee;}
|
||||||
|
.disabledlink:hover {background: #fee;}
|
||||||
.sectionnumber {font-weight: bolder;
|
.sectionnumber {font-weight: bolder;
|
||||||
margin-left: 50%%;
|
margin-left: 50%%;
|
||||||
margin-right: 50%%;}
|
margin-right: 50%%;}
|
||||||
|
|
4
todo.org
4
todo.org
|
@ -1,4 +1,4 @@
|
||||||
* TODO [37/65] [56%]
|
* TODO [38/65] [58%]
|
||||||
- [X] Debug output
|
- [X] Debug output
|
||||||
- [X] DOT output
|
- [X] DOT output
|
||||||
- [X] LaTeX output
|
- [X] LaTeX output
|
||||||
|
@ -43,7 +43,7 @@
|
||||||
- [X] HTML hide intro sections with link to display again
|
- [X] HTML hide intro sections with link to display again
|
||||||
- [X] Only accept specific characters in section names
|
- [X] Only accept specific characters in section names
|
||||||
eg [a-z][a-z_0-9]+
|
eg [a-z][a-z_0-9]+
|
||||||
- [ ] Random pick of link to follow from a section.
|
- [X] Random pick of link to follow from a section.
|
||||||
- [ ] Possibility to make predictable random numbers and shuffling for testing
|
- [ ] Possibility to make predictable random numbers and shuffling for testing
|
||||||
- [ ] Test generate examples and compare to expected output in all formats
|
- [ ] Test generate examples and compare to expected output in all formats
|
||||||
- [ ] Unit tests (finally...)
|
- [ ] Unit tests (finally...)
|
||||||
|
|
Loading…
Reference in a new issue