# HG changeset patch # User IBBoard # Date 1249149335 0 # Node ID 129636305ad73f827c26afdff2f22f71d156a7fc # Parent 46ad6f478203b5af29fa646c91da212a937efbbe Re #50: Complete core loading of XML files * Load remaining attributes of UnitEquipmentItem from XML files diff -r 46ad6f478203 -r 129636305ad7 api/Factories/Xml/WarFoundryXmlRaceFactory.cs --- a/api/Factories/Xml/WarFoundryXmlRaceFactory.cs Sat Aug 01 16:06:25 2009 +0000 +++ b/api/Factories/Xml/WarFoundryXmlRaceFactory.cs Sat Aug 01 17:55:35 2009 +0000 @@ -9,6 +9,7 @@ using System.Xml; using IBBoard.Xml; using IBBoard.IO; +using IBBoard.Lang; using IBBoard.Logging; using ICSharpCode.SharpZipLib.Zip; using IBBoard.WarFoundry.API.Objects; @@ -150,22 +151,79 @@ { foreach (XmlElement equip in WarFoundryXmlFactoryUtils.SelectNodes(elem, "race:unitEquipment/race:unitEquipmentItem")) { - /* - - - - - - - - - */ string id = equip.GetAttribute("id"); EquipmentItem equipItem = type.Race.GetEquipmentItem(id); if (equipItem!=null) { UnitEquipmentItem unitEquipItem = new UnitEquipmentItem(equipItem); + unitEquipItem.MutexGroup = elem.GetAttribute("exclusivityGroup"); + unitEquipItem.RoundNumberUp = elem.GetAttribute("roundDirection").Equals("up"); + + + try + { + unitEquipItem.IsRequired = bool.Parse(elem.GetAttribute("required")); + } + catch(FormatException e) + { + throw new InvalidFileException("Attribute 'required' of unit equipment item " + id + " for " + type.Name + " was not a valid boolean", ex); + } + + try + { + unitEquipItem.MinNumber = int.Parse(elem.GetAttribute("minNum")); + } + catch (FormatException e) + { + throw new InvalidFileException("Attribute 'minNum' of unit equipment item " + id + " for " + type.Name + " was not a valid integer", ex); + } + + try + { + unitEquipItem.MaxNumber = int.Parse(elem.GetAttribute("maxNum")); + } + catch (FormatException e) + { + throw new InvalidFileException("Attribute 'maxNum' of unit equipment item " + id + " for " + type.Name + " was not a valid integer", ex); + } + + try + { + unitEquipItem.MinPercentage = double.Parse(elem.GetAttribute("minPercentage")); + } + catch (FormatException e) + { + throw new InvalidFileException("Attribute 'minPercentage' of unit equipment item " + id + " for " + type.Name + " was not a valid decimal number", ex); + } + + try + { + unitEquipItem.MaxPercentage = double.Parse(elem.GetAttribute("maxPercentage")); + } + catch (FormatException e) + { + throw new InvalidFileException("Attribute 'maxPercentage' of unit equipment item " + id + " for " + type.Name + " was not a valid decimal number", ex); + } + + try + { + unitEquipItem.CostMultiplier = double.Parse(elem.GetAttribute("costMultiplier")); + } + catch (FormatException e) + { + throw new InvalidFileException("Attribute 'costMultiplier' of unit equipment item " + id + " for " + type.Name + " was not a valid decimal number", ex); + } + + try + { + unitEquipItem.CostRoundType = Enum.Parse(typeof(RoundType), elem.GetAttribute("costRounding")); + } + catch (ArgumentException e) + { + throw new InvalidFileException("Attribute 'costRounding' of unit equipment item " + id + " for " + type.Name + " was not a valid rounding type", ex); + } + type.AddEquipmentItem(unitEquipItem); } else