Mercurial > repos > IBBoard.WarFoundry.API
comparison api/Factories/Xml/WarFoundryXmlArmyParser.cs @ 119:0cdc0b07fe11
Re #54: Add army loading
* Add unit to army once it is loaded
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sun, 23 Aug 2009 10:32:09 +0000 |
parents | 093ee2da0f6e |
children | 53654e938982 |
comparison
equal
deleted
inserted
replaced
118:d39de20f2ba1 | 119:0cdc0b07fe11 |
---|---|
63 units = new Dictionary<string, Unit>(); | 63 units = new Dictionary<string, Unit>(); |
64 | 64 |
65 foreach (XmlElement unitElem in WarFoundryXmlFactoryUtils.SelectNodes(elem, "/army:army/army:units/army:unit")) | 65 foreach (XmlElement unitElem in WarFoundryXmlFactoryUtils.SelectNodes(elem, "/army:army/army:units/army:unit")) |
66 { | 66 { |
67 string id = unitElem.GetAttribute("id"); | 67 string id = unitElem.GetAttribute("id"); |
68 Unit unit = DictionaryUtils.GetValue(units, id); | |
69 | 68 |
70 if (unit == null) | 69 if (!units.ContainsKey(id)) |
71 { | 70 { |
72 string unitTypeId = unitElem.GetAttribute("unitType"); | 71 string unitTypeId = unitElem.GetAttribute("unitType"); |
73 UnitType unitType = army.Race.GetUnitType(unitTypeId); | 72 UnitType unitType = army.Race.GetUnitType(unitTypeId); |
74 | 73 |
75 if (unitType == null) | 74 if (unitType == null) |
76 { | 75 { |
77 throw new RequiredDataMissingException(file.Name, "unitType", unitTypeId); | 76 throw new RequiredDataMissingException(file.Name, "unitType", unitTypeId); |
78 } | 77 } |
79 | 78 |
80 unit = new Unit(unitType, army.GetCategory(unitType.MainCategory)); | 79 Unit unit = new Unit(unitType, army.GetCategory(unitType.MainCategory)); |
80 army.AddUnit(unit); | |
81 units.Add(id, unit); | 81 units.Add(id, unit); |
82 | |
83 //LoadUnitEquipment( | |
82 } | 84 } |
83 } | 85 } |
84 } | 86 } |
85 } | 87 } |
86 } | 88 } |