# HG changeset patch # User IBBoard # Date 1292274182 0 # Node ID 5ed39187b0e3fc8355f1c001ffbb3481b9b4d264 # Parent 08a9c960e17fea08c1dd24d4acf5fdf011a48bc3 Re #318: DefaultWarFoundryLoader throws null ref when loading individual files * Initial quick fix that should resolve the issues, but isn't ideal in the long run diff -r 08a9c960e17f -r 5ed39187b0e3 api/DefaultWarFoundryLoader.cs --- a/api/DefaultWarFoundryLoader.cs Mon Dec 13 20:20:00 2010 +0000 +++ b/api/DefaultWarFoundryLoader.cs Mon Dec 13 21:03:02 2010 +0000 @@ -16,35 +16,37 @@ private Dictionary systemsTable; private Dictionary>> racesTable; //Keys are: System, Race, SubRace - public DefaultWarFoundryLoader () + public DefaultWarFoundryLoader() { + systemsTable = new Dictionary(); + racesTable = new Dictionary>>(); } - + protected override void PrepareForFileLoad() { //Just set up blank dictionaries for now - may try different and more complex handling in future - systemsTable = new Dictionary(); - racesTable = new Dictionary>>(); + systemsTable.Clear(); + racesTable.Clear(); } - - protected override GameSystem GetExistingSystemForSystem (GameSystem system) + + protected override GameSystem GetExistingSystemForSystem(GameSystem system) { return DictionaryUtils.GetValue(systemsTable, system.ID.ToLower()); } - - protected override void DoStoreGameSystem (GameSystem system) + + protected override void DoStoreGameSystem(GameSystem system) { systemsTable[system.ID.ToLower()] = system; } - protected override void DoStoreRace (Race race) + protected override void DoStoreRace(Race race) { Dictionary> systemRaces; string systemID = race.GameSystem.ID.ToLower(); racesTable.TryGetValue(systemID, out systemRaces); - if (systemRaces==null) + if (systemRaces == null) { systemRaces = new Dictionary>(); racesTable.Add(systemID, systemRaces); @@ -53,7 +55,7 @@ Dictionary subRaces; systemRaces.TryGetValue(race.ID.ToLower(), out subRaces); - if (subRaces==null) + if (subRaces == null) { subRaces = new Dictionary(); systemRaces.Add(race.ID.ToLower(), subRaces); @@ -76,20 +78,20 @@ subRaces.Add(race.SubID.ToLower(), race); } } - + public override GameSystem[] GetGameSystems() { - if (systemsTable==null) + if (systemsTable == null) { LoadFiles(); } return DictionaryUtils.ToArray(systemsTable); } - + public override GameSystem GetGameSystem(string systemID) { - if (systemsTable==null) + if (systemsTable == null) { LoadFiles(); } @@ -98,12 +100,12 @@ systemsTable.TryGetValue(systemID.ToLower(), out system); return system; } - + protected internal override void RemoveGameSystem(GameSystem system) { systemsTable.Remove(system.ID.ToLower()); } - + public override Race[] GetRaces(GameSystem system) { return GetRaces(system.ID); @@ -120,7 +122,7 @@ /// public Race[] GetRaces(string systemID) { - if (racesTable==null) + if (racesTable == null) { LoadFiles(); } @@ -129,7 +131,7 @@ Dictionary> system; racesTable.TryGetValue(systemID, out system); - if (system==null) + if (system == null) { return new Race[0]; } @@ -138,7 +140,7 @@ foreach (Dictionary racesDict in system.Values) { - count+= racesDict.Count; + count += racesDict.Count; } Race[] races = new Race[count]; @@ -154,7 +156,7 @@ return races; } - + public override Race GetRace(GameSystem system, string raceID) { return GetRace(system.ID, raceID); @@ -199,7 +201,7 @@ /// public Race GetRace(string systemID, string raceID, string raceSubID) { - if (racesTable==null) + if (racesTable == null) { LoadFiles(); } @@ -239,17 +241,17 @@ subraces.Remove(race.SubID.ToLower()); } } - + public override string[] GetGameSystemIDs() { - if (systemsTable==null) + if (systemsTable == null) { LoadFiles(); } return DictionaryUtils.ToKeyArray(systemsTable); } - + public override string[] GetSystemRaceIDs(GameSystem system) { return GetSystemRaceIDs(system.ID); @@ -273,7 +275,7 @@ Dictionary> races = racesTable[systemID.ToLower()]; - if (races==null) + if (races == null) { return new string[0]; }