This commit is contained in:
@@ -25,7 +25,7 @@ import hank.Alt.AltInstance;
|
|||||||
**/
|
**/
|
||||||
enum StoryFrame {
|
enum StoryFrame {
|
||||||
HasText(text:String);
|
HasText(text:String);
|
||||||
HasChoices(choices:Array<String>);
|
HasChoices(choices:Array<String>, tags:Array<Array<String>>);
|
||||||
Finished;
|
Finished;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -182,7 +182,7 @@ class Story {
|
|||||||
while (idx < embeddedBlocks.length) {
|
while (idx < embeddedBlocks.length) {
|
||||||
var nf = embeddedBlocks[idx].nextFrame();
|
var nf = embeddedBlocks[idx].nextFrame();
|
||||||
switch (nf) {
|
switch (nf) {
|
||||||
case HasChoices(_) | Finished:
|
case HasChoices(_, _) | Finished:
|
||||||
// trace('Hit end of flow for thread $idx');
|
// trace('Hit end of flow for thread $idx');
|
||||||
idx++;
|
idx++;
|
||||||
// exprIndex++;
|
// exprIndex++;
|
||||||
@@ -322,7 +322,7 @@ class Story {
|
|||||||
++exprIndex;
|
++exprIndex;
|
||||||
return nextFrame();
|
return nextFrame();
|
||||||
|
|
||||||
case EChoice(choice):
|
case EChoice(choice) | ETagged(EChoice(choice), _):
|
||||||
if (choice.depth > weaveDepth) {
|
if (choice.depth > weaveDepth) {
|
||||||
weaveDepth = choice.depth;
|
weaveDepth = choice.depth;
|
||||||
} else if (choice.depth < weaveDepth) {
|
} else if (choice.depth < weaveDepth) {
|
||||||
@@ -340,12 +340,17 @@ class Story {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private function nextChoiceFrame() {
|
private function nextChoiceFrame() {
|
||||||
|
var choices = availableChoices();
|
||||||
var optionsText = [
|
var optionsText = [
|
||||||
for (choiceInfo in availableChoices())
|
for (choiceInfo in choices)
|
||||||
choiceInfo.choice.output.format(this, hInterface, random, altInstances, nodeScopes, false)
|
choiceInfo.choice.output.format(this, hInterface, random, altInstances, nodeScopes, false)
|
||||||
];
|
];
|
||||||
|
var tags = [
|
||||||
|
for (choiceInfo in choices)
|
||||||
|
choiceInfo.tags
|
||||||
|
];
|
||||||
if (optionsText.length > 0) {
|
if (optionsText.length > 0) {
|
||||||
return finalChoiceProcessing(optionsText);
|
return finalChoiceProcessing(optionsText, tags);
|
||||||
} else {
|
} else {
|
||||||
var fallback = fallbackChoice();
|
var fallback = fallbackChoice();
|
||||||
switch (fallback.choiceInfo.choice.divertTarget) {
|
switch (fallback.choiceInfo.choice.divertTarget) {
|
||||||
@@ -386,7 +391,7 @@ class Story {
|
|||||||
|
|
||||||
if (exprIndex < ast.length &&
|
if (exprIndex < ast.length &&
|
||||||
(ast[exprIndex].expr.match(EChoice(_))
|
(ast[exprIndex].expr.match(EChoice(_))
|
||||||
|| ast[exprIndex].expr.match(EGather(_, _, EChoice(_))))) {
|
|| ast[exprIndex].expr.match(ETagged(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) {
|
||||||
@@ -560,7 +565,7 @@ class Story {
|
|||||||
|
|
||||||
public function choose(choiceIndex:Int):String {
|
public function choose(choiceIndex:Int):String {
|
||||||
var nf = nextFrame();
|
var nf = nextFrame();
|
||||||
if (!nf.match(HasChoices(_))) {
|
if (!nf.match(HasChoices(_, _))) {
|
||||||
throw 'Trying to make a choice when next frame is $nf';
|
throw 'Trying to make a choice when next frame is $nf';
|
||||||
}
|
}
|
||||||
// trace('choosing $choiceIndex');
|
// trace('choosing $choiceIndex');
|
||||||
@@ -637,8 +642,8 @@ class Story {
|
|||||||
return removeDoubleSpaces(t).trim();
|
return removeDoubleSpaces(t).trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
private function finalChoiceProcessing(choices:Array<String>) {
|
private function finalChoiceProcessing(choices:Array<String>, tags:Array<Array<String>>) {
|
||||||
return HasChoices([for (c in choices) removeDoubleSpaces(c).trim()]);
|
return HasChoices([for (c in choices) removeDoubleSpaces(c).trim()], tags);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -670,7 +675,7 @@ class Story {
|
|||||||
|
|
||||||
public function run(
|
public function run(
|
||||||
showText:(String,Void->Void)->Void,
|
showText:(String,Void->Void)->Void,
|
||||||
showChoices:(Array<String>,Int->Void)->Void,
|
showChoices:(Array<String>,Array<Array<String>>,Int->Void)->Void,
|
||||||
finish:Void->Void)
|
finish:Void->Void)
|
||||||
{
|
{
|
||||||
var loop = run.bind(showText, showChoices, finish);
|
var loop = run.bind(showText, showChoices, finish);
|
||||||
@@ -679,8 +684,8 @@ class Story {
|
|||||||
showText(text, () -> {
|
showText(text, () -> {
|
||||||
loop();
|
loop();
|
||||||
});
|
});
|
||||||
case HasChoices(choices):
|
case HasChoices(choices, tags):
|
||||||
showChoices(choices, (choiceIndex) -> {
|
showChoices(choices, tags, (choiceIndex) -> {
|
||||||
choose(choiceIndex);
|
choose(choiceIndex);
|
||||||
loop();
|
loop();
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user