1
0
Fork 0
mirror of https://github.com/Oreolek/ink-instead.git synced 2024-04-28 07:09:25 +03:00

runtime basic knot/divert support

This commit is contained in:
premek 2016-12-03 04:13:50 +01:00
parent 2d2ddf7e43
commit 2e2fd68e4f
4 changed files with 67 additions and 26 deletions

View file

@ -1,7 +1,14 @@
=== start ===
"What that's?" my master asked.
* "I am somewhat tired[."]," I repeated.
"Really," he responded. "How deleterious."
* "Nothing, Monsieur!"[] I replied.
"Very good, then."
-> finale
* "I said, this journey is appalling[."] and I want no more of it."
"Ah," he replied, not unkindly. "I see you are feeling frustrated. Tomorrow, things will improve."
* [Leave] -> finale
=== finale ===
Bye

View file

@ -36,11 +36,12 @@ local ink = P({
stmt = glue + divert + V'knott' + V'stitch' + optionDiv + comm,
text = C((1-nl-V'stmt')^1) *wh,
textE = C((1-nl-V'stmt')^0) *wh,
optionAnsWithDiv = V'text' * optionDiv * V'text' * wh,
optionAnsWithoutDiv = V'text' * Cc ''* Cc ''* wh, -- huh?
optionAnsWithDiv = V'textE' * optionDiv * V'textE' * wh,
optionAnsWithoutDiv = V'textE' * Cc ''* Cc ''* wh, -- huh?
optionHead = P'*'/'option' * sp * (V'optionAnsWithDiv' + V'optionAnsWithoutDiv'),
option = Ct(V'optionHead' * (V'line'-V'optionHead')^0 * wh),
option = Ct(V'optionHead' * (V'line'-V'optionHead'-V'knott'-V'stitch')^0 * wh), --TODO which can by toplevel only?
choice = Ct(Cc'choice' * V'option'^1),
para = Ct(Cc'para' * V'text'),

View file

@ -10,15 +10,37 @@ end
return function (tree)
--print(to_string(tree))
print(to_string(tree))
local s = {}
local pointer = 1
local tab = tree
local knots = {}
local process = function ()
for i, v in ipairs(tree) do
if is('knot', v) then
knots[v[2]] = v
end
end
end
local update = function ()
local next = tab[pointer]
if is('knot', next) then
tab = next
pointer = 3
next = tab[pointer]
end
if is('divert', next) then
tab = knots[next[2]]
pointer = 3
next = tab[pointer]
end
s.canContinue = is('para', next)
s.currentChoices = {}
@ -26,14 +48,14 @@ return function (tree)
for i=2, #next do
--print(to_string(next[i]))
table.insert(s.currentChoices, {
text = next[i][2] .. (next[i][3] or ''),
text = (next[i][2] or '') .. (next[i][3] or ''),
choiceText = next[i][2] .. (next[i][4] or ''),
})
end
end
end
s.canContinue = true
s.canContinue = nil
s.continue = function()
local res = getPara(tab[pointer])
@ -42,7 +64,7 @@ return function (tree)
return res;
end
s.currentChoices = {}
s.currentChoices = nil
s.chooseChoiceIndex = function(index)
s.currentChoices = {}
@ -56,5 +78,8 @@ return function (tree)
s.choosePathString = function(knotName) end
s.variablesState = {}
-- s.state.ToJson();s.state.LoadJson(savedJson);
update()
process()
return s
end

View file

@ -1,5 +1,6 @@
return {
ink=[[
== start ==
* I dont know
* "I am somewhat tired[."]," I repeated.
"Really," he responded.
@ -8,26 +9,33 @@ ink=[[
"Very good, *then."
* I said no more
"Ah,". "I see you"
== finale ==
]],
expected= {
{'choice',
{"option", "I dont know", "", ""},
{
"option",
'"I am somewhat tired',
'."',
'," I repeated.',
{"para", '"Really," he responded.'},
{"para", '"How deleterious."'}
"knot",
"start",
{
"choice",
{"option", "I dont know", "", ""},
{
"option",
'"I am somewhat tired',
'."',
'," I repeated.',
{"para", '"Really," he responded.'},
{"para", '"How deleterious."'}
},
{
"option",
'"Nothing, Monsieur!"',
"",
" I replied.",
{"para", '"Very good, *then."'}
},
{"option", "I said no more", "", "", {"para", '"Ah,". "I see you"'}}
}
},
{
"option",
'"Nothing, Monsieur!"',
"",
" I replied.",
{"para", '"Very good, *then."'}
},
{"option", 'I said no more', '', '',
{"para", '"Ah,". "I see you"'}}
}
}}
{"knot", "finale"}
}
}