public void ParseNodeHelper(Yarn.Parser.Node n, Block block, Dictionary <string, Yarn.Parser.Node> nodes, Dictionary <string, Block> blocks) { List <Parser.Statement> commands = n._statements; foreach (Parser.Statement statement in commands) { if (statement.line != null) { CreateSay(statement.line, block); } else if (statement.optionStatement != null) { CreateCallCommand(statement.optionStatement.destination, block, blocks); } else if (statement.customCommand != null) { CreateCustomCommand(statement.customCommand.clientCommand, block); } else if (statement.shortcutOptionGroup != null) { CreateOptionGroup(statement.shortcutOptionGroup._options, block, nodes, blocks); } else if (statement.ifStatement != null) { List <Parser.IfStatement.Clause> clauses = statement.ifStatement.clauses; CreateConditional(clauses, block, nodes, blocks); } } }
// executes a node, and returns either the name of the next node to run // or null (indicating the dialogue is over) internal IEnumerable <Dialogue.RunnerResult> RunNode(Yarn.Parser.Node node) { // Clear the list of options when we start a new node currentOptions = new List <Parser.OptionStatement> (); // Run all of the statements in this node foreach (var command in RunStatements(node.statements)) { yield return(command); } // If we have no options, we're all done if (currentOptions.Count == 0) { yield return(new Dialogue.NodeCompleteResult(null)); yield break; } else { // We have options! // If we have precisely one option and it's got no label, jump to it if (currentOptions.Count == 1 && currentOptions[0].label == null) { yield return(new Dialogue.NodeCompleteResult(currentOptions [0].destination)); yield break; } // Otherwise, ask which option to pick... var optionStrings = new List <string> (); foreach (var option in currentOptions) { var label = option.label ?? option.destination; optionStrings.Add(label); } Parser.OptionStatement selectedOption = null; yield return(new Dialogue.OptionSetResult(optionStrings, delegate(int selectedOptionIndex) { selectedOption = currentOptions[selectedOptionIndex]; })); if (selectedOption == null) { dialogue.LogErrorMessage("Option chooser was never called!"); yield break; } // And jump to its destination! yield return(new Dialogue.NodeCompleteResult(selectedOption.destination)); } yield break; }
// Recursively parses the node public void ParseNode(Yarn.Parser.Node node, Dictionary <string, Yarn.Parser.Node> nodes, Dictionary <string, Block> blocks, string name) { if (!blocks.ContainsKey(node.name)) { Block b = currentFlowchartObj.AddComponent <Block>(); b.BlockName = node.name; blocks[node.name] = b; ParseNodeHelper(node, b, nodes, blocks); } else { ParseNodeHelper(node, blocks[node.name], nodes, blocks); } }
public abstract IEnumerable <Diagnosis> Diagnose(Yarn.Parser.Node node);