# HG changeset patch # User IBBoard # Date 1274212757 0 # Node ID 435eb28b4549c2840be865b97935f75958d11817 # Parent 958ecd7b28448761f5285a7d7c4ca626c4b9c1fd 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 diff -r 958ecd7b2844 -r 435eb28b4549 api/Factories/Xml/WarFoundryXmlRaceFactory.cs --- a/api/Factories/Xml/WarFoundryXmlRaceFactory.cs Mon May 17 20:03:05 2010 +0000 +++ b/api/Factories/Xml/WarFoundryXmlRaceFactory.cs Tue May 18 19:59:17 2010 +0000 @@ -160,8 +160,9 @@ throw new InvalidFileException(ex.Message, ex); } + Race race = type.Race; string mainCatID = elem.GetAttribute("cat"); - Category cat = type.Race.GetCategory(mainCatID); + Category cat = race.GetCategory(mainCatID); if (cat == null) { @@ -169,6 +170,22 @@ } type.MainCategory = cat; + + XmlNodeList unitCategories = WarFoundryXmlFactoryUtils.SelectNodes(elem, "race:unitCategories/race:unitCategory"); + + foreach (XmlElement unitCategory in unitCategories) + { + string catID = unitCategory.GetAttribute("catID"); + Category unitCat = race.GetCategory(catID); + + if (unitCat == null) + { + throw new InvalidFileException(String.Format("Category with ID '{1}' did not exist for UnitType '{0}'", type.Name, catID)); + } + + type.AddCategory(unitCat); + } + XmlElement statsElement = WarFoundryXmlFactoryUtils.SelectSingleElement(elem, "race:stats"); if (statsElement!=null) @@ -182,7 +199,7 @@ foreach (XmlElement unitMemberRef in unitMemberReferences) { string typeID = unitMemberRef.GetAttribute("typeID"); - UnitMemberType unitMemberType = type.Race.GetUnitMemberType(typeID); + UnitMemberType unitMemberType = race.GetUnitMemberType(typeID); type.AddUnitMemberType(unitMemberType); } } diff -r 958ecd7b2844 -r 435eb28b4549 api/Objects/UnitType.cs --- a/api/Objects/UnitType.cs Mon May 17 20:03:05 2010 +0000 +++ b/api/Objects/UnitType.cs Tue May 18 19:59:17 2010 +0000 @@ -112,7 +112,7 @@ { cats.Add(cat); - if (cats.Count == 1) + if (MainCategory == null) { MainCategory = cat; } diff -r 958ecd7b2844 -r 435eb28b4549 schemas/race.xsd --- a/schemas/race.xsd Mon May 17 20:03:05 2010 +0000 +++ b/schemas/race.xsd Tue May 18 19:59:17 2010 +0000 @@ -202,6 +202,21 @@ + + + + + + + + + + + + + + +