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 diff
     1.1 --- a/api/Factories/Xml/WarFoundryXmlFactory.cs	Sat Mar 28 16:37:27 2009 +0000
     1.2 +++ b/api/Factories/Xml/WarFoundryXmlFactory.cs	Sat Mar 28 16:45:24 2009 +0000
     1.3 @@ -93,7 +93,7 @@
     1.4  			Race race = WarFoundryLoader.GetDefault().GetRace(system, raceID);
     1.5  			int points = GetIntValueFromAttribute(elem, "maxPoints");			
     1.6  			Army army = new Army(race, name, points, file);
     1.7 -			StoreExtraData(army, elem);
     1.8 +			//TODO: Complete loading of army
     1.9  			return army;
    1.10  		}
    1.11  		
    1.12 @@ -249,6 +249,12 @@
    1.13  		{
    1.14  			return element.SelectSingleNode(xpathQuery, GetNamespaceManager());
    1.15  		}
    1.16 +		
    1.17 +		private XmlElement SelectSingleElement(XmlNode element, string xpathQuery)
    1.18 +		{
    1.19 +			XmlNode node = SelectSingleNode(element, xpathQuery);
    1.20 +			return (node is XmlElement) ? (XmlElement) node : null;
    1.21 +		}
    1.22  				
    1.23  		private int GetIntValueFromAttribute(XmlElement elem, string attributeName)
    1.24  		{
    1.25 @@ -298,10 +304,6 @@
    1.26  			{
    1.27  				CompleteLoading((Race)obj);
    1.28  			}
    1.29 -			else if (obj is Army)
    1.30 -			{
    1.31 -				CompleteLoading((Army) obj);
    1.32 -			}
    1.33  		}
    1.34  		
    1.35  		public void CompleteLoading(GameSystem system)
    1.36 @@ -322,7 +324,7 @@
    1.37  			
    1.38  			XmlDocument extraData = GetExtraData(system);
    1.39  			LoadCategoriesForSystem(system, extraData);
    1.40 -			XmlElement statsElem = SelectSingleNode(extraData, "/system:system/system:sysStatsList");
    1.41 +			XmlElement statsElem = SelectSingleElement(extraData, "/system:system/system:sysStatsList");
    1.42  			string defaultStatsID = statsElem.GetAttribute("defaultStats");
    1.43  			LoadSystemStatsForSystem(system, extraData);
    1.44  			system.StandardSystemStatsID = defaultStatsID;
    1.45 @@ -446,7 +448,7 @@
    1.46  			}
    1.47  			
    1.48  			type.MainCategory = cat;
    1.49 -			XmlElement statsElement = SelectSingleNodes(elem, "/race:race/race:units/race:unit/race:stats");
    1.50 +			XmlElement statsElement = SelectSingleElement(elem, "/race:race/race:units/race:unit/race:stats");
    1.51  			type.UnitStats = ParseUnitStats(statsElement, system);
    1.52  			//TODO: Add unit requirements
    1.53  			LogNotifier.Debug(GetType(), "Loaded "+type.Name);