changeset 259:35dc06030355

Re #270: Add multiple categories to API * Add "category" attribute to army schema * Add method to define category when adding unit to army * Make army loading check new attribute and assign to correct category or main category TODO: Write out category of unit to army file
author IBBoard <dev@ibboard.co.uk>
date Wed, 19 May 2010 20:07:07 +0000
parents 3b395ab8784d
children b72cc74a240b
files api/Factories/Xml/WarFoundryXmlArmyParser.cs api/Objects/Army.cs schemas/army.xsd
diffstat 3 files changed, 18 insertions(+), 3 deletions(-) [+]
line diff
     1.1 --- a/api/Factories/Xml/WarFoundryXmlArmyParser.cs	Wed May 19 19:23:29 2010 +0000
     1.2 +++ b/api/Factories/Xml/WarFoundryXmlArmyParser.cs	Wed May 19 20:07:07 2010 +0000
     1.3 @@ -79,9 +79,17 @@
     1.4  					
     1.5  					string name = unitElem.GetAttribute("unitName");
     1.6  					int size = XmlTools.GetIntValueFromAttribute(unitElem, "size");
     1.7 +					
     1.8 +					string catID = unitElem.GetAttribute("category");
     1.9 +					Category cat = army.Race.GetCategory(catID);
    1.10 +					
    1.11 +					if (cat == null)
    1.12 +					{
    1.13 +						cat = unitType.MainCategory;
    1.14 +					}
    1.15  
    1.16 -					Unit unit = new Unit(id, name, size, unitType, army.GetCategory(unitType.MainCategory));
    1.17 -					army.AddUnit(unit);
    1.18 +					Unit unit = new Unit(id, name, size, unitType, army.GetCategory(cat));
    1.19 +					army.AddUnit(unit, cat);
    1.20  					units.Add(id, unit);
    1.21  
    1.22  					LoadUnitEquipment(unitElem, unit);
     2.1 --- a/api/Objects/Army.cs	Wed May 19 19:23:29 2010 +0000
     2.2 +++ b/api/Objects/Army.cs	Wed May 19 20:07:07 2010 +0000
     2.3 @@ -169,7 +169,13 @@
     2.4  		
     2.5  		public void AddUnit(Unit unit)
     2.6  		{
     2.7 -			ArmyCategory armyCat = GetCategory(unit.UnitType.MainCategory);
     2.8 +			Category category = unit.UnitType.MainCategory;
     2.9 +			AddUnit(unit, category);
    2.10 +		}
    2.11 +		
    2.12 +		public void AddUnit(Unit unit, Category category)
    2.13 +		{			
    2.14 +			ArmyCategory armyCat = GetCategory(category);
    2.15  			armyCat.AddUnit(unit);
    2.16  		}
    2.17  		
     3.1 --- a/schemas/army.xsd	Wed May 19 19:23:29 2010 +0000
     3.2 +++ b/schemas/army.xsd	Wed May 19 20:07:07 2010 +0000
     3.3 @@ -92,6 +92,7 @@
     3.4  	<xs:attribute name="unitName" type="xs:string" use="required"/>
     3.5  	<xs:attribute name="size" type="xs:positiveInteger" use="required"/>
     3.6  	<xs:attribute name="race" type="xs:string" default=""/>
     3.7 +	<xs:attribute name="category" type="xs:string" default=""/>
     3.8  	<xs:anyAttribute processContents="lax"/>
     3.9  </xs:complexType>
    3.10