annotate api/WarFoundryLoader.cs @ 64:2094bd0ba652

Re #61 - Complete structure of WarFoundry API objects * Make Unit work with EquipmentItem objects as it doesn't need to know about the limits * Add methods to UnitType to check limits on an EquipmentItem Also: * Remove some unnecessary casting now that we're using genericed lists
author IBBoard <dev@ibboard.co.uk>
date Thu, 09 Apr 2009 15:36:22 +0000
parents 422ddd5fedd1
children 3ea0ab04352b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
15
306558904c2a Re #1 - LGPL license all code
IBBoard <dev@ibboard.co.uk>
parents: 14
diff changeset
1 // This file (WarFoundryLoader.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2009 IBBoard.
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
2 //
16
bf518618eb69 Re #1 - LGPL license all code
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
3 // The file and the library/program it is in are licensed under the GNU LGPL license, either version 3 of the License or (at your option) any later version. Please see COPYING.LGPL for more information and the full license.
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
4
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
5 using System;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
6 using System.Collections.Generic;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
7 using System.IO;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
8 using IBBoard.Collections;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
9 using IBBoard.IO;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
10 using IBBoard.Logging;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
11 using IBBoard.WarFoundry.API.Factories;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
12 using IBBoard.WarFoundry.API.Objects;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
13 using ICSharpCode.SharpZipLib.Zip;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
14
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
15 namespace IBBoard.WarFoundry.API
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
16 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
17 public class WarFoundryLoader
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
18 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
19 private static WarFoundryLoader loader;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
20
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
21 /// <summary>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
22 /// Gets the default <see cref="WarFoundryLoader"/> used to load WarFoundry data files.
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
23 /// </summary>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
24 /// <returns>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
25 /// The default <see cref="WarFoundryLoader"/>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
26 /// </returns>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
27 public static WarFoundryLoader GetDefault()
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
28 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
29 if (loader == null)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
30 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
31 loader = new WarFoundryLoader();
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
32 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
33
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
34 return loader;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
35 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
36
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
37 private ICollection<DirectoryInfo> directories;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
38 private ICollection<INativeWarFoundryFactory> factories;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
39 private ICollection<INonNativeWarFoundryFactory> nonNativeFactories;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
40 private Dictionary<string, GameSystem> systemsTable;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
41 private Dictionary<string, Dictionary<string, Dictionary<string, Race>>> racesTable; //Keys are: System, Race, SubRace
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
42 private Dictionary<IWarFoundryFactory, SimpleSet<IWarFoundryObject>> loadedObjects;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
43
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
44 protected WarFoundryLoader()
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
45 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
46 directories = new List<DirectoryInfo>();
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
47 factories = new List<INativeWarFoundryFactory>();
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
48 nonNativeFactories = new List<INonNativeWarFoundryFactory>();
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
49 loadedObjects = new Dictionary<IWarFoundryFactory,SimpleSet<IWarFoundryObject>>();
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
50 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
51
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
52 /// <summary>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
53 /// Adds a directory to the collection of directories that will be searched for WarFoundry data files.
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
54 /// </summary>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
55 /// <param name="directory">
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
56 /// The <see cref="DirectoryInfo"/> to add to the list for searching for data files
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
57 /// </param>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
58 public void AddLoadDirectory(DirectoryInfo directory)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
59 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
60 if (!directories.Contains(directory))
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
61 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
62 directories.Add(directory);
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
63 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
64 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
65
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
66 /// <summary>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
67 /// Removes a directory from the collection of directories that will be searched for WarFoundry data files.
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
68 /// </summary>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
69 /// <param name="directory">
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
70 /// A <see cref="DirectoryInfo"/>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
71 /// </param>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
72 public void RemoveLoadDirectory(DirectoryInfo directory)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
73 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
74 if (directories.Contains(directory))
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
75 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
76 directories.Remove(directory);
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
77 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
78 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
79
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
80 /// <summary>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
81 /// Registers a <see cref="INativeWarFoundryFactory"/> as a factory that can parse native data files.
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
82 /// </summary>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
83 /// <param name="factory">
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
84 /// The <see cref="INativeWarFoundryFactory"/> to register to parse native data files.
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
85 /// </param>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
86 public void RegisterFactory(INativeWarFoundryFactory factory)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
87 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
88 if (!factories.Contains(factory))
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
89 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
90 factories.Add(factory);
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
91 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
92 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
93
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
94 /// <summary>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
95 /// Unregisters a <see cref="INativeWarFoundryFactory"/> so that it will no longer be used to try to parse native data files.
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
96 /// </summary>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
97 /// <param name="factory">
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
98 /// The <see cref="INativeWarFoundryFactory"/> to remove from the collection of factories that are used to try to parse native data files.
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
99 /// </param>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
100 public void UnregisterFactory(INativeWarFoundryFactory factory)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
101 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
102 if (factories.Contains(factory))
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
103 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
104 factories.Remove(factory);
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
105 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
106 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
107
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
108 /// <summary>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
109 /// Registers a <see cref="INonNativeWarFoundryFactory"/> so that it will be used to try to parse non-native data files from other applications.
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
110 /// </summary>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
111 /// <param name="factory">
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
112 /// The <see cref="INonNativeWarFoundryFactory"/> to register to parse non-native data files.
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
113 /// </param>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
114 public void RegisterNonNativeFactory(INonNativeWarFoundryFactory factory)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
115 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
116 if (!nonNativeFactories.Contains(factory))
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
117 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
118 nonNativeFactories.Add(factory);
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
119 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
120 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
121
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
122 /// <summary>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
123 /// Unregisters a <see cref="INonNativeWarFoundryFactory"/> so that it will no longer be used to try to parse non-native data files from other applications.
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
124 /// </summary>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
125 /// <param name="factory">
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
126 /// The <see cref="INonNativeWarFoundryFactory"/> to remove from the collection of factories that are used to try to parse non-native data files.
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
127 /// </param>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
128 public void UnregisterNonNativeFactory(INonNativeWarFoundryFactory factory)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
129 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
130 if (nonNativeFactories.Contains(factory))
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
131 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
132 nonNativeFactories.Remove(factory);
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
133 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
134 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
135
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
136 /// <summary>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
137 /// Loads all of the data files in the registered directories.
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
138 /// </summary>
14
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
139 /// <returns>
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
140 /// A <see cref="Dictionary"/> of files that failed to load mapped against the message that their failure returned
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
141 /// </returns>
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
142 public List<FileLoadFailure> LoadFiles()
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
143 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
144 LogNotifier.Debug(GetType(), "Load files");
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
145 PrepareForFileLoad();
14
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
146 Dictionary<FileInfo, IWarFoundryFactory> loadableRaces = new Dictionary<FileInfo, IWarFoundryFactory>();
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
147 Dictionary<FileInfo, IWarFoundryFactory> loadableGameSystems = new Dictionary<FileInfo, IWarFoundryFactory>();
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
148 List<FileLoadFailure> failedLoads = FillLoadableFiles(loadableRaces, loadableGameSystems);
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
149 failedLoads.AddRange(LoadGameSystems(loadableGameSystems));
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
150 failedLoads.AddRange(LoadRaces(loadableRaces));
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
151
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
152 LogNotifier.Debug(GetType(), failedLoads.Count + " failed file loads");
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
153
14
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
154 return failedLoads;
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
155 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
156
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
157 protected void PrepareForFileLoad()
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
158 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
159 //Just set up blank dictionaries for now - may try different and more complex handling in future
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
160 systemsTable = new Dictionary<string,GameSystem>();
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
161 racesTable = new Dictionary<string,Dictionary<string,Dictionary<string,Race>>>();
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
162 }
14
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
163
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
164 private List<FileLoadFailure> FillLoadableFiles(Dictionary<FileInfo, IWarFoundryFactory> loadableRaces, Dictionary<FileInfo, IWarFoundryFactory> loadableGameSystems)
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
165 {
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
166 List<FileLoadFailure> fails = new List<FileLoadFailure>();
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
167
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
168 foreach (DirectoryInfo directory in directories)
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
169 {
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
170 if (directory.Exists)
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
171 {
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
172 List<FileLoadFailure> directoryFails = FillLoadableFilesForDirectory(loadableRaces, loadableGameSystems, directory);
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
173 fails.AddRange(directoryFails);
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
174 }
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
175 else
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
176 {
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
177 LogNotifier.WarnFormat(GetType(), "Load for {0} failed because directory didn't exist", directory.FullName);
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
178 }
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
179 }
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
180
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
181 return fails;
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
182 }
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
183
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
184 private List<FileLoadFailure> FillLoadableFilesForDirectory(Dictionary<FileInfo, IWarFoundryFactory> loadableRaces, Dictionary<FileInfo, IWarFoundryFactory> loadableGameSystems, DirectoryInfo directory)
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
185 {
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
186 List<FileLoadFailure> fails = new List<FileLoadFailure>();
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
187 LogNotifier.Debug(GetType(), "Load from "+directory.FullName);
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
188
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
189 foreach (FileInfo file in directory.GetFiles())
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
190 {
27
e7de5c96f5c2 Re #44 - Fix API tests
IBBoard <dev@ibboard.co.uk>
parents: 23
diff changeset
191 IWarFoundryFactory factory = GetGameSystemLoadingFactoryForFile(file);
14
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
192
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
193 if (factory != null)
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
194 {
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
195 loadableGameSystems.Add(file, factory);
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
196 }
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
197 else
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
198 {
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
199 factory = GetRaceLoadingFactoryForFile(file);
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
200
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
201 if (factory!=null)
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
202 {
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
203 loadableRaces.Add(file, factory);
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
204 }
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
205 else
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
206 {
30
92cf25b0493b Re #32 - Migrate to using Schemas
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
207 FileLoadFailure failure = new FileLoadFailure(file, "File not handled as a Race or Game System definition: {0}", "FileNotHandled");
92cf25b0493b Re #32 - Migrate to using Schemas
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
208 fails.Add(failure);
92cf25b0493b Re #32 - Migrate to using Schemas
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
209 LogNotifier.Info(GetType(), failure.Message);
14
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
210 }
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
211 }
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
212 }
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
213
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
214 return fails;
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
215 }
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
216
27
e7de5c96f5c2 Re #44 - Fix API tests
IBBoard <dev@ibboard.co.uk>
parents: 23
diff changeset
217 private IWarFoundryFactory GetGameSystemLoadingFactoryForFile(FileInfo file)
14
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
218 {
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
219 IWarFoundryFactory loadingFactory = null;
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
220
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
221 foreach (INonNativeWarFoundryFactory factory in nonNativeFactories)
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
222 {
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
223 if (factory.CanHandleFileAsGameSystem(file))
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
224 {
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
225 loadingFactory = factory;
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
226 break;
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
227 }
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
228 }
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
229
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
230 if (loadingFactory == null)
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
231 {
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
232 foreach (INativeWarFoundryFactory factory in factories)
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
233 {
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
234 if (factory.CanHandleFileAsGameSystem(file))
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
235 {
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
236 loadingFactory = factory;
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
237 break;
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
238 }
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
239 }
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
240 }
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
241
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
242 return loadingFactory;
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
243 }
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
244
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
245 private IWarFoundryFactory GetRaceLoadingFactoryForFile(FileInfo file)
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
246 {
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
247 IWarFoundryFactory loadingFactory = null;
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
248
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
249 foreach (INonNativeWarFoundryFactory factory in nonNativeFactories)
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
250 {
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
251 if (factory.CanHandleFileAsRace(file))
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
252 {
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
253 loadingFactory = factory;
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
254 break;
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
255 }
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
256 }
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
257
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
258 if (loadingFactory == null)
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
259 {
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
260 foreach (INativeWarFoundryFactory factory in factories)
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
261 {
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
262 if (factory.CanHandleFileAsRace(file))
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
263 {
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
264 loadingFactory = factory;
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
265 break;
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
266 }
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
267 }
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
268 }
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
269
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
270 return loadingFactory;
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
271 }
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
272
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
273 private List<FileLoadFailure> LoadGameSystems(Dictionary<FileInfo, IWarFoundryFactory> gameSystemFiles)
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
274 {
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
275 List<FileLoadFailure> fails = new List<FileLoadFailure>();
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
276
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
277
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
278 foreach (FileInfo file in gameSystemFiles.Keys)
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
279 {
23
f9846f896df3 Re #32 - Migrate WarFoundry files to using Schemas
IBBoard <dev@ibboard.co.uk>
parents: 20
diff changeset
280 FileLoadFailure failure = null;
f9846f896df3 Re #32 - Migrate WarFoundry files to using Schemas
IBBoard <dev@ibboard.co.uk>
parents: 20
diff changeset
281
14
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
282 try
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
283 {
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
284 bool loaded = LoadObject(file, gameSystemFiles[file]);
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
285
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
286 if (!loaded)
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
287 {
41
422ddd5fedd1 Re #48 - Require schemas to validate
IBBoard <dev@ibboard.co.uk>
parents: 30
diff changeset
288 failure = new FileLoadFailure(file, "FileLoadFailed", "Failed to load {0} as GameSystem using {1}");
14
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
289 }
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
290 }
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
291 catch (Exception ex)
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
292 {
30
92cf25b0493b Re #32 - Migrate to using Schemas
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
293 failure = new FileLoadFailure(file, null, ex.Message, null, ex);
23
f9846f896df3 Re #32 - Migrate WarFoundry files to using Schemas
IBBoard <dev@ibboard.co.uk>
parents: 20
diff changeset
294 }
f9846f896df3 Re #32 - Migrate WarFoundry files to using Schemas
IBBoard <dev@ibboard.co.uk>
parents: 20
diff changeset
295
f9846f896df3 Re #32 - Migrate WarFoundry files to using Schemas
IBBoard <dev@ibboard.co.uk>
parents: 20
diff changeset
296 if (failure!=null)
f9846f896df3 Re #32 - Migrate WarFoundry files to using Schemas
IBBoard <dev@ibboard.co.uk>
parents: 20
diff changeset
297 {
f9846f896df3 Re #32 - Migrate WarFoundry files to using Schemas
IBBoard <dev@ibboard.co.uk>
parents: 20
diff changeset
298 fails.Add(failure);
41
422ddd5fedd1 Re #48 - Require schemas to validate
IBBoard <dev@ibboard.co.uk>
parents: 30
diff changeset
299 LogNotifier.Warn(GetType(), failure.Message, failure.Exception);
14
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
300 }
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
301 }
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
302
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
303 return fails;
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
304 }
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
305
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
306 private List<FileLoadFailure> LoadRaces(Dictionary<FileInfo, IWarFoundryFactory> raceFiles)
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
307 {
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
308 List<FileLoadFailure> fails = new List<FileLoadFailure>();
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
309
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
310 foreach (FileInfo file in raceFiles.Keys)
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
311 {
23
f9846f896df3 Re #32 - Migrate WarFoundry files to using Schemas
IBBoard <dev@ibboard.co.uk>
parents: 20
diff changeset
312 FileLoadFailure failure = null;
f9846f896df3 Re #32 - Migrate WarFoundry files to using Schemas
IBBoard <dev@ibboard.co.uk>
parents: 20
diff changeset
313
14
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
314 try
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
315 {
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
316 bool loaded = LoadObject(file, raceFiles[file]);
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
317
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
318 if (!loaded)
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
319 {
23
f9846f896df3 Re #32 - Migrate WarFoundry files to using Schemas
IBBoard <dev@ibboard.co.uk>
parents: 20
diff changeset
320 failure = new FileLoadFailure(file, "FileLoadFailed", "Failed to load {0} as Race using {1}");
14
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
321 }
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
322 }
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
323 catch (Exception ex)
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
324 {
30
92cf25b0493b Re #32 - Migrate to using Schemas
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
325 failure = new FileLoadFailure(file, null, ex.Message, null, ex);
23
f9846f896df3 Re #32 - Migrate WarFoundry files to using Schemas
IBBoard <dev@ibboard.co.uk>
parents: 20
diff changeset
326 }
f9846f896df3 Re #32 - Migrate WarFoundry files to using Schemas
IBBoard <dev@ibboard.co.uk>
parents: 20
diff changeset
327
f9846f896df3 Re #32 - Migrate WarFoundry files to using Schemas
IBBoard <dev@ibboard.co.uk>
parents: 20
diff changeset
328 if (failure!=null)
f9846f896df3 Re #32 - Migrate WarFoundry files to using Schemas
IBBoard <dev@ibboard.co.uk>
parents: 20
diff changeset
329 {
f9846f896df3 Re #32 - Migrate WarFoundry files to using Schemas
IBBoard <dev@ibboard.co.uk>
parents: 20
diff changeset
330 fails.Add(failure);
30
92cf25b0493b Re #32 - Migrate to using Schemas
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
331 LogNotifier.Warn(GetType(), failure.Message, failure.Exception);
14
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
332 }
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
333 }
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
334
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
335 return fails;
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
336 }
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
337
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
338 private bool LoadObject(FileInfo file, IWarFoundryFactory factory)
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
339 {
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
340 bool loaded = false;
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
341
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
342 LogNotifier.DebugFormat(GetType(), "Loading {0} using {1}", file.FullName, factory.GetType().Name);
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
343 ICollection<IWarFoundryObject> objects = factory.CreateObjectsFromFile(file);
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
344
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
345 if (objects.Count > 0)
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
346 {
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
347 AddLoadedObjects(objects, factory);
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
348 loaded = true;
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
349 }
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
350
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
351 return loaded;
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
352 }
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
353
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
354
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
355 /// <summary>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
356 /// Loads a single file through the registered WarFoundryFactories, if a factory exists that supports the file format.
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
357 /// </summary>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
358 /// <param name="file">
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
359 /// A <see cref="FileInfo"/> for the file to attempt to load
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
360 /// </param>
14
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
361 /// <returns>
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
362 /// An ICollection of IWarFoundryObjects loaded from <code>file</code>
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
363 /// </returns>
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
364 public ICollection<IWarFoundryObject> LoadFile(FileInfo file)
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
365 {
19
57451981545c Re #10 and re #11 - Refactor code and document code
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
366 ICollection<IWarFoundryObject> objs = null;
14
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
367 IWarFoundryFactory loadFactory = null;
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
368
19
57451981545c Re #10 and re #11 - Refactor code and document code
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
369 try
57451981545c Re #10 and re #11 - Refactor code and document code
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
370 {
57451981545c Re #10 and re #11 - Refactor code and document code
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
371 objs = LoadFileWithNonNativeFactories(file, out loadFactory);
57451981545c Re #10 and re #11 - Refactor code and document code
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
372
57451981545c Re #10 and re #11 - Refactor code and document code
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
373 if (objs == null)
57451981545c Re #10 and re #11 - Refactor code and document code
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
374 {
57451981545c Re #10 and re #11 - Refactor code and document code
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
375 objs = LoadFileWithNativeFactories(file, out loadFactory);
57451981545c Re #10 and re #11 - Refactor code and document code
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
376 }
57451981545c Re #10 and re #11 - Refactor code and document code
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
377 }
57451981545c Re #10 and re #11 - Refactor code and document code
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
378 catch (InvalidFileException ex)
57451981545c Re #10 and re #11 - Refactor code and document code
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
379 {
20
b7c93a5821cd * Remove unnecessary project dependency
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
380 LogNotifier.Error(GetType(), file.FullName+" failed to load", ex);
19
57451981545c Re #10 and re #11 - Refactor code and document code
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
381 }
57451981545c Re #10 and re #11 - Refactor code and document code
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
382
57451981545c Re #10 and re #11 - Refactor code and document code
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
383 if (objs!=null)
57451981545c Re #10 and re #11 - Refactor code and document code
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
384 {
57451981545c Re #10 and re #11 - Refactor code and document code
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
385 AddLoadedObjects(objs, loadFactory);
57451981545c Re #10 and re #11 - Refactor code and document code
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
386 }
57451981545c Re #10 and re #11 - Refactor code and document code
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
387 else
57451981545c Re #10 and re #11 - Refactor code and document code
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
388 {
57451981545c Re #10 and re #11 - Refactor code and document code
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
389 objs = new List<IWarFoundryObject>();
57451981545c Re #10 and re #11 - Refactor code and document code
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
390 }
57451981545c Re #10 and re #11 - Refactor code and document code
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
391
57451981545c Re #10 and re #11 - Refactor code and document code
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
392 return objs;
57451981545c Re #10 and re #11 - Refactor code and document code
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
393 }
57451981545c Re #10 and re #11 - Refactor code and document code
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
394
57451981545c Re #10 and re #11 - Refactor code and document code
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
395 private ICollection<IWarFoundryObject> LoadFileWithNonNativeFactories(FileInfo file, out IWarFoundryFactory loadFactory)
57451981545c Re #10 and re #11 - Refactor code and document code
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
396 {
57451981545c Re #10 and re #11 - Refactor code and document code
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
397 ICollection<IWarFoundryObject> objs = null;
57451981545c Re #10 and re #11 - Refactor code and document code
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
398 loadFactory = null;
57451981545c Re #10 and re #11 - Refactor code and document code
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
399
14
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
400 if (nonNativeFactories.Count > 0)
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
401 {
14
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
402 LogNotifier.Debug(GetType(), "Attempting to load "+file.FullName+" as a non-native file");
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
403
14
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
404 foreach (INonNativeWarFoundryFactory factory in nonNativeFactories)
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
405 {
14
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
406 bool canLoad = factory.CanHandleFileFormat(file);
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
407 LogNotifier.Debug(GetType(), "Load using "+factory.GetType().FullName+"? " + (canLoad ? "yes" : "no"));
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
408
14
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
409 if (canLoad)
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
410 {
14
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
411 objs = factory.CreateObjectsFromFile(file);
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
412
14
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
413 if (objs!=null)
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
414 {
14
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
415 loadFactory = factory;
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
416 break;
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
417 }
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
418 }
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
419 }
14
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
420 }
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
421
19
57451981545c Re #10 and re #11 - Refactor code and document code
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
422 return objs;
57451981545c Re #10 and re #11 - Refactor code and document code
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
423 }
57451981545c Re #10 and re #11 - Refactor code and document code
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
424
57451981545c Re #10 and re #11 - Refactor code and document code
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
425 private ICollection<IWarFoundryObject> LoadFileWithNativeFactories(FileInfo file, out IWarFoundryFactory loadFactory)
57451981545c Re #10 and re #11 - Refactor code and document code
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
426 {
57451981545c Re #10 and re #11 - Refactor code and document code
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
427 ICollection<IWarFoundryObject> objs = null;
57451981545c Re #10 and re #11 - Refactor code and document code
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
428 loadFactory = null;
57451981545c Re #10 and re #11 - Refactor code and document code
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
429
57451981545c Re #10 and re #11 - Refactor code and document code
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
430 if (factories.Count > 0)
14
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
431 {
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
432 LogNotifier.Debug(GetType(), "Attempting to load "+file.FullName+" as native file");
19
57451981545c Re #10 and re #11 - Refactor code and document code
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
433
14
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
434 foreach (INativeWarFoundryFactory factory in factories)
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
435 {
14
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
436 if (factory.CanHandleFileFormat(file))
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
437 {
14
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
438 objs = factory.CreateObjectsFromFile(file);
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
439
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
440 if (objs!=null)
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
441 {
14
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
442 loadFactory = factory;
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
443 break;
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
444 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
445 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
446 }
14
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
447 }
19
57451981545c Re #10 and re #11 - Refactor code and document code
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
448
14
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
449 return objs;
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
450 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
451
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
452 private void AddLoadedObjects(ICollection<IWarFoundryObject> loadedObjs, IWarFoundryFactory factory)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
453 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
454 SimpleSet<IWarFoundryObject> objs;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
455 loadedObjects.TryGetValue(factory, out objs);
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
456
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
457 if (objs == null)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
458 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
459 objs = new SimpleSet<IWarFoundryObject>();
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
460 loadedObjects.Add(factory, objs);
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
461 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
462
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
463 objs.AddRange(loadedObjs);
14
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
464 StoreObjects(loadedObjs);
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
465 }
14
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
466
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
467 private void StoreObjects(ICollection<IWarFoundryObject> loadedObjects)
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
468 {
14
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
469 foreach (IWarFoundryObject loadedObject in loadedObjects)
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
470 {
14
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
471 if (loadedObject is GameSystem)
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
472 {
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
473 StoreGameSystem((GameSystem)loadedObject);
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
474 }
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
475 else if (loadedObject is Race)
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
476 {
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
477 StoreRace((Race)loadedObject);
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
478 }
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
479 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
480 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
481
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
482 protected void StoreGameSystem(GameSystem system)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
483 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
484 string sysid = system.ID.ToLower();
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
485
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
486 if (systemsTable.ContainsKey(sysid))
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
487 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
488 LogNotifier.WarnFormat(GetType(), "System {0} ({1}) has already been loaded. Duplicate file ({3}) discarded", system.Name, system.ID, system.SourceFile.FullName);
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
489 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
490 else
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
491 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
492 systemsTable.Add(sysid, (GameSystem)system);
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
493 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
494 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
495
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
496 protected void StoreRace(Race race)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
497 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
498 Dictionary<string, Dictionary<string, Race>> systemRaces;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
499
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
500 if (race.GameSystem == null)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
501 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
502 throw new InvalidOperationException("Race cannot have null game system. Game system should be loaded before race.");
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
503 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
504
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
505 string systemID = race.GameSystem.ID.ToLower();
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
506 racesTable.TryGetValue(systemID, out systemRaces);
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
507
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
508 if (systemRaces==null)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
509 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
510 systemRaces = new Dictionary<string,Dictionary<string,Race>>();
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
511 racesTable.Add(systemID, systemRaces);
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
512 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
513
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
514 Dictionary<string, Race> subRaces;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
515 systemRaces.TryGetValue(race.ID.ToLower(), out subRaces);
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
516
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
517 if (subRaces==null)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
518 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
519 subRaces = new Dictionary<string,Race>();
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
520 systemRaces.Add(race.ID.ToLower(), subRaces);
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
521 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
522
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
523 if (subRaces.ContainsKey(race.SubID.ToLower()))
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
524 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
525 LogNotifier.WarnFormat(GetType(), "Race {0} ({1} - {2}) for system {3} ({4}) has already been loaded. Duplicate file ({5}) discarded", race.Name, race.ID, race.SubID, race.GameSystem.ID, race.GameSystem.Name, race.SourceFile.Name);
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
526 race = null;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
527 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
528 else
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
529 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
530 subRaces.Add(race.SubID.ToLower(), race);
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
531 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
532 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
533
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
534 /// <summary>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
535 /// Gets all <see cref="GameSystem"/>s that are currently available, determined by those that can be loaded with the current <see cref="IWarFoundryFactory"/>s.
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
536 /// </summary>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
537 /// <returns>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
538 /// An array of <see cref="GameSystem"/>s that are currently available.
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
539 /// </returns>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
540 public GameSystem[] GetGameSystems()
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
541 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
542 if (systemsTable==null)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
543 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
544 LoadFiles();
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
545 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
546
14
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
547 return DictionaryUtils.ToArray<string, GameSystem>(systemsTable);
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
548 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
549
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
550 /// <summary>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
551 /// Gets a single <see cref="GameSystem"/> with a given ID.
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
552 /// </summary>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
553 /// <param name="systemID">
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
554 /// The ID of the <see cref="GameSystem"/> to get, as a <see cref="System.String"/>.
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
555 /// </param>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
556 /// <returns>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
557 /// The <see cref="GameSystem"/> with the given ID, or <code>null</code> if one doesn't exist.
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
558 /// </returns>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
559 public GameSystem GetGameSystem(string systemID)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
560 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
561 if (systemsTable==null)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
562 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
563 LoadFiles();
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
564 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
565
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
566 GameSystem system;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
567 systemsTable.TryGetValue(systemID.ToLower(), out system);
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
568 return system;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
569 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
570
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
571 /// <summary>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
572 /// Gets an array of the races for the specified <see cref="GameSystem"/>.
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
573 /// </summary>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
574 /// <param name="system">
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
575 /// The <see cref="GameSystem"/> to get the available races for.
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
576 /// </param>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
577 /// <returns>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
578 /// An array of <see cref="Race"/>s for the <see cref="GameSystem"/>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
579 /// </returns>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
580 public Race[] GetRaces(GameSystem system)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
581 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
582 return GetRaces(system.ID);
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
583 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
584
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
585 /// <summary>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
586 /// Gets an array of the races for a game system by ID.
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
587 /// </summary>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
588 /// <param name="systemID">
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
589 /// The <see cref="System.String"/> ID of the game system to get races for
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
590 /// </param>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
591 /// <returns>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
592 /// An array of <see cref="Race"/>s for the specified game system
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
593 /// </returns>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
594 public Race[] GetRaces(string systemID)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
595 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
596 if (racesTable==null)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
597 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
598 LoadFiles();
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
599 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
600
8
613bc5eaac59 Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents: 5
diff changeset
601 systemID = systemID.ToLower();
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
602 Dictionary<string, Dictionary<string, Race>> system;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
603 racesTable.TryGetValue(systemID, out system);
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
604
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
605 if (system==null)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
606 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
607 return new Race[0];
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
608 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
609
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
610 int count = 0;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
611
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
612 foreach (Dictionary<string, Race> racesDict in system.Values)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
613 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
614 count+= racesDict.Count;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
615 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
616
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
617 Race[] races = new Race[count];
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
618 int i = 0;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
619
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
620 foreach (string raceID in system.Keys)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
621 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
622 foreach (string raceSubId in system[raceID].Keys)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
623 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
624 races[i++] = GetRace(systemID, raceID, raceSubId);
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
625 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
626 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
627
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
628 return races;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
629 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
630
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
631 /// <summary>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
632 /// Gets a single race for a given <see cref="GameSystem"/> by ID of the race.
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
633 /// </summary>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
634 /// <param name="system">
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
635 /// The <see cref="GameSystem"/> that the race is part of.
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
636 /// </param>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
637 /// <param name="raceID">
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
638 /// A <see cref="System.String"/> ID for the race to load.
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
639 /// </param>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
640 /// <returns>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
641 /// A <see cref="Race"/> with the specified ID from the <see cref="GameSystem"/>, or <code>null</code> if one doesn't exist.
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
642 /// </returns>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
643 public Race GetRace(GameSystem system, string raceID)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
644 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
645 return GetRace(system.ID, raceID);
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
646 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
647
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
648 /// <summary>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
649 /// Gets a single race for a given game system by ID of the game system and race.
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
650 /// </summary>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
651 /// <param name="systemID">
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
652 /// The <see cref="System.String"/> ID of the game system that the race is part of.
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
653 /// </param>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
654 /// <param name="raceID">
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
655 /// The <see cref="System.String"/> ID for the race to load.
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
656 /// </param>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
657 /// <returns>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
658 /// A <see cref="Race"/> with the specified ID from the game system with the specified ID, or <code>null</code> if there is no race or game system with those IDs.
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
659 /// </returns>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
660 public Race GetRace(string systemID, string raceID)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
661 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
662 return GetRace(systemID, raceID, "");
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
663 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
664
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
665 /// <summary>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
666 /// Gets a single race for a given <see cref="GameSystem"/> by the race's ID and sub-race ID.
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
667 /// </summary>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
668 /// <param name="system">
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
669 /// The <see cref="GameSystem"/> that the race is part of.
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
670 /// </param>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
671 /// <param name="raceID">
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
672 /// The <see cref="System.String"/> ID for the race to load.
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
673 /// </param>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
674 /// <param name="raceSubID">
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
675 /// A <see cref="System.String"/>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
676 /// </param>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
677 /// <returns>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
678 /// A <see cref="Race"/>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
679 /// </returns>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
680 public Race GetRace(GameSystem system, string raceID, string raceSubID)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
681 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
682 return GetRace(system.ID, raceID, raceSubID);
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
683 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
684
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
685 /// <summary>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
686 /// Gets a single race for a given game system by the game system's ID and the race's ID and sub-race ID.
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
687 /// </summary>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
688 /// <param name="systemID">
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
689 /// The <see cref="System.String"/> ID of the game system that the race is part of.
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
690 /// </param>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
691 /// <param name="raceID">
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
692 /// The <see cref="System.String"/> ID for the race to load.
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
693 /// </param>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
694 /// <param name="raceSubID">
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
695 /// A <see cref="System.String"/>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
696 /// </param>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
697 /// <returns>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
698 /// A <see cref="Race"/>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
699 /// </returns>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
700 public Race GetRace(string systemID, string raceID, string raceSubID)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
701 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
702 if (racesTable==null)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
703 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
704 LoadFiles();
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
705 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
706
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
707 Race race = null;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
708
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
709 systemID = systemID.ToLower();
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
710
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
711 Dictionary<string, Dictionary<string, Race>> races;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
712 racesTable.TryGetValue(systemID, out races);
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
713
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
714 if (races!=null)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
715 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
716 Dictionary<string, Race> subraces;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
717 races.TryGetValue(raceID, out subraces);
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
718
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
719 if (subraces!=null)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
720 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
721 subraces.TryGetValue(raceSubID, out race);
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
722 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
723 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
724
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
725 return race;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
726 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
727
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
728 /// <summary>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
729 /// Gets the IDs of all of the game systems currently available.
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
730 /// </summary>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
731 /// <returns>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
732 /// An array of <see cref="System.String"/>s representing the IDs of the game systems.
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
733 /// </returns>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
734 public string[] GetGameSystemIDs()
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
735 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
736 if (systemsTable==null)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
737 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
738 LoadFiles();
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
739 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
740
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
741 string[] keys = new string[systemsTable.Keys.Count];
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
742 int i = 0;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
743
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
744 foreach (string key in systemsTable.Keys)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
745 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
746 keys[i++] = key;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
747 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
748
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
749 return keys;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
750 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
751
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
752 /// <summary>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
753 /// Gets the IDs of all of the races of a specified game system.
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
754 /// </summary>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
755 /// <param name="system">
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
756 /// The <see cref="GameSystem"/> to get the available races for.
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
757 /// </param>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
758 /// <returns>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
759 /// An array of <see cref="System.String"/>s representing the IDs of the races of the specified game system.
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
760 /// </returns>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
761 public string[] GetSystemRaceIDs(GameSystem system)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
762 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
763 return GetSystemRaceIDs(system.ID);
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
764 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
765
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
766 /// <summary>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
767 /// Gets the IDs of all of the races of a specified game system.
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
768 /// </summary>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
769 /// <param name="systemID">
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
770 /// The <see cref="System.String"/> ID of the game system to get the available races for.
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
771 /// </param>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
772 /// <returns>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
773 /// An array of <see cref="System.String"/>s representing the IDs of the races of the specified game system.
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
774 /// </returns>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
775 public string[] GetSystemRaceIDs(string systemID)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
776 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
777 if (racesTable == null)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
778 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
779 LoadFiles();
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
780 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
781
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
782 Dictionary<string, Dictionary<string, Race>> races = racesTable[systemID.ToLower()];
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
783
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
784 if (races==null)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
785 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
786 return new string[0];
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
787 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
788 else
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
789 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
790 string[] keys = new string[races.Keys.Count];
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
791 int i = 0;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
792
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
793 foreach (string key in races.Keys)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
794 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
795 keys[i++] = key;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
796 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
797
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
798 return keys;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
799 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
800 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
801 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
802 }