comparison 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
comparison
equal deleted inserted replaced
84:2b977962302a 85:46ad6f478203
62 foreach (XmlElement node in WarFoundryXmlFactoryUtils.SelectNodes(extraData, "/race:race/race:categories/cat:cat")) 62 foreach (XmlElement node in WarFoundryXmlFactoryUtils.SelectNodes(extraData, "/race:race/race:categories/cat:cat"))
63 { 63 {
64 CreateCategoryFromElement(node, race); 64 CreateCategoryFromElement(node, race);
65 } 65 }
66 66
67 foreach (XmlElement node in WarFoundryXmlFactoryUtils.SelectNodes(extraData, "/race:race/race:equipment/cat:equipmentItem")) 67 foreach (XmlElement node in WarFoundryXmlFactoryUtils.SelectNodes(extraData, "/race:race/race:equipment/race:equipmentItem"))
68 { 68 {
69 CreateEquipmentItemFromElement(node, race); 69 CreateEquipmentItemFromElement(node, race);
70 } 70 }
71 71
72 foreach (XmlElement node in WarFoundryXmlFactoryUtils.SelectNodes(extraData, "/race:race/race:abilities/cat:ability")) 72 foreach (XmlElement node in WarFoundryXmlFactoryUtils.SelectNodes(extraData, "/race:race/race:abilities/race:ability"))
73 { 73 {
74 CreateAbilityFromElement(node, race); 74 CreateAbilityFromElement(node, race);
75 } 75 }
76 76
77 foreach (XmlElement node in WarFoundryXmlFactoryUtils.SelectNodes(extraData, "/race:race/race:units/race:unit")) 77 foreach (XmlElement node in WarFoundryXmlFactoryUtils.SelectNodes(extraData, "/race:race/race:units/race:unit"))
146 type.SetUnitStats(unitStats); 146 type.SetUnitStats(unitStats);
147 } 147 }
148 148
149 private void LoadEquipmentForUnitType(XmlElement elem, UnitType type) 149 private void LoadEquipmentForUnitType(XmlElement elem, UnitType type)
150 { 150 {
151 foreach (XmlElement equip in WarFoundryXmlFactoryUtils.SelectNodes(elem, "race:unitEquipment/race:unitEquipmentItem"))
152 {
153 /* <xs:attribute name="id" type="xs:IDREF" />
154 <xs:attribute name="required" type="xs:boolean" default="false"/>
155 <xs:attribute name="exclusivityGroup" type="xs:string" default=""/>
156 <xs:attribute name="minNum" type="core:nonNegativeOrInfiniteInteger" default="-1"/>
157 <xs:attribute name="maxNum" type="core:nonNegativeOrInfiniteInteger" default="-1"/>
158 <xs:attribute name="minPercentage" type="core:percentage" default="100"/>
159 <xs:attribute name="maxPercentage" type="core:percentage" default="100"/>
160 <xs:attribute name="roundDirection" type="updowntype" default="up"/>
161 <xs:attribute name="costMultiplier" type="core:nonNegativeDouble" default="1"/>
162 <xs:attribute name="costRounding" type="costroundingtype" default="UpToHalf"/>*/
163 string id = equip.GetAttribute("id");
164 EquipmentItem equipItem = type.Race.GetEquipmentItem(id);
165
166 if (equipItem!=null)
167 {
168 UnitEquipmentItem unitEquipItem = new UnitEquipmentItem(equipItem);
169 type.AddEquipmentItem(unitEquipItem);
170 }
171 else
172 {
173 //TODO: Warn about missing item
174 }
175 }
176
151 } 177 }
152 178
153 private void LoadAbilitiesForUnitType(XmlElement elem, UnitType type) 179 private void LoadAbilitiesForUnitType(XmlElement elem, UnitType type)
154 { 180 {
155 foreach (XmlElement ability in WarFoundryXmlFactoryUtils.SelectNodes(elem, "race:unitAbilities/race:unitAbility")) 181 foreach (XmlElement ability in WarFoundryXmlFactoryUtils.SelectNodes(elem, "race:unitAbilities/race:unitAbility"))
225 private EquipmentItem CreateEquipmentItemFromElement(XmlElement elem, Race race) 251 private EquipmentItem CreateEquipmentItemFromElement(XmlElement elem, Race race)
226 { 252 {
227 string id = elem.GetAttribute("id"); 253 string id = elem.GetAttribute("id");
228 EquipmentItem item = race.GetEquipmentItem(id); 254 EquipmentItem item = race.GetEquipmentItem(id);
229 255
230 if (item==null) 256 if (item == null)
231 { 257 {
232 item = CreateEquipmentItemFromElement(elem, id, race); 258 item = CreateEquipmentItemFromElement(elem, id, race);
233 } 259 }
234 260
235 return item; 261 return item;
261 } 287 }
262 288
263 //TODO: Parse equipment stats if there are any 289 //TODO: Parse equipment stats if there are any
264 item.Cost = cost; 290 item.Cost = cost;
265 item.ItemArmourType = armourType; 291 item.ItemArmourType = armourType;
266 292 race.AddEquipmentItem(item);
267 return item; 293 return item;
268 } 294 }
269 295
270 private Ability CreateAbilityFromElement(XmlElement elem, Race race) 296 private Ability CreateAbilityFromElement(XmlElement elem, Race race)
271 { 297 {
272 string id = elem.GetAttribute("id"); 298 string id = elem.GetAttribute("id");
273 string name = elem.GetAttribute("name"); 299 string name = elem.GetAttribute("name");
274 Ability ability = new Ability(id, name); 300 Ability ability = new Ability(id, name);
275 XmlNode node = elem.SelectSingleNode("description", WarFoundryXmlFactoryUtils.GetNamespaceManager()); 301 XmlNode node = elem.SelectSingleNode("description", WarFoundryXmlFactoryUtils.GetNamespaceManager());
276 ability.Description = (node == null) ? "" : node.InnerText; 302 ability.Description = (node == null) ? "" : node.InnerText;
303 race.AddAbility(ability);
277 return ability; 304 return ability;
278 } 305 }
279 } 306 }
280 } 307 }