# HG changeset patch # User IBBoard # Date 1250971349 0 # Node ID 093ee2da0f6e72def1c3b34a21c429be72f3d155 # Parent 2010a7e8bf9a8e94ff649800a1ecd7a33390bfdf Re #54: Add Army support to WarFoundryFactory * Add starts of army unit loading diff -r 2010a7e8bf9a -r 093ee2da0f6e api/Factories/Xml/WarFoundryXmlArmyParser.cs --- a/api/Factories/Xml/WarFoundryXmlArmyParser.cs Sat Aug 22 19:42:04 2009 +0000 +++ b/api/Factories/Xml/WarFoundryXmlArmyParser.cs Sat Aug 22 20:02:29 2009 +0000 @@ -3,6 +3,7 @@ // The file and the library/program it is in are licensed and distributed, without warranty, under the GNU Affero GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license. using System; +using System.Collections.Generic; using System.Xml; using IBBoard.Xml; using ICSharpCode.SharpZipLib.Zip; @@ -15,6 +16,7 @@ private ZipFile file; private XmlElement elem; private Army army; + private Dictionary units; public WarFoundryXmlArmyParser(ZipFile file, XmlElement elem) { @@ -53,7 +55,32 @@ int points = XmlTools.GetIntValueFromAttribute(elem, "maxPoints"); army = new Army(race, name, points, file); - //TODO: Complete loading of army + LoadUnits(); + } + + private void LoadUnits() + { + units = new Dictionary(); + + foreach (XmlElement unitElem in WarFoundryXmlFactoryUtils.SelectNodes(elem, "/army:army/army:units/army:unit")) + { + string id = unitElem.GetAttribute("id"); + Unit unit = DictionaryUtils.GetValue(units, id); + + if (unit == null) + { + string unitTypeId = unitElem.GetAttribute("unitType"); + UnitType unitType = army.Race.GetUnitType(unitTypeId); + + if (unitType == null) + { + throw new RequiredDataMissingException(file.Name, "unitType", unitTypeId); + } + + unit = new Unit(unitType, army.GetCategory(unitType.MainCategory)); + units.Add(id, unit); + } + } } } }