# HG changeset patch # User IBBoard # Date 1274126585 0 # Node ID 958ecd7b28448761f5285a7d7c4ca626c4b9c1fd # Parent 0db25d5d0992eb4e5ca12afe8ab0d57aa5976574 Re #270: Add multiple categories to API * Add Categories property * Add method to add Category * Tie up Categories with MainCategory for default behaviour diff -r 0db25d5d0992 -r 958ecd7b2844 api/Objects/UnitType.cs --- a/api/Objects/UnitType.cs Wed May 12 20:01:34 2010 +0000 +++ b/api/Objects/UnitType.cs Mon May 17 20:03:05 2010 +0000 @@ -34,6 +34,8 @@ private Dictionary extraData = new Dictionary(); private Dictionary slotLimits = new Dictionary(); private Dictionary unitMemberTypes = new Dictionary(); + private List cats = new List(); + public UnitType(string id, string typeName, Race parentRace) : base(id, typeName) { @@ -72,17 +74,48 @@ } /// - /// Gets or sets the that this unit type is a member of. + /// Gets or sets the default that this unit type is a member of. + /// If it is not already in the collection of categories then it will be added. /// public virtual Category MainCategory { get - { + { return mainCat; } set { mainCat = value; + AddCategory(value); + } + } + /// + /// Gets the collection of objects that this UnitType can be a member of + /// + public Category[] Categories + { + get + { + return cats.ToArray(); + } + } + + /// + /// Adds a category to the set of categories that this unit can be taken from. The first category added will automatically become the MainCategory. + /// + /// + /// A that this unit can be taken from + /// + public void AddCategory(Category cat) + { + if (!cats.Contains(cat)) + { + cats.Add(cat); + + if (cats.Count == 1) + { + MainCategory = cat; + } } }