public override void GenerateIntoContainer (Runtime.Container container) { Expression constantValue = null; // Name can be null if it's actually a path to a knot/stitch etc for a read count var varName = name; // If it's a constant reference, just generate the literal expression value if ( varName != null && story.constants.TryGetValue (varName, out constantValue) ) { constantValue.GenerateConstantIntoContainer (container); isConstantReference = true; } else { _runtimeVarRef = new Runtime.VariableReference (name); container.AddContent(_runtimeVarRef); } }
public override void GenerateIntoContainer(Runtime.Container container) { Expression constantValue = null; // If it's a constant reference, just generate the literal expression value // It's okay to access the constants at code generation time, since the // first thing the ExportRuntime function does it search for all the constants // in the story hierarchy, so they're all available. if (story.constants.TryGetValue(name, out constantValue)) { constantValue.GenerateConstantIntoContainer(container); isConstantReference = true; return; } _runtimeVarRef = new Runtime.VariableReference(name); // List item reference? // Path might be to a list (listName.listItemName or just listItemName) if (path.Count == 1 || path.Count == 2) { string listItemName = null; string listName = null; if (path.Count == 1) { listItemName = path [0]; } else { listName = path [0]; listItemName = path [1]; } var listItem = story.ResolveListItem(listName, listItemName, this); if (listItem) { isListItemReference = true; } } container.AddContent(_runtimeVarRef); }
public override void GenerateIntoContainer(Runtime.Container container) { Expression constantValue = null; // Name can be null if it's actually a path to a knot/stitch etc for a read count var varName = name; // If it's a constant reference, just generate the literal expression value if (varName != null && story.constants.TryGetValue(varName, out constantValue)) { constantValue.GenerateIntoContainer(container); isConstantReference = true; } else { _runtimeVarRef = new Runtime.VariableReference(name); container.AddContent(_runtimeVarRef); } }
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); }