Пример #1
0
        private void FillNode(XmlNode toFill, GraphConversation graphConversation, params IDOMWriterParam[] options)
        {
            XmlElement conversationElement = toFill as XmlElement;

            // Get the complete node list
            List <ConversationNode> nodes = graphConversation.getAllNodes();

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

            // Create the root node
            conversationElement.SetAttribute("id", graphConversation.getId());

            // For each node
            for (int i = 0; i < nodes.Count; i++)
            {
                ConversationNode node = nodes[i];

                XmlElement nodeElement            = null;
                var        dialogConversationNode = node as DialogueConversationNode;

                // If the node is a dialogue node
                if (dialogConversationNode != null)
                {
                    // Create the node element and set the nodeindex
                    nodeElement = doc.CreateElement("dialogue-node");
                    nodeElement.SetAttribute("nodeindex", i.ToString());
                    // Adds a random attribute if "keepShowing" is activate in conversation node data
                    if (dialogConversationNode.isKeepShowing())
                    {
                        nodeElement.SetAttribute("keepShowing", "yes");
                    }
                    if (node.getEditorX() != -1)
                    {
                        nodeElement.SetAttribute("editor-x", node.getEditorX().ToString());
                    }
                    if (node.getEditorY() != -1)
                    {
                        nodeElement.SetAttribute("editor-y", node.getEditorY().ToString());
                    }
                    if (node.getEditorCollapsed())
                    {
                        nodeElement.SetAttribute("editor-collapsed", "yes");
                    }
                    // For each line of the node
                    for (int j = 0; j < node.getLineCount(); j++)
                    {
                        // Create a phrase element, and extract the actual text line
                        XmlElement       phrase;
                        ConversationLine line = node.getLine(j);

                        // 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 = doc.CreateElement("speak-player");
                        }
                        else
                        {
                            phrase = doc.CreateElement("speak-char");
                            if (!line.getName().Equals("NPC"))
                            {
                                phrase.SetAttribute("idTarget", line.getName());
                            }
                        }

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

                        // Add the line text into the element

                        var text = doc.CreateElement("text");
                        text.InnerText = line.getText();
                        phrase.AppendChild(text);

                        // Add the element to the node
                        nodeElement.AppendChild(phrase);

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

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

                        // If the terminal node has an effect, include it into the DOM
                        if (node.hasEffects())
                        {
                            DOMWriterUtility.DOMWrite(endConversation, node.getEffects(), options);
                        }

                        // Add the "end-conversation" tag into the node
                        nodeElement.AppendChild(endConversation);
                    }
                    else
                    {
                        // Otherwise, if the node has a child, add the element
                        XmlElement childElement = doc.CreateElement("child");

                        // Add the number of the child node (index of the node in the structure)
                        childElement.SetAttribute("nodeindex", nodes.IndexOf(node.getChild(0)).ToString());

                        // Insert the tag into the node
                        nodeElement.AppendChild(childElement);

                        // If the terminal node has an effect, include it into the DOM
                        if (node.hasEffects())
                        {
                            DOMWriterUtility.DOMWrite(nodeElement, node.getEffects(), options);
                        }
                    }
                }

                var optionConversationNode = node as OptionConversationNode;
                // If the node is a option node
                if (optionConversationNode != null)
                {
                    // Create the node element and set the nodeindex
                    nodeElement = doc.CreateElement("option-node");
                    nodeElement.SetAttribute("nodeindex", i.ToString());

                    if (!string.IsNullOrEmpty(optionConversationNode.getXApiQuestion()))
                    {
                        nodeElement.SetAttribute("question", optionConversationNode.getXApiQuestion());
                    }

                    // Adds a random attribute if "random" is activate in conversation node data
                    if (optionConversationNode.isRandom())
                    {
                        nodeElement.SetAttribute("random", "yes");
                    }
                    // Adds a random attribute if "keepShowing" is activate in conversation node data
                    if (optionConversationNode.isKeepShowing())
                    {
                        nodeElement.SetAttribute("keepShowing", "yes");
                    }
                    // Adds a random attribute if "showUserOption" is activate in conversation node data
                    if (optionConversationNode.isShowUserOption())
                    {
                        nodeElement.SetAttribute("showUserOption", "yes");
                    }
                    // Adds a random attribute if "preListening" is activate in conversation node data
                    if (optionConversationNode.isPreListening())
                    {
                        nodeElement.SetAttribute("preListening", "yes");
                    }
                    if (node.getEditorX() != -1)
                    {
                        nodeElement.SetAttribute("editor-x", node.getEditorX().ToString());
                    }
                    if (node.getEditorY() != -1)
                    {
                        nodeElement.SetAttribute("editor-y", node.getEditorY().ToString());
                    }
                    if (node.getEditorCollapsed())
                    {
                        nodeElement.SetAttribute("editor-collapsed", "yes");
                    }
                    // Adds the x position of the options conversations node
                    nodeElement.SetAttribute("x", optionConversationNode.getEditorX().ToString());
                    // Adds a random attribute if "preListening" is activate in conversation node data
                    nodeElement.SetAttribute("y", optionConversationNode.getEditorY().ToString());

                    // For each line of the node
                    for (int j = 0; j < node.getLineCount(); j++)
                    {
                        // Take the current conversation line
                        ConversationLine line = node.getLine(j);

                        // Create the actual option (a "speak-player" element) and add its respective text
                        XmlElement lineElement = doc.CreateElement("speak-player");

                        var text = doc.CreateElement("text");
                        text.InnerText = node.getLine(j).getText();
                        lineElement.AppendChild(text);

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

                        if (line.getXApiCorrect())
                        {
                            lineElement.SetAttribute("correct", line.getXApiCorrect().ToString().ToLower());
                        }

                        // Create a child tag, and set it the index of the child
                        XmlElement childElement = doc.CreateElement("child");
                        childElement.SetAttribute("nodeindex", nodes.IndexOf(node.getChild(j)).ToString());


                        // Insert the text line in the option node
                        nodeElement.AppendChild(lineElement);
                        // Add conditions associated to that effect
                        DOMWriterUtility.DOMWrite(nodeElement, line.getConditions(), options);
                        // Insert child tag
                        nodeElement.AppendChild(childElement);
                    }

                    if (optionConversationNode.Timeout >= 0)
                    {
                        // Timeout
                        XmlElement timeoutElement = doc.CreateElement("timeout");
                        timeoutElement.InnerText = optionConversationNode.Timeout.ToString();
                        nodeElement.AppendChild(timeoutElement);
                        // Timeout conditions
                        DOMWriterUtility.DOMWrite(nodeElement, optionConversationNode.TimeoutConditions);

                        // Create a child tag, and set it the index of the child
                        XmlElement timeoutchildElement = doc.CreateElement("child");
                        timeoutchildElement.SetAttribute("nodeindex", nodes.IndexOf(node.getChild(node.getChildCount() - 1)).ToString());
                        nodeElement.AppendChild(timeoutchildElement);
                    }

                    // If node has an effect, include it into the DOM
                    if (node.hasEffects())
                    {
                        DOMWriterUtility.DOMWrite(nodeElement, node.getEffects(), options);
                    }
                }

                // Add the node to the conversation
                conversationElement.AppendChild(nodeElement);
            }
        }
Пример #2
0
        // Methods



        /**
         * Returns true if the xapi question is a correct option
         *
         * @return true if the xapi question is a correct option
         */

        public bool getXApiCorrect()
        {
            return(conversationLine.getXApiCorrect());
        }