Mercurial > repos > snowblizz-super-API-ideas
changeset 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 | c19e61262400 |
children | 0dd8dbe8afe9 |
files | API/Objects/Requirement/RequirementHandler.cs |
diffstat | 1 files changed, 26 insertions(+), 18 deletions(-) [+] |
line wrap: on
line diff
--- a/API/Objects/Requirement/RequirementHandler.cs Sun May 01 15:39:05 2011 +0000 +++ b/API/Objects/Requirement/RequirementHandler.cs Sun May 01 19:16:23 2011 +0000 @@ -14,40 +14,48 @@ private RequirementHandler() { } - - public static Validation ValidateArmy (Army army) + + + public static Validation ValidateArmy(Army army) { ICollection<string> ignored; return ValidateArmy(army, out ignored); } - public static Validation ValidateArmy (Army army, out ICollection<string> failureMessages) - { + public static Validation ValidateArmy(Army army, out ICollection<string> failureMessages) + { Validation result = Validation.Passed; - failureMessages = new List<string>(); - - foreach (IRequirement requirement in army.GetRequirements()) - { - if (!Validates.AsOkay(requirement.ValidatesArmy(army))) - { + failureMessages = new List<string>(); + + foreach (IRequirement requirement in army.GetRequirements()) + { + if (!Validates.AsOkay(requirement.ValidatesArmy(army))) + { result = Validation.Failed; - failureMessages.Add(requirement.GetValidationMessage(army)); - } - } - - return result; - } + failureMessages.Add(requirement.GetValidationMessage(army)); + } + } + + return result; + } public static Validation AllowsAdding(UnitType unitType, Army army) { + ICollection<string> ignored; + return AllowsAdding(unitType, army, out ignored); + } + + public static Validation AllowsAdding(UnitType unitType, Army army, out ICollection<string> failureMessages) + { Validation result = Validation.Passed; - + failureMessages = new List<string>(); + foreach (IRequirement requirement in army.GetRequirements()) { if (!Validates.AsOkay(requirement.AllowsAdding(unitType, army))) { result = Validation.Failed; - break; + failureMessages.Add(requirement.GetAllowsAddingMessage(unitType, army)); } }