1
0
Fork 0
mirror of https://github.com/Oreolek/gamebookformat.git synced 2024-06-29 05:05:13 +03:00

Xor (ex-haselse) and Auto modifiers on secrion references.

This commit is contained in:
Pelle Nilsson 2013-06-10 21:21:13 +02:00
parent ec7a054d42
commit 18c76ce0b0
9 changed files with 46 additions and 27 deletions

View file

@ -13,22 +13,35 @@ turn to [[the_end]]. If you do not have the codeword
[hasnot code]fun[/hasnot], you may turn to [[notsofun]]. [hasnot code]fun[/hasnot], you may turn to [[notsofun]].
If you have the codeword [has code]fun[/has], you may instead If you have the codeword [has code]fun[/has], you may instead
turn to [[cheater]]. turn to [[cheater]].
Otherwise see [[haselsetest]]. Otherwise see [[xortest]].
* notsofun * notsofun
This is just to demonstrate choices allowed when not This is just to demonstrate choices allowed when not
having a codeword. Now go on to [[haselsetest]]. having a codeword. Now go on to [[autotest]] (autotest)
or [[xortest]] (xor test).
* autotest
If you have codeword [has code]warrior[/has] turn to
[[auto noautotest]].
Otherwise you can go to the end at [[the_end]] or back to
[[start]].
* noautotest
If you have the codeword [has code]fun[/has] turn
to [[auto cheater]].
Otherwise you can go to the end at [[the_end]] or to the
xortest at [[xortest]].
* cheater * cheater
Cheater! There is no way you can have codeword fun. Cheater! There is no way you can have codeword fun.
* haselsetest * xortest
OK, if you have the codeword [haselse code]warrior[/has], OK, if you have the codeword [has code]warrior[/has],
you may turn to you may turn to
[[auto the_end]] otherwise you may go back to [[second]]. Although [[xor the_end]] otherwise you may go back to [[second]]. Although
we both know you have that codeword. we both know you have that codeword.
If you have the codeword [haselse code]fun[/has] you may turn If you have the codeword [has code]fun[/has] you may turn
to [[cheater]], without it you can go to [[notsofun]]. to [[xor cheater]], without it you can go to [[notsofun]].
* the_end * the_end
That was easy. That was easy.

View file

@ -34,6 +34,7 @@ class OutputFormat (object):
def format_section(self, section, references): def format_section(self, section, references):
i = 0 i = 0
res = "" res = ""
# FIXME refactor for readability once good tests are in place
while i < len(section.text): while i < len(section.text):
ref_start = section.text.find('[[', i) ref_start = section.text.find('[[', i)
tag_start = section.text.find('[', i) tag_start = section.text.find('[', i)

View file

@ -1 +0,0 @@
[HAS ELSE %(arg1)s]%(inner)s[/HAS]

1
templates/html/auto.html Normal file
View file

@ -0,0 +1 @@
<span class="auto"></span>

View file

@ -84,21 +84,23 @@
'runActions' : function(e) { 'runActions' : function(e) {
var enableNextLink = true; var enableNextLink = true;
var hasElseScope = false; var hasXorScope = false;
var hasElseEnable = false; var hasAutoScope = false;
var xorEnableNext = false;
var autoDisableAllRemainingLinks = false;
Array.prototype.forEach.call(e.childNodes, function(c) { Array.prototype.forEach.call(e.childNodes, function(c) {
if (/sectionref$/.test(c.className)) { if (/sectionref$/.test(c.className)) {
if (enableNextLink) { if (enableNextLink && !autoDisableAllRemainingLinks) {
gamebook.enableLink(c); gamebook.enableLink(c);
if (hasAutoScope) {
autoDisableAllRemainingLinks = true;
}
} else { } else {
gamebook.disableLink(c); gamebook.disableLink(c);
} }
if (hasElseScope) { enableNextLink = !(hasXorScope && !xorEnableNext);
enableNextLink = hasElseEnable; hasAutoScope = false;
hasElseScope = false; hasXorScope = false;
} else {
enableNextLink = true;
}
} else if (c.className === 'collect') { } else if (c.className === 'collect') {
gamebook.player.collect(c.dataset.type, c.dataset.name); gamebook.player.collect(c.dataset.type, c.dataset.name);
} else if (c.className === 'add') { } else if (c.className === 'add') {
@ -115,11 +117,11 @@
c.dataset.what); c.dataset.what);
console.log("has not " + c.dataset.type + console.log("has not " + c.dataset.type +
" " + c.dataset.what + " " + enableNextLink); " " + c.dataset.what + " " + enableNextLink);
} else if (c.className === 'haselse') { } else if (c.className === 'xor') {
enableNextLink = gamebook.player.has(c.dataset.type, hasXorScope = true;
c.dataset.what); xorEnableNext = !enableNextLink;
hasElseScope = true; } else if (c.className === 'auto') {
hasElseEnable = !enableNextLink; hasAutoScope = true;
} }
}); });
}, },

View file

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

1
templates/html/xor.html Normal file
View file

@ -0,0 +1 @@
<span class="xor"></span>

View file

@ -1 +0,0 @@
\textit{%(inner)s}

View file

@ -1,4 +1,4 @@
* TODO [25/53] [47%] * TODO [27/59] [45%]
- [X] Debug output - [X] Debug output
- [X] DOT output - [X] DOT output
- [X] LaTeX output - [X] LaTeX output
@ -28,12 +28,15 @@
They are the same, sort of, and it might be good to be able to They are the same, sort of, and it might be good to be able to
add other similar entities as well, like skills or spells or whatever. add other similar entities as well, like skills or spells or whatever.
- [X] Otherwise/else handling for has. - [X] Otherwise/else handling for has.
- [ ] Disable all links after finding an auto link (that is enabled). - [X] Redesign otherwise/else to use xor tag on section reference.
- [X] Disable all links after finding an auto link (that is enabled).
- [ ] Default templates. (templates/default?)
- [ ] Book option to set pdf layout (page size and number of columns) - [ ] Book option to set pdf layout (page size and number of columns)
- [ ] Book option to set title - [ ] Book option to set title
- [ ] Book option to set author - [ ] Book option to set author
- [ ] Book option to set date - [ ] Book option to set date
- [ ] Quote strings to not break formatting. - [ ] Quote strings to not break formatting.
- [ ] Include other templates from a template.
- [ ] Template for book introduction (including rules etc) - [ ] Template for book introduction (including rules etc)
Sections with some markup (has number 0?) are added as chapters Sections with some markup (has number 0?) are added as chapters
of introduction, otherwise formatted identical to other sections. of introduction, otherwise formatted identical to other sections.
@ -56,6 +59,8 @@
- [ ] Buy (optionally decrease a counter to add something to a collection) - [ ] Buy (optionally decrease a counter to add something to a collection)
- [ ] Sell (optionally increase a counter to drop something to a collection) - [ ] Sell (optionally increase a counter to drop something to a collection)
- [ ] Pick a (maximum) number of things from those found in a section - [ ] Pick a (maximum) number of things from those found in a section
- [ ] Macros for input(quests etc etc). Generate one or more sections.
- [ ] Macros that can add content to sections (pre or post).
- [ ] Some way to insert character sheet in book introduction - [ ] Some way to insert character sheet in book introduction
- [ ] Some way to insert dice at bottom of pages for LaTeX - [ ] Some way to insert dice at bottom of pages for LaTeX
- [ ] Some way to insert optional random numbers table at end of book - [ ] Some way to insert optional random numbers table at end of book