Mercurial > repos > snowblizz-super-API-ideas
changeset 290:5ed39187b0e3
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
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Mon, 13 Dec 2010 21:03:02 +0000 |
parents | 08a9c960e17f |
children | 24e7b571f50f |
files | api/DefaultWarFoundryLoader.cs |
diffstat | 1 files changed, 28 insertions(+), 26 deletions(-) [+] |
line wrap: on
line diff
--- 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<string, GameSystem> systemsTable; private Dictionary<string, Dictionary<string, Dictionary<string, Race>>> racesTable; //Keys are: System, Race, SubRace - public DefaultWarFoundryLoader () + public DefaultWarFoundryLoader() { + systemsTable = new Dictionary<string,GameSystem>(); + racesTable = new Dictionary<string,Dictionary<string,Dictionary<string,Race>>>(); } - + protected override void PrepareForFileLoad() { //Just set up blank dictionaries for now - may try different and more complex handling in future - systemsTable = new Dictionary<string,GameSystem>(); - racesTable = new Dictionary<string,Dictionary<string,Dictionary<string,Race>>>(); + 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<string, Dictionary<string, Race>> systemRaces; string systemID = race.GameSystem.ID.ToLower(); racesTable.TryGetValue(systemID, out systemRaces); - if (systemRaces==null) + if (systemRaces == null) { systemRaces = new Dictionary<string,Dictionary<string,Race>>(); racesTable.Add(systemID, systemRaces); @@ -53,7 +55,7 @@ Dictionary<string, Race> subRaces; systemRaces.TryGetValue(race.ID.ToLower(), out subRaces); - if (subRaces==null) + if (subRaces == null) { subRaces = new Dictionary<string,Race>(); 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<string, GameSystem>(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 @@ /// </returns> public Race[] GetRaces(string systemID) { - if (racesTable==null) + if (racesTable == null) { LoadFiles(); } @@ -129,7 +131,7 @@ Dictionary<string, Dictionary<string, Race>> system; racesTable.TryGetValue(systemID, out system); - if (system==null) + if (system == null) { return new Race[0]; } @@ -138,7 +140,7 @@ foreach (Dictionary<string, Race> 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 @@ /// </returns> 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<string, Dictionary<string, Race>> races = racesTable[systemID.ToLower()]; - if (races==null) + if (races == null) { return new string[0]; }