Mercurial > repos > IBBoard.WarFoundry.API
view api/Objects/Category.cs @ 14:0770e5cbba7c
Closes #21 - File loading in order
* Reworked LoadFiles to smaller methods for readability (also re #10) and structure
* Now determine expected load return before loading then load all "expected GameSystem" before "expected Race"
* Make "can load as race/game system/army" methods public in interface
Re #22 - Get errored file loading
* Created FileLoadFailure class and made LoadFiles return a list of them
Also
* Some code cleanup
* Change to DictionaryUtils calls
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sun, 25 Jan 2009 14:03:20 +0000 |
parents | ac232763858b |
children | 306558904c2a |
line wrap: on
line source
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); } } } }