Mercurial > repos > IBBoard.WarFoundry.API
annotate API/Objects/Requirement/RequirementHandler.cs @ 361:8781e53c59bb
Re #345: Add failure message to requirements
* Return message for each failure (don't stop at first one)
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sun, 01 May 2011 14:45:56 +0000 |
parents | 47712a323cf2 |
children | 506af4cbe3f5 |
rev | line source |
---|---|
353 | 1 // This file (RequirementHandler.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2011 IBBoard |
2 // | |
3 // The file and the library/program it is in are licensed and distributed, without warranty, under the GNU Affero GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license. | |
4 using System; | |
361
8781e53c59bb
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
355
diff
changeset
|
5 using System.Collections.Generic; |
353 | 6 |
7 namespace IBBoard.WarFoundry.API.Objects.Requirement | |
8 { | |
9 /// <summary> | |
10 /// The requirement handler that tests the validity of armies. | |
11 /// </summary> | |
12 public class RequirementHandler | |
13 { | |
14 private RequirementHandler() | |
15 { | |
16 } | |
17 | |
18 public static Validation ValidateArmy (Army army) | |
361
8781e53c59bb
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
355
diff
changeset
|
19 { |
8781e53c59bb
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
355
diff
changeset
|
20 ICollection<string> ignored; |
8781e53c59bb
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
355
diff
changeset
|
21 return ValidateArmy(army, out ignored); |
8781e53c59bb
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
355
diff
changeset
|
22 } |
8781e53c59bb
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
355
diff
changeset
|
23 |
8781e53c59bb
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
355
diff
changeset
|
24 public static Validation ValidateArmy (Army army, out ICollection<string> failureMessages) |
353 | 25 { |
361
8781e53c59bb
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
355
diff
changeset
|
26 Validation result = Validation.Passed; |
8781e53c59bb
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
355
diff
changeset
|
27 failureMessages = new List<string>(); |
353 | 28 |
29 foreach (IRequirement requirement in army.GetRequirements()) | |
30 { | |
31 if (!Validates.AsOkay(requirement.ValidatesArmy(army))) | |
32 { | |
361
8781e53c59bb
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
355
diff
changeset
|
33 result = Validation.Failed; |
8781e53c59bb
Re #345: Add failure message to requirements
IBBoard <dev@ibboard.co.uk>
parents:
355
diff
changeset
|
34 failureMessages.Add(requirement.GetValidationMessage(army)); |
353 | 35 } |
36 } | |
37 | |
38 return result; | |
39 } | |
355 | 40 |
41 public static Validation AllowsAdding(UnitType unitType, Army army) | |
42 { | |
43 Validation result = Validation.Passed; | |
44 | |
45 foreach (IRequirement requirement in army.GetRequirements()) | |
46 { | |
47 if (!Validates.AsOkay(requirement.AllowsAdding(unitType, army))) | |
48 { | |
49 result = Validation.Failed; | |
50 break; | |
51 } | |
52 } | |
53 | |
54 return result; | |
55 } | |
353 | 56 } |
57 } | |
58 |