diff api/Factories/Xml/WarFoundryXmlRaceFactory.cs @ 156:62ff1ac132d2

Fixes #185: Problems with decimals in race definitions * Problem fixed with ibboard:r103 (XmlTools were using int.parse in double parsing code!) * Catch and wrap exceptions so that they get caught with a dialog for the user
author IBBoard <dev@ibboard.co.uk>
date Tue, 29 Sep 2009 19:21:50 +0000
parents 4a02c07278e7
children eb9a6d91a6db
line wrap: on
line diff
--- a/api/Factories/Xml/WarFoundryXmlRaceFactory.cs	Mon Sep 28 19:48:37 2009 +0000
+++ b/api/Factories/Xml/WarFoundryXmlRaceFactory.cs	Tue Sep 29 19:21:50 2009 +0000
@@ -123,20 +123,28 @@
 		}
 
 		private void LoadCoreValuesForUnitType(XmlElement elem, UnitType type)
-		{
-			type.MaxNumber = XmlTools.GetIntValueFromAttribute(elem, "maxNum");
-			type.MinNumber = XmlTools.GetIntValueFromAttribute(elem, "minNum");
-			type.MaxSize = XmlTools.GetIntValueFromAttribute(elem, "maxSize");
-			type.MinSize = XmlTools.GetIntValueFromAttribute(elem, "minSize");
-			type.BaseSize = XmlTools.GetIntValueFromAttribute(elem, "baseSize");
-			type.CostPerTrooper = XmlTools.GetDoubleValueFromAttribute(elem, "points");
-			type.BaseUnitCost = XmlTools.GetDoubleValueFromAttribute(elem, "unitPoints");
+		{
+			try
+			{
+				type.MaxNumber = XmlTools.GetIntValueFromAttribute(elem, "maxNum");
+				type.MinNumber = XmlTools.GetIntValueFromAttribute(elem, "minNum");
+				type.MaxSize = XmlTools.GetIntValueFromAttribute(elem, "maxSize");
+				type.MinSize = XmlTools.GetIntValueFromAttribute(elem, "minSize");
+				type.BaseSize = XmlTools.GetIntValueFromAttribute(elem, "baseSize");
+				type.CostPerTrooper = XmlTools.GetDoubleValueFromAttribute(elem, "points");
+				type.BaseUnitCost = XmlTools.GetDoubleValueFromAttribute(elem, "unitPoints");
+			}
+			catch (FormatException ex)
+			{
+				throw new InvalidDataException(ex.Message, ex);
+			}
+
 			string mainCatID = elem.GetAttribute("cat");
 			Category cat = type.Race.GetCategory(mainCatID);
 			
 			if (cat == null)
 			{
-				throw new InvalidDataException(String.Format("Attribute 'cat' of UnitType {0} (value: {1}) did not reference a valid category", type.ID, mainCatID));
+				throw new InvalidDataException(String.Format("Category with ID '{1}' did not exist for UnitType '{0}'", type.Name, mainCatID));
 			}
 			
 			type.MainCategory = cat;