Mercurial > repos > IBDev-IBBoard.WarFoundry.API
comparison api/Factories/Xml/WarFoundryXmlRaceFactory.cs @ 257:435eb28b4549
Re #270: Add multiple categories to API
* Add section for multiple categories to schema
* Add category loading to factory
Also:
* Do more sensible check on whether we need to set MainCategory when adding category to unit type
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Tue, 18 May 2010 19:59:17 +0000 |
parents | a54da5a8b5bb |
children | 7933d852181e |
comparison
equal
deleted
inserted
replaced
256:958ecd7b2844 | 257:435eb28b4549 |
---|---|
158 catch (FormatException ex) | 158 catch (FormatException ex) |
159 { | 159 { |
160 throw new InvalidFileException(ex.Message, ex); | 160 throw new InvalidFileException(ex.Message, ex); |
161 } | 161 } |
162 | 162 |
163 Race race = type.Race; | |
163 string mainCatID = elem.GetAttribute("cat"); | 164 string mainCatID = elem.GetAttribute("cat"); |
164 Category cat = type.Race.GetCategory(mainCatID); | 165 Category cat = race.GetCategory(mainCatID); |
165 | 166 |
166 if (cat == null) | 167 if (cat == null) |
167 { | 168 { |
168 throw new InvalidFileException(String.Format("Category with ID '{1}' did not exist for UnitType '{0}'", type.Name, mainCatID)); | 169 throw new InvalidFileException(String.Format("Category with ID '{1}' did not exist for UnitType '{0}'", type.Name, mainCatID)); |
169 } | 170 } |
170 | 171 |
171 type.MainCategory = cat; | 172 type.MainCategory = cat; |
173 | |
174 XmlNodeList unitCategories = WarFoundryXmlFactoryUtils.SelectNodes(elem, "race:unitCategories/race:unitCategory"); | |
175 | |
176 foreach (XmlElement unitCategory in unitCategories) | |
177 { | |
178 string catID = unitCategory.GetAttribute("catID"); | |
179 Category unitCat = race.GetCategory(catID); | |
180 | |
181 if (unitCat == null) | |
182 { | |
183 throw new InvalidFileException(String.Format("Category with ID '{1}' did not exist for UnitType '{0}'", type.Name, catID)); | |
184 } | |
185 | |
186 type.AddCategory(unitCat); | |
187 } | |
188 | |
172 XmlElement statsElement = WarFoundryXmlFactoryUtils.SelectSingleElement(elem, "race:stats"); | 189 XmlElement statsElement = WarFoundryXmlFactoryUtils.SelectSingleElement(elem, "race:stats"); |
173 | 190 |
174 if (statsElement!=null) | 191 if (statsElement!=null) |
175 { | 192 { |
176 Stats unitStats = ParseUnitStats(statsElement, type.GameSystem); | 193 Stats unitStats = ParseUnitStats(statsElement, type.GameSystem); |
180 XmlNodeList unitMemberReferences = WarFoundryXmlFactoryUtils.SelectNodes(elem, "race:unitMembers/race:unitMember"); | 197 XmlNodeList unitMemberReferences = WarFoundryXmlFactoryUtils.SelectNodes(elem, "race:unitMembers/race:unitMember"); |
181 | 198 |
182 foreach (XmlElement unitMemberRef in unitMemberReferences) | 199 foreach (XmlElement unitMemberRef in unitMemberReferences) |
183 { | 200 { |
184 string typeID = unitMemberRef.GetAttribute("typeID"); | 201 string typeID = unitMemberRef.GetAttribute("typeID"); |
185 UnitMemberType unitMemberType = type.Race.GetUnitMemberType(typeID); | 202 UnitMemberType unitMemberType = race.GetUnitMemberType(typeID); |
186 type.AddUnitMemberType(unitMemberType); | 203 type.AddUnitMemberType(unitMemberType); |
187 } | 204 } |
188 } | 205 } |
189 | 206 |
190 private void LoadEquipmentSlotsForUnitType(XmlElement elem, UnitType type) | 207 private void LoadEquipmentSlotsForUnitType(XmlElement elem, UnitType type) |