Mercurial > repos > IBDev-IBBoard.WarFoundry.API
changeset 452:b671085871b7
Re #379: Fix validation of requirements to check for unit
* Separate messages for adding unit and validating army.
* Make translation easier (once we add it in)
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sun, 29 Jan 2012 19:39:25 +0000 |
parents | 676f5ce04176 |
children | dace3b7779ca |
files | API/Objects/Requirement/RequiresAtLeastNUnitsRequirement.cs API/Objects/Requirement/UnitRequiresAtLeastNUnitsRequirement.cs |
diffstat | 2 files changed, 25 insertions(+), 18 deletions(-) [+] |
line wrap: on
line diff
--- a/API/Objects/Requirement/RequiresAtLeastNUnitsRequirement.cs Sat Jan 28 16:57:59 2012 +0000 +++ b/API/Objects/Requirement/RequiresAtLeastNUnitsRequirement.cs Sun Jan 29 19:39:25 2012 +0000 @@ -20,7 +20,6 @@ public RequiresAtLeastNUnitsRequirement(params UnitType[] requiredUnitTypes) { - FailureStringPrefix = "Army must contain: "; requiredTypes = new List<UnitCountRequirementData>(); foreach (UnitType unitType in requiredUnitTypes) @@ -29,7 +28,6 @@ } } - public override string RequirementID { get @@ -38,7 +36,7 @@ } } - protected override bool TypeEquals (object obj) + protected override bool TypeEquals(object obj) { RequiresAtLeastNUnitsRequirement otherReq = (RequiresAtLeastNUnitsRequirement)obj; if (!Collections.Collections.AreEqual(requiredTypes, otherReq.requiredTypes)) @@ -98,7 +96,7 @@ return isApplicable; } - protected UnitType GetUnitTypeFromObject (WarFoundryObject toObject) + protected UnitType GetUnitTypeFromObject(WarFoundryObject toObject) { UnitType unitType = null; @@ -114,7 +112,7 @@ return unitType; } - private bool IsApplicable (UnitType unitType) + private bool IsApplicable(UnitType unitType) { bool isApplicable = false; foreach (UnitCountRequirementData requirement in requiredTypes) @@ -174,7 +172,7 @@ /// <param name='unitType'> /// The unit type to require. /// </param> - public void AddUnitTypeRequirement (UnitType unitType) + public void AddUnitTypeRequirement(UnitType unitType) { AddUnitTypeRequirement(unitType, 1); } @@ -204,15 +202,11 @@ return isValid; } - protected string FailureStringPrefix { get; set; } + protected virtual string ValidationFailedMessage { get { return "Army must contain: {0}."; } } protected override string GetValidationFailedMessage(Army army) { - StringBuilder sb = new StringBuilder(); - sb.Append(FailureStringPrefix); - sb.Append(String.Join("; ", GetFailedRequirements(army).ToArray())); - sb.Append("."); - return sb.ToString(); + return String.Format(ValidationFailedMessage, String.Join("; ", GetFailedRequirements(army).ToArray())); } private List<string> GetFailedRequirements(Army army) @@ -232,13 +226,11 @@ return failures; } + protected virtual string AllowsAddingFailedMessage { get { return ValidationFailedMessage; } } + protected override string GetAllowsAddingFailedMessage(UnitType toAdd, Army toArmy) { - StringBuilder sb = new StringBuilder(); - sb.Append(FailureStringPrefix); - sb.Append(String.Join("; ", GetFailedAddingRequirements(toAdd, toArmy).ToArray())); - sb.Append("."); - return sb.ToString(); + return String.Format(AllowsAddingFailedMessage, String.Join("; ", GetFailedAddingRequirements(toAdd, toArmy).ToArray())); } private List<string> GetFailedAddingRequirements(UnitType unitType, Army army)
--- a/API/Objects/Requirement/UnitRequiresAtLeastNUnitsRequirement.cs Sat Jan 28 16:57:59 2012 +0000 +++ b/API/Objects/Requirement/UnitRequiresAtLeastNUnitsRequirement.cs Sun Jan 29 19:39:25 2012 +0000 @@ -17,7 +17,6 @@ public UnitRequiresAtLeastNUnitsRequirement(UnitType requirementOn) : base() { requirementOnType = requirementOn; - FailureStringPrefix = "Army contains " + requirementOn.Name + " and so must contain: "; } protected override bool IsApplicable(WarFoundryObject toObjectAdded) @@ -39,6 +38,22 @@ { return IsApplicable(toArmy) ? base.ValidatesArmy(toArmy) : Validation.NotApplicable; } + + protected override string ValidationFailedMessage + { + get + { + return "Army contains " + requirementOnType.Name + " and so must contain: {0}."; + } + } + + protected override string AllowsAddingFailedMessage + { + get + { + return "Army would contain " + requirementOnType.Name + " and so must contain: {0}."; + } + } } }