comparison api/Factories/Xml/WarFoundryXmlRaceFactory.cs @ 167:9ba56a8e5096

Re #198: Add slots with counts to units * Add initial API methods * Add value loading
author IBBoard <dev@ibboard.co.uk>
date Tue, 06 Oct 2009 14:59:54 +0000
parents eb9a6d91a6db
children 3045a168714a
comparison
equal deleted inserted replaced
166:6902f49e16e0 167:9ba56a8e5096
110 private UnitType CreateUnitTypeFromElement(XmlElement elem, string id, Race parentRace) 110 private UnitType CreateUnitTypeFromElement(XmlElement elem, string id, Race parentRace)
111 { 111 {
112 string name = elem.GetAttribute("typeName"); 112 string name = elem.GetAttribute("typeName");
113 UnitType type = new UnitType(id, name, parentRace); 113 UnitType type = new UnitType(id, name, parentRace);
114 LoadCoreValuesForUnitType(elem, type); 114 LoadCoreValuesForUnitType(elem, type);
115 LoadEquipmentSlotsForUnitType(elem, type);
115 LoadEquipmentForUnitType(elem, type); 116 LoadEquipmentForUnitType(elem, type);
116 LoadAbilitiesForUnitType(elem, type); 117 LoadAbilitiesForUnitType(elem, type);
117 LoadContainedUnitsForUnitType(elem, type); 118 LoadContainedUnitsForUnitType(elem, type);
118 LoadRequirementsForUnitType(elem, type); 119 LoadRequirementsForUnitType(elem, type);
119 LoadExtraDataForUnitType(elem, type); 120 LoadExtraDataForUnitType(elem, type);
151 XmlElement statsElement = WarFoundryXmlFactoryUtils.SelectSingleElement(elem, "race:stats"); 152 XmlElement statsElement = WarFoundryXmlFactoryUtils.SelectSingleElement(elem, "race:stats");
152 Stats unitStats = ParseUnitStats(statsElement, type.GameSystem); 153 Stats unitStats = ParseUnitStats(statsElement, type.GameSystem);
153 type.SetUnitStats(unitStats); 154 type.SetUnitStats(unitStats);
154 } 155 }
155 156
157 private void LoadEquipmentSlotsForUnitType(XmlElement elem, UnitType type)
158 {
159 foreach (XmlElement equip in WarFoundryXmlFactoryUtils.SelectNodes(elem, "race:equipmentSlots/race:equipmentSlot"))
160 {
161 string slotName = equip.GetAttribute("name");
162 int slotLimit = XmlTools.GetIntValueFromAttribute(equip, "limit");
163 type.AddEquipmentSlot(slotName, slotLimit);
164 }
165 }
166
156 private void LoadEquipmentForUnitType(XmlElement elem, UnitType type) 167 private void LoadEquipmentForUnitType(XmlElement elem, UnitType type)
157 { 168 {
158 foreach (XmlElement equip in WarFoundryXmlFactoryUtils.SelectNodes(elem, "race:unitEquipment/race:unitEquipmentItem")) 169 foreach (XmlElement equip in WarFoundryXmlFactoryUtils.SelectNodes(elem, "race:unitEquipment/race:unitEquipmentItem"))
159 { 170 {
160 string id = equip.GetAttribute("id"); 171 string id = equip.GetAttribute("id");
186 { 197 {
187 mutexGroups = new string[0]; 198 mutexGroups = new string[0];
188 } 199 }
189 200
190 UnitEquipmentItem unitEquipItem = new UnitEquipmentItem(equipItem, type, mutexGroups); 201 UnitEquipmentItem unitEquipItem = new UnitEquipmentItem(equipItem, type, mutexGroups);
202
203 string equipSlot = equip.GetAttribute("equipmentSlot");
204
205 if (equipSlot != "")
206 {
207 if (type.HasEquipmentSlot(equipSlot))
208 {
209 unitEquipItem.SlotName = equipSlot;
210 }
211 else
212 {
213 throw new InvalidFileException("Attribute 'equipmentSlot' of unit equipment item " + id + " for " + type.Name + " was not a valid slot name");
214 }
215 }
216
191 unitEquipItem.RoundNumberUp = equip.GetAttribute("roundDirection").Equals("up"); 217 unitEquipItem.RoundNumberUp = equip.GetAttribute("roundDirection").Equals("up");
192 218
193 219
194 try 220 try
195 { 221 {