comparison api/Objects/Category.cs @ 38:548cfc776f54

Fixes #34 - Remove "Choices" and "Base/Increment" from Category * Remove Choices and Base/Increment from code Re #47: Remove magic numbers * Replace "-1" magic number with WarFoundryCore.INFINITY * Use INFINITY instead of -1 in code * Use INF in schemas instead of -1 * Handle and parse INF as a special value in XML Factory
author IBBoard <dev@ibboard.co.uk>
date Thu, 19 Mar 2009 20:11:07 +0000
parents 306558904c2a
children a5855fcd75ab
comparison
equal deleted inserted replaced
37:465a215a21a2 38:548cfc776f54
12 /// Summary description for Category. 12 /// Summary description for Category.
13 /// </summary> 13 /// </summary>
14 public class Category : WarFoundryObject 14 public class Category : WarFoundryObject
15 { 15 {
16 private int minPts = 0; 16 private int minPts = 0;
17 private int maxPts = -1; 17 private int maxPts = WarFoundryCore.INFINITY;
18 private int minPc = 0; 18 private int minPc = 0;
19 private int maxPc = 100; 19 private int maxPc = 100;
20 private int minChoice = 0;
21 private int maxChoice = -1;
22 private int baseVal = 0;
23 private int incVal = 0;
24 private int incAmount = 0;
25 20
26 21
27 public Category(string id, string name) : base(id, name) 22 public Category(string id, string name) : base(id, name)
28 { 23 {
29 } 24 }
33 { 28 {
34 MinimumPoints = minPoints; 29 MinimumPoints = minPoints;
35 MaximumPoints = maxPoints; 30 MaximumPoints = maxPoints;
36 MinimumPercentage = minPercent; 31 MinimumPercentage = minPercent;
37 MaximumPercentage = maxPercent; 32 MaximumPercentage = maxPercent;
38 BaseValue = baseValue;
39 IncrementValue = incrementValue;
40 IncrementAmount = incrementAmount;
41 } 33 }
42 34
43 protected override string DefaultName() 35 protected override string DefaultName()
44 { 36 {
45 return ""; 37 return "";
58 public int MaximumPoints 50 public int MaximumPoints
59 { 51 {
60 get { return maxPts; } 52 get { return maxPts; }
61 set 53 set
62 { 54 {
63 maxPts = (value >= -1 ? value : -1); 55 maxPts = (value >= 0 ? value : WarFoundryCore.INFINITY);
64 CheckMinimumPoints(); 56 CheckMinimumPoints();
65 } 57 }
66 } 58 }
67 59
68 private void CheckMinimumPoints() 60 private void CheckMinimumPoints()
69 { 61 {
70 if (MinimumPoints > MaximumPoints && MaximumPoints!=-1) 62 if (MinimumPoints > MaximumPoints && MaximumPoints!=WarFoundryCore.INFINITY)
71 { 63 {
72 MinimumPoints = MaximumPoints; 64 MinimumPoints = MaximumPoints;
73 LogNotifier.WarnFormat(GetType(), "Category {0} ({1}) had a minimum points limit greater than its maximum points limit.", Name, ID); 65 LogNotifier.WarnFormat(GetType(), "Category {0} ({1}) had a minimum points limit greater than its maximum points limit.", Name, ID);
74 } 66 }
75 } 67 }
112 { 104 {
113 MinimumPercentage = MaximumPercentage; 105 MinimumPercentage = MaximumPercentage;
114 LogNotifier.WarnFormat(GetType(), "Category {0} ({1}) had a minimum percentage limit greater than its maximum percentage limit.", Name, ID); 106 LogNotifier.WarnFormat(GetType(), "Category {0} ({1}) had a minimum percentage limit greater than its maximum percentage limit.", Name, ID);
115 } 107 }
116 } 108 }
117
118 public int MinimumChoices
119 {
120 get { return minChoice; }
121 set
122 {
123 minChoice = (value >= 0 ? value : 0);
124 CheckMinimumChoices();
125 }
126 }
127
128 public int MaximumChoices
129 {
130 get { return maxChoice; }
131 set
132 {
133 maxChoice = (value >= -1 ? value : -1);
134 CheckMinimumChoices();
135 }
136 }
137
138 private void CheckMinimumChoices()
139 {
140 if (MinimumPercentage > MaximumPercentage && MaximumPercentage!=-1)
141 {
142 MinimumPercentage = MaximumPercentage;
143 LogNotifier.WarnFormat(GetType(), "Category {0} ({1}) had a minimum number of choices greater than its maximum number of choices.", Name, ID);
144 }
145 }
146
147 public int BaseValue
148 {
149 get { return baseVal; }
150 set { baseVal = (value >= 0 ? value : 0); }
151 }
152
153 public int IncrementValue
154 {
155 get { return incVal; }
156 set { incVal = (value >= 0 ? value : 0); }
157 }
158
159 public int IncrementAmount
160 {
161 get { return incAmount; }
162 set { incAmount = (value >= 0 ? value : 0); }
163 }
164 } 109 }
165 } 110 }