comparison API/Factories/Requirement/UnitRequiresAtLeastNUnitsRequirementFactory.cs @ 374:13793f3a2a2e

Re #351: Add extensible requirement handling method * Add initial conditional to fetching of factory * Exception if content isn't correct
author IBBoard <dev@ibboard.co.uk>
date Sat, 02 Jul 2011 14:59:45 +0000
parents e10630f39ec2
children d9bf78a8f517
comparison
equal deleted inserted replaced
373:e10630f39ec2 374:13793f3a2a2e
25 private void AddRequirements(UnitRequiresAtLeastNUnitsRequirement req, Race race, string data) 25 private void AddRequirements(UnitRequiresAtLeastNUnitsRequirement req, Race race, string data)
26 { 26 {
27 foreach (string requirement in data.Split('|')) 27 foreach (string requirement in data.Split('|'))
28 { 28 {
29 string[] requirementParts = requirement.Split(':'); 29 string[] requirementParts = requirement.Split(':');
30 UnitType unitType = race.GetUnitType(requirementParts[0]);
31
32 if (unitType == null)
33 {
34 throw new InvalidRequirementException(String.Format("Invalid unit type '{0}' for 'Requires at least N units' requirement", requirementParts[0]));
35 }
36
30 if (requirementParts.Length == 2) 37 if (requirementParts.Length == 2)
31 { 38 {
32 req.AddUnitTypeRequirement(race.GetUnitType(requirementParts[0]), Int32.Parse(requirementParts[1])); 39 req.AddUnitTypeRequirement(unitType, Int32.Parse(requirementParts[1]));
33 } 40 }
34 else 41 else
35 { 42 {
36 req.AddUnitTypeRequirement(race.GetUnitType(requirementParts[0])); 43 req.AddUnitTypeRequirement(unitType);
37 } 44 }
38 } 45 }
39 } 46 }
40 } 47 }
41 } 48 }