Tags available on choices
Some checks failed
/ test (push) Failing after 11s

This commit is contained in:
2025-10-28 17:51:00 -05:00
parent 05e6bc30c3
commit 4411015597

View File

@@ -25,7 +25,7 @@ import hank.Alt.AltInstance;
**/
enum StoryFrame {
HasText(text:String);
HasChoices(choices:Array<String>);
HasChoices(choices:Array<String>, tags:Array<Array<String>>);
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<String>) {
return HasChoices([for (c in choices) removeDoubleSpaces(c).trim()]);
private function finalChoiceProcessing(choices:Array<String>, tags:Array<Array<String>>) {
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<String>,Int->Void)->Void,
showChoices:(Array<String>,Array<Array<String>>,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();
});