예제 #1
0
        private void parseLines(ConversationNode node, XmlElement lines, params object[] parameters)
        {
            string tmpArgVal = "";

            currentLinks = new List <int>();
            bool addline           = true;
            bool timeoutConditions = false;

            foreach (XmlElement ell in lines.ChildNodes)
            {
                addline = true;
                // If there is a "keepShowing" attribute, store its value
                keepShowingLine = ExString.EqualsDefault(ell.GetAttribute("keepShowing"), "yes", false);

                if (ell.Name == "speak-player")
                {
                    // Store the read string into the current node, and then delete the string. The trim is performed so we
                    // don't have to worry with indentations or leading/trailing spaces


                    conversationLine = new ConversationLine(ConversationLine.PLAYER, GetText(ell));
                    conversationLine.setKeepShowing(keepShowingLine);
                    //XAPI ELEMENTS
                    conversationLine.setXApiCorrect("true".Equals(ell.GetAttribute("correct")));
                    //END OF XAPI
                    // RESOURCES
                    foreach (var res in DOMParserUtility.DOMParse <ResourcesUni>(ell.SelectNodes("resources"), parameters))
                    {
                        conversationLine.addResources(res);
                    }
                }
                else if (ell.Name == "speak-char")
                {
                    // If it is a non-player character line, store the character name and audio path (if present)
                    // Set default name to "NPC"
                    characterName = "NPC";
                    // If there is a "idTarget" attribute, store it
                    characterName = ell.GetAttribute("idTarget");

                    // Store the read string into the current node, and then delete the string. The trim is performed so we
                    // don't have to worry with indentations or leading/trailing spaces
                    conversationLine = new ConversationLine(characterName, GetText(ell));
                    conversationLine.setKeepShowing(keepShowingLine);
                    // RESOURCES
                    foreach (var res in DOMParserUtility.DOMParse <ResourcesUni>(ell.SelectNodes("resources"), parameters))
                    {
                        conversationLine.addResources(res);
                    }
                }
                else if (ell.Name == "condition")
                {
                    addline = false;
                    var currentConditions = DOMParserUtility.DOMParse(ell, parameters) as Conditions ?? new Conditions();

                    if (timeoutConditions)
                    {
                        ((OptionConversationNode)currentNode).TimeoutConditions = currentConditions;
                    }
                    else
                    {
                        currentNode.getLine(currentNode.getLineCount() - 1).setConditions(currentConditions);
                    }
                }
                else if (ell.Name == "child")
                {
                    addline   = false;
                    tmpArgVal = ell.GetAttribute("nodeindex");
                    if (!string.IsNullOrEmpty(tmpArgVal))
                    {
                        // Get the child node index, and store it
                        int childIndex = int.Parse(tmpArgVal);
                        currentLinks.Add(childIndex);
                    }
                }
                else if (ell.Name == "timeout")
                {
                    ((OptionConversationNode)currentNode).Timeout = ExParsers.ParseDefault(GetText(ell), CultureInfo.InvariantCulture, 10f);
                    timeoutConditions = true;
                    addline           = false;
                }
                else
                {
                    addline = false;
                }

                if (addline)
                {
                    node.addLine(conversationLine);
                }
            }
        }
        private void parseLines(ConversationNode node, XmlElement lines, params object[] parameters)
        {
            string tmpArgVal = "";

            currentLinks = new List <int>();
            bool addline = true;

            foreach (XmlElement ell in lines.ChildNodes)
            {
                addline = true;

                audioPath = ell.GetAttribute("uri");
                // If there is a "synthesize" attribute, store its value
                synthesizerVoice = "yes".Equals(ell.GetAttribute("synthesize"));
                // If there is a "keepShowing" attribute, store its value
                keepShowingLine = "yes".Equals(ell.GetAttribute("keepShowing"));

                if (ell.Name == "speak-player")
                {
                    // Store the read string into the current node, and then delete the string. The trim is performed so we
                    // don't have to worry with indentations or leading/trailing spaces
                    conversationLine = new ConversationLine(ConversationLine.PLAYER, ell.InnerText);

                    conversationLine.setAudioPath(audioPath);
                    conversationLine.setSynthesizerVoice(synthesizerVoice);
                    conversationLine.setKeepShowing(keepShowingLine);

                    //XAPI ELEMENTS
                    conversationLine.setXApiCorrect("true".Equals(ell.GetAttribute("correct")));
                    //END OF XAPI
                }
                else if (ell.Name == "speak-char")
                {
                    // If it is a non-player character line, store the character name and audio path (if present)
                    // Set default name to "NPC"
                    characterName = "NPC";
                    // If there is a "idTarget" attribute, store it
                    characterName = ell.GetAttribute("idTarget") ?? "";

                    // Store the read string into the current node, and then delete the string. The trim is performed so we
                    // don't have to worry with indentations or leading/trailing spaces
                    conversationLine = new ConversationLine(characterName, ell.InnerText);
                    conversationLine.setAudioPath(audioPath);
                    conversationLine.setSynthesizerVoice(synthesizerVoice);
                    conversationLine.setKeepShowing(keepShowingLine);
                }
                else if (ell.Name == "condition")
                {
                    addline = false;
                    var currentConditions = DOMParserUtility.DOMParse(ell, parameters) as Conditions ?? new Conditions();
                    currentNode.getLine(currentNode.getLineCount() - 1).setConditions(currentConditions);
                }
                else if (ell.Name == "child")
                {
                    addline   = false;
                    tmpArgVal = ell.GetAttribute("nodeindex");
                    if (!string.IsNullOrEmpty(tmpArgVal))
                    {
                        // Get the child node index, and store it
                        int childIndex = int.Parse(tmpArgVal);
                        currentLinks.Add(childIndex);
                    }
                }
                else
                {
                    addline = false;
                }

                if (addline)
                {
                    node.addLine(conversationLine);
                }
            }
        }