diff api/Factories/Xml/WarFoundryXmlRaceFactory.cs @ 85:46ad6f478203

Re #50: Complete core loading of WarFoundry XML files * Start loading of UnitEquipmentItems * Fix XPath queries for equipment items and abilities * Allow UnitEquipmentItem to be created without a UnitType * Make adding UnitEquipmentItem to UnitType set UnitType of UnitEquipmentItem * Make loading of abilities and equipment items add the item to the race Also: * Code cleanup (line endings) * Make method to get equipment by ID return null instead of throwing "no such key" exception
author IBBoard <dev@ibboard.co.uk>
date Sat, 01 Aug 2009 16:06:25 +0000
parents 032b174fc17a
children 129636305ad7
line wrap: on
line diff
--- a/api/Factories/Xml/WarFoundryXmlRaceFactory.cs	Sun Jul 05 09:50:40 2009 +0000
+++ b/api/Factories/Xml/WarFoundryXmlRaceFactory.cs	Sat Aug 01 16:06:25 2009 +0000
@@ -64,12 +64,12 @@
 				CreateCategoryFromElement(node, race);
 			}
 							
-			foreach (XmlElement node  in WarFoundryXmlFactoryUtils.SelectNodes(extraData, "/race:race/race:equipment/cat:equipmentItem"))
+			foreach (XmlElement node  in WarFoundryXmlFactoryUtils.SelectNodes(extraData, "/race:race/race:equipment/race:equipmentItem"))
 			{
 				CreateEquipmentItemFromElement(node, race);
 			}
 							
-			foreach (XmlElement node  in WarFoundryXmlFactoryUtils.SelectNodes(extraData, "/race:race/race:abilities/cat:ability"))
+			foreach (XmlElement node  in WarFoundryXmlFactoryUtils.SelectNodes(extraData, "/race:race/race:abilities/race:ability"))
 			{
 				CreateAbilityFromElement(node, race);
 			}
@@ -148,6 +148,32 @@
 
 		private void LoadEquipmentForUnitType(XmlElement elem, UnitType type)
 		{
+			foreach (XmlElement equip in WarFoundryXmlFactoryUtils.SelectNodes(elem, "race:unitEquipment/race:unitEquipmentItem"))
+			{
+													/*	<xs:attribute name="id" type="xs:IDREF" />
+														<xs:attribute name="required" type="xs:boolean" default="false"/>
+														<xs:attribute name="exclusivityGroup" type="xs:string" default=""/>
+														<xs:attribute name="minNum" type="core:nonNegativeOrInfiniteInteger" default="-1"/>
+														<xs:attribute name="maxNum" type="core:nonNegativeOrInfiniteInteger" default="-1"/>
+														<xs:attribute name="minPercentage" type="core:percentage" default="100"/>
+														<xs:attribute name="maxPercentage" type="core:percentage" default="100"/>
+														<xs:attribute name="roundDirection" type="updowntype" default="up"/>
+														<xs:attribute name="costMultiplier" type="core:nonNegativeDouble" default="1"/>
+														<xs:attribute name="costRounding" type="costroundingtype" default="UpToHalf"/>*/
+				string id = equip.GetAttribute("id");
+				EquipmentItem equipItem = type.Race.GetEquipmentItem(id);
+				
+				if (equipItem!=null)
+				{
+					UnitEquipmentItem unitEquipItem = new UnitEquipmentItem(equipItem);
+					type.AddEquipmentItem(unitEquipItem);
+				}
+				else
+				{
+					//TODO: Warn about missing item	
+				}
+			}
+				
 		}
 		
 		private void LoadAbilitiesForUnitType(XmlElement elem, UnitType type)
@@ -227,7 +253,7 @@
 			string id = elem.GetAttribute("id");
 			EquipmentItem item = race.GetEquipmentItem(id);
 
-			if (item==null)
+			if (item == null)
 			{
 				item = CreateEquipmentItemFromElement(elem, id, race);
 			}
@@ -263,7 +289,7 @@
 			//TODO: Parse equipment stats if there are any
 			item.Cost = cost;
 			item.ItemArmourType = armourType;
-			
+			race.AddEquipmentItem(item);			
 			return item;
 		}
 		
@@ -274,6 +300,7 @@
 			Ability ability = new Ability(id, name);
 			XmlNode node = elem.SelectSingleNode("description", WarFoundryXmlFactoryUtils.GetNamespaceManager());
 			ability.Description = (node == null) ? "" : node.InnerText;
+			race.AddAbility(ability);
 			return ability;
 		}
 	}