Skip to content

Commit

Permalink
Fixed but with diverting to nested labels
Browse files Browse the repository at this point in the history
  • Loading branch information
astrochili committed Oct 17, 2021
1 parent 3006e46 commit 4d93449
Show file tree
Hide file tree
Showing 13 changed files with 80 additions and 7 deletions.
13 changes: 7 additions & 6 deletions narrator/story.lua
Original file line number Diff line number Diff line change
Expand Up @@ -260,12 +260,13 @@ function Story:pathChainForLabel(path)
local function findLabelChainInItems(items)
for index, item in ipairs(items) do

if item.label == label then return { index }
if item.label == label then
return { index }

elseif item.node ~= nil then
local result = findLabelChainInItems(item.node)
if result ~= nil then
table.insert(result, 0, index)
table.insert(result, 1, index)
return result
end

Expand All @@ -276,8 +277,8 @@ function Story:pathChainForLabel(path)
for caseIndex, case in ipairs(cases) do
local result = findLabelChainInItems(case)
if result ~= nil then
table.insert(result, 0, 't' .. caseIndex)
table.insert(result, 0, index)
table.insert(result, 1, 't' .. caseIndex)
table.insert(result, 1, index)
return result
end
end
Expand All @@ -286,8 +287,8 @@ function Story:pathChainForLabel(path)
if type(item.failure) == 'table' then
local result = findLabelChainInItems(item.failure)
if result ~= nil then
table.insert(result, 0, 'f')
table.insert(result, 0, index)
table.insert(result, 1, 'f')
table.insert(result, 1, index)
return result
end
end
Expand Down
4 changes: 3 additions & 1 deletion test/cases.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@ local units = {
'choices-sticky',
'choices-fallback',

'labels-choices',
'labels-nested',

'branching',
'nesting',
'labels',
'loop',
'vars',
'constants',
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
22 changes: 22 additions & 0 deletions test/units/labels-nested.ink
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
-> dialog_start
==dialog_start==

* [Tell me about the mister]
- - (dima)
- - His name is Dima.
* * {not vika} [Tell me about Vika]
-> vika
* * [Finish conversation]
-> stop_dialog

* [Tell me about the missis]
- - (vika)
Her name is Vika.
* * {not dima} [Tell me about Dima]
-> dima
* * [Finish conversation]
-> stop_dialog

==stop_dialog==
That's all.
-> END
14 changes: 14 additions & 0 deletions test/units/labels-nested/1-1-1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

>) Tell me about the mister
2) Tell me about the missis

His name is Dima.

>) Tell me about Vika
2) Finish conversation

Her name is Vika.

>) Finish conversation

That's all.
10 changes: 10 additions & 0 deletions test/units/labels-nested/1-2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

>) Tell me about the mister
2) Tell me about the missis

His name is Dima.

1) Tell me about Vika
>) Finish conversation

That's all.
14 changes: 14 additions & 0 deletions test/units/labels-nested/2-1-1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

1) Tell me about the mister
>) Tell me about the missis

Her name is Vika.

>) Tell me about Dima
2) Finish conversation

His name is Dima.

>) Finish conversation

That's all.
10 changes: 10 additions & 0 deletions test/units/labels-nested/2-2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

1) Tell me about the mister
>) Tell me about the missis

Her name is Vika.

1) Tell me about Dima
>) Finish conversation

That's all.

0 comments on commit 4d93449

Please sign in to comment.