changeset 49:9d31d063b194

Re #10 - Refactor source code for readability * Add SelectSingleElement method that checks type and casts return as XmlElement Also: * Delete code to staged load Army and add TODO
author IBBoard <dev@ibboard.co.uk>
date Sat, 28 Mar 2009 16:45:24 +0000
parents b49372dd8afa
children bb6b993b98bf
files api/Factories/Xml/WarFoundryXmlFactory.cs
diffstat 1 files changed, 9 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/api/Factories/Xml/WarFoundryXmlFactory.cs	Sat Mar 28 16:37:27 2009 +0000
+++ b/api/Factories/Xml/WarFoundryXmlFactory.cs	Sat Mar 28 16:45:24 2009 +0000
@@ -93,7 +93,7 @@
 			Race race = WarFoundryLoader.GetDefault().GetRace(system, raceID);
 			int points = GetIntValueFromAttribute(elem, "maxPoints");			
 			Army army = new Army(race, name, points, file);
-			StoreExtraData(army, elem);
+			//TODO: Complete loading of army
 			return army;
 		}
 		
@@ -249,6 +249,12 @@
 		{
 			return element.SelectSingleNode(xpathQuery, GetNamespaceManager());
 		}
+		
+		private XmlElement SelectSingleElement(XmlNode element, string xpathQuery)
+		{
+			XmlNode node = SelectSingleNode(element, xpathQuery);
+			return (node is XmlElement) ? (XmlElement) node : null;
+		}
 				
 		private int GetIntValueFromAttribute(XmlElement elem, string attributeName)
 		{
@@ -298,10 +304,6 @@
 			{
 				CompleteLoading((Race)obj);
 			}
-			else if (obj is Army)
-			{
-				CompleteLoading((Army) obj);
-			}
 		}
 		
 		public void CompleteLoading(GameSystem system)
@@ -322,7 +324,7 @@
 			
 			XmlDocument extraData = GetExtraData(system);
 			LoadCategoriesForSystem(system, extraData);
-			XmlElement statsElem = SelectSingleNode(extraData, "/system:system/system:sysStatsList");
+			XmlElement statsElem = SelectSingleElement(extraData, "/system:system/system:sysStatsList");
 			string defaultStatsID = statsElem.GetAttribute("defaultStats");
 			LoadSystemStatsForSystem(system, extraData);
 			system.StandardSystemStatsID = defaultStatsID;
@@ -446,7 +448,7 @@
 			}
 			
 			type.MainCategory = cat;
-			XmlElement statsElement = SelectSingleNodes(elem, "/race:race/race:units/race:unit/race:stats");
+			XmlElement statsElement = SelectSingleElement(elem, "/race:race/race:units/race:unit/race:stats");
 			type.UnitStats = ParseUnitStats(statsElement, system);
 			//TODO: Add unit requirements
 			LogNotifier.Debug(GetType(), "Loaded "+type.Name);