Ejemplo n.º 1
0
 private void DisplayNode(Node node)
 {
     Console.WriteLine(node.Text);
     foreach (var input in node.Inputs)
     {
         Console.Write(input.MatchText+"\t");
     }
     Console.WriteLine();
 }
Ejemplo n.º 2
0
        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;
        }
Ejemplo n.º 3
0
 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);
 }
Ejemplo n.º 4
0
 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;
 }
Ejemplo n.º 5
0
 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;
             }
         }
     }
 }