public void AddTextureChange(TextureChangeTag tag) { m_textureChanges[tag.Role] = tag; }
/// <summary> /// Reads a DialogOption from an XML node /// </summary> /// <param name="node">The node to read from</param> /// <returns>A DialogOption read from the node</returns> public static DialogueOutput ReadFromXML(XmlNode node) { // Throw an exception if the ID is not defined if (node.Attributes["id"] == null) { throw new XmlException("ID is not defined for this node!"); } // Throw an exception if the ID is not defined if (node.Attributes["speaker"] == null) { throw new XmlException("Speaker is not defined for this node!"); } // Define a new Dialog option to return the result in DialogueOutput option = new DialogueOutput(); // Try parsing ID from XML, and throw an exception if it fails if (!int.TryParse(node.Attributes["id"].Value, out option.m_id)) { throw new XmlException("Could not parse ID to integer"); } // Try parsing ID from XML, and throw an exception if it fails if (!int.TryParse(node.Attributes["speaker"].Value, out option.m_activeSpeaker)) { throw new XmlException("Could not parse Speaker to integer"); } // Try parsing ID from XML, and throw an exception if it fails if (node.Attributes["nextId"] != null && !int.TryParse(node.Attributes["nextId"].Value, out option.m_nextId)) { throw new XmlException("Could not parse NextID to integer"); } // Get the choices subnode if (node.Attributes["choices"] != null) { XmlAttribute choices = node.Attributes["choices"]; string value = choices.InnerText; string[] ints = value.Split(','); foreach (string val in ints.Where(s => s.Length > 0)) { option.m_choices.Add(int.Parse(val)); } } // Get the script if there is one if (node["script"] != null) { option.m_script = node["script"].Value; } // As long as the message exists, we load it if (node["message"] != null) { option.m_message = node["message"].InnerText; } // Otherwise, set it's message to an error text and log the warning else { option.m_message = string.Format(MISSING_MESSAGE, option.m_id); Logger.LogMessage(LogMessageType.Warning, "Dialog Option #{0} is missing a message content", option.m_id); } foreach (XmlNode texNode in node.SelectNodes("TextureChange")) { TextureChangeTag tag = new TextureChangeTag(); tag.Role = (TextureRole)Enum.Parse(typeof(TextureRole), texNode.Attributes["role"].Value); if (texNode.Attributes["texture"] != null) { tag.TextureName = texNode.Attributes["texture"].Value; } option.m_textureChanges[tag.Role] = tag; } // return the result return(option); }