Inline divert example
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
This is a line that diverts -> part2
|
This is a line that diverts -> part2
|
||||||
|
|
||||||
- (start)
|
- (start)
|
||||||
This is a text line {if (seen_once>0) "-> second_route"} with a conditional divert in it.
|
This is a text line {if (seen_once>0) ",-> second_route"} with a conditional divert in it.
|
||||||
|
|
||||||
- (seen_once) -> start
|
- (seen_once) -> start
|
||||||
|
|
||||||
@@ -19,6 +19,7 @@ enum OutputType {
|
|||||||
@:allow(tests.ParserTest)
|
@:allow(tests.ParserTest)
|
||||||
class Output {
|
class Output {
|
||||||
var parts: Array<OutputType> = [];
|
var parts: Array<OutputType> = [];
|
||||||
|
var diverted: Bool = false;
|
||||||
|
|
||||||
public function new(?parts: Array<OutputType>) {
|
public function new(?parts: Array<OutputType>) {
|
||||||
this.parts = if (parts != null) {
|
this.parts = if (parts != null) {
|
||||||
@@ -169,15 +170,28 @@ class Output {
|
|||||||
fullOutput += altInstances[a].next().format(story, hInterface, random, altInstances, scope, displayToggles);
|
fullOutput += altInstances[a].next().format(story, hInterface, random, altInstances, scope, displayToggles);
|
||||||
case HExpression(h):
|
case HExpression(h):
|
||||||
trace(h);
|
trace(h);
|
||||||
fullOutput += hInterface.evaluateExpr(h, scope);
|
var value = hInterface.evaluateExpr(h, scope);
|
||||||
|
// HExpressions that start with ',' will be parsed and formatted as their own outputs
|
||||||
|
if (value.startsWith(',')) {
|
||||||
|
var nestedOutput = Output.parse(HankBuffer.Dummy(value.substr(1)));
|
||||||
|
value = nestedOutput.format(story, hInterface, random, altInstances, scope, displayToggles);
|
||||||
|
fullOutput += value;
|
||||||
|
if (nestedOutput.diverted) break;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
fullOutput += value;
|
||||||
|
}
|
||||||
case InlineDivert(t):
|
case InlineDivert(t):
|
||||||
// follow the divert. If the next expression is an output, concatenate the pieces together. Otherwise, terminate formatting
|
// follow the divert. If the next expression is an output, concatenate the pieces together. Otherwise, terminate formatting
|
||||||
story.divertTo(t);
|
story.divertTo(t);
|
||||||
|
// Track whether the last call to format() resulted in a divert, so nested Outputs can interrupt the flow of their parents
|
||||||
|
diverted = true;
|
||||||
switch (story.nextFrame()) {
|
switch (story.nextFrame()) {
|
||||||
case HasText(text):
|
case HasText(text):
|
||||||
fullOutput += text;
|
fullOutput += text;
|
||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
|
break; // Don't format the rest of this Output's parts
|
||||||
|
|
||||||
case ToggleOutput(o, b):
|
case ToggleOutput(o, b):
|
||||||
if (b == displayToggles) {
|
if (b == displayToggles) {
|
||||||
@@ -186,6 +200,11 @@ class Output {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Remove double spaces from the output
|
||||||
|
while (fullOutput.indexOf(" ") != -1) {
|
||||||
|
fullOutput = fullOutput.replace(" ", " ");
|
||||||
|
}
|
||||||
|
|
||||||
return fullOutput;
|
return fullOutput;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user