Support gather at a choice
Some checks failed
/ test (push) Failing after 48s

This commit is contained in:
2025-10-26 08:27:36 -05:00
parent 2cbb79b58c
commit b631e7d0ee
4 changed files with 31 additions and 4 deletions

View File

@@ -0,0 +1,11 @@
What a beautiful morning!
* Drink water
- * Brush teeth
- * Egg breakfast
* Toast breakfast
* Easy breakfast
- Done

View File

@@ -0,0 +1,10 @@
What a beautiful morning!
* Drink water
> 1: Drink water
* Brush teeth
> 1: Brush teeth
* Egg breakfast
* Toast breakfast
* Easy breakfast
> 2: Toast breakfast
Done

View File

@@ -80,7 +80,12 @@ class ASTExtension {
case EChoice(choice): case EChoice(choice):
if (tryAdd(choice, [])) lastChoiceIndex = i; if (tryAdd(choice, [])) lastChoiceIndex = i;
case ETagged(EChoice(choice), tags): case ETagged(EChoice(choice), tags):
if (tryAdd(choice, tags)) lastChoiceIndex = 1; if (tryAdd(choice, tags)) lastChoiceIndex = i;
// Choice immediatly after gather at current depth:
case EGather(_, d, EChoice(choice)) if(i == startingIndex && d == depth):
if (tryAdd(choice, [])) lastChoiceIndex = i;
case EGather(_, d, ETagged(EChoice(choice), tags)) if(i == startingIndex && d == depth):
if (tryAdd(choice, tags)) lastChoiceIndex = i;
// Stop at the next gather of this depth // Stop at the next gather of this depth
case EGather(_, d, _) if (d == depth): case EGather(_, d, _) if (d == depth):
break; break;
@@ -111,7 +116,7 @@ class ASTExtension {
for (i in 0...ast.length) { for (i in 0...ast.length) {
var expr = ast[i].expr; var expr = ast[i].expr;
switch (expr) { switch (expr) {
case EChoice(c) | ETagged(EChoice(c), _): case EChoice(c) | ETagged(EChoice(c), _) | EGather(_, _, EChoice(c)):
if (c.id == id) if (c.id == id)
return i; return i;
default: default:

View File

@@ -383,7 +383,9 @@ class Story {
} }
} }
if (exprIndex < ast.length && ast[exprIndex].expr.match(EChoice(_))) { if (exprIndex < ast.length &&
(ast[exprIndex].expr.match(EChoice(_))
|| ast[exprIndex].expr.match(EGather(_, _, EChoice(_))))) {
var allChoiceInfo = ast.collectChoices(exprIndex, weaveDepth).choices; var allChoiceInfo = ast.collectChoices(exprIndex, weaveDepth).choices;
for (choiceInfo in allChoiceInfo) { for (choiceInfo in allChoiceInfo) {
if (choicesTaken.indexOf(choiceInfo.choice.id) == -1 || !choiceInfo.choice.onceOnly) { if (choicesTaken.indexOf(choiceInfo.choice.id) == -1 || !choiceInfo.choice.onceOnly) {
@@ -404,7 +406,6 @@ class Story {
// trace('final:'); // trace('final:');
// traceChoiceArray(choices); // traceChoiceArray(choices);
// traceChoiceArray(choices);
return choices; return choices;
} }