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 diff
     1.1 --- a/API/Objects/Requirement/RequirementHandler.cs	Sun May 01 15:39:05 2011 +0000
     1.2 +++ b/API/Objects/Requirement/RequirementHandler.cs	Sun May 01 19:16:23 2011 +0000
     1.3 @@ -14,40 +14,48 @@
     1.4  		private RequirementHandler()
     1.5  		{
     1.6  		}
     1.7 -
     1.8 -		public static Validation ValidateArmy (Army army)
     1.9 +
    1.10 +
    1.11 +		public static Validation ValidateArmy(Army army)
    1.12  		{
    1.13  			ICollection<string> ignored;
    1.14  			return ValidateArmy(army, out ignored);
    1.15  		}
    1.16  
    1.17 -		public static Validation ValidateArmy (Army army, out ICollection<string> failureMessages)
    1.18 -		{
    1.19 +		public static Validation ValidateArmy(Army army, out ICollection<string> failureMessages)
    1.20 +		{
    1.21  			Validation result = Validation.Passed;
    1.22 -			failureMessages = new List<string>();
    1.23 -
    1.24 -			foreach (IRequirement requirement in army.GetRequirements())
    1.25 -			{
    1.26 -				if (!Validates.AsOkay(requirement.ValidatesArmy(army)))
    1.27 -				{
    1.28 +			failureMessages = new List<string>();
    1.29 +
    1.30 +			foreach (IRequirement requirement in army.GetRequirements())
    1.31 +			{
    1.32 +				if (!Validates.AsOkay(requirement.ValidatesArmy(army)))
    1.33 +				{
    1.34  					result = Validation.Failed;
    1.35 -					failureMessages.Add(requirement.GetValidationMessage(army));
    1.36 -				}
    1.37 -			}
    1.38 -
    1.39 -			return result;
    1.40 -		}
    1.41 +					failureMessages.Add(requirement.GetValidationMessage(army));
    1.42 +				}
    1.43 +			}
    1.44 +
    1.45 +			return result;
    1.46 +		}
    1.47  
    1.48  		public static Validation AllowsAdding(UnitType unitType, Army army)
    1.49  		{
    1.50 +			ICollection<string> ignored;
    1.51 +			return AllowsAdding(unitType, army, out ignored);
    1.52 +		}
    1.53 +
    1.54 +		public static Validation AllowsAdding(UnitType unitType, Army army, out ICollection<string> failureMessages)
    1.55 +		{
    1.56  			Validation result = Validation.Passed;
    1.57 -
    1.58 +			failureMessages = new List<string>();
    1.59 +			
    1.60  			foreach (IRequirement requirement in army.GetRequirements())
    1.61  			{
    1.62  				if (!Validates.AsOkay(requirement.AllowsAdding(unitType, army)))
    1.63  				{
    1.64  					result = Validation.Failed;
    1.65 -					break;
    1.66 +					failureMessages.Add(requirement.GetAllowsAddingMessage(unitType, army));
    1.67  				}
    1.68  			}
    1.69