comparison api/Objects/AbstractUnitEquipmentItemSelection.cs @ 183:36adabb1c3ea

Re #198: Add slots with counts to units * Remove old Min/MaxNumber/Percentage for equipment and replace with limits * Refactor equipment selections and remove "numeric for ratio" as the limits handle the upper/lower limit differences * Stop equipment selections taking an amount of 0 for out of range amounts * Add "IsValid" property for selections * Removed use of "-1" as an 'infinity' limit - now use 100% as a more correct value * Change "unlimitedSize" limit in schema to "unitSizeLimit"
author IBBoard <dev@ibboard.co.uk>
date Mon, 26 Oct 2009 20:55:04 +0000
parents 2f3cafb69799
children dce340f9cedc
comparison
equal deleted inserted replaced
182:6fe336109128 183:36adabb1c3ea
44 { 44 {
45 return amountTaken; 45 return amountTaken;
46 } 46 }
47 set 47 set
48 { 48 {
49 if (IsValidValue(value)) 49 amountTaken = value;
50 { 50
51 amountTaken = value; 51 if (!IsValidValue(value))
52 }
53 else
54 { 52 {
55 //Fire validation failed event (once we have one) 53 //Fire validation failed event (once we have one)
56 } 54 }
57 } 55 }
58 } 56 }
59 57
60 protected bool IsValidValue(double newValue) 58 public bool IsValid
61 { 59 {
62 return IsInRange(newValue); 60 get
61 {
62 return IsValidValue(AmountTaken) && IsInRange(AmountTaken);
63 }
63 } 64 }
64 65
65 protected abstract bool IsInRange(double newValue); 66 protected virtual bool IsValidValue(double newValue)
67 {
68 return true;
69 }
70
71 protected bool IsInRange(double newValue)
72 {
73 int unitSize = EquipmentForUnit.Size;
74 int minLimit = EquipmentItem.MinLimit.GetLimit(unitSize);
75 int maxLimit = EquipmentItem.MaxLimit.GetLimit(unitSize);
76 return (minLimit <= newValue) && (newValue <= maxLimit);
77 }
66 78
67 public double TotalCost 79 public double TotalCost
68 { 80 {
69 get 81 get
70 { 82 {