Mercurial > repos > IBBoard.WarFoundry.API
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 wrap: on
line diff
--- a/api/Factories/Xml/WarFoundryXmlArmyParser.cs Wed May 19 19:23:29 2010 +0000 +++ b/api/Factories/Xml/WarFoundryXmlArmyParser.cs Wed May 19 20:07:07 2010 +0000 @@ -79,9 +79,17 @@ string name = unitElem.GetAttribute("unitName"); int size = XmlTools.GetIntValueFromAttribute(unitElem, "size"); + + string catID = unitElem.GetAttribute("category"); + Category cat = army.Race.GetCategory(catID); + + if (cat == null) + { + cat = unitType.MainCategory; + } - Unit unit = new Unit(id, name, size, unitType, army.GetCategory(unitType.MainCategory)); - army.AddUnit(unit); + Unit unit = new Unit(id, name, size, unitType, army.GetCategory(cat)); + army.AddUnit(unit, cat); units.Add(id, unit); LoadUnitEquipment(unitElem, unit);
--- a/api/Objects/Army.cs Wed May 19 19:23:29 2010 +0000 +++ b/api/Objects/Army.cs Wed May 19 20:07:07 2010 +0000 @@ -169,7 +169,13 @@ public void AddUnit(Unit unit) { - ArmyCategory armyCat = GetCategory(unit.UnitType.MainCategory); + Category category = unit.UnitType.MainCategory; + AddUnit(unit, category); + } + + public void AddUnit(Unit unit, Category category) + { + ArmyCategory armyCat = GetCategory(category); armyCat.AddUnit(unit); }
--- a/schemas/army.xsd Wed May 19 19:23:29 2010 +0000 +++ b/schemas/army.xsd Wed May 19 20:07:07 2010 +0000 @@ -92,6 +92,7 @@ <xs:attribute name="unitName" type="xs:string" use="required"/> <xs:attribute name="size" type="xs:positiveInteger" use="required"/> <xs:attribute name="race" type="xs:string" default=""/> + <xs:attribute name="category" type="xs:string" default=""/> <xs:anyAttribute processContents="lax"/> </xs:complexType>