changeset 123:52e8c3cdde10

Re #127: Unit creation always assigns default equipment * Add and use new constructor for Unit that doesn't assign default values Re #54: Add Army support to WarFoundryFactory * Load unit name and unit size
author IBBoard <dev@ibboard.co.uk>
date Mon, 24 Aug 2009 19:30:19 +0000
parents 571eee2b7b30
children d59aa4e46761
files api/Factories/Xml/WarFoundryXmlArmyParser.cs api/Objects/Unit.cs
diffstat 2 files changed, 10 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/api/Factories/Xml/WarFoundryXmlArmyParser.cs	Sun Aug 23 11:07:47 2009 +0000
+++ b/api/Factories/Xml/WarFoundryXmlArmyParser.cs	Mon Aug 24 19:30:19 2009 +0000
@@ -75,8 +75,11 @@
 					{
 						throw new RequiredDataMissingException(file.Name, "unitType", unitTypeId);
 					}
+					
+					string name = unitElem.GetAttribute("unitName");
+					int size = XmlTools.GetIntValueFromAttribute(unitElem, "size");
 
-					Unit unit = new Unit(unitType, army.GetCategory(unitType.MainCategory));
+					Unit unit = new Unit(id, name, size, unitType, army.GetCategory(unitType.MainCategory));
 					army.AddUnit(unit);
 					units.Add(id, unit);
 
--- a/api/Objects/Unit.cs	Sun Aug 23 11:07:47 2009 +0000
+++ b/api/Objects/Unit.cs	Mon Aug 24 19:30:19 2009 +0000
@@ -28,12 +28,16 @@
 
 		public Unit(UnitType unitType, ArmyCategory parentArmyCat) : this(unitType, unitType.MinSize, parentArmyCat) { }
 
-		public Unit(UnitType unitType, int startSize, ArmyCategory parentArmyCat)
+		public Unit(UnitType unitType, int startSize, ArmyCategory parentArmyCat) : this("", "", startSize, unitType, parentArmyCat)
+		{
+			SetInitialEquipment();
+		}		
+		
+		public Unit(string id, string name, int startSize, UnitType unitType, ArmyCategory parentArmyCat) : base(id, name)
 		{
 			Category = parentArmyCat;
 			type = unitType;
 			Size = startSize;
-			SetInitialEquipment();
 			CalcCost();
 			UnitEquipmentAmountChanged+= new DoubleValChangedDelegate(UnitEquipmentAmountChangedHandler);
 			UnitSizeChanged+= new IntValChangedDelegate(UnitSizeChangedHandler);