private void DisplayNode(Node node) { Console.WriteLine(node.Text); foreach (var input in node.Inputs) { Console.Write(input.MatchText+"\t"); } Console.WriteLine(); }
private Node HandleInput(Node currentNode, string input) { var nodeLabel = currentNode.Inputs.Find(o => o.MatchText == input); if (nodeLabel == null) { return currentNode; } var nextNode = Nodes.Find(o => o.Label == nodeLabel.Target); if (nextNode == null) { return null; } return nextNode; }
private void ApplyCommand(Command command, Node newNode) { switch (command.Type) { case CommandType.end: break; case CommandType.input: var input = new UserInput(); input.MatchText = command.Attributes["input"]; input.Target = command.Attributes["target"]; newNode.Inputs.Add(input); break; case CommandType.label: newNode.Label = command.Attributes["label"]; break; default: throw new ArgumentOutOfRangeException(); } HandleModifiers(command, newNode); }
public Node GetNextNode() { var nodeText = new StringBuilder(); var newNode = new Node(); var line = ""; while (line != "#end") { line = _reader.ReadLine(); if (!string.IsNullOrEmpty(line)) { if (line[0] == '#') //Must be a command line { var command = GetCommandFromLine(line); ApplyCommand(command, newNode); } else //must be node text then { nodeText.AppendLine(line); } } } newNode.Text = nodeText.ToString(); return newNode; }
private void HandleModifiers(Command command, Node newNode) { if (command.Type == CommandType.label) { foreach (var commandModifyer in command.Modifyers) { if (commandModifyer == CommandModifyer.start || commandModifyer == CommandModifyer.finish) { newNode.Type = commandModifyer; } } } }