Mercurial > repos > IBDev-IBBoard.WarFoundry.API
annotate api/Objects/Category.cs @ 12:ac232763858b
Re #9 - Make WarFoundry API use smaller methods
* Obselete old Category and UnitType constructors and add minimal constructors
* Add setters to properties where needed
* Add value sanity checking to Category and UnitType
* Set default values for percentages, choices and points for Category
* Make XML factory use new constructor and setter properties
* Add DuplicateItemException to project file
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sun, 18 Jan 2009 20:52:29 +0000 |
parents | 613bc5eaac59 |
children | 306558904c2a |
rev | line source |
---|---|
0 | 1 using System; |
2 using System.Xml; | |
12
ac232763858b
Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
3 using IBBoard.Logging; |
0 | 4 |
5 namespace IBBoard.WarFoundry.API.Objects | |
6 { | |
7 /// <summary> | |
8 /// Summary description for Category. | |
9 /// </summary> | |
10 public class Category : WarFoundryObject | |
11 { | |
12
ac232763858b
Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
12 private int minPts = 0; |
ac232763858b
Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
13 private int maxPts = -1; |
ac232763858b
Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
14 private int minPc = 0; |
ac232763858b
Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
15 private int maxPc = 100; |
ac232763858b
Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
16 private int minChoice = 0; |
ac232763858b
Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
17 private int maxChoice = -1; |
ac232763858b
Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
18 private int baseVal = 0; |
ac232763858b
Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
19 private int incVal = 0; |
ac232763858b
Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
20 private int incAmount = 0; |
ac232763858b
Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
21 |
ac232763858b
Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
22 |
ac232763858b
Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
23 public Category(string id, string name) : base(id, name) |
ac232763858b
Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
24 { |
ac232763858b
Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
25 } |
ac232763858b
Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
26 |
ac232763858b
Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
27 [Obsolete("Use the two argument constructor and the appropriate 'set' methods")] |
0 | 28 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) |
29 { | |
12
ac232763858b
Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
30 MinimumPoints = minPoints; |
ac232763858b
Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
31 MaximumPoints = maxPoints; |
ac232763858b
Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
32 MinimumPercentage = minPercent; |
ac232763858b
Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
33 MaximumPercentage = maxPercent; |
ac232763858b
Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
34 BaseValue = baseValue; |
ac232763858b
Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
35 IncrementValue = incrementValue; |
ac232763858b
Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
36 IncrementAmount = incrementAmount; |
0 | 37 } |
38 | |
39 protected override string DefaultName() | |
40 { | |
41 return ""; | |
42 } | |
43 | |
44 public int MinimumPoints | |
45 { | |
46 get { return minPts; } | |
12
ac232763858b
Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
47 set |
ac232763858b
Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
48 { |
ac232763858b
Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
49 minPts = (value >= 0 ? value : 0); |
ac232763858b
Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
50 CheckMinimumPoints(); |
ac232763858b
Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
51 } |
0 | 52 } |
53 | |
54 public int MaximumPoints | |
55 { | |
56 get { return maxPts; } | |
12
ac232763858b
Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
57 set |
ac232763858b
Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
58 { |
ac232763858b
Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
59 maxPts = (value >= -1 ? value : -1); |
ac232763858b
Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
60 CheckMinimumPoints(); |
ac232763858b
Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
61 } |
ac232763858b
Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
62 } |
ac232763858b
Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
63 |
ac232763858b
Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
64 private void CheckMinimumPoints() |
ac232763858b
Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
65 { |
ac232763858b
Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
66 if (MinimumPoints > MaximumPoints && MaximumPoints!=-1) |
ac232763858b
Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
67 { |
ac232763858b
Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
68 MinimumPoints = MaximumPoints; |
ac232763858b
Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
69 LogNotifier.WarnFormat(GetType(), "Category {0} ({1}) had a minimum points limit greater than its maximum points limit.", Name, ID); |
ac232763858b
Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
70 } |
0 | 71 } |
72 | |
73 public int MinimumPercentage | |
74 { | |
75 get { return minPc; } | |
12
ac232763858b
Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
76 set |
ac232763858b
Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
77 { |
ac232763858b
Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
78 minPc = (value >= 0 ? value : 0); |
ac232763858b
Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
79 CheckMinimumPercentage(); |
ac232763858b
Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
80 } |
0 | 81 } |
82 | |
83 public int MaximumPercentage | |
84 { | |
85 get { return maxPc; } | |
12
ac232763858b
Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
86 set |
ac232763858b
Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
87 { |
ac232763858b
Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
88 if (value < 0) |
ac232763858b
Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
89 { |
ac232763858b
Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
90 maxPc = 0; |
ac232763858b
Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
91 } |
ac232763858b
Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
92 else if (value > 100) |
ac232763858b
Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
93 { |
ac232763858b
Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
94 maxPc = 100; |
ac232763858b
Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
95 } |
ac232763858b
Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
96 else |
ac232763858b
Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
97 { |
ac232763858b
Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
98 maxPc = value; |
ac232763858b
Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
99 } |
ac232763858b
Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
100 |
ac232763858b
Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
101 CheckMinimumPercentage(); |
ac232763858b
Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
102 } |
ac232763858b
Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
103 } |
ac232763858b
Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
104 |
ac232763858b
Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
105 private void CheckMinimumPercentage() |
ac232763858b
Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
106 { |
ac232763858b
Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
107 if (MinimumPercentage > MaximumPercentage) |
ac232763858b
Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
108 { |
ac232763858b
Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
109 MinimumPercentage = MaximumPercentage; |
ac232763858b
Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
110 LogNotifier.WarnFormat(GetType(), "Category {0} ({1}) had a minimum percentage limit greater than its maximum percentage limit.", Name, ID); |
ac232763858b
Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
111 } |
0 | 112 } |
113 | |
114 public int MinimumChoices | |
115 { | |
116 get { return minChoice; } | |
12
ac232763858b
Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
117 set |
ac232763858b
Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
118 { |
ac232763858b
Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
119 minChoice = (value >= 0 ? value : 0); |
ac232763858b
Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
120 CheckMinimumChoices(); |
ac232763858b
Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
121 } |
0 | 122 } |
123 | |
124 public int MaximumChoices | |
125 { | |
126 get { return maxChoice; } | |
12
ac232763858b
Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
127 set |
ac232763858b
Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
128 { |
ac232763858b
Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
129 maxChoice = (value >= -1 ? value : -1); |
ac232763858b
Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
130 CheckMinimumChoices(); |
ac232763858b
Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
131 } |
ac232763858b
Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
132 } |
ac232763858b
Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
133 |
ac232763858b
Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
134 private void CheckMinimumChoices() |
ac232763858b
Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
135 { |
ac232763858b
Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
136 if (MinimumPercentage > MaximumPercentage && MaximumPercentage!=-1) |
ac232763858b
Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
137 { |
ac232763858b
Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
138 MinimumPercentage = MaximumPercentage; |
ac232763858b
Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
139 LogNotifier.WarnFormat(GetType(), "Category {0} ({1}) had a minimum number of choices greater than its maximum number of choices.", Name, ID); |
ac232763858b
Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
140 } |
0 | 141 } |
142 | |
143 public int BaseValue | |
144 { | |
145 get { return baseVal; } | |
12
ac232763858b
Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
146 set { baseVal = (value >= 0 ? value : 0); } |
0 | 147 } |
148 | |
149 public int IncrementValue | |
150 { | |
151 get { return incVal; } | |
12
ac232763858b
Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
152 set { incVal = (value >= 0 ? value : 0); } |
0 | 153 } |
154 | |
155 public int IncrementAmount | |
156 { | |
157 get { return incAmount; } | |
12
ac232763858b
Re #9 - Make WarFoundry API use smaller methods
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
158 set { incAmount = (value >= 0 ? value : 0); } |
0 | 159 } |
160 } | |
161 } |