comparison api/DefaultWarFoundryLoader.cs @ 291:24e7b571f50f

Re #318: DefaultWarFoundryLoader throws null ref when loading individual files * Fix quick fix so that it actually works and loads files - but it is still a quick-fix that needs double-checking
author IBBoard <dev@ibboard.co.uk>
date Tue, 14 Dec 2010 20:17:07 +0000
parents 5ed39187b0e3
children
comparison
equal deleted inserted replaced
290:5ed39187b0e3 291:24e7b571f50f
13 /// </summary> 13 /// </summary>
14 public class DefaultWarFoundryLoader : AbstractWarFoundryLoader 14 public class DefaultWarFoundryLoader : AbstractWarFoundryLoader
15 { 15 {
16 private Dictionary<string, GameSystem> systemsTable; 16 private Dictionary<string, GameSystem> systemsTable;
17 private Dictionary<string, Dictionary<string, Dictionary<string, Race>>> racesTable; //Keys are: System, Race, SubRace 17 private Dictionary<string, Dictionary<string, Dictionary<string, Race>>> racesTable; //Keys are: System, Race, SubRace
18 private bool loaded = false;
19 private bool loading = false;
18 20
19 public DefaultWarFoundryLoader() 21 public DefaultWarFoundryLoader()
20 { 22 {
21 systemsTable = new Dictionary<string,GameSystem>(); 23 systemsTable = new Dictionary<string,GameSystem>();
22 racesTable = new Dictionary<string,Dictionary<string,Dictionary<string,Race>>>(); 24 racesTable = new Dictionary<string,Dictionary<string,Dictionary<string,Race>>>();
23 } 25 }
24 26
25 protected override void PrepareForFileLoad() 27 protected override void PrepareForFileLoad()
26 { 28 {
27 //Just set up blank dictionaries for now - may try different and more complex handling in future 29 loading = true;
28 systemsTable.Clear(); 30 systemsTable.Clear();
29 racesTable.Clear(); 31 racesTable.Clear();
32 }
33
34 protected override void FinishFileLoad()
35 {
36 loaded = true;
37 loading = false;
30 } 38 }
31 39
32 protected override GameSystem GetExistingSystemForSystem(GameSystem system) 40 protected override GameSystem GetExistingSystemForSystem(GameSystem system)
33 { 41 {
34 return DictionaryUtils.GetValue(systemsTable, system.ID.ToLower()); 42 return DictionaryUtils.GetValue(systemsTable, system.ID.ToLower());
79 } 87 }
80 } 88 }
81 89
82 public override GameSystem[] GetGameSystems() 90 public override GameSystem[] GetGameSystems()
83 { 91 {
84 if (systemsTable == null) 92 if (!loaded && !loading)
85 { 93 {
86 LoadFiles(); 94 LoadFiles();
87 } 95 }
88 96
89 return DictionaryUtils.ToArray<string, GameSystem>(systemsTable); 97 return DictionaryUtils.ToArray<string, GameSystem>(systemsTable);
90 } 98 }
91 99
92 public override GameSystem GetGameSystem(string systemID) 100 public override GameSystem GetGameSystem(string systemID)
93 { 101 {
94 if (systemsTable == null) 102 if (!loaded && !loading)
95 { 103 {
96 LoadFiles(); 104 LoadFiles();
97 } 105 }
98 106
99 GameSystem system; 107 GameSystem system;
120 /// <returns> 128 /// <returns>
121 /// An array of <see cref="Race"/>s for the specified game system 129 /// An array of <see cref="Race"/>s for the specified game system
122 /// </returns> 130 /// </returns>
123 public Race[] GetRaces(string systemID) 131 public Race[] GetRaces(string systemID)
124 { 132 {
125 if (racesTable == null) 133 if (!loaded && !loading)
126 { 134 {
127 LoadFiles(); 135 LoadFiles();
128 } 136 }
129 137
130 systemID = systemID.ToLower(); 138 systemID = systemID.ToLower();
199 /// <returns> 207 /// <returns>
200 /// A <see cref="Race"/> 208 /// A <see cref="Race"/>
201 /// </returns> 209 /// </returns>
202 public Race GetRace(string systemID, string raceID, string raceSubID) 210 public Race GetRace(string systemID, string raceID, string raceSubID)
203 { 211 {
204 if (racesTable == null) 212 if (!loaded && !loading)
205 { 213 {
206 LoadFiles(); 214 LoadFiles();
207 } 215 }
208 216
209 Race race = null; 217 Race race = null;
242 } 250 }
243 } 251 }
244 252
245 public override string[] GetGameSystemIDs() 253 public override string[] GetGameSystemIDs()
246 { 254 {
247 if (systemsTable == null) 255 if (!loaded && !loading)
248 { 256 {
249 LoadFiles(); 257 LoadFiles();
250 } 258 }
251 259
252 return DictionaryUtils.ToKeyArray(systemsTable); 260 return DictionaryUtils.ToKeyArray(systemsTable);
266 /// <returns> 274 /// <returns>
267 /// An array of <see cref="System.String"/>s representing the IDs of the races of the specified game system. 275 /// An array of <see cref="System.String"/>s representing the IDs of the races of the specified game system.
268 /// </returns> 276 /// </returns>
269 public string[] GetSystemRaceIDs(string systemID) 277 public string[] GetSystemRaceIDs(string systemID)
270 { 278 {
271 if (racesTable == null) 279 if (!loaded && !loading)
272 { 280 {
273 LoadFiles(); 281 LoadFiles();
274 } 282 }
275 283
276 Dictionary<string, Dictionary<string, Race>> races = racesTable[systemID.ToLower()]; 284 Dictionary<string, Dictionary<string, Race>> races = racesTable[systemID.ToLower()];