Mercurial > repos > snowblizz-super-API-ideas
changeset 373:e10630f39ec2
Re #351: Add extensible requirement handling method
* Add handling of different requirements:
* Multiple unit types
* Unit types with numbers
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Tue, 14 Jun 2011 14:27:14 +0000 |
parents | 2f8b2467ba99 |
children | 13793f3a2a2e |
files | API/Factories/Requirement/UnitRequiresAtLeastNUnitsRequirementFactory.cs |
diffstat | 1 files changed, 19 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/API/Factories/Requirement/UnitRequiresAtLeastNUnitsRequirementFactory.cs Tue Jun 14 13:58:16 2011 +0000 +++ b/API/Factories/Requirement/UnitRequiresAtLeastNUnitsRequirementFactory.cs Tue Jun 14 14:27:14 2011 +0000 @@ -14,12 +14,29 @@ //Do nothing special } - public UnitRequiresAtLeastNUnitsRequirement CreateRequirement (UnitType type, string data) + public UnitRequiresAtLeastNUnitsRequirement CreateRequirement(UnitType type, string data) { UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(type); - req.AddUnitTypeRequirement(type.Race.GetUnitType(data)); + Race race = type.Race; + AddRequirements(req, race, data); return req; } + + private void AddRequirements(UnitRequiresAtLeastNUnitsRequirement req, Race race, string data) + { + foreach (string requirement in data.Split('|')) + { + string[] requirementParts = requirement.Split(':'); + if (requirementParts.Length == 2) + { + req.AddUnitTypeRequirement(race.GetUnitType(requirementParts[0]), Int32.Parse(requirementParts[1])); + } + else + { + req.AddUnitTypeRequirement(race.GetUnitType(requirementParts[0])); + } + } + } } }