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 diff
     1.1 --- a/api/DefaultWarFoundryLoader.cs	Mon Dec 13 20:20:00 2010 +0000
     1.2 +++ b/api/DefaultWarFoundryLoader.cs	Mon Dec 13 21:03:02 2010 +0000
     1.3 @@ -16,35 +16,37 @@
     1.4  		private Dictionary<string, GameSystem> systemsTable;
     1.5  		private Dictionary<string, Dictionary<string, Dictionary<string, Race>>> racesTable; //Keys are: System, Race, SubRace
     1.6  
     1.7 -		public DefaultWarFoundryLoader ()
     1.8 +		public DefaultWarFoundryLoader()
     1.9  		{
    1.10 +			systemsTable = new Dictionary<string,GameSystem>();
    1.11 +			racesTable = new Dictionary<string,Dictionary<string,Dictionary<string,Race>>>();
    1.12  		}
    1.13 -		
    1.14 +
    1.15  		protected override void PrepareForFileLoad()
    1.16  		{
    1.17  			//Just set up blank dictionaries for now - may try different and more complex handling in future
    1.18 -			systemsTable = new Dictionary<string,GameSystem>();
    1.19 -			racesTable = new Dictionary<string,Dictionary<string,Dictionary<string,Race>>>();
    1.20 +			systemsTable.Clear();
    1.21 +			racesTable.Clear();
    1.22  		}
    1.23 -		
    1.24 -		protected override GameSystem GetExistingSystemForSystem (GameSystem system)
    1.25 +
    1.26 +		protected override GameSystem GetExistingSystemForSystem(GameSystem system)
    1.27  		{
    1.28  			return DictionaryUtils.GetValue(systemsTable, system.ID.ToLower());
    1.29  		}
    1.30 -		
    1.31 -		protected override void DoStoreGameSystem (GameSystem system)
    1.32 +
    1.33 +		protected override void DoStoreGameSystem(GameSystem system)
    1.34  		{
    1.35  			systemsTable[system.ID.ToLower()] = system;
    1.36  		}
    1.37  
    1.38 -		protected override void DoStoreRace (Race race)
    1.39 +		protected override void DoStoreRace(Race race)
    1.40  		{
    1.41  			Dictionary<string, Dictionary<string, Race>> systemRaces;
    1.42  			
    1.43  			string systemID = race.GameSystem.ID.ToLower();
    1.44  			racesTable.TryGetValue(systemID, out systemRaces);
    1.45  			
    1.46 -			if (systemRaces==null)
    1.47 +			if (systemRaces == null)
    1.48  			{
    1.49  				systemRaces = new Dictionary<string,Dictionary<string,Race>>();
    1.50  				racesTable.Add(systemID, systemRaces);
    1.51 @@ -53,7 +55,7 @@
    1.52  			Dictionary<string, Race> subRaces;
    1.53  			systemRaces.TryGetValue(race.ID.ToLower(), out subRaces);
    1.54  			
    1.55 -			if (subRaces==null)
    1.56 +			if (subRaces == null)
    1.57  			{
    1.58  				subRaces = new Dictionary<string,Race>();
    1.59  				systemRaces.Add(race.ID.ToLower(), subRaces);
    1.60 @@ -76,20 +78,20 @@
    1.61  				subRaces.Add(race.SubID.ToLower(), race);
    1.62  			}
    1.63  		}
    1.64 -		
    1.65 +
    1.66  		public override GameSystem[] GetGameSystems()
    1.67  		{
    1.68 -			if (systemsTable==null)
    1.69 +			if (systemsTable == null)
    1.70  			{
    1.71  				LoadFiles();
    1.72  			}
    1.73  			
    1.74  			return DictionaryUtils.ToArray<string, GameSystem>(systemsTable);
    1.75  		}
    1.76 -		
    1.77 +
    1.78  		public override GameSystem GetGameSystem(string systemID)
    1.79  		{
    1.80 -			if (systemsTable==null)
    1.81 +			if (systemsTable == null)
    1.82  			{
    1.83  				LoadFiles();
    1.84  			}
    1.85 @@ -98,12 +100,12 @@
    1.86  			systemsTable.TryGetValue(systemID.ToLower(), out system);
    1.87  			return system;
    1.88  		}
    1.89 -		
    1.90 +
    1.91  		protected internal override void RemoveGameSystem(GameSystem system)
    1.92  		{
    1.93  			systemsTable.Remove(system.ID.ToLower());
    1.94  		}
    1.95 -		
    1.96 +
    1.97  		public override Race[] GetRaces(GameSystem system)
    1.98  		{
    1.99  			return GetRaces(system.ID);
   1.100 @@ -120,7 +122,7 @@
   1.101  		/// </returns>
   1.102  		public Race[] GetRaces(string systemID)
   1.103  		{
   1.104 -			if (racesTable==null)
   1.105 +			if (racesTable == null)
   1.106  			{
   1.107  				LoadFiles();
   1.108  			}
   1.109 @@ -129,7 +131,7 @@
   1.110  			Dictionary<string, Dictionary<string, Race>> system;
   1.111  			racesTable.TryGetValue(systemID, out system);
   1.112  			
   1.113 -			if (system==null)
   1.114 +			if (system == null)
   1.115  			{
   1.116  				return new Race[0];
   1.117  			}
   1.118 @@ -138,7 +140,7 @@
   1.119  
   1.120  			foreach (Dictionary<string, Race> racesDict in system.Values)
   1.121  			{
   1.122 -				count+= racesDict.Count;
   1.123 +				count += racesDict.Count;
   1.124  			}
   1.125  
   1.126  			Race[] races = new Race[count];
   1.127 @@ -154,7 +156,7 @@
   1.128  
   1.129  			return races;
   1.130  		}
   1.131 -		
   1.132 +
   1.133  		public override Race GetRace(GameSystem system, string raceID)
   1.134  		{
   1.135  			return GetRace(system.ID, raceID);
   1.136 @@ -199,7 +201,7 @@
   1.137  		/// </returns>
   1.138  		public Race GetRace(string systemID, string raceID, string raceSubID)
   1.139  		{
   1.140 -			if (racesTable==null)
   1.141 +			if (racesTable == null)
   1.142  			{
   1.143  				LoadFiles();
   1.144  			}
   1.145 @@ -239,17 +241,17 @@
   1.146  				subraces.Remove(race.SubID.ToLower());
   1.147  			}
   1.148  		}
   1.149 -		
   1.150 +
   1.151  		public override string[] GetGameSystemIDs()
   1.152  		{
   1.153 -			if (systemsTable==null)
   1.154 +			if (systemsTable == null)
   1.155  			{
   1.156  				LoadFiles();
   1.157  			}
   1.158  
   1.159  			return DictionaryUtils.ToKeyArray(systemsTable);
   1.160  		}
   1.161 -		
   1.162 +
   1.163  		public override string[] GetSystemRaceIDs(GameSystem system)
   1.164  		{
   1.165  			return GetSystemRaceIDs(system.ID);
   1.166 @@ -273,7 +275,7 @@
   1.167  
   1.168  			Dictionary<string, Dictionary<string, Race>> races = racesTable[systemID.ToLower()];
   1.169  
   1.170 -			if (races==null)
   1.171 +			if (races == null)
   1.172  			{
   1.173  				return new string[0];
   1.174  			}