mirror of
https://github.com/Oreolek/ink-instead.git
synced 2024-06-26 03:50:45 +03:00
story.state.visitCountAtPathString
This commit is contained in:
parent
c3a60e3126
commit
1eadf9b3bb
|
@ -1,3 +1,5 @@
|
||||||
|
Hello world
|
||||||
|
|
||||||
=== back_in_london ===
|
=== back_in_london ===
|
||||||
|
|
||||||
We arrived into London at 9.45pm exactly.
|
We arrived into London at 9.45pm exactly.
|
||||||
|
|
|
@ -2,14 +2,15 @@ local pink = require('pink.pink')
|
||||||
|
|
||||||
local story = pink.getStory('examples/game.ink')
|
local story = pink.getStory('examples/game.ink')
|
||||||
|
|
||||||
|
-- you can also jump to a story knot based on some event in your game
|
||||||
|
story.choosePathString('back_in_london');
|
||||||
|
|
||||||
local currentText = nil
|
local currentText = nil
|
||||||
local a=10
|
local a=10
|
||||||
|
|
||||||
function love.update(dt)
|
function love.update(dt)
|
||||||
a = a + dt*3
|
a = a + dt*3
|
||||||
|
|
||||||
-- TODO to start from a new knot on a game event just set pink to that knot here
|
|
||||||
|
|
||||||
if not currentText then
|
if not currentText then
|
||||||
if story.canContinue then
|
if story.canContinue then
|
||||||
currentText = story.continue() .. '\n\n(press space to continue)'
|
currentText = story.continue() .. '\n\n(press space to continue)'
|
||||||
|
|
|
@ -17,6 +17,11 @@ return function (tree)
|
||||||
|
|
||||||
local knots = {}
|
local knots = {}
|
||||||
|
|
||||||
|
-- TODO state should contain tab/pointer to be able to save / load
|
||||||
|
s.state = {
|
||||||
|
visitCount = {}
|
||||||
|
}
|
||||||
|
|
||||||
local process = function ()
|
local process = function ()
|
||||||
for _, v in ipairs(tree) do
|
for _, v in ipairs(tree) do
|
||||||
if is('knot', v) then
|
if is('knot', v) then
|
||||||
|
@ -25,20 +30,25 @@ return function (tree)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local goToKnot = function(knotName)
|
||||||
|
if knots[knotName] then
|
||||||
|
s.state.visitCount[knotName] = (s.state.visitCount[knotName] or 0) + 1
|
||||||
|
tab = knots[knotName]
|
||||||
|
pointer = 3
|
||||||
|
return tab[pointer]
|
||||||
|
else
|
||||||
|
print('unknown knot', knotName)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
local update = function ()
|
local update = function ()
|
||||||
local next = tab[pointer]
|
local next = tab[pointer]
|
||||||
|
|
||||||
if is('knot', next) then
|
if is('knot', next) then -- FIXME: we shouldn't continue to next knot automatically probably - how about stitches?
|
||||||
tab = next
|
next = goToKnot(next)
|
||||||
pointer = 3
|
|
||||||
next = tab[pointer]
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if is('divert', next) then
|
if is('divert', next) then next = goToKnot(next[2]) end
|
||||||
tab = knots[next[2]]
|
|
||||||
pointer = 3
|
|
||||||
next = tab[pointer]
|
|
||||||
end
|
|
||||||
|
|
||||||
s.canContinue = is('para', next)
|
s.canContinue = is('para', next)
|
||||||
|
|
||||||
|
@ -91,7 +101,16 @@ return function (tree)
|
||||||
stepTo(option, 5)
|
stepTo(option, 5)
|
||||||
end
|
end
|
||||||
|
|
||||||
s.choosePathString = function(knotName) end
|
s.choosePathString = function(knotName)
|
||||||
|
goToKnot(knotName)
|
||||||
|
update()
|
||||||
|
end
|
||||||
|
|
||||||
|
s.state.visitCountAtPathString = function(knotName)
|
||||||
|
return s.state.visitCount[knotName] or 0
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
s.variablesState = {}
|
s.variablesState = {}
|
||||||
-- s.state.ToJson();s.state.LoadJson(savedJson);
|
-- s.state.ToJson();s.state.LoadJson(savedJson);
|
||||||
|
|
||||||
|
|
16
test.lua
16
test.lua
|
@ -1,5 +1,6 @@
|
||||||
local luaunit = require('luaunit')
|
local luaunit = require('luaunit')
|
||||||
local parser = require('pink.parser')
|
local parser = require('pink.parser')
|
||||||
|
local pink = require('pink.pink')
|
||||||
|
|
||||||
|
|
||||||
function testEmpt() doTestS(
|
function testEmpt() doTestS(
|
||||||
|
@ -26,8 +27,21 @@ function testKnot() doTest('knot') end
|
||||||
function testBranching() doTest('branching') end
|
function testBranching() doTest('branching') end
|
||||||
function testGlue() doTest('glue') end
|
function testGlue() doTest('glue') end
|
||||||
|
|
||||||
-- TODO test runtime
|
|
||||||
|
|
||||||
|
function testVisitCount()
|
||||||
|
local story = pink.getStory('test/branching.lua')
|
||||||
|
story.choosePathString('hurry_outside');
|
||||||
|
luaunit.assertEquals(story.state.visitCountAtPathString('as_fast_as_we_could'), 0)
|
||||||
|
while story.canContinue do story.continue() end
|
||||||
|
luaunit.assertEquals(story.state.visitCountAtPathString('as_fast_as_we_could'), 1)
|
||||||
|
story.choosePathString('hurry_outside');
|
||||||
|
while story.canContinue do story.continue() end
|
||||||
|
luaunit.assertEquals(story.state.visitCountAtPathString('as_fast_as_we_could'), 2)
|
||||||
|
luaunit.assertEquals(story.state.visitCountAtPathString('as_fast_as_we_could'), 2)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
-- TODO test runtime more, test public pink API
|
||||||
|
|
||||||
-----------------------------
|
-----------------------------
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue