Beispiel #1
0
        private void FillNode(XmlNode node, TreeConversation treeConversation, params IDOMWriterParam[] options)
        {
            XmlElement rootNode = node as XmlElement;

            // Set the identification attribute of the new conversation, and its type
            rootNode.SetAttribute("id", treeConversation.getId());

            // Call the recursive function that will create the nodes. We pass the root of the tree, the DOM document,
            // the root DOM node that will be used to add the elements, and a depth level for indentation (2 by default)
            WriteNodeInDom(treeConversation.getRootNode(), rootNode, options);
        }
Beispiel #2
0
    /**
     * Recursive function that deletes the references of nodeToDelete in node
     * and its children.
     *
     * @param node
     *            Node to check for references to the node being deleted
     * @param nodeToDelete
     *            Reference to the node that is being deleted
     * @return True if the node to delete was found and deleted, false otherwise
     */
    private bool recursiveDeleteNode(ConversationNode node, ConversationNode nodeToDelete)
    {
        bool isDeleted = false;

        // If it is a dialogue node
        if (node.getType() == ConversationNodeViewEnum.DIALOGUE)
        {
            // If the node has a valid child
            if (!node.isTerminal() && !TreeConversation.thereIsGoBackTag(node))
            {
                // If the child equals the node to be deleted, delete the child
                if (node.getChild(0) == nodeToDelete)
                {
                    node.removeChild(0);
                    isDeleted = true;
                }

                // If not, call the function with the child of the current node
                else
                {
                    isDeleted = recursiveDeleteNode(node.getChild(0), nodeToDelete);
                }
            }
        }

        // If the node is a option node
        else if (node.getType() == ConversationNodeViewEnum.OPTION)
        {
            int i = 0;

            // For each child
            while (i < node.getChildCount())
            {
                // If the child equals the node to be deleted, delete the child and its line
                if (node.getChild(i) == nodeToDelete)
                {
                    node.removeChild(i);
                    node.removeLine(i);
                    isDeleted = true;
                }

                // If not, make a recursive call with the current child, and increase i
                else
                {
                    isDeleted = isDeleted || recursiveDeleteNode(node.getChild(i), nodeToDelete);
                    i++;
                }
            }
        }

        return(isDeleted);
    }
    protected static XmlNode buildTreeConversationDOM(TreeConversation treeConversation)
    {
        XmlElement rootNode = null;


        // Create the necessary elements to create the DOM
        XmlDocument doc = Writer.GetDoc();

        // Create the root node
        rootNode = doc.CreateElement("tree-conversation");

        // Set the identification attribute of the new conversation, and its type
        rootNode.SetAttribute("id", treeConversation.getId());

        // Call the recursive function that will create the nodes. We pass the root of the tree, the DOM document,
        // the root DOM node that will be used to add the elements, and a depth level for indentation (2 by default)
        writeNodeInDOM(treeConversation.getRootNode(), rootNode);

        return(rootNode);
    }
Beispiel #4
0
 public GraphConversation(TreeConversation conversation) : base(Conversation.GRAPH, conversation.getId(), conversation.getRootNode())
 {
 }
 public GraphConversation(TreeConversation conversation)
     : base(Conversation.GRAPH, conversation.getId(), conversation.getRootNode())
 {
 }
Beispiel #6
0
    /*
     * @Override
     * public Object clone() throws CloneNotSupportedException
     * {
     *
     *  TreeConversation tc = (TreeConversation) super.clone( );
     *  return tc;
     * }*/

    public override object Clone()
    {
        TreeConversation tc = (TreeConversation)base.Clone();

        return(tc);
    }
Beispiel #7
0
        /**
         * Recursive function responsible for transforming a node (and its children)
         * into a DOM structure
         *
         * @param currentNode
         *            Node to be transformed
         * @param rootDOMNode
         *            DOM node in which the elements must be attached
         */

        private static void WriteNodeInDom(ConversationNode currentNode, XmlNode rootDOMNode, params IDOMWriterParam[] options)
        {
            // Extract the document
            XmlDocument document = rootDOMNode.OwnerDocument;

            // If the node is a DialogueNode write the lines one after another, and then the child (or the mark if it is no
            // child)
            if (currentNode is DialogueConversationNode)
            {
                // For each line of the node
                for (int i = 0; i < currentNode.getLineCount(); i++)
                {
                    // Create a phrase element, and extract the actual text line
                    XmlElement       phrase;
                    ConversationLine line = currentNode.getLine(i);

                    // If the line belongs to the player, create a "speak-player" element. Otherwise, if it belongs to a
                    // NPC,
                    // create a "speak-char" element, which will have an attribute "idTarget" with the name of the
                    // non-playable character,
                    // if there is no name the attribute won't be written
                    if (line.isPlayerLine())
                    {
                        phrase = document.CreateElement("speak-player");
                    }
                    else
                    {
                        phrase = document.CreateElement("speak-char");
                        if (!line.getName().Equals("NPC"))
                        {
                            phrase.SetAttribute("idTarget", line.getName());
                        }
                    }

                    // Add the line text into the element
                    var text = document.CreateElement("text");
                    text.InnerText = line.getText();
                    phrase.AppendChild(text);

                    // Append the resources
                    foreach (ResourcesUni resources in line.getResources())
                    {
                        XmlNode resourcesNode = ResourcesDOMWriter.buildDOM(resources, ResourcesDOMWriter.RESOURCES_CONVERSATION_LINE);
                        document.ImportNode(resourcesNode, true);
                        phrase.AppendChild(resourcesNode);
                    }

                    // Add the element to the DOM root
                    rootDOMNode.AppendChild(phrase);

                    // Create conditions for current effect
                    DOMWriterUtility.DOMWrite(rootDOMNode, line.getConditions(), options);
                }

                // Check if the node is terminal
                if (currentNode.isTerminal())
                {
                    // If it is terminal add a "end-conversation" element
                    XmlElement endConversation = document.CreateElement("end-conversation");

                    // Add the "end-conversation" tag into the root
                    rootDOMNode.AppendChild(endConversation);

                    // If the terminal node has an effect, include it into the DOM
                    if (currentNode.hasEffects())
                    {
                        DOMWriterUtility.DOMWrite(endConversation, currentNode.getEffects(), options);
                    }
                }
                else
                {
                    // If the node isn't terminal, check if it performing a "go-back" (going back to the inmediatly upper
                    // OptionNode)
                    if (TreeConversation.thereIsGoBackTag(currentNode))
                    {
                        // If it is the case, add a "go-back" element
                        rootDOMNode.AppendChild(document.CreateElement("go-back"));
                    }
                    else
                    {
                        // Otherwise, if the node has a child, call the recursive function with the child node, and the same
                        // DOM root node
                        WriteNodeInDom(currentNode.getChild(0), rootDOMNode);
                    }
                }
            }

            // If the node is a OptionNode write a "response" element, and inside it a "option" element with its content
            else if (currentNode is OptionConversationNode)
            {
                // Create the "response" element
                XmlElement response = document.CreateElement("response");
                // Adds a random attribute if "random" is activate in conversation node data
                if (((OptionConversationNode)currentNode).isRandom())
                {
                    response.SetAttribute("random", "yes");
                }
                // For each line of the node (we suppose the number of line equals the number of links, or children nodes)
                for (int i = 0; i < currentNode.getLineCount(); i++)
                {
                    // Create the "option" element
                    XmlElement       optionElement = document.CreateElement("option");
                    ConversationLine line          = currentNode.getLine(i);
                    // Create the actual option (a "speak-player" element) and add its respective text
                    XmlElement lineElement = document.CreateElement("speak-player");

                    var text = document.CreateElement("text");
                    text.InnerText = currentNode.getLine(i).getText();
                    lineElement.AppendChild(text);

                    // Append the resources
                    foreach (ResourcesUni resources in line.getResources())
                    {
                        XmlNode resourcesNode = ResourcesDOMWriter.buildDOM(resources, ResourcesDOMWriter.RESOURCES_CONVERSATION_LINE);
                        document.ImportNode(resourcesNode, true);
                        lineElement.AppendChild(resourcesNode);
                    }

                    // Insert the text line in the option node
                    optionElement.AppendChild(lineElement);

                    // Call the recursive function, to write in the "option" node the appropiate elements
                    // Note that the root DOM node is the "option" element
                    WriteNodeInDom(currentNode.getChild(i), optionElement);

                    // Add the "option" element
                    response.AppendChild(optionElement);
                }
                // If the terminal node has an effect, include it into the DOM
                if (currentNode.hasEffects())
                {
                    DOMWriterUtility.DOMWrite(response, currentNode.getEffects(), options);
                }

                // Add the element
                rootDOMNode.AppendChild(response);
            }
        }
Beispiel #8
0
        /**
         * Recursive function responsible for transforming a node (and its children)
         * into a DOM structure
         *
         * @param currentNode
         *            Node to be transformed
         * @param rootDOMNode
         *            DOM node in which the elements must be attached
         */

        private static void writeNodeInDOM(ConversationNode currentNode, XmlNode rootDOMNode)
        {
            // Extract the document
            XmlDocument document = rootDOMNode.OwnerDocument;

            // If the node is a DialogueNode write the lines one after another, and then the child (or the mark if it is no
            // child)
            if (currentNode.getType() == ConversationNodeViewEnum.DIALOGUE)
            {
                // For each line of the node
                for (int i = 0; i < currentNode.getLineCount(); i++)
                {
                    // Create a phrase element, and extract the actual text line
                    XmlElement       phrase;
                    XmlNode          conditionsNode = null;
                    ConversationLine line           = currentNode.getLine(i);

                    // If the line belongs to the player, create a "speak-player" element. Otherwise, if it belongs to a
                    // NPC,
                    // create a "speak-char" element, which will have an attribute "idTarget" with the name of the
                    // non-playable character,
                    // if there is no name the attribute won't be written
                    if (line.isPlayerLine())
                    {
                        phrase = document.CreateElement("speak-player");
                    }
                    else
                    {
                        phrase = document.CreateElement("speak-char");
                        if (!line.getName().Equals("NPC"))
                        {
                            phrase.SetAttribute("idTarget", line.getName());
                        }
                    }

                    // Add the line text into the element
                    phrase.InnerText = (line.getText());

                    //If there is audio track, store it as attribute
                    if (line.isValidAudio())
                    {
                        phrase.SetAttribute("uri", line.getAudioPath());
                    }
                    //If there is a synthesizer valid voice, store it as attribute
                    if (line.getSynthesizerVoice())
                    {
                        phrase.SetAttribute("synthesize", "yes");
                    }

                    // Add the element to the DOM root
                    rootDOMNode.AppendChild(phrase);

                    // Create conditions for current effect
                    DOMWriterUtility.DOMWrite(rootDOMNode, line.getConditions());
                }

                // Check if the node is terminal
                if (currentNode.isTerminal())
                {
                    // If it is terminal add a "end-conversation" element
                    XmlElement endConversation = document.CreateElement("end-conversation");

                    // Add the "end-conversation" tag into the root
                    rootDOMNode.AppendChild(endConversation);

                    // If the terminal node has an effect, include it into the DOM
                    if (currentNode.hasEffects())
                    {
                        DOMWriterUtility.DOMWrite(endConversation, currentNode.getEffects());
                    }
                }
                else
                {
                    // If the node isn't terminal, check if it performing a "go-back" (going back to the inmediatly upper
                    // OptionNode)
                    if (TreeConversation.thereIsGoBackTag(currentNode))
                    {
                        // If it is the case, add a "go-back" element
                        rootDOMNode.AppendChild(document.CreateElement("go-back"));
                    }
                    else
                    {
                        // Otherwise, if the node has a child, call the recursive function with the child node, and the same
                        // DOM root node
                        writeNodeInDOM(currentNode.getChild(0), rootDOMNode);
                    }
                }
            }

            // If the node is a OptionNode write a "response" element, and inside it a "option" element with its content
            else if (currentNode.getType() == ConversationNodeViewEnum.OPTION)
            {
                // Create the "response" element
                XmlElement response = document.CreateElement("response");
                // Adds a random attribute if "random" is activate in conversation node data
                if (((OptionConversationNode)currentNode).isRandom())
                {
                    response.SetAttribute("random", "yes");
                }
                // For each line of the node (we suppose the number of line equals the number of links, or children nodes)
                for (int i = 0; i < currentNode.getLineCount(); i++)
                {
                    // Create the "option" element
                    XmlElement       optionElement = document.CreateElement("option");
                    ConversationLine line          = currentNode.getLine(i);
                    // Create the actual option (a "speak-player" element) and add its respective text
                    XmlElement lineElement = document.CreateElement("speak-player");
                    lineElement.InnerText = currentNode.getLine(i).getText();

                    //If there is audio track, store it as attribute
                    if (line.isValidAudio())
                    {
                        lineElement.SetAttribute("uri", line.getAudioPath());
                    }
                    //If there is a synthesizer valid voice, store it as attribute
                    if (line.getSynthesizerVoice())
                    {
                        lineElement.SetAttribute("synthesize", "yes");
                    }

                    // Insert the text line in the option node
                    optionElement.AppendChild(lineElement);

                    // Call the recursive function, to write in the "option" node the appropiate elements
                    // Note that the root DOM node is the "option" element
                    writeNodeInDOM(currentNode.getChild(i), optionElement);

                    // Add the "option" element
                    response.AppendChild(optionElement);
                }
                // If the terminal node has an effect, include it into the DOM
                if (currentNode.hasEffects())
                {
                    DOMWriterUtility.DOMWrite(response, currentNode.getEffects());
                }

                // Add the element
                rootDOMNode.AppendChild(response);
            }
        }