changeset 256:958ecd7b2844

Re #270: Add multiple categories to API * Add Categories property * Add method to add Category * Tie up Categories with MainCategory for default behaviour
author IBBoard <dev@ibboard.co.uk>
date Mon, 17 May 2010 20:03:05 +0000
parents 0db25d5d0992
children 435eb28b4549
files api/Objects/UnitType.cs
diffstat 1 files changed, 35 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- 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<string, string> extraData = new Dictionary<string, string>();
 		private Dictionary<string, AbstractLimit> slotLimits = new Dictionary<string, AbstractLimit>();
 		private Dictionary<string, UnitMemberType> unitMemberTypes = new Dictionary<string, UnitMemberType>();
+		private List<Category> cats = new List<Category>();
+			
 
 		public UnitType(string id, string typeName, Race parentRace) : base(id, typeName)
 		{
@@ -72,17 +74,48 @@
 		}
 
 		/// <value>
-		/// Gets or sets the <see cref=" Category"/> that this unit type is a member of.
+		/// Gets or sets the default <see cref=" Category"/> that this unit type is a member of.
+		/// If it is not already in the collection of categories then it will be added.
 		/// </value>
 		public virtual Category MainCategory
 		{
 			get
-			{					
+			{ 
 				return mainCat;
 			}
 			set
 			{
 				mainCat = value;
+				AddCategory(value);
+			}
+		}
+		/// <summary>
+		/// Gets the collection of <see cref="Category"/> objects that this UnitType can be a member of
+		/// </summary>
+		public Category[] Categories
+		{
+			get
+			{
+				return cats.ToArray();
+			}
+		}
+		
+		/// <summary>
+		/// Adds a category to the set of categories that this unit can be taken from. The first category added will automatically become the MainCategory.
+		/// </summary>
+		/// <param name="cat">
+		/// A <see cref="Category"/> that this unit can be taken from
+		/// </param>
+		public void AddCategory(Category cat)
+		{
+			if (!cats.Contains(cat))
+			{
+				cats.Add(cat);
+				
+				if (cats.Count == 1)
+				{
+					MainCategory = cat;
+				}
 			}
 		}