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