diff api/Factories/Xml/WarFoundryXmlRaceFactory.cs @ 231:d1c90159547a

Fixes #236: Race loading should fail cleanly if system doesn't exist * Exception if we get a null game system Also: * Remove unused variable
author IBBoard <dev@ibboard.co.uk>
date Thu, 24 Dec 2009 14:54:43 +0000
parents f097888efcfe
children f5009a00a50d
line wrap: on
line diff
--- a/api/Factories/Xml/WarFoundryXmlRaceFactory.cs	Thu Dec 24 10:33:20 2009 +0000
+++ b/api/Factories/Xml/WarFoundryXmlRaceFactory.cs	Thu Dec 24 14:54:43 2009 +0000
@@ -35,7 +35,7 @@
 		private XmlDocument GetExtraData(Race obj)
 		{
 			XmlDocument extra = null;
-			extraData.TryGetValue(obj, out extra);			
+			extraData.TryGetValue(obj, out extra);
 			return extra;
 		}
 		
@@ -45,7 +45,14 @@
 			string subid = elem.GetAttribute("subid");
 			string systemID = elem.GetAttribute("system");
 			string name = elem.GetAttribute("name");
-			Race race = new Race(id, subid, name, WarFoundryLoader.GetDefault().GetGameSystem(systemID), mainFactory);
+			GameSystem gameSystem = WarFoundryLoader.GetDefault ().GetGameSystem (systemID);
+			
+			if (gameSystem == null)
+			{
+				throw new InvalidFileException("Referenced game system, "+systemID+" did not exist");
+			}
+			
+			Race race = new Race(id, subid, name, gameSystem, mainFactory);
 			StoreExtraData(race, elem);
 			return race;
 		}