Exemplo n.º 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);
                }
            }
        }
Exemplo n.º 2
0
        public override void ParseElement(XmlElement element)
        {
            XmlNodeList
                speakschar   = element.SelectNodes("speak-char"),
                speaksplayer = element.SelectNodes("speak-player"),
                responses    = element.SelectNodes("response"),
                options      = element.SelectNodes("option"),
                effects      = element.SelectNodes("effect"),
                gosback      = element.SelectNodes("go-back");


            string tmpArgVal;

            // Store the name
            string conversationName = "";

            tmpArgVal = element.GetAttribute("id");
            if (!string.IsNullOrEmpty(tmpArgVal))
            {
                conversationName = tmpArgVal;
            }

            // Create a dialogue node (which will be the root node) and add it to a new tree
            // The content of the tree will be built adding nodes directly to the root
            currentNode     = new DialogueConversationNode();
            conversation    = new TreeConversation(conversationName, currentNode);
            pastOptionNodes = new List <ConversationNode>();

            foreach (XmlElement el in speakschar)
            {
                // Set default name to "NPC"
                characterName = "NPC";

                // If there is a "idTarget" attribute, store it
                tmpArgVal = el.GetAttribute("idTarget");
                if (!string.IsNullOrEmpty(tmpArgVal))
                {
                    characterName = tmpArgVal;
                }

                // 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 line = new ConversationLine(characterName, GetText(el));

                // RESOURCES
                foreach (var res in DOMParserUtility.DOMParse <ResourcesUni>(el.SelectNodes("resources")))
                {
                    line.addResources(res);
                }
                currentNode.addLine(line);
            }

            foreach (XmlElement el in speaksplayer)
            {
                // 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 line = new ConversationLine(ConversationLine.PLAYER, GetText(el));

                // RESOURCES
                foreach (var res in DOMParserUtility.DOMParse <ResourcesUni>(el.SelectNodes("resources")))
                {
                    line.addResources(res);
                }

                currentNode.addLine(line);
            }

            foreach (XmlElement el in responses)
            {
                //If there is a "random" attribute, store is the options will be random
                tmpArgVal = el.GetAttribute("random");
                if (!string.IsNullOrEmpty(tmpArgVal))
                {
                    if (tmpArgVal.Equals("yes"))
                    {
                        random = true;
                    }
                    else
                    {
                        random = false;
                    }
                }

                //If there is a "keepShowing" attribute, keep the previous conversation line showing
                tmpArgVal = el.GetAttribute("keepShowing");
                if (!string.IsNullOrEmpty(tmpArgVal))
                {
                    if (tmpArgVal.Equals("yes"))
                    {
                        keepShowing = true;
                    }
                    else
                    {
                        keepShowing = false;
                    }
                }

                //If there is a "showUserOption" attribute, identify if show the user response at option node
                tmpArgVal = el.GetAttribute("showUserOption");
                if (!string.IsNullOrEmpty(tmpArgVal))
                {
                    if (tmpArgVal.Equals("yes"))
                    {
                        showUserOption = true;
                    }
                    else
                    {
                        showUserOption = false;
                    }
                }


                //If there is a "showUserOption" attribute, identify if show the user response at option node
                tmpArgVal = el.GetAttribute("preListening");
                if (!string.IsNullOrEmpty(tmpArgVal))
                {
                    if (tmpArgVal.Equals("yes"))
                    {
                        preListening = true;
                    }
                    else
                    {
                        preListening = false;
                    }
                }

                //If there is a "x" and "y" attributes with the position where the option node has to be painted,
                tmpArgVal = el.GetAttribute("preListening");
                if (!string.IsNullOrEmpty(tmpArgVal))
                {
                    if (tmpArgVal.Equals("yes"))
                    {
                        preListening = true;
                    }
                    else
                    {
                        preListening = false;
                    }
                }

                //If there is a "x" and "y" attributes with the position where the option node has to be painted
                tmpArgVal = el.GetAttribute("x");
                if (!string.IsNullOrEmpty(tmpArgVal))
                {
                    x = int.Parse(tmpArgVal);
                }
                tmpArgVal = el.GetAttribute("y");
                if (!string.IsNullOrEmpty(tmpArgVal))
                {
                    y = int.Parse(tmpArgVal);
                }

                // Create a new OptionNode, and link it to the current node
                ConversationNode nuevoNodoOpcion = new OptionConversationNode(random, keepShowing, showUserOption, preListening);
                nuevoNodoOpcion.setEditorX(x);
                nuevoNodoOpcion.setEditorY(y);
                currentNode.addChild(nuevoNodoOpcion);

                // Change the actual node for the option node recently created
                currentNode = nuevoNodoOpcion;
            }

            {
                var iterator = options.GetEnumerator();
                while (iterator.MoveNext())
                {
                    currentNode = pastOptionNodes[pastOptionNodes.Count - 1];
                    pastOptionNodes.RemoveAt(pastOptionNodes.Count - 1);
                }
            }

            foreach (XmlElement el in effects)
            {
                currentEffects = new Effects();
                //new EffectSubParser_(currentEffects, chapter).ParseElement(el);
                currentNode.setEffects(currentEffects);
            }
            {
                var i = gosback.GetEnumerator();
                while (i.MoveNext())
                {
                    currentNode.addChild(pastOptionNodes[pastOptionNodes.Count - 1]);
                }
            }

            chapter.addConversation(new GraphConversation((TreeConversation)conversation));
        }