diff api/WarFoundryLoader.cs @ 226:c931684f9024

Re #234: Invalid data file doesn't stop load * Add internal methods to remove game systems or races that fail to load * Add error handling on XML CompleteLoading so that game system or race is removed, but make sure not to affect error
author IBBoard <dev@ibboard.co.uk>
date Sat, 19 Dec 2009 15:40:50 +0000
parents 721891008b5c
children a36a0e9cc05d
line wrap: on
line diff
--- a/api/WarFoundryLoader.cs	Thu Dec 17 20:52:22 2009 +0000
+++ b/api/WarFoundryLoader.cs	Sat Dec 19 15:40:50 2009 +0000
@@ -588,6 +588,15 @@
 			GameSystem system;
 			systemsTable.TryGetValue(systemID.ToLower(), out system);
 			return system;
+		}
+
+		/// <summary>
+		/// Removes a loaded <see cref="GameSystem"/>. Used when a GameSystem fails to complete loading
+		/// </summary>
+		/// <param name="system">The GameSystem to remove</param>
+		internal void RemoveGameSystem(GameSystem system)
+		{
+			systemsTable.Remove(system.ID.ToLower());
 		}
 
 		/// <summary>
@@ -727,26 +736,39 @@
 			}
 			
 			Race race = null;
-			
-			systemID = systemID.ToLower();
-			raceID = raceID.ToLower();
-			raceSubID = raceSubID.ToLower();
-
-			Dictionary<string, Dictionary<string, Race>> races;	
-			racesTable.TryGetValue(systemID, out races);
-
-			if (races!=null)
-			{
-				Dictionary<string, Race> subraces;
-				races.TryGetValue(raceID, out subraces);
-
-				if (subraces!=null)
-				{
-					subraces.TryGetValue(raceSubID, out race);
-				}
+			
+			Dictionary<string, Race> subraces = GetRaceTable(systemID, raceID);
+
+			if (subraces != null)
+			{
+				subraces.TryGetValue(raceSubID.ToLower(), out race);
 			}
 			
-			return race;
+			return race;
+		}
+
+		private Dictionary<string, Race> GetRaceTable(string systemID, string raceID)
+		{
+			Dictionary<string, Dictionary<string, Race>> races;
+			racesTable.TryGetValue(systemID.ToLower(), out races);
+			Dictionary<string, Race> subraces = null;
+
+			if (races != null)
+			{
+				races.TryGetValue(raceID.ToLower(), out subraces);
+			}
+
+			return subraces;
+		}
+
+		internal void RemoveRace(Race race)
+		{
+			Dictionary<string, Race> subraces = GetRaceTable(race.GameSystem.ID, race.ID);
+
+			if (subraces != null)
+			{
+				subraces.Remove(race.SubID.ToLower());
+			}
 		}
 
 		/// <summary>
@@ -873,6 +895,6 @@
 			}
 
 			return loadingFactory;
-		}
+		}
 	}
 }