diff 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
line wrap: on
line diff
--- a/API/Factories/Requirement/UnitRequiresAtLeastNUnitsRequirementFactory.cs	Tue Jun 14 14:27:14 2011 +0000
+++ b/API/Factories/Requirement/UnitRequiresAtLeastNUnitsRequirementFactory.cs	Sat Jul 02 14:59:45 2011 +0000
@@ -27,13 +27,20 @@
 			foreach (string requirement in data.Split('|'))
 			{
 				string[] requirementParts = requirement.Split(':');
+				UnitType unitType = race.GetUnitType(requirementParts[0]);
+
+				if (unitType == null)
+				{
+					throw new InvalidRequirementException(String.Format("Invalid unit type '{0}' for 'Requires at least N units' requirement", requirementParts[0]));
+				}
+
 				if (requirementParts.Length == 2)
 				{
-					req.AddUnitTypeRequirement(race.GetUnitType(requirementParts[0]), Int32.Parse(requirementParts[1]));
+					req.AddUnitTypeRequirement(unitType, Int32.Parse(requirementParts[1]));
 				}
 				else
 				{
-					req.AddUnitTypeRequirement(race.GetUnitType(requirementParts[0]));
+					req.AddUnitTypeRequirement(unitType);
 				}
 			}
 		}