view api/Objects/Category.cs @ 15:306558904c2a

Re #1 - LGPL license all code * Add LGPL header to all files * Add COPYING.LGPL and COPYING.GPL with content of license
author IBBoard <dev@ibboard.co.uk>
date Sun, 25 Jan 2009 14:50:36 +0000
parents ac232763858b
children 548cfc776f54
line wrap: on
line source

// This file (Category.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2009 IBBoard.
//
// The file and the library/program it is in are licensed under the GNU LGPL license, either version 3 of the License or (at your option) any later version. Please see COPYING.LGPL for more information and the full license.

using System;
using System.Xml;
using IBBoard.Logging;

namespace IBBoard.WarFoundry.API.Objects
{
	/// <summary>
	/// Summary description for Category.
	/// </summary>
	public class Category : WarFoundryObject
	{
		private int minPts = 0;
		private int maxPts = -1;
		private int minPc = 0;
		private int maxPc = 100;
		private int minChoice = 0;
		private int maxChoice = -1;
		private int baseVal = 0;
		private int incVal = 0;
		private int incAmount = 0;

		
		public Category(string id, string name) : base(id, name)
		{
		}

		[Obsolete("Use the two argument constructor and the appropriate 'set' methods")]
		public Category(string id, string name, int minPoints, int maxPoints, int minPercent, int maxPercent, int minChoices, int maxChoices, int baseValue, int incrementValue, int incrementAmount) : base(id, name)
		{
			MinimumPoints = minPoints;
			MaximumPoints = maxPoints;
			MinimumPercentage = minPercent;
			MaximumPercentage = maxPercent;
			BaseValue = baseValue;
			IncrementValue = incrementValue;
			IncrementAmount = incrementAmount;
		}

		protected override string DefaultName()
		{
			return "";
		}

		public int MinimumPoints
		{
			get { return minPts; }
			set
			{
				minPts = (value >= 0 ? value : 0);
				CheckMinimumPoints();
			}
		}

		public int MaximumPoints
		{
			get { return maxPts; }
			set
			{
				maxPts = (value >= -1 ? value : -1);
				CheckMinimumPoints();
			}
		}

		private void CheckMinimumPoints()
		{
			if (MinimumPoints > MaximumPoints && MaximumPoints!=-1)
			{
				MinimumPoints = MaximumPoints;
				LogNotifier.WarnFormat(GetType(), "Category {0} ({1}) had a minimum points limit greater than its maximum points limit.", Name, ID);
			}
		}
		
		public int MinimumPercentage
		{
			get { return minPc; }
			set
			{
				minPc = (value >= 0 ? value : 0);
				CheckMinimumPercentage();
			}
		}

		public int MaximumPercentage
		{
			get { return maxPc; }
			set
			{
				if (value < 0)
				{
					maxPc = 0;
				}
				else if (value > 100)
				{
					maxPc = 100;
				}
				else
				{
					maxPc = value;
				}
				
				CheckMinimumPercentage();
			}
		}

		private void CheckMinimumPercentage()
		{
			if (MinimumPercentage > MaximumPercentage)
			{
				MinimumPercentage = MaximumPercentage;
				LogNotifier.WarnFormat(GetType(), "Category {0} ({1}) had a minimum percentage limit greater than its maximum percentage limit.", Name, ID);
			}
		}

		public int MinimumChoices
		{
			get { return minChoice; }
			set
			{
				minChoice = (value >= 0 ? value : 0);
				CheckMinimumChoices();
			}
		}

		public int MaximumChoices
		{
			get { return maxChoice; }
			set
			{
				maxChoice = (value >= -1 ? value : -1);
				CheckMinimumChoices();
			}
		}

		private void CheckMinimumChoices()
		{
			if (MinimumPercentage > MaximumPercentage && MaximumPercentage!=-1)
			{
				MinimumPercentage = MaximumPercentage;
				LogNotifier.WarnFormat(GetType(), "Category {0} ({1}) had a minimum number of choices greater than its maximum number of choices.", Name, ID);
			}
		}

		public int BaseValue
		{
			get { return baseVal; }
			set { baseVal = (value >= 0 ? value : 0); }
		}

		public int IncrementValue
		{
			get { return incVal; }
			set { incVal = (value >= 0 ? value : 0); }
		}

		public int IncrementAmount
		{
			get { return incAmount; }
			set { incAmount = (value >= 0 ? value : 0); }
		}
	}
}