/* * (non-Javadoc) * * @see es.eucm.eadventure.engine.loader.subparsers.SubParser#endElement(java.lang.string, java.lang.string, * java.lang.string) */ public override void endElement(string namespaceURI, string sName, string qName) { // If no element is being subparsed if (subParsing == SUBPARSING_NONE) { // If it is a character tag, store the character in the game data if (qName.Equals("character")) { chapter.addCharacter(npc); } // If it is a documentation tag, hold the documentation in the character else if (qName.Equals("documentation")) { if (reading == READING_NONE) { npc.setDocumentation(currentstring.ToString().Trim()); } else if (reading == READING_CONVERSATION_REFERENCE) { conversationReference.setDocumentation(currentstring.ToString().Trim()); } } // If it is a resources tag, add the resources in the character else if (qName.Equals("resources")) { npc.addResources(currentResources); reading = READING_NONE; } // If it is a conversation reference tag, add the reference to the character else if (qName.Equals("conversation-ref")) { //npc.addConversationReference( conversationReference ); Action action = new Action(Action.TALK_TO); action.setConditions(conversationReference.getConditions()); action.setDocumentation(conversationReference.getDocumentation()); TriggerConversationEffect effect = new TriggerConversationEffect(conversationReference.getTargetId()); action.getEffects().add(effect); npc.addAction(action); reading = READING_NONE; } // Reset the current string currentstring = ""; } // If a condition is being subparsed else if (subParsing == SUBPARSING_CONDITION) { // Spread the end element call subParser.endElement(namespaceURI, sName, qName); // If the condition is being closed if (qName.Equals("condition")) { // Add the condition to the resources if (reading == READING_RESOURCES) { currentResources.setConditions(currentConditions); } // Add the condition to the conversation reference if (reading == READING_CONVERSATION_REFERENCE) { conversationReference.setConditions(currentConditions); } // Stop subparsing subParsing = SUBPARSING_NONE; } } else if (subParsing == SUBPARSING_ACTIONS) { subParser.endElement(namespaceURI, sName, qName); if (qName.Equals("actions")) { subParsing = SUBPARSING_NONE; } } // If it is a description tag, create the new description (with its id) else if (subParsing == SUBPARSING_DESCRIPTION) { // Spread the call subParser.endElement(namespaceURI, sName, qName); if (qName.Equals("description")) { this.descriptions.Add(description); subParsing = SUBPARSING_NONE; } } }
public override void ParseElement(XmlElement element) { XmlNodeList resourcess = element.SelectNodes("resources"), descriptionss = element.SelectNodes("description"), assets, conditions, frontcolors, bordercolors, textcolors = element.SelectNodes("textcolor"), conversationsref = element.SelectNodes("conversation-ref"), voices = element.SelectNodes("voice"), actionss = element.SelectNodes("actions"); string tmpArgVal; string characterId = element.GetAttribute("id"); npc = new NPC(characterId); descriptions = new List<Description>(); npc.setDescriptions(descriptions); if (element.SelectSingleNode("documentation") != null) npc.setDocumentation(element.SelectSingleNode("documentation").InnerText); foreach (XmlElement el in resourcess) { currentResources = new ResourcesUni(); tmpArgVal = el.GetAttribute("name"); if (!string.IsNullOrEmpty(tmpArgVal)) { currentResources.setName(el.GetAttribute(tmpArgVal)); } assets = el.SelectNodes("asset"); foreach (XmlElement ell in assets) { string type = ""; string path = ""; tmpArgVal = ell.GetAttribute("type"); if (!string.IsNullOrEmpty(tmpArgVal)) { type = tmpArgVal; } tmpArgVal = ell.GetAttribute("uri"); if (!string.IsNullOrEmpty(tmpArgVal)) { path = tmpArgVal; } currentResources.addAsset(type, path); } conditions = el.SelectNodes("condition"); foreach (XmlElement ell in conditions) { currentConditions = new Conditions(); new ConditionSubParser_(currentConditions, chapter).ParseElement(ell); currentResources.setConditions(currentConditions); } npc.addResources(currentResources); } foreach (XmlElement el in textcolors) { tmpArgVal = el.GetAttribute("showsSpeechBubble"); if (!string.IsNullOrEmpty(tmpArgVal)) { npc.setShowsSpeechBubbles(tmpArgVal.Equals("yes")); } tmpArgVal = el.GetAttribute("bubbleBkgColor"); if (!string.IsNullOrEmpty(tmpArgVal)) { npc.setBubbleBkgColor(tmpArgVal); } tmpArgVal = el.GetAttribute("bubbleBorderColor"); if (!string.IsNullOrEmpty(tmpArgVal)) { npc.setBubbleBorderColor(tmpArgVal); } frontcolors = el.SelectNodes("frontcolor"); foreach (XmlElement ell in frontcolors) { string color = ""; tmpArgVal = ell.GetAttribute("color"); if (!string.IsNullOrEmpty(tmpArgVal)) { color = tmpArgVal; } npc.setTextFrontColor(color); } bordercolors = el.SelectNodes("bordercolor"); foreach (XmlElement ell in bordercolors) { string color = ""; tmpArgVal = ell.GetAttribute("color"); if (!string.IsNullOrEmpty(tmpArgVal)) { color = tmpArgVal; } npc.setTextBorderColor(color); } } foreach (XmlElement el in conversationsref) { string idTarget = ""; tmpArgVal = el.GetAttribute("idTarget"); if (!string.IsNullOrEmpty(tmpArgVal)) { idTarget = tmpArgVal; } conversationReference = new ConversationReference(idTarget); conditions = el.SelectNodes("condition"); foreach (XmlElement ell in conditions) { currentConditions = new Conditions(); new ConditionSubParser_(currentConditions, chapter).ParseElement(ell); conversationReference.setConditions(currentConditions); } conversationReference.setDocumentation(el.SelectSingleNode("documentation").InnerText); Action action = new Action(Action.TALK_TO); action.setConditions(conversationReference.getConditions()); action.setDocumentation(conversationReference.getDocumentation()); TriggerConversationEffect effect = new TriggerConversationEffect(conversationReference.getTargetId()); action.getEffects().add(effect); npc.addAction(action); } foreach (XmlElement el in voices) { string voice = ""; string response; bool alwaysSynthesizer = false; tmpArgVal = el.GetAttribute("name"); if (!string.IsNullOrEmpty(tmpArgVal)) { voice = tmpArgVal; } tmpArgVal = el.GetAttribute("synthesizeAlways"); if (!string.IsNullOrEmpty(tmpArgVal)) { response = tmpArgVal; if (response.Equals("yes")) alwaysSynthesizer = true; } npc.setAlwaysSynthesizer(alwaysSynthesizer); npc.setVoice(voice); } foreach (XmlElement el in actionss) { new ActionsSubParser_(chapter, npc).ParseElement(el); } foreach (XmlElement el in descriptionss) { description = new Description(); new DescriptionsSubParser_(description, chapter).ParseElement(el); this.descriptions.Add(description); } chapter.addCharacter(npc); }
public override void ParseElement(XmlElement element) { XmlNodeList resourcess = element.SelectNodes("resources"), descriptionss = element.SelectNodes("description"), assets, conditions, frontcolors, bordercolors, textcolors = element.SelectNodes("textcolor"), conversationsref = element.SelectNodes("conversation-ref"), voices = element.SelectNodes("voice"), actionss = element.SelectNodes("actions"); string tmpArgVal; string characterId = element.GetAttribute("id"); npc = new NPC(characterId); descriptions = new List <Description>(); npc.setDescriptions(descriptions); if (element.SelectSingleNode("documentation") != null) { npc.setDocumentation(element.SelectSingleNode("documentation").InnerText); } foreach (XmlElement el in resourcess) { currentResources = new ResourcesUni(); tmpArgVal = el.GetAttribute("name"); if (!string.IsNullOrEmpty(tmpArgVal)) { currentResources.setName(el.GetAttribute(tmpArgVal)); } assets = el.SelectNodes("asset"); foreach (XmlElement ell in assets) { string type = ""; string path = ""; tmpArgVal = ell.GetAttribute("type"); if (!string.IsNullOrEmpty(tmpArgVal)) { type = tmpArgVal; } tmpArgVal = ell.GetAttribute("uri"); if (!string.IsNullOrEmpty(tmpArgVal)) { path = tmpArgVal; } currentResources.addAsset(type, path); } conditions = el.SelectNodes("condition"); foreach (XmlElement ell in conditions) { currentConditions = new Conditions(); new ConditionSubParser_(currentConditions, chapter).ParseElement(ell); currentResources.setConditions(currentConditions); } npc.addResources(currentResources); } foreach (XmlElement el in textcolors) { tmpArgVal = el.GetAttribute("showsSpeechBubble"); if (!string.IsNullOrEmpty(tmpArgVal)) { npc.setShowsSpeechBubbles(tmpArgVal.Equals("yes")); } tmpArgVal = el.GetAttribute("bubbleBkgColor"); if (!string.IsNullOrEmpty(tmpArgVal)) { npc.setBubbleBkgColor(tmpArgVal); } tmpArgVal = el.GetAttribute("bubbleBorderColor"); if (!string.IsNullOrEmpty(tmpArgVal)) { npc.setBubbleBorderColor(tmpArgVal); } frontcolors = el.SelectNodes("frontcolor"); foreach (XmlElement ell in frontcolors) { string color = ""; tmpArgVal = ell.GetAttribute("color"); if (!string.IsNullOrEmpty(tmpArgVal)) { color = tmpArgVal; } npc.setTextFrontColor(color); } bordercolors = el.SelectNodes("bordercolor"); foreach (XmlElement ell in bordercolors) { string color = ""; tmpArgVal = ell.GetAttribute("color"); if (!string.IsNullOrEmpty(tmpArgVal)) { color = tmpArgVal; } npc.setTextBorderColor(color); } } foreach (XmlElement el in conversationsref) { string idTarget = ""; tmpArgVal = el.GetAttribute("idTarget"); if (!string.IsNullOrEmpty(tmpArgVal)) { idTarget = tmpArgVal; } conversationReference = new ConversationReference(idTarget); conditions = el.SelectNodes("condition"); foreach (XmlElement ell in conditions) { currentConditions = new Conditions(); new ConditionSubParser_(currentConditions, chapter).ParseElement(ell); conversationReference.setConditions(currentConditions); } conversationReference.setDocumentation(el.SelectSingleNode("documentation").InnerText); Action action = new Action(Action.TALK_TO); action.setConditions(conversationReference.getConditions()); action.setDocumentation(conversationReference.getDocumentation()); TriggerConversationEffect effect = new TriggerConversationEffect(conversationReference.getTargetId()); action.getEffects().add(effect); npc.addAction(action); } foreach (XmlElement el in voices) { string voice = ""; string response; bool alwaysSynthesizer = false; tmpArgVal = el.GetAttribute("name"); if (!string.IsNullOrEmpty(tmpArgVal)) { voice = tmpArgVal; } tmpArgVal = el.GetAttribute("synthesizeAlways"); if (!string.IsNullOrEmpty(tmpArgVal)) { response = tmpArgVal; if (response.Equals("yes")) { alwaysSynthesizer = true; } } npc.setAlwaysSynthesizer(alwaysSynthesizer); npc.setVoice(voice); } foreach (XmlElement el in actionss) { new ActionsSubParser_(chapter, npc).ParseElement(el); } foreach (XmlElement el in descriptionss) { description = new Description(); new DescriptionsSubParser_(description, chapter).ParseElement(el); this.descriptions.Add(description); } chapter.addCharacter(npc); }