Mercurial > repos > snowblizz-super-API-ideas
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 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;