From 4411015597d64507fac31261e068752481c75f91 Mon Sep 17 00:00:00 2001 From: Nat Quayle Nelson Date: Tue, 28 Oct 2025 17:51:00 -0500 Subject: [PATCH] Tags available on choices --- hank/Story.hx | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/hank/Story.hx b/hank/Story.hx index 31b3352..64ca74b 100644 --- a/hank/Story.hx +++ b/hank/Story.hx @@ -25,7 +25,7 @@ import hank.Alt.AltInstance; **/ enum StoryFrame { HasText(text:String); - HasChoices(choices:Array); + HasChoices(choices:Array, tags:Array>); Finished; } @@ -182,7 +182,7 @@ class Story { while (idx < embeddedBlocks.length) { var nf = embeddedBlocks[idx].nextFrame(); switch (nf) { - case HasChoices(_) | Finished: + case HasChoices(_, _) | Finished: // trace('Hit end of flow for thread $idx'); idx++; // exprIndex++; @@ -322,7 +322,7 @@ class Story { ++exprIndex; return nextFrame(); - case EChoice(choice): + case EChoice(choice) | ETagged(EChoice(choice), _): if (choice.depth > weaveDepth) { weaveDepth = choice.depth; } else if (choice.depth < weaveDepth) { @@ -340,12 +340,17 @@ class Story { } private function nextChoiceFrame() { + var choices = availableChoices(); var optionsText = [ - for (choiceInfo in availableChoices()) + for (choiceInfo in choices) choiceInfo.choice.output.format(this, hInterface, random, altInstances, nodeScopes, false) ]; + var tags = [ + for (choiceInfo in choices) + choiceInfo.tags + ]; if (optionsText.length > 0) { - return finalChoiceProcessing(optionsText); + return finalChoiceProcessing(optionsText, tags); } else { var fallback = fallbackChoice(); switch (fallback.choiceInfo.choice.divertTarget) { @@ -386,7 +391,7 @@ class Story { if (exprIndex < ast.length && (ast[exprIndex].expr.match(EChoice(_)) - || ast[exprIndex].expr.match(EGather(_, _, EChoice(_))))) { + || ast[exprIndex].expr.match(ETagged(EChoice(_), _)))) { var allChoiceInfo = ast.collectChoices(exprIndex, weaveDepth).choices; for (choiceInfo in allChoiceInfo) { if (choicesTaken.indexOf(choiceInfo.choice.id) == -1 || !choiceInfo.choice.onceOnly) { @@ -560,7 +565,7 @@ class Story { public function choose(choiceIndex:Int):String { var nf = nextFrame(); - if (!nf.match(HasChoices(_))) { + if (!nf.match(HasChoices(_, _))) { throw 'Trying to make a choice when next frame is $nf'; } // trace('choosing $choiceIndex'); @@ -637,8 +642,8 @@ class Story { return removeDoubleSpaces(t).trim(); } - private function finalChoiceProcessing(choices:Array) { - return HasChoices([for (c in choices) removeDoubleSpaces(c).trim()]); + private function finalChoiceProcessing(choices:Array, tags:Array>) { + return HasChoices([for (c in choices) removeDoubleSpaces(c).trim()], tags); } /** @@ -670,7 +675,7 @@ class Story { public function run( showText:(String,Void->Void)->Void, - showChoices:(Array,Int->Void)->Void, + showChoices:(Array,Array>,Int->Void)->Void, finish:Void->Void) { var loop = run.bind(showText, showChoices, finish); @@ -679,8 +684,8 @@ class Story { showText(text, () -> { loop(); }); - case HasChoices(choices): - showChoices(choices, (choiceIndex) -> { + case HasChoices(choices, tags): + showChoices(choices, tags, (choiceIndex) -> { choose(choiceIndex); loop(); });