public override void GenerateIntoContainer(Runtime.Container container) { divert.GenerateRuntimeObject(); _runtimeDivert = (Runtime.Divert)divert.runtimeDivert; _runtimeDivertTargetValue = new Runtime.DivertTargetValue(); container.AddContent(_runtimeDivertTargetValue); }
public override void GenerateIntoContainer(Runtime.Container container) { divert.GenerateRuntimeObject(); _runtimeDivert = (Runtime.Divert) divert.runtimeDivert; _runtimeDivertTargetValue = new Runtime.DivertTargetValue (); if (divert.arguments != null && divert.arguments.Count > 0) { Error ("Can't use a divert target as a variable if it has parameters"); return; } container.AddContent (_runtimeDivertTargetValue); }
public override void GenerateIntoContainer(Runtime.Container container) { divert.GenerateRuntimeObject(); _runtimeDivert = (Runtime.Divert)divert.runtimeDivert; _runtimeDivertTargetValue = new Runtime.DivertTargetValue(); if (divert.arguments != null && divert.arguments.Count > 0) { Error("Can't use a divert target as a variable if it has parameters"); return; } container.AddContent(_runtimeDivertTargetValue); }
public override Runtime.Object GenerateRuntimeObject () { var container = new Runtime.Container (); // Set override path for tunnel onwards (or nothing) container.AddContent (Runtime.ControlCommand.EvalStart ()); if (overrideReturnPath != null) { _overrideDivertTarget = new Runtime.DivertTargetValue (); container.AddContent (_overrideDivertTarget); } else { container.AddContent (new Runtime.Void ()); } container.AddContent (Runtime.ControlCommand.EvalEnd ()); container.AddContent (Runtime.ControlCommand.PopTunnel ()); return container; }
public override Runtime.Object GenerateRuntimeObject() { var container = new Runtime.Container(); // Set override path for tunnel onwards (or nothing) container.AddContent(Runtime.ControlCommand.EvalStart()); if (overrideReturnPath != null) { _overrideDivertTarget = new Runtime.DivertTargetValue(); container.AddContent(_overrideDivertTarget); } else { container.AddContent(new Runtime.Void()); } container.AddContent(Runtime.ControlCommand.EvalEnd()); container.AddContent(Runtime.ControlCommand.PopTunnel()); return(container); }
public override Runtime.Object GenerateRuntimeObject() { var container = new Runtime.Container(); // Set override path for tunnel onwards (or nothing) container.AddContent(Runtime.ControlCommand.EvalStart()); if (divertAfter) { // Generate runtime object's generated code and steal the arguments runtime code var returnRuntimeObj = divertAfter.GenerateRuntimeObject(); var returnRuntimeContainer = returnRuntimeObj as Runtime.Container; if (returnRuntimeContainer) { // Steal all code for generating arguments from the divert var args = divertAfter.arguments; if (args != null && args.Count > 0) { // Steal everything betwen eval start and eval end int evalStart = -1; int evalEnd = -1; for (int i = 0; i < returnRuntimeContainer.content.Count; i++) { var cmd = returnRuntimeContainer.content [i] as Runtime.ControlCommand; if (cmd) { if (evalStart == -1 && cmd.commandType == Runtime.ControlCommand.CommandType.EvalStart) { evalStart = i; } else if (cmd.commandType == Runtime.ControlCommand.CommandType.EvalEnd) { evalEnd = i; } } } for (int i = evalStart + 1; i < evalEnd; i++) { var obj = returnRuntimeContainer.content [i]; obj.parent = null; // prevent error of being moved between owners container.AddContent(returnRuntimeContainer.content [i]); } } } // Supply the divert target for the tunnel onwards target, either variable or more commonly, the explicit name var returnDivertObj = returnRuntimeObj as Runtime.Divert; if (returnDivertObj != null && returnDivertObj.hasVariableTarget) { var runtimeVarRef = new Runtime.VariableReference(returnDivertObj.variableDivertName); container.AddContent(runtimeVarRef); } else { _overrideDivertTarget = new Runtime.DivertTargetValue(); container.AddContent(_overrideDivertTarget); } } // No divert after tunnel onwards else { container.AddContent(new Runtime.Void()); } container.AddContent(Runtime.ControlCommand.EvalEnd()); container.AddContent(Runtime.ControlCommand.PopTunnel()); return(container); }
public override Runtime.Object GenerateRuntimeObject() { _outerContainer = new Runtime.Container(); // Content names for different types of choice: // * start content [choice only content] inner content // * start content -> divert // * start content // * [choice only content] // Hmm, this structure has become slightly insane! // // [ // EvalStart // assign $r = $r1 -- return target = return label 1 // BeginString // -> s // [(r1)] -- return label 1 (after start content) // EndString // BeginString // ... choice only content // EndEval // Condition expression // choice: -> "c-0" // (s) = [ // start content // -> r -- goto return label 1 or 2 // ] // ] // // in parent's container: (the inner content for the choice) // // (c-0) = [ // EvalStart // assign $r = $r2 -- return target = return label 2 // EndEval // -> s // [(r2)] -- return label 1 (after start content) // inner content // ] // _runtimeChoice = new Runtime.ChoicePoint(onceOnly); _runtimeChoice.isInvisibleDefault = this.isInvisibleDefault; if (startContent || choiceOnlyContent || condition) { _outerContainer.AddContent(Runtime.ControlCommand.EvalStart()); } // Start content is put into a named container that's referenced both // when displaying the choice initially, and when generating the text // when the choice is chosen. if (startContent) { // Generate start content and return // - We can't use a function since it uses a call stack element, which would // put temporary values out of scope. Instead we manually divert around. // - $r is a variable divert target contains the return point _returnToR1 = new Runtime.DivertTargetValue(); _outerContainer.AddContent(_returnToR1); var varAssign = new Runtime.VariableAssignment("$r", true); _outerContainer.AddContent(varAssign); // Mark the start of the choice text generation, so that the runtime // knows where to rewind to to extract the content from the output stream. _outerContainer.AddContent(Runtime.ControlCommand.BeginString()); _divertToStartContentOuter = new Runtime.Divert(); _outerContainer.AddContent(_divertToStartContentOuter); // Start content itself in a named container _startContentRuntimeContainer = startContent.GenerateRuntimeObject() as Runtime.Container; _startContentRuntimeContainer.name = "s"; // Effectively, the "return" statement - return to the point specified by $r var varDivert = new Runtime.Divert(); varDivert.variableDivertName = "$r"; _startContentRuntimeContainer.AddContent(varDivert); // Add the container _outerContainer.AddToNamedContentOnly(_startContentRuntimeContainer); // This is the label to return to _r1Label = new Runtime.Container(); _r1Label.name = "$r1"; _outerContainer.AddContent(_r1Label); _outerContainer.AddContent(Runtime.ControlCommand.EndString()); _runtimeChoice.hasStartContent = true; } // Choice only content - mark the start, then generate it directly into the outer container if (choiceOnlyContent) { _outerContainer.AddContent(Runtime.ControlCommand.BeginString()); var choiceOnlyRuntimeContent = choiceOnlyContent.GenerateRuntimeObject() as Runtime.Container; _outerContainer.AddContentsOfContainer(choiceOnlyRuntimeContent); _outerContainer.AddContent(Runtime.ControlCommand.EndString()); _runtimeChoice.hasChoiceOnlyContent = true; } // Generate any condition for this choice if (condition) { condition.GenerateIntoContainer(_outerContainer); _runtimeChoice.hasCondition = true; } if (startContent || choiceOnlyContent || condition) { _outerContainer.AddContent(Runtime.ControlCommand.EvalEnd()); } // Add choice itself _outerContainer.AddContent(_runtimeChoice); // Container that choice points to for when it's chosen _innerContentContainer = new Runtime.Container(); // Repeat start content by diverting to its container if (startContent) { // Set the return point when jumping back into the start content // - In this case, it's the $r2 point, within the choice content "c". _returnToR2 = new Runtime.DivertTargetValue(); _innerContentContainer.AddContent(Runtime.ControlCommand.EvalStart()); _innerContentContainer.AddContent(_returnToR2); _innerContentContainer.AddContent(Runtime.ControlCommand.EvalEnd()); var varAssign = new Runtime.VariableAssignment("$r", true); _innerContentContainer.AddContent(varAssign); // Main divert into start content _divertToStartContentInner = new Runtime.Divert(); _innerContentContainer.AddContent(_divertToStartContentInner); // Define label to return to _r2Label = new Runtime.Container(); _r2Label.name = "$r2"; _innerContentContainer.AddContent(_r2Label); } // Choice's own inner content if (innerContent) { var innerChoiceOnlyContent = innerContent.GenerateRuntimeObject() as Runtime.Container; _innerContentContainer.AddContentsOfContainer(innerChoiceOnlyContent); } if (this.story.countAllVisits) { _innerContentContainer.visitsShouldBeCounted = true; } _innerContentContainer.countingAtStartOnly = true; return(_outerContainer); }
public override Runtime.Object GenerateRuntimeObject () { _outerContainer = new Runtime.Container (); // Content names for different types of choice: // * start content [choice only content] inner content // * start content -> divert // * start content // * [choice only content] // Hmm, this structure has become slightly insane! // // [ // EvalStart // assign $r = $r1 -- return target = return label 1 // BeginString // -> s // [(r1)] -- return label 1 (after start content) // EndString // BeginString // ... choice only content // EndEval // Condition expression // choice: -> "c" // (s) = [ // start content // -> r -- goto return label 1 or 2 // ] // (c) = [ // EvalStart // assign $r = $r2 -- return target = return label 2 // EndEval // -> s // [(r2)] -- return label 1 (after start content) // inner content // ] // ] _runtimeChoice = new Runtime.ChoicePoint (onceOnly); _runtimeChoice.isInvisibleDefault = this.isInvisibleDefault; if (startContent || choiceOnlyContent || condition) { _outerContainer.AddContent (Runtime.ControlCommand.EvalStart ()); } // Start content is put into a named container that's referenced both // when displaying the choice initially, and when generating the text // when the choice is chosen. if (startContent) { // Generate start content and return // - We can't use a function since it uses a call stack element, which would // put temporary values out of scope. Instead we manually divert around. // - $r is a variable divert target contains the return point _returnToR1 = new Runtime.DivertTargetValue (); _outerContainer.AddContent (_returnToR1); var varAssign = new Runtime.VariableAssignment ("$r", true); _outerContainer.AddContent (varAssign); // Mark the start of the choice text generation, so that the runtime // knows where to rewind to to extract the content from the output stream. _outerContainer.AddContent (Runtime.ControlCommand.BeginString ()); _divertToStartContentOuter = new Runtime.Divert (); _outerContainer.AddContent (_divertToStartContentOuter); // Start content itself in a named container _startContentRuntimeContainer = startContent.GenerateRuntimeObject () as Runtime.Container; _startContentRuntimeContainer.name = "s"; // Effectively, the "return" statement - return to the point specified by $r var varDivert = new Runtime.Divert (); varDivert.variableDivertName = "$r"; _startContentRuntimeContainer.AddContent (varDivert); // Add the container _outerContainer.AddToNamedContentOnly (_startContentRuntimeContainer); // This is the label to return to _r1Label = new Runtime.Container (); _r1Label.name = "$r1"; _outerContainer.AddContent (_r1Label); _outerContainer.AddContent (Runtime.ControlCommand.EndString ()); _runtimeChoice.hasStartContent = true; } // Choice only content - mark the start, then generate it directly into the outer container if (choiceOnlyContent) { _outerContainer.AddContent (Runtime.ControlCommand.BeginString ()); var choiceOnlyRuntimeContent = choiceOnlyContent.GenerateRuntimeObject () as Runtime.Container; _outerContainer.AddContentsOfContainer (choiceOnlyRuntimeContent); _outerContainer.AddContent (Runtime.ControlCommand.EndString ()); _runtimeChoice.hasChoiceOnlyContent = true; } // Generate any condition for this choice if (condition) { condition.GenerateIntoContainer (_outerContainer); _runtimeChoice.hasCondition = true; } if (startContent || choiceOnlyContent || condition) { _outerContainer.AddContent (Runtime.ControlCommand.EvalEnd ()); } // Add choice itself _outerContainer.AddContent (_runtimeChoice); // Container that choice points to for when it's chosen _innerContentContainer = new Runtime.Container (); // Repeat start content by diverting to its container if (startContent) { // Set the return point when jumping back into the start content // - In this case, it's the $r2 point, within the choice content "c". _returnToR2 = new Runtime.DivertTargetValue (); _innerContentContainer.AddContent (Runtime.ControlCommand.EvalStart ()); _innerContentContainer.AddContent (_returnToR2); _innerContentContainer.AddContent (Runtime.ControlCommand.EvalEnd ()); var varAssign = new Runtime.VariableAssignment ("$r", true); _innerContentContainer.AddContent (varAssign); // Main divert into start content _divertToStartContentInner = new Runtime.Divert (); _innerContentContainer.AddContent (_divertToStartContentInner); // Define label to return to _r2Label = new Runtime.Container (); _r2Label.name = "$r2"; _innerContentContainer.AddContent (_r2Label); } // Choice's own inner content if (innerContent) { var innerChoiceOnlyContent = innerContent.GenerateRuntimeObject () as Runtime.Container; _innerContentContainer.AddContentsOfContainer (innerChoiceOnlyContent); } // Fully parsed choice will be a full line, so it needs to be terminated if (startContent || innerContent) { _innerContentContainer.AddContent(new Runtime.StringValue("\n")); } // Use "c" as the destination name within the choice's outer container _innerContentContainer.name = "c"; _outerContainer.AddToNamedContentOnly (_innerContentContainer); if (this.story.countAllVisits) { _innerContentContainer.visitsShouldBeCounted = true; _innerContentContainer.turnIndexShouldBeCounted = true; } _innerContentContainer.countingAtStartOnly = true; // Does this choice end in an explicit divert? if (terminatingDivert) { _innerContentContainer.AddContent (terminatingDivert.runtimeObject); } return _outerContainer; }