public object DOMParse(XmlElement element, params object[] parameters) { XmlNode effects; XmlNode end_conversation; string tmpArgVal; // Store the name conversationName = ""; tmpArgVal = element.GetAttribute("id"); if (!string.IsNullOrEmpty(tmpArgVal)) { conversationName = tmpArgVal; } graphNodes = new List <ConversationNode>(); nodeLinks = new List <List <int> >(); foreach (XmlElement el in element) { //If there is a "editor-x" and "editor-y" attributes editorX = Mathf.Max(-1, ExParsers.ParseDefault(el.GetAttribute("editor-x"), -1)); editorY = Mathf.Max(-1, ExParsers.ParseDefault(el.GetAttribute("editor-y"), -1)); editorCollapsed = ExString.EqualsDefault(el.GetAttribute("editor-collapsed"), "yes", false); //If there is a "waitUserInteraction" attribute, store if the lines will wait until user interacts keepShowingDialogue = ExString.EqualsDefault(el.GetAttribute("waitUserInteraction"), "yes", false); // Node effects end_conversation = el.SelectSingleNode("end-conversation"); if (end_conversation != null) { effects = end_conversation.SelectSingleNode("effect"); } else { effects = el.SelectSingleNode("effect"); } var parsedEffects = DOMParserUtility.DOMParse(effects, parameters) as Effects ?? new Effects(); if (el.Name == "dialogue-node") { currentNode = new DialogueConversationNode(keepShowingDialogue); } else if (el.Name == "option-node") { random = ExString.EqualsDefault(el.GetAttribute("random"), "yes", false); showUserOption = ExString.EqualsDefault(el.GetAttribute("showUserOption"), "yes", false); keepShowing = ExString.EqualsDefault(el.GetAttribute("keepShowing"), "yes", false); preListening = ExString.EqualsDefault(el.GetAttribute("preListening"), "yes", false) || editorX >= 0 || editorY >= 0; var optionConversationNode = new OptionConversationNode(random, keepShowing, showUserOption, preListening) { Horizontal = ExString.EqualsDefault(el.GetAttribute("horizontal"), "yes", false), MaxElemsPerRow = ExParsers.ParseDefault(el.GetAttribute("max-elements-per-row"), -1), Alignment = el.HasAttribute("alignment") ? ExParsers.ParseEnum <TextAnchor>(el.GetAttribute("alignment")) : TextAnchor.UpperCenter }; currentNode = optionConversationNode; //XAPI ELEMENTS optionConversationNode.setXApiQuestion(el.GetAttribute("question")); //END OF XAPI } if (currentNode != null) { // Node editor properties currentNode.setEditorX(editorX); currentNode.setEditorY(editorY); currentNode.setEditorCollapsed(editorCollapsed); // Create a new vector for the links of the current node currentLinks = new List <int>(); parseLines(currentNode, el, parameters); currentNode.setEffects(parsedEffects); // Add the current node to the node list, and the set of children references into the node links graphNodes.Add(currentNode); nodeLinks.Add(currentLinks); } } setNodeLinks(); return(new GraphConversation(conversationName, graphNodes[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"; audioPath = ""; // If there is a "idTarget" attribute, store it tmpArgVal = el.GetAttribute("idTarget"); if (!string.IsNullOrEmpty(tmpArgVal)) { characterName = tmpArgVal; } // If there is a "uri" attribute, store it as audio path tmpArgVal = el.GetAttribute("uri"); if (!string.IsNullOrEmpty(tmpArgVal)) { audioPath = tmpArgVal; } // If there is a "uri" attribute, store it as audio path tmpArgVal = el.GetAttribute("synthesize"); if (!string.IsNullOrEmpty(tmpArgVal)) { string response = tmpArgVal; if (response.Equals("yes")) { synthesizerVoice = true; } else { synthesizerVoice = false; } } // 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, el.InnerText); if (audioPath != null && !this.audioPath.Equals("")) { line.setAudioPath(audioPath); } line.setSynthesizerVoice(synthesizerVoice); currentNode.addLine(line); } foreach (XmlElement el in speaksplayer) { audioPath = ""; // If there is a "uri" attribute, store it as audio path tmpArgVal = el.GetAttribute("uri"); if (!string.IsNullOrEmpty(tmpArgVal)) { audioPath = tmpArgVal; } // If there is a "uri" attribute, store it as audio path tmpArgVal = el.GetAttribute("synthesize"); if (!string.IsNullOrEmpty(tmpArgVal)) { string response = tmpArgVal; if (response.Equals("yes")) { synthesizerVoice = true; } else { synthesizerVoice = false; } } // 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, el.InnerText); if (audioPath != null && !this.audioPath.Equals("")) { line.setAudioPath(audioPath); } line.setSynthesizerVoice(synthesizerVoice); 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)); }
public object DOMParse(XmlElement element, params object[] parameters) { XmlNode effects; XmlNode end_conversation; string tmpArgVal; // Store the name conversationName = ""; tmpArgVal = element.GetAttribute("id"); if (!string.IsNullOrEmpty(tmpArgVal)) { conversationName = tmpArgVal; } graphNodes = new List <ConversationNode>(); nodeLinks = new List <List <int> >(); foreach (XmlElement el in element) { //If there is a "editor-x" and "editor-y" attributes editorX = Mathf.Max(-1, ExParsers.ParseDefault(element.GetAttribute("editor-x"), -1)); editorY = Mathf.Max(-1, ExParsers.ParseDefault(element.GetAttribute("editor-y"), -1)); //If there is a "waitUserInteraction" attribute, store if the lines will wait until user interacts keepShowingDialogue = "yes".Equals(element.GetAttribute("keepShowing")); // Node effects end_conversation = el.SelectSingleNode("end-conversation"); if (end_conversation != null) { effects = end_conversation.SelectSingleNode("effect"); } else { effects = el.SelectSingleNode("effect"); } var parsedEffects = DOMParserUtility.DOMParse(effects, parameters) as Effects ?? new Effects(); if (el.Name == "dialogue-node") { currentNode = new DialogueConversationNode(keepShowingDialogue); currentNode.setEditorX(editorX); currentNode.setEditorY(editorY); // Create a new vector for the links of the current node currentLinks = new List <int>(); parseLines(currentNode, el, parameters); currentNode.setEffects(parsedEffects); // Add the current node to the node list, and the set of children references into the node links graphNodes.Add(currentNode); nodeLinks.Add(currentLinks); } else if (el.Name == "option-node") { random = "yes".Equals(el.GetAttribute("random")); showUserOption = "yes".Equals(el.GetAttribute("showUserOption")); preListening = "yes".Equals(el.GetAttribute("preListening")) || editorX >= 0 || editorY >= 0; currentNode = new OptionConversationNode(random, keepShowing, showUserOption, preListening, editorX, editorY); //XAPI ELEMENTS ((OptionConversationNode)currentNode).setXApiQuestion(el.GetAttribute("question") ?? ""); //END OF XAPI // Create a new vector for the links of the current node currentLinks = new List <int>(); parseLines(currentNode, el, parameters); currentNode.setEffects(parsedEffects); // Add the current node to the node list, and the set of children references into the node links graphNodes.Add(currentNode); nodeLinks.Add(currentLinks); } } setNodeLinks(); return(new GraphConversation(conversationName, graphNodes[0])); }