changeset 86:129636305ad7

Re #50: Complete core loading of XML files * Load remaining attributes of UnitEquipmentItem from XML files
author IBBoard <dev@ibboard.co.uk>
date Sat, 01 Aug 2009 17:55:35 +0000
parents 46ad6f478203
children 9fba3b4ccdcd
files api/Factories/Xml/WarFoundryXmlRaceFactory.cs
diffstat 1 files changed, 68 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- 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"))
 			{
-													/*	<xs:attribute name="id" type="xs:IDREF" />
-														<xs:attribute name="required" type="xs:boolean" default="false"/>
-														<xs:attribute name="exclusivityGroup" type="xs:string" default=""/>
-														<xs:attribute name="minNum" type="core:nonNegativeOrInfiniteInteger" default="-1"/>
-														<xs:attribute name="maxNum" type="core:nonNegativeOrInfiniteInteger" default="-1"/>
-														<xs:attribute name="minPercentage" type="core:percentage" default="100"/>
-														<xs:attribute name="maxPercentage" type="core:percentage" default="100"/>
-														<xs:attribute name="roundDirection" type="updowntype" default="up"/>
-														<xs:attribute name="costMultiplier" type="core:nonNegativeDouble" default="1"/>
-														<xs:attribute name="costRounding" type="costroundingtype" default="UpToHalf"/>*/
 				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