Exemplo n.º 1
0
 private void getAllNodes(ConversationNode firstNode, List <ConversationNode> nodes)
 {
     for (int i = -1; i < firstNode.getChildCount(); i++)
     {
         ConversationNode child = null;
         if (i == -1)
         {
             child = firstNode;
         }
         else
         {
             child = firstNode.getChild(i);
         }
         // Check the child is not in the list yet
         bool isInList = false;
         foreach (ConversationNode aNode in nodes)
         {
             if (aNode == child)
             {
                 isInList = true;
                 break;
             }
         }
         if (!isInList)
         {
             nodes.Add(child);
             getAllNodes(child, nodes);
         }
     }
 }
        /**
         * Checks if there is a "go-back" tag in the given node. This is, if the
         * node is a DialogueNode, and is linked to the OptionNode from which came
         * from
         *
         * @param node
         *            Node (must be a DialogueNode) to check
         * @return True if the node has a "go-back" tag, false otherwise
         */
        public static bool thereIsGoBackTag(ConversationNode node)
        {
            bool goBackTag = false;

            // Perform the check only if the node is a DialogueNode and it has a child
            if (node is DialogueConversationNode && node.getChildCount() > 0)
            {
                ConversationNode possibleFather = node.getChild(0);

                // For each child of the possible father node, check if it match with the possible child
                for (int i = 0; i < possibleFather.getChildCount(); i++)
                {
                    if (possibleFather.getChild(i) == node)
                    {
                        goBackTag = true;
                    }
                }
            }

            return(goBackTag);
        }
Exemplo n.º 3
0
        /**
         * Returns a list with all the nodes in the conversation.
         *
         * @return List with the nodes of the conversation
         */
        public override List <ConversationNode> getAllNodes()
        {
            List <ConversationNode> nodes = new List <ConversationNode>();

            nodes.Add(getRootNode());
            int i = 0;

            while (i < nodes.Count)
            {
                ConversationNode temp = nodes[i];
                i++;
                for (int j = 0; j < temp.getChildCount(); j++)
                {
                    ConversationNode temp2 = temp.getChild(j);
                    if (!nodes.Contains(temp2))
                    {
                        nodes.Add(temp2);
                    }
                }
            }

            return(nodes);
        }
Exemplo n.º 4
0
        public virtual object Clone()
        {
            Conversation c = (Conversation)this.MemberwiseClone();

            c.conversationId   = (conversationId != null ? conversationId : null);
            c.conversationType = conversationType;

            Dictionary <ConversationNode, ConversationNode> clonedNodes =
                new Dictionary <ConversationNode, ConversationNode>();

            c.root = (root != null ? (ConversationNode)root.Clone() : null);

            clonedNodes.Add(root, c.root);
            List <ConversationNode> nodes   = new List <ConversationNode>();
            List <ConversationNode> visited = new List <ConversationNode>();

            nodes.Add(root);

            while (nodes.Count > 0)
            {
                ConversationNode temp   = nodes[0];
                ConversationNode cloned = clonedNodes[temp];
                nodes.RemoveAt(0);
                visited.Add(temp);

                for (int i = 0; i < temp.getChildCount(); i++)
                {
                    ConversationNode tempCloned = clonedNodes[temp.getChild(i)];
                    if (tempCloned == null)
                    {
                        tempCloned = (ConversationNode)temp.getChild(i).Clone();
                        clonedNodes.Add(temp.getChild(i), tempCloned);
                    }
                    cloned.addChild(tempCloned);

                    if (!visited.Contains(temp.getChild(i)) && !nodes.Contains(temp.getChild(i)))
                    {
                        nodes.Add(temp.getChild(i));
                    }
                }
            }
            return(c);
        }