changeset 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 df61d26c23fb
children 6ff68daab5dc
files api/Factories/Xml/WarFoundryXmlRaceFactory.cs
diffstat 1 files changed, 17 insertions(+), 9 deletions(-) [+]
line diff
     1.1 --- a/api/Factories/Xml/WarFoundryXmlRaceFactory.cs	Mon Sep 28 19:48:37 2009 +0000
     1.2 +++ b/api/Factories/Xml/WarFoundryXmlRaceFactory.cs	Tue Sep 29 19:21:50 2009 +0000
     1.3 @@ -123,20 +123,28 @@
     1.4  		}
     1.5  
     1.6  		private void LoadCoreValuesForUnitType(XmlElement elem, UnitType type)
     1.7 -		{
     1.8 -			type.MaxNumber = XmlTools.GetIntValueFromAttribute(elem, "maxNum");
     1.9 -			type.MinNumber = XmlTools.GetIntValueFromAttribute(elem, "minNum");
    1.10 -			type.MaxSize = XmlTools.GetIntValueFromAttribute(elem, "maxSize");
    1.11 -			type.MinSize = XmlTools.GetIntValueFromAttribute(elem, "minSize");
    1.12 -			type.BaseSize = XmlTools.GetIntValueFromAttribute(elem, "baseSize");
    1.13 -			type.CostPerTrooper = XmlTools.GetDoubleValueFromAttribute(elem, "points");
    1.14 -			type.BaseUnitCost = XmlTools.GetDoubleValueFromAttribute(elem, "unitPoints");
    1.15 +		{
    1.16 +			try
    1.17 +			{
    1.18 +				type.MaxNumber = XmlTools.GetIntValueFromAttribute(elem, "maxNum");
    1.19 +				type.MinNumber = XmlTools.GetIntValueFromAttribute(elem, "minNum");
    1.20 +				type.MaxSize = XmlTools.GetIntValueFromAttribute(elem, "maxSize");
    1.21 +				type.MinSize = XmlTools.GetIntValueFromAttribute(elem, "minSize");
    1.22 +				type.BaseSize = XmlTools.GetIntValueFromAttribute(elem, "baseSize");
    1.23 +				type.CostPerTrooper = XmlTools.GetDoubleValueFromAttribute(elem, "points");
    1.24 +				type.BaseUnitCost = XmlTools.GetDoubleValueFromAttribute(elem, "unitPoints");
    1.25 +			}
    1.26 +			catch (FormatException ex)
    1.27 +			{
    1.28 +				throw new InvalidDataException(ex.Message, ex);
    1.29 +			}
    1.30 +
    1.31  			string mainCatID = elem.GetAttribute("cat");
    1.32  			Category cat = type.Race.GetCategory(mainCatID);
    1.33  			
    1.34  			if (cat == null)
    1.35  			{
    1.36 -				throw new InvalidDataException(String.Format("Attribute 'cat' of UnitType {0} (value: {1}) did not reference a valid category", type.ID, mainCatID));
    1.37 +				throw new InvalidDataException(String.Format("Category with ID '{1}' did not exist for UnitType '{0}'", type.Name, mainCatID));
    1.38  			}
    1.39  			
    1.40  			type.MainCategory = cat;