comparison api/Factories/Xml/WarFoundryXmlRaceFactory.cs @ 221:78f7456f6419

Re #228: Crash with missing abilityID * Quick fix to check if an ability ID doesn't match an ability and throw a standard error if it isn't found TODO: * Need to check why it isn't handled by the attribute type (IDREF) * Need to test it works! Problem shouldn't occur for <notes> because it is just a block of text and isn't referenced anywhere
author IBBoard <dev@ibboard.co.uk>
date Mon, 07 Dec 2009 19:40:12 +0000
parents f609bcf7035b
children 2f9ad5385707
comparison
equal deleted inserted replaced
220:7441a62c5a06 221:78f7456f6419
328 private void LoadAbilitiesForUnitType(XmlElement elem, UnitType type) 328 private void LoadAbilitiesForUnitType(XmlElement elem, UnitType type)
329 { 329 {
330 foreach (XmlElement ability in WarFoundryXmlFactoryUtils.SelectNodes(elem, "race:unitAbilities/race:unitAbility")) 330 foreach (XmlElement ability in WarFoundryXmlFactoryUtils.SelectNodes(elem, "race:unitAbilities/race:unitAbility"))
331 { 331 {
332 string id = ability.GetAttribute("abilityID"); 332 string id = ability.GetAttribute("abilityID");
333 Ability ability = type.Race.GetAbility(id);
334
335 if (ability == null)
336 {
337 throw new InvalidFileException("Ability for "+type.Name+ " with ID "+id+ " did not exist in race definition");
338 }
339
333 bool required = XmlTools.GetBoolValueFromAttribute(ability, "required"); 340 bool required = XmlTools.GetBoolValueFromAttribute(ability, "required");
334 type.AddAbility(type.Race.GetAbility(id), required); 341 type.AddAbility(ability, required);
335 } 342 }
336 } 343 }
337 344
338 private void LoadContainedUnitsForUnitType(XmlElement elem, UnitType type) 345 private void LoadContainedUnitsForUnitType(XmlElement elem, UnitType type)
339 { 346 {