From 4d9344903f490f0e583efd8e70631012fd0130d9 Mon Sep 17 00:00:00 2001 From: Roman Silin Date: Sun, 17 Oct 2021 20:33:21 +0300 Subject: [PATCH] Fixed but with diverting to nested labels --- narrator/story.lua | 13 ++++++----- test/cases.lua | 4 +++- test/units/{labels.ink => labels-choices.ink} | 0 test/units/{labels => labels-choices}/1-1.txt | 0 test/units/{labels => labels-choices}/1-2.txt | 0 test/units/{labels => labels-choices}/2-1.txt | 0 .../{labels => labels-choices}/2-2-1.txt | 0 .../{labels => labels-choices}/2-2-2.txt | 0 test/units/labels-nested.ink | 22 +++++++++++++++++++ test/units/labels-nested/1-1-1.txt | 14 ++++++++++++ test/units/labels-nested/1-2.txt | 10 +++++++++ test/units/labels-nested/2-1-1.txt | 14 ++++++++++++ test/units/labels-nested/2-2.txt | 10 +++++++++ 13 files changed, 80 insertions(+), 7 deletions(-) rename test/units/{labels.ink => labels-choices.ink} (100%) rename test/units/{labels => labels-choices}/1-1.txt (100%) rename test/units/{labels => labels-choices}/1-2.txt (100%) rename test/units/{labels => labels-choices}/2-1.txt (100%) rename test/units/{labels => labels-choices}/2-2-1.txt (100%) rename test/units/{labels => labels-choices}/2-2-2.txt (100%) create mode 100644 test/units/labels-nested.ink create mode 100644 test/units/labels-nested/1-1-1.txt create mode 100644 test/units/labels-nested/1-2.txt create mode 100644 test/units/labels-nested/2-1-1.txt create mode 100644 test/units/labels-nested/2-2.txt diff --git a/narrator/story.lua b/narrator/story.lua index d0e4912..d3a4393 100644 --- a/narrator/story.lua +++ b/narrator/story.lua @@ -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 @@ -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 @@ -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 diff --git a/test/cases.lua b/test/cases.lua index 320d88b..cbca3aa 100644 --- a/test/cases.lua +++ b/test/cases.lua @@ -29,9 +29,11 @@ local units = { 'choices-sticky', 'choices-fallback', + 'labels-choices', + 'labels-nested', + 'branching', 'nesting', - 'labels', 'loop', 'vars', 'constants', diff --git a/test/units/labels.ink b/test/units/labels-choices.ink similarity index 100% rename from test/units/labels.ink rename to test/units/labels-choices.ink diff --git a/test/units/labels/1-1.txt b/test/units/labels-choices/1-1.txt similarity index 100% rename from test/units/labels/1-1.txt rename to test/units/labels-choices/1-1.txt diff --git a/test/units/labels/1-2.txt b/test/units/labels-choices/1-2.txt similarity index 100% rename from test/units/labels/1-2.txt rename to test/units/labels-choices/1-2.txt diff --git a/test/units/labels/2-1.txt b/test/units/labels-choices/2-1.txt similarity index 100% rename from test/units/labels/2-1.txt rename to test/units/labels-choices/2-1.txt diff --git a/test/units/labels/2-2-1.txt b/test/units/labels-choices/2-2-1.txt similarity index 100% rename from test/units/labels/2-2-1.txt rename to test/units/labels-choices/2-2-1.txt diff --git a/test/units/labels/2-2-2.txt b/test/units/labels-choices/2-2-2.txt similarity index 100% rename from test/units/labels/2-2-2.txt rename to test/units/labels-choices/2-2-2.txt diff --git a/test/units/labels-nested.ink b/test/units/labels-nested.ink new file mode 100644 index 0000000..704f3c8 --- /dev/null +++ b/test/units/labels-nested.ink @@ -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 \ No newline at end of file diff --git a/test/units/labels-nested/1-1-1.txt b/test/units/labels-nested/1-1-1.txt new file mode 100644 index 0000000..0bd52b5 --- /dev/null +++ b/test/units/labels-nested/1-1-1.txt @@ -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. \ No newline at end of file diff --git a/test/units/labels-nested/1-2.txt b/test/units/labels-nested/1-2.txt new file mode 100644 index 0000000..7e1caa2 --- /dev/null +++ b/test/units/labels-nested/1-2.txt @@ -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. \ No newline at end of file diff --git a/test/units/labels-nested/2-1-1.txt b/test/units/labels-nested/2-1-1.txt new file mode 100644 index 0000000..f9156dc --- /dev/null +++ b/test/units/labels-nested/2-1-1.txt @@ -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. \ No newline at end of file diff --git a/test/units/labels-nested/2-2.txt b/test/units/labels-nested/2-2.txt new file mode 100644 index 0000000..6ed2c42 --- /dev/null +++ b/test/units/labels-nested/2-2.txt @@ -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. \ No newline at end of file