changeset 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 958ecd7b2844
children 3b395ab8784d
files api/Factories/Xml/WarFoundryXmlRaceFactory.cs api/Objects/UnitType.cs schemas/race.xsd
diffstat 3 files changed, 35 insertions(+), 3 deletions(-) [+]
line diff
     1.1 --- a/api/Factories/Xml/WarFoundryXmlRaceFactory.cs	Mon May 17 20:03:05 2010 +0000
     1.2 +++ b/api/Factories/Xml/WarFoundryXmlRaceFactory.cs	Tue May 18 19:59:17 2010 +0000
     1.3 @@ -160,8 +160,9 @@
     1.4  				throw new InvalidFileException(ex.Message, ex);
     1.5  			}
     1.6  
     1.7 +			Race race = type.Race;
     1.8  			string mainCatID = elem.GetAttribute("cat");
     1.9 -			Category cat = type.Race.GetCategory(mainCatID);
    1.10 +			Category cat = race.GetCategory(mainCatID);
    1.11  			
    1.12  			if (cat == null)
    1.13  			{
    1.14 @@ -169,6 +170,22 @@
    1.15  			}
    1.16  			
    1.17  			type.MainCategory = cat;
    1.18 +			
    1.19 +			XmlNodeList unitCategories = WarFoundryXmlFactoryUtils.SelectNodes(elem, "race:unitCategories/race:unitCategory");
    1.20 +			
    1.21 +			foreach (XmlElement unitCategory in unitCategories)
    1.22 +			{
    1.23 +				string catID = unitCategory.GetAttribute("catID");
    1.24 +				Category unitCat = race.GetCategory(catID);
    1.25 +				
    1.26 +				if (unitCat == null)
    1.27 +				{
    1.28 +					throw new InvalidFileException(String.Format("Category with ID '{1}' did not exist for UnitType '{0}'", type.Name, catID));
    1.29 +				}
    1.30 +				
    1.31 +				type.AddCategory(unitCat);
    1.32 +			}
    1.33 +			
    1.34  			XmlElement statsElement = WarFoundryXmlFactoryUtils.SelectSingleElement(elem, "race:stats");
    1.35  			
    1.36  			if (statsElement!=null)
    1.37 @@ -182,7 +199,7 @@
    1.38  			foreach (XmlElement unitMemberRef in unitMemberReferences)
    1.39  			{
    1.40  				string typeID = unitMemberRef.GetAttribute("typeID");
    1.41 -				UnitMemberType unitMemberType = type.Race.GetUnitMemberType(typeID);
    1.42 +				UnitMemberType unitMemberType = race.GetUnitMemberType(typeID);
    1.43  				type.AddUnitMemberType(unitMemberType);
    1.44  			}
    1.45  		}
     2.1 --- a/api/Objects/UnitType.cs	Mon May 17 20:03:05 2010 +0000
     2.2 +++ b/api/Objects/UnitType.cs	Tue May 18 19:59:17 2010 +0000
     2.3 @@ -112,7 +112,7 @@
     2.4  			{
     2.5  				cats.Add(cat);
     2.6  				
     2.7 -				if (cats.Count == 1)
     2.8 +				if (MainCategory == null)
     2.9  				{
    2.10  					MainCategory = cat;
    2.11  				}
     3.1 --- a/schemas/race.xsd	Mon May 17 20:03:05 2010 +0000
     3.2 +++ b/schemas/race.xsd	Tue May 18 19:59:17 2010 +0000
     3.3 @@ -202,6 +202,21 @@
     3.4  				</xs:sequence>
     3.5  			</xs:complexType>
     3.6  		</xs:element>
     3.7 +		<xs:element name="unitCategories" minOccurs="0">
     3.8 +			<xs:complexType>
     3.9 +				<xs:sequence>
    3.10 +					<xs:element name="unitCategory" maxOccurs="unbounded">
    3.11 +						<xs:complexType>
    3.12 +							<xs:sequence>
    3.13 +								<xs:any minOccurs="0" maxOccurs="unbounded" processContents="lax"/>
    3.14 +							</xs:sequence>
    3.15 +							<xs:attribute name="catID" type="xs:string" use="required"/>
    3.16 +							<xs:anyAttribute processContents="lax"/>						
    3.17 +						</xs:complexType>
    3.18 +					</xs:element>
    3.19 +				</xs:sequence>
    3.20 +			</xs:complexType>
    3.21 +		</xs:element>
    3.22  		<xs:element name="notes" type="xs:string" minOccurs="0" />
    3.23  		<xs:any minOccurs="0" maxOccurs="unbounded" processContents="lax"/>
    3.24  	</xs:sequence>