diff api/Factories/Xml/WarFoundryXmlFactory.cs @ 12:ac232763858b

Re #9 - Make WarFoundry API use smaller methods * Obselete old Category and UnitType constructors and add minimal constructors * Add setters to properties where needed * Add value sanity checking to Category and UnitType * Set default values for percentages, choices and points for Category * Make XML factory use new constructor and setter properties * Add DuplicateItemException to project file
author IBBoard <dev@ibboard.co.uk>
date Sun, 18 Jan 2009 20:52:29 +0000
parents 5a1df00b0359
children 306558904c2a
line wrap: on
line diff
--- a/api/Factories/Xml/WarFoundryXmlFactory.cs	Sun Jan 18 16:24:03 2009 +0000
+++ b/api/Factories/Xml/WarFoundryXmlFactory.cs	Sun Jan 18 20:52:29 2009 +0000
@@ -385,49 +385,28 @@
 		{
 			string id = elem.GetAttribute("id");
 			string name = elem.GetAttribute("typeName");
-			string mainCatID = elem.GetAttribute("cat");
-			int minNum, maxNum, minSize, maxSize, baseSize;//TODO: Add base size
-			float points, unitPoints;
-			Stats stats;
-			List<UnitRequirement> unitRequirements = new List<UnitRequirement>();
-			bool found = false;
-			List<string> catIDs = new List<string>();
-			string catID;
-			minNum = GetIntValueFromAttribute(elem, "minNum");
-			maxNum = GetIntValueFromAttribute(elem, "maxNum");
-			minSize = GetIntValueFromAttribute(elem, "minSize");
-			maxSize = GetIntValueFromAttribute(elem, "maxSize");
-			
-			if (minSize > maxSize && maxSize!=-1)
-			{
-				minSize = maxSize;
-			}
-			
-			points = GetIntValueFromAttribute(elem, "points");
-			unitPoints = GetIntValueFromAttribute(elem, "unitPoints");
+			UnitType type = new UnitType(id, name, parentRace);
+			type.MinNumber = GetIntValueFromAttribute(elem, "minNum");
+			type.MaxNumber = GetIntValueFromAttribute(elem, "maxNum");
+			type.MinSize = GetIntValueFromAttribute(elem, "minSize");
+			type.MaxSize = GetIntValueFromAttribute(elem, "maxSize");
+			//TODO: Add base size
+			type.CostPerTrooper = GetIntValueFromAttribute(elem, "points");
+			type.BaseUnitCost = GetIntValueFromAttribute(elem, "unitPoints");
 			
 			XmlNode node = elem.FirstChild;
 			
 			foreach(XmlElement cat in node.ChildNodes)
 			{
-				catID = cat.GetAttribute("catID");
-				catIDs.Add(catID);
-				
-				if (catID == mainCatID)
-				{
-					found = true;
-				}
+				string catID = cat.GetAttribute("catID");
+				type.AddCategory(parentRace.GetCategory(catID));
 			}
-			
-			if (!found)
-			{
-				throw new InvalidFileException("The main cat "+mainCatID+" was not found in the list of categories for unit "+id);
-			}
-			
+
+			string mainCatID = elem.GetAttribute("cat");
+			type.MainCategory = parentRace.GetCategory(mainCatID);						
 			node = node.NextSibling;			
-			stats = ParseUnitStats((XmlElement)node, system);
+			type.UnitStats = ParseUnitStats((XmlElement)node, system);
 			//TODO: Add unit requirements
-			UnitType type = new UnitType(id, name, mainCatID, catIDs.ToArray(), minNum, maxNum, minSize, maxSize, unitPoints, points, stats, unitRequirements.ToArray(), parentRace);
 			
 			return type;
 		}