private void LoadAttachments(XmlElement xml) { var root = xml.GetNotEmptyChild(SpawnItemAttachmentRootName); foreach (XmlElement elemType in root.GetChildElements()) { string type = elemType.Name; if (AttachmentTypes.ContainsKey(type)) throw new LevelXmlException("\"{0}\" contains multiple \"{1}\" elements", SpawnItemAttachmentRootName, type); var attachmentNames = new Dictionary<string, string>(); AttachmentTypes[type] = attachmentNames; foreach (var elemName in elemType.GetChildElements()) { string name = elemName.Name; string imageFileName = null; #if LEVEL_EDITOR if (attachmentNames.ContainsKey(name)) throw new LevelXmlException("Multiple \"{0}\" of type \"{1}\" have the same name \"{2}\"", SpawnItemAttachmentRootName, type, name); imageFileName = elemName.GetStringAttribute("Image"); #endif attachmentNames.Add(name, imageFileName); } } }
private void LoadTypes(XmlElement xml) { var root = xml.GetNotEmptyChild(SpawnItemRootName); foreach (XmlElement elemType in root.GetChildElements()) { string type = elemType.Name; string imageFileName = null; #if LEVEL_EDITOR if (Types.ContainsKey(type)) throw new LevelXmlException("Multiple \"{0}\" have the same type \"{1}\"", SpawnItemRootName, type); imageFileName = elemType.GetStringAttribute("Image"); #endif Types.Add(type, imageFileName); } }
private static string[] GetList(XmlElement xml, string rootName) { var listRoot = xml.GetNotEmptyChild(rootName); var childElements = listRoot.GetChildElements(); var result = new string[childElements.Length]; for (int i = 0; i < childElements.Length; i++) { string name = childElements[i].Name; if (result.Contains(name)) throw new LevelXmlException("\"{0}\" contained multiple times in {1} list.", name, rootName); result[i] = childElements[i].Name; } return result; }