comparison API/Objects/Requirement/RequirementHandler.cs @ 363:506af4cbe3f5

Fixes #33: Add centralised requirement checker * Implement validation with messages for adding (Other features added under #27 and not separately marked)
author IBBoard <dev@ibboard.co.uk>
date Sun, 01 May 2011 19:16:23 +0000
parents 8781e53c59bb
children 676f5ce04176
comparison
equal deleted inserted replaced
362:c19e61262400 363:506af4cbe3f5
13 { 13 {
14 private RequirementHandler() 14 private RequirementHandler()
15 { 15 {
16 } 16 }
17 17
18 public static Validation ValidateArmy (Army army) 18
19 public static Validation ValidateArmy(Army army)
19 { 20 {
20 ICollection<string> ignored; 21 ICollection<string> ignored;
21 return ValidateArmy(army, out ignored); 22 return ValidateArmy(army, out ignored);
22 } 23 }
23 24
24 public static Validation ValidateArmy (Army army, out ICollection<string> failureMessages) 25 public static Validation ValidateArmy(Army army, out ICollection<string> failureMessages)
25 { 26 {
26 Validation result = Validation.Passed; 27 Validation result = Validation.Passed;
27 failureMessages = new List<string>(); 28 failureMessages = new List<string>();
28 29
29 foreach (IRequirement requirement in army.GetRequirements()) 30 foreach (IRequirement requirement in army.GetRequirements())
38 return result; 39 return result;
39 } 40 }
40 41
41 public static Validation AllowsAdding(UnitType unitType, Army army) 42 public static Validation AllowsAdding(UnitType unitType, Army army)
42 { 43 {
44 ICollection<string> ignored;
45 return AllowsAdding(unitType, army, out ignored);
46 }
47
48 public static Validation AllowsAdding(UnitType unitType, Army army, out ICollection<string> failureMessages)
49 {
43 Validation result = Validation.Passed; 50 Validation result = Validation.Passed;
44 51 failureMessages = new List<string>();
52
45 foreach (IRequirement requirement in army.GetRequirements()) 53 foreach (IRequirement requirement in army.GetRequirements())
46 { 54 {
47 if (!Validates.AsOkay(requirement.AllowsAdding(unitType, army))) 55 if (!Validates.AsOkay(requirement.AllowsAdding(unitType, army)))
48 { 56 {
49 result = Validation.Failed; 57 result = Validation.Failed;
50 break; 58 failureMessages.Add(requirement.GetAllowsAddingMessage(unitType, army));
51 } 59 }
52 } 60 }
53 61
54 return result; 62 return result;
55 } 63 }