view api/Objects/Category.cs @ 41:422ddd5fedd1

Re #48 - Require schemas to validate * Restructure schema caching so that it warns instead of exceptioning - allows a missing schema to not kill an unrelated file load * Fix exception handling for GameSystems while working out where exceptions were being caught Current situation: Missing Race/System schema stops file loading but missing cat/core schema doesn't
author IBBoard <dev@ibboard.co.uk>
date Sat, 21 Mar 2009 20:52:26 +0000
parents 548cfc776f54
children a5855fcd75ab
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 = WarFoundryCore.INFINITY;
		private int minPc = 0;
		private int maxPc = 100;

		
		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;
		}

		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 >= 0 ? value : WarFoundryCore.INFINITY);
				CheckMinimumPoints();
			}
		}

		private void CheckMinimumPoints()
		{
			if (MinimumPoints > MaximumPoints && MaximumPoints!=WarFoundryCore.INFINITY)
			{
				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);
			}
		}
	}
}