Mercurial > repos > snowblizz-super-API-ideas
comparison api/Factories/Xml/WarFoundryXmlFactory.cs @ 11:5a1df00b0359
Re #9 - Make WarFoundry API load files in small methods
* Add "add unit type" and "add equipment" methods to Race
* Deprecate old "set unit types" and "set equipment" methods on Race
* Update WarFoundryXmlFactory to use new methods
* Create DuplicateItemException for later use
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sun, 18 Jan 2009 16:24:03 +0000 |
parents | 607c3232d689 |
children | ac232763858b |
comparison
equal
deleted
inserted
replaced
10:607c3232d689 | 11:5a1df00b0359 |
---|---|
236 return; | 236 return; |
237 } | 237 } |
238 | 238 |
239 XmlNode elem = GetExtraData(race); | 239 XmlNode elem = GetExtraData(race); |
240 XmlNode colNode = elem.FirstChild; | 240 XmlNode colNode = elem.FirstChild; |
241 | 241 |
242 Dictionary<string, UnitType> unitTypes = new Dictionary<string, UnitType>(); | |
243 | |
244 foreach (XmlElement node in colNode.ChildNodes) | 242 foreach (XmlElement node in colNode.ChildNodes) |
245 { | 243 { |
246 UnitType type = CreateUnitTypeFromElement(node, race, race.GameSystem); | 244 UnitType type = CreateUnitTypeFromElement(node, race, race.GameSystem); |
247 unitTypes.Add(type.ID, type); | 245 race.AddUnitType(type); |
248 } | 246 } |
249 | 247 |
250 colNode = colNode.NextSibling; | 248 colNode = colNode.NextSibling; |
251 | 249 |
252 if (colNode!=null && colNode.Name == WarFoundryXmlElementName.CATEGORIES_ELEMENT.Value) | 250 if (colNode!=null && colNode.Name == WarFoundryXmlElementName.CATEGORIES_ELEMENT.Value) |
256 race.AddCategory(CreateCategoryFromElement(node)); | 254 race.AddCategory(CreateCategoryFromElement(node)); |
257 } | 255 } |
258 | 256 |
259 colNode = colNode.NextSibling; | 257 colNode = colNode.NextSibling; |
260 } | 258 } |
261 | 259 |
262 Dictionary<string, EquipmentItem> raceEquipment = new Dictionary<string, EquipmentItem>(); | |
263 | |
264 if (colNode!=null && colNode.Name == WarFoundryXmlElementName.RACE_EQUIPMENT_ITEMS_ELEMENT.Value) | 260 if (colNode!=null && colNode.Name == WarFoundryXmlElementName.RACE_EQUIPMENT_ITEMS_ELEMENT.Value) |
265 { | 261 { |
266 foreach (XmlElement node in colNode.ChildNodes) | 262 foreach (XmlElement node in colNode.ChildNodes) |
267 { | 263 { |
268 EquipmentItem item = CreateEquipmentItemFromElement(node, race); | 264 EquipmentItem item = CreateEquipmentItemFromElement(node, race); |
269 raceEquipment.Add(item.ID, item); | 265 race.AddEquipmentItem(item); |
270 } | 266 } |
271 } | 267 } |
272 | 268 |
273 Dictionary<string, Ability> raceAbilities = new Dictionary<string, Ability>(); | 269 Dictionary<string, Ability> raceAbilities = new Dictionary<string, Ability>(); |
274 //TODO: Load abilities | 270 //TODO: Load abilities |
275 | |
276 race.SetUnitTypes(unitTypes); | |
277 race.SetEquipmentItems(raceEquipment); | |
278 race.SetAbilities(raceAbilities); | 271 race.SetAbilities(raceAbilities); |
279 race.SetAsFullyLoaded(); | 272 race.SetAsFullyLoaded(); |
280 LogNotifier.DebugFormat(GetType(), "Completed loading of Race with ID {0}", race.Name); | 273 LogNotifier.DebugFormat(GetType(), "Completed loading of Race with ID {0}", race.Name); |
281 } | 274 } |
282 | 275 |