Mercurial > repos > snowblizz-super-API-ideas
annotate api/WarFoundryLoader.cs @ 114:a143b077a825
Re #54: Add Army support to WarFoundryFactory
* Make sure that race and sub-race IDs are lower case so that we can find them when we load
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sat, 22 Aug 2009 18:35:03 +0000 |
parents | 863518044d38 |
children | 32b774f24017 |
rev | line source |
---|---|
104
2f3cafb69799
Re #121: Migrate to AGPL license
IBBoard <dev@ibboard.co.uk>
parents:
102
diff
changeset
|
1 // This file (WarFoundryLoader.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2007, 2008, 2009 IBBoard. |
0 | 2 // |
104
2f3cafb69799
Re #121: Migrate to AGPL license
IBBoard <dev@ibboard.co.uk>
parents:
102
diff
changeset
|
3 // The file and the library/program it is in are licensed and distributed, without warranty, under the GNU Affero GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license. |
0 | 4 |
5 using System; | |
6 using System.Collections.Generic; | |
7 using System.IO; | |
8 using IBBoard.Collections; | |
9 using IBBoard.IO; | |
10 using IBBoard.Logging; | |
11 using IBBoard.WarFoundry.API.Factories; | |
12 using IBBoard.WarFoundry.API.Objects; | |
13 using ICSharpCode.SharpZipLib.Zip; | |
14 | |
15 namespace IBBoard.WarFoundry.API | |
16 { | |
17 public class WarFoundryLoader | |
18 { | |
19 private static WarFoundryLoader loader; | |
20 | |
21 /// <summary> | |
22 /// Gets the default <see cref="WarFoundryLoader"/> used to load WarFoundry data files. | |
23 /// </summary> | |
24 /// <returns> | |
25 /// The default <see cref="WarFoundryLoader"/> | |
26 /// </returns> | |
27 public static WarFoundryLoader GetDefault() | |
28 { | |
29 if (loader == null) | |
30 { | |
31 loader = new WarFoundryLoader(); | |
32 } | |
33 | |
34 return loader; | |
35 } | |
36 | |
37 private ICollection<DirectoryInfo> directories; | |
38 private ICollection<INativeWarFoundryFactory> factories; | |
39 private ICollection<INonNativeWarFoundryFactory> nonNativeFactories; | |
40 private Dictionary<string, GameSystem> systemsTable; | |
41 private Dictionary<string, Dictionary<string, Dictionary<string, Race>>> racesTable; //Keys are: System, Race, SubRace | |
42 private Dictionary<IWarFoundryFactory, SimpleSet<IWarFoundryObject>> loadedObjects; | |
43 | |
44 protected WarFoundryLoader() | |
45 { | |
46 directories = new List<DirectoryInfo>(); | |
47 factories = new List<INativeWarFoundryFactory>(); | |
48 nonNativeFactories = new List<INonNativeWarFoundryFactory>(); | |
49 loadedObjects = new Dictionary<IWarFoundryFactory,SimpleSet<IWarFoundryObject>>(); | |
50 } | |
51 | |
52 /// <summary> | |
53 /// Adds a directory to the collection of directories that will be searched for WarFoundry data files. | |
54 /// </summary> | |
55 /// <param name="directory"> | |
56 /// The <see cref="DirectoryInfo"/> to add to the list for searching for data files | |
57 /// </param> | |
58 public void AddLoadDirectory(DirectoryInfo directory) | |
59 { | |
60 if (!directories.Contains(directory)) | |
61 { | |
62 directories.Add(directory); | |
63 } | |
64 } | |
65 | |
66 /// <summary> | |
67 /// Removes a directory from the collection of directories that will be searched for WarFoundry data files. | |
68 /// </summary> | |
69 /// <param name="directory"> | |
70 /// A <see cref="DirectoryInfo"/> | |
71 /// </param> | |
72 public void RemoveLoadDirectory(DirectoryInfo directory) | |
73 { | |
74 if (directories.Contains(directory)) | |
75 { | |
76 directories.Remove(directory); | |
77 } | |
78 } | |
79 | |
80 /// <summary> | |
81 /// Registers a <see cref="INativeWarFoundryFactory"/> as a factory that can parse native data files. | |
82 /// </summary> | |
83 /// <param name="factory"> | |
84 /// The <see cref="INativeWarFoundryFactory"/> to register to parse native data files. | |
85 /// </param> | |
86 public void RegisterFactory(INativeWarFoundryFactory factory) | |
87 { | |
88 if (!factories.Contains(factory)) | |
89 { | |
90 factories.Add(factory); | |
91 } | |
92 } | |
93 | |
94 /// <summary> | |
95 /// Unregisters a <see cref="INativeWarFoundryFactory"/> so that it will no longer be used to try to parse native data files. | |
96 /// </summary> | |
97 /// <param name="factory"> | |
98 /// The <see cref="INativeWarFoundryFactory"/> to remove from the collection of factories that are used to try to parse native data files. | |
99 /// </param> | |
100 public void UnregisterFactory(INativeWarFoundryFactory factory) | |
101 { | |
102 if (factories.Contains(factory)) | |
103 { | |
104 factories.Remove(factory); | |
105 } | |
106 } | |
107 | |
108 /// <summary> | |
109 /// Registers a <see cref="INonNativeWarFoundryFactory"/> so that it will be used to try to parse non-native data files from other applications. | |
110 /// </summary> | |
111 /// <param name="factory"> | |
112 /// The <see cref="INonNativeWarFoundryFactory"/> to register to parse non-native data files. | |
113 /// </param> | |
114 public void RegisterNonNativeFactory(INonNativeWarFoundryFactory factory) | |
115 { | |
116 if (!nonNativeFactories.Contains(factory)) | |
117 { | |
118 nonNativeFactories.Add(factory); | |
119 } | |
120 } | |
121 | |
122 /// <summary> | |
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. | |
124 /// </summary> | |
125 /// <param name="factory"> | |
126 /// The <see cref="INonNativeWarFoundryFactory"/> to remove from the collection of factories that are used to try to parse non-native data files. | |
127 /// </param> | |
128 public void UnregisterNonNativeFactory(INonNativeWarFoundryFactory factory) | |
129 { | |
130 if (nonNativeFactories.Contains(factory)) | |
131 { | |
132 nonNativeFactories.Remove(factory); | |
133 } | |
134 } | |
135 | |
136 /// <summary> | |
137 /// Loads all of the data files in the registered directories. | |
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 | 143 { |
144 LogNotifier.Debug(GetType(), "Load files"); | |
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 | 153 |
14
0770e5cbba7c
Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
154 return failedLoads; |
0 | 155 } |
156 | |
157 protected void PrepareForFileLoad() | |
158 { | |
159 //Just set up blank dictionaries for now - may try different and more complex handling in future | |
160 systemsTable = new Dictionary<string,GameSystem>(); | |
161 racesTable = new Dictionary<string,Dictionary<string,Dictionary<string,Race>>>(); | |
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 | 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 | 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 | 354 |
355 /// <summary> | |
356 /// Loads a single file through the registered WarFoundryFactories, if a factory exists that supports the file format. | |
357 /// </summary> | |
358 /// <param name="file"> | |
359 /// A <see cref="FileInfo"/> for the file to attempt to load | |
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 | 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 | 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 | 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 | 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 | 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 | 408 |
14
0770e5cbba7c
Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
409 if (canLoad) |
0 | 410 { |
14
0770e5cbba7c
Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
411 objs = factory.CreateObjectsFromFile(file); |
0 | 412 |
14
0770e5cbba7c
Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
413 if (objs!=null) |
0 | 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 | 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 | 435 { |
14
0770e5cbba7c
Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
436 if (factory.CanHandleFileFormat(file)) |
0 | 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 | 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 | 444 } |
445 } | |
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 | 450 } |
451 | |
452 private void AddLoadedObjects(ICollection<IWarFoundryObject> loadedObjs, IWarFoundryFactory factory) | |
453 { | |
454 SimpleSet<IWarFoundryObject> objs; | |
455 loadedObjects.TryGetValue(factory, out objs); | |
456 | |
457 if (objs == null) | |
458 { | |
459 objs = new SimpleSet<IWarFoundryObject>(); | |
460 loadedObjects.Add(factory, objs); | |
461 } | |
462 | |
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 | 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 | 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 | 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 | 479 } |
480 } | |
481 | |
482 protected void StoreGameSystem(GameSystem system) | |
483 { | |
484 string sysid = system.ID.ToLower(); | |
82 | 485 |
486 if (systemsTable.ContainsKey(sysid)) | |
0 | 487 { |
102
c85ea8988455
Re #123: Rollcall plugin won't re-add Game System on reload
IBBoard <dev@ibboard.co.uk>
parents:
82
diff
changeset
|
488 GameSystem existingSystem = systemsTable[sysid]; |
c85ea8988455
Re #123: Rollcall plugin won't re-add Game System on reload
IBBoard <dev@ibboard.co.uk>
parents:
82
diff
changeset
|
489 |
c85ea8988455
Re #123: Rollcall plugin won't re-add Game System on reload
IBBoard <dev@ibboard.co.uk>
parents:
82
diff
changeset
|
490 if (!system.Equals(existingSystem)) |
c85ea8988455
Re #123: Rollcall plugin won't re-add Game System on reload
IBBoard <dev@ibboard.co.uk>
parents:
82
diff
changeset
|
491 { |
c85ea8988455
Re #123: Rollcall plugin won't re-add Game System on reload
IBBoard <dev@ibboard.co.uk>
parents:
82
diff
changeset
|
492 //TODO: Raise an event to say we got a different duplicate |
c85ea8988455
Re #123: Rollcall plugin won't re-add Game System on reload
IBBoard <dev@ibboard.co.uk>
parents:
82
diff
changeset
|
493 //We can't just fail, because failing is for completely unhandled files, not for objects in a file |
c85ea8988455
Re #123: Rollcall plugin won't re-add Game System on reload
IBBoard <dev@ibboard.co.uk>
parents:
82
diff
changeset
|
494 } |
82 | 495 } |
496 else | |
497 { | |
498 systemsTable.Add(sysid, (GameSystem)system); | |
0 | 499 } |
500 } | |
501 | |
502 protected void StoreRace(Race race) | |
503 { | |
504 Dictionary<string, Dictionary<string, Race>> systemRaces; | |
505 | |
506 if (race.GameSystem == null) | |
507 { | |
508 throw new InvalidOperationException("Race cannot have null game system. Game system should be loaded before race."); | |
509 } | |
510 | |
511 string systemID = race.GameSystem.ID.ToLower(); | |
512 racesTable.TryGetValue(systemID, out systemRaces); | |
513 | |
514 if (systemRaces==null) | |
515 { | |
516 systemRaces = new Dictionary<string,Dictionary<string,Race>>(); | |
517 racesTable.Add(systemID, systemRaces); | |
518 } | |
519 | |
520 Dictionary<string, Race> subRaces; | |
521 systemRaces.TryGetValue(race.ID.ToLower(), out subRaces); | |
522 | |
523 if (subRaces==null) | |
524 { | |
525 subRaces = new Dictionary<string,Race>(); | |
526 systemRaces.Add(race.ID.ToLower(), subRaces); | |
527 } | |
102
c85ea8988455
Re #123: Rollcall plugin won't re-add Game System on reload
IBBoard <dev@ibboard.co.uk>
parents:
82
diff
changeset
|
528 |
c85ea8988455
Re #123: Rollcall plugin won't re-add Game System on reload
IBBoard <dev@ibboard.co.uk>
parents:
82
diff
changeset
|
529 string subID = race.SubID.ToLower(); |
0 | 530 |
102
c85ea8988455
Re #123: Rollcall plugin won't re-add Game System on reload
IBBoard <dev@ibboard.co.uk>
parents:
82
diff
changeset
|
531 if (subRaces.ContainsKey(subID)) |
0 | 532 { |
102
c85ea8988455
Re #123: Rollcall plugin won't re-add Game System on reload
IBBoard <dev@ibboard.co.uk>
parents:
82
diff
changeset
|
533 Race existingRace = subRaces[subID]; |
c85ea8988455
Re #123: Rollcall plugin won't re-add Game System on reload
IBBoard <dev@ibboard.co.uk>
parents:
82
diff
changeset
|
534 |
c85ea8988455
Re #123: Rollcall plugin won't re-add Game System on reload
IBBoard <dev@ibboard.co.uk>
parents:
82
diff
changeset
|
535 if (!race.Equals(existingRace)) |
c85ea8988455
Re #123: Rollcall plugin won't re-add Game System on reload
IBBoard <dev@ibboard.co.uk>
parents:
82
diff
changeset
|
536 { |
c85ea8988455
Re #123: Rollcall plugin won't re-add Game System on reload
IBBoard <dev@ibboard.co.uk>
parents:
82
diff
changeset
|
537 //TODO: Raise an event to say we got a different duplicate |
c85ea8988455
Re #123: Rollcall plugin won't re-add Game System on reload
IBBoard <dev@ibboard.co.uk>
parents:
82
diff
changeset
|
538 //We can't just fail, because failing is for completely unhandled files, not for objects in a file |
c85ea8988455
Re #123: Rollcall plugin won't re-add Game System on reload
IBBoard <dev@ibboard.co.uk>
parents:
82
diff
changeset
|
539 } |
0 | 540 } |
541 else | |
542 { | |
543 subRaces.Add(race.SubID.ToLower(), race); | |
544 } | |
545 } | |
546 | |
547 /// <summary> | |
548 /// Gets all <see cref="GameSystem"/>s that are currently available, determined by those that can be loaded with the current <see cref="IWarFoundryFactory"/>s. | |
549 /// </summary> | |
550 /// <returns> | |
551 /// An array of <see cref="GameSystem"/>s that are currently available. | |
552 /// </returns> | |
553 public GameSystem[] GetGameSystems() | |
82 | 554 { |
555 if (systemsTable==null) | |
556 { | |
557 LoadFiles(); | |
0 | 558 } |
559 | |
14
0770e5cbba7c
Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
560 return DictionaryUtils.ToArray<string, GameSystem>(systemsTable); |
82 | 561 } |
0 | 562 |
563 /// <summary> | |
564 /// Gets a single <see cref="GameSystem"/> with a given ID. | |
565 /// </summary> | |
566 /// <param name="systemID"> | |
567 /// The ID of the <see cref="GameSystem"/> to get, as a <see cref="System.String"/>. | |
568 /// </param> | |
569 /// <returns> | |
570 /// The <see cref="GameSystem"/> with the given ID, or <code>null</code> if one doesn't exist. | |
82 | 571 /// </returns> |
572 public GameSystem GetGameSystem(string systemID) | |
573 { | |
574 if (systemsTable==null) | |
575 { | |
576 LoadFiles(); | |
0 | 577 } |
578 | |
579 GameSystem system; | |
82 | 580 systemsTable.TryGetValue(systemID.ToLower(), out system); |
581 return system; | |
582 } | |
0 | 583 |
584 /// <summary> | |
585 /// Gets an array of the races for the specified <see cref="GameSystem"/>. | |
586 /// </summary> | |
587 /// <param name="system"> | |
588 /// The <see cref="GameSystem"/> to get the available races for. | |
589 /// </param> | |
590 /// <returns> | |
591 /// An array of <see cref="Race"/>s for the <see cref="GameSystem"/> | |
82 | 592 /// </returns> |
593 public Race[] GetRaces(GameSystem system) | |
594 { | |
595 return GetRaces(system.ID); | |
596 } | |
0 | 597 |
598 /// <summary> | |
599 /// Gets an array of the races for a game system by ID. | |
600 /// </summary> | |
601 /// <param name="systemID"> | |
602 /// The <see cref="System.String"/> ID of the game system to get races for | |
603 /// </param> | |
604 /// <returns> | |
605 /// An array of <see cref="Race"/>s for the specified game system | |
82 | 606 /// </returns> |
607 public Race[] GetRaces(string systemID) | |
608 { | |
609 if (racesTable==null) | |
610 { | |
611 LoadFiles(); | |
0 | 612 } |
613 | |
82 | 614 systemID = systemID.ToLower(); |
0 | 615 Dictionary<string, Dictionary<string, Race>> system; |
82 | 616 racesTable.TryGetValue(systemID, out system); |
617 | |
618 if (system==null) | |
619 { | |
620 return new Race[0]; | |
621 } | |
622 | |
623 int count = 0; | |
624 | |
625 foreach (Dictionary<string, Race> racesDict in system.Values) | |
626 { | |
627 count+= racesDict.Count; | |
628 } | |
629 | |
630 Race[] races = new Race[count]; | |
631 int i = 0; | |
632 | |
633 foreach (string raceID in system.Keys) | |
634 { | |
635 foreach (string raceSubId in system[raceID].Keys) | |
636 { | |
637 races[i++] = GetRace(systemID, raceID, raceSubId); | |
638 } | |
639 } | |
640 | |
641 return races; | |
642 } | |
0 | 643 |
644 /// <summary> | |
645 /// Gets a single race for a given <see cref="GameSystem"/> by ID of the race. | |
646 /// </summary> | |
647 /// <param name="system"> | |
648 /// The <see cref="GameSystem"/> that the race is part of. | |
649 /// </param> | |
650 /// <param name="raceID"> | |
651 /// A <see cref="System.String"/> ID for the race to load. | |
652 /// </param> | |
653 /// <returns> | |
654 /// A <see cref="Race"/> with the specified ID from the <see cref="GameSystem"/>, or <code>null</code> if one doesn't exist. | |
82 | 655 /// </returns> |
656 public Race GetRace(GameSystem system, string raceID) | |
657 { | |
658 return GetRace(system.ID, raceID); | |
659 } | |
0 | 660 |
661 /// <summary> | |
662 /// Gets a single race for a given game system by ID of the game system and race. | |
663 /// </summary> | |
664 /// <param name="systemID"> | |
665 /// The <see cref="System.String"/> ID of the game system that the race is part of. | |
666 /// </param> | |
667 /// <param name="raceID"> | |
668 /// The <see cref="System.String"/> ID for the race to load. | |
669 /// </param> | |
670 /// <returns> | |
671 /// 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. | |
82 | 672 /// </returns> |
673 public Race GetRace(string systemID, string raceID) | |
674 { | |
675 return GetRace(systemID, raceID, ""); | |
676 } | |
0 | 677 |
678 /// <summary> | |
679 /// Gets a single race for a given <see cref="GameSystem"/> by the race's ID and sub-race ID. | |
680 /// </summary> | |
681 /// <param name="system"> | |
682 /// The <see cref="GameSystem"/> that the race is part of. | |
683 /// </param> | |
684 /// <param name="raceID"> | |
685 /// The <see cref="System.String"/> ID for the race to load. | |
686 /// </param> | |
687 /// <param name="raceSubID"> | |
688 /// A <see cref="System.String"/> | |
689 /// </param> | |
690 /// <returns> | |
691 /// A <see cref="Race"/> | |
82 | 692 /// </returns> |
693 public Race GetRace(GameSystem system, string raceID, string raceSubID) | |
694 { | |
695 return GetRace(system.ID, raceID, raceSubID); | |
696 } | |
0 | 697 |
698 /// <summary> | |
699 /// Gets a single race for a given game system by the game system's ID and the race's ID and sub-race ID. | |
700 /// </summary> | |
701 /// <param name="systemID"> | |
702 /// The <see cref="System.String"/> ID of the game system that the race is part of. | |
703 /// </param> | |
704 /// <param name="raceID"> | |
705 /// The <see cref="System.String"/> ID for the race to load. | |
706 /// </param> | |
707 /// <param name="raceSubID"> | |
708 /// A <see cref="System.String"/> | |
709 /// </param> | |
710 /// <returns> | |
711 /// A <see cref="Race"/> | |
82 | 712 /// </returns> |
713 public Race GetRace(string systemID, string raceID, string raceSubID) | |
714 { | |
715 if (racesTable==null) | |
716 { | |
717 LoadFiles(); | |
0 | 718 } |
719 | |
720 Race race = null; | |
721 | |
82 | 722 systemID = systemID.ToLower(); |
114
a143b077a825
Re #54: Add Army support to WarFoundryFactory
IBBoard <dev@ibboard.co.uk>
parents:
112
diff
changeset
|
723 raceID = raceID.ToLower(); |
a143b077a825
Re #54: Add Army support to WarFoundryFactory
IBBoard <dev@ibboard.co.uk>
parents:
112
diff
changeset
|
724 raceSubID = raceSubID.ToLower(); |
82 | 725 |
114
a143b077a825
Re #54: Add Army support to WarFoundryFactory
IBBoard <dev@ibboard.co.uk>
parents:
112
diff
changeset
|
726 Dictionary<string, Dictionary<string, Race>> races; |
82 | 727 racesTable.TryGetValue(systemID, out races); |
728 | |
729 if (races!=null) | |
730 { | |
0 | 731 Dictionary<string, Race> subraces; |
82 | 732 races.TryGetValue(raceID, out subraces); |
733 | |
734 if (subraces!=null) | |
0 | 735 { |
82 | 736 subraces.TryGetValue(raceSubID, out race); |
737 } | |
0 | 738 } |
739 | |
82 | 740 return race; |
741 } | |
0 | 742 |
743 /// <summary> | |
744 /// Gets the IDs of all of the game systems currently available. | |
745 /// </summary> | |
746 /// <returns> | |
747 /// An array of <see cref="System.String"/>s representing the IDs of the game systems. | |
82 | 748 /// </returns> |
749 public string[] GetGameSystemIDs() | |
750 { | |
751 if (systemsTable==null) | |
752 { | |
753 LoadFiles(); | |
754 } | |
755 | |
756 string[] keys = new string[systemsTable.Keys.Count]; | |
757 int i = 0; | |
758 | |
759 foreach (string key in systemsTable.Keys) | |
760 { | |
761 keys[i++] = key; | |
762 } | |
763 | |
764 return keys; | |
0 | 765 } |
766 | |
767 /// <summary> | |
768 /// Gets the IDs of all of the races of a specified game system. | |
769 /// </summary> | |
770 /// <param name="system"> | |
771 /// The <see cref="GameSystem"/> to get the available races for. | |
772 /// </param> | |
773 /// <returns> | |
774 /// An array of <see cref="System.String"/>s representing the IDs of the races of the specified game system. | |
775 /// </returns> | |
776 public string[] GetSystemRaceIDs(GameSystem system) | |
777 { | |
778 return GetSystemRaceIDs(system.ID); | |
82 | 779 } |
0 | 780 |
781 /// <summary> | |
782 /// Gets the IDs of all of the races of a specified game system. | |
783 /// </summary> | |
784 /// <param name="systemID"> | |
785 /// The <see cref="System.String"/> ID of the game system to get the available races for. | |
786 /// </param> | |
787 /// <returns> | |
788 /// An array of <see cref="System.String"/>s representing the IDs of the races of the specified game system. | |
82 | 789 /// </returns> |
790 public string[] GetSystemRaceIDs(string systemID) | |
791 { | |
792 if (racesTable == null) | |
793 { | |
794 LoadFiles(); | |
795 } | |
796 | |
797 Dictionary<string, Dictionary<string, Race>> races = racesTable[systemID.ToLower()]; | |
798 | |
799 if (races==null) | |
800 { | |
801 return new string[0]; | |
802 } | |
803 else | |
804 { | |
805 string[] keys = new string[races.Keys.Count]; | |
806 int i = 0; | |
807 | |
808 foreach (string key in races.Keys) | |
809 { | |
810 keys[i++] = key; | |
811 } | |
812 | |
813 return keys; | |
814 } | |
0 | 815 } |
111
b5ae022ce7b8
Re #54: Add army loading support
IBBoard <dev@ibboard.co.uk>
parents:
104
diff
changeset
|
816 |
b5ae022ce7b8
Re #54: Add army loading support
IBBoard <dev@ibboard.co.uk>
parents:
104
diff
changeset
|
817 public Army LoadArmy(FileInfo file) |
b5ae022ce7b8
Re #54: Add army loading support
IBBoard <dev@ibboard.co.uk>
parents:
104
diff
changeset
|
818 { |
112
863518044d38
Re #54: Add Army support to WarFoundryFactory
IBBoard <dev@ibboard.co.uk>
parents:
111
diff
changeset
|
819 IWarFoundryFactory factory = GetArmyLoadingFactoryForFile(file); |
111
b5ae022ce7b8
Re #54: Add army loading support
IBBoard <dev@ibboard.co.uk>
parents:
104
diff
changeset
|
820 Army loadedArmy = null; |
b5ae022ce7b8
Re #54: Add army loading support
IBBoard <dev@ibboard.co.uk>
parents:
104
diff
changeset
|
821 |
112
863518044d38
Re #54: Add Army support to WarFoundryFactory
IBBoard <dev@ibboard.co.uk>
parents:
111
diff
changeset
|
822 if (factory != null) |
111
b5ae022ce7b8
Re #54: Add army loading support
IBBoard <dev@ibboard.co.uk>
parents:
104
diff
changeset
|
823 { |
112
863518044d38
Re #54: Add Army support to WarFoundryFactory
IBBoard <dev@ibboard.co.uk>
parents:
111
diff
changeset
|
824 ICollection<IWarFoundryObject> objs = factory.CreateObjectsFromFile(file); |
863518044d38
Re #54: Add Army support to WarFoundryFactory
IBBoard <dev@ibboard.co.uk>
parents:
111
diff
changeset
|
825 |
863518044d38
Re #54: Add Army support to WarFoundryFactory
IBBoard <dev@ibboard.co.uk>
parents:
111
diff
changeset
|
826 if (objs.Count == 1) |
111
b5ae022ce7b8
Re #54: Add army loading support
IBBoard <dev@ibboard.co.uk>
parents:
104
diff
changeset
|
827 { |
112
863518044d38
Re #54: Add Army support to WarFoundryFactory
IBBoard <dev@ibboard.co.uk>
parents:
111
diff
changeset
|
828 foreach (IWarFoundryObject obj in objs) |
111
b5ae022ce7b8
Re #54: Add army loading support
IBBoard <dev@ibboard.co.uk>
parents:
104
diff
changeset
|
829 { |
112
863518044d38
Re #54: Add Army support to WarFoundryFactory
IBBoard <dev@ibboard.co.uk>
parents:
111
diff
changeset
|
830 if (obj is Army) |
863518044d38
Re #54: Add Army support to WarFoundryFactory
IBBoard <dev@ibboard.co.uk>
parents:
111
diff
changeset
|
831 { |
863518044d38
Re #54: Add Army support to WarFoundryFactory
IBBoard <dev@ibboard.co.uk>
parents:
111
diff
changeset
|
832 loadedArmy = (Army) obj; |
863518044d38
Re #54: Add Army support to WarFoundryFactory
IBBoard <dev@ibboard.co.uk>
parents:
111
diff
changeset
|
833 } |
111
b5ae022ce7b8
Re #54: Add army loading support
IBBoard <dev@ibboard.co.uk>
parents:
104
diff
changeset
|
834 } |
b5ae022ce7b8
Re #54: Add army loading support
IBBoard <dev@ibboard.co.uk>
parents:
104
diff
changeset
|
835 } |
b5ae022ce7b8
Re #54: Add army loading support
IBBoard <dev@ibboard.co.uk>
parents:
104
diff
changeset
|
836 } |
b5ae022ce7b8
Re #54: Add army loading support
IBBoard <dev@ibboard.co.uk>
parents:
104
diff
changeset
|
837 |
b5ae022ce7b8
Re #54: Add army loading support
IBBoard <dev@ibboard.co.uk>
parents:
104
diff
changeset
|
838 return loadedArmy; |
b5ae022ce7b8
Re #54: Add army loading support
IBBoard <dev@ibboard.co.uk>
parents:
104
diff
changeset
|
839 } |
b5ae022ce7b8
Re #54: Add army loading support
IBBoard <dev@ibboard.co.uk>
parents:
104
diff
changeset
|
840 |
b5ae022ce7b8
Re #54: Add army loading support
IBBoard <dev@ibboard.co.uk>
parents:
104
diff
changeset
|
841 private IWarFoundryFactory GetArmyLoadingFactoryForFile(FileInfo file) |
b5ae022ce7b8
Re #54: Add army loading support
IBBoard <dev@ibboard.co.uk>
parents:
104
diff
changeset
|
842 { |
b5ae022ce7b8
Re #54: Add army loading support
IBBoard <dev@ibboard.co.uk>
parents:
104
diff
changeset
|
843 IWarFoundryFactory loadingFactory = null; |
b5ae022ce7b8
Re #54: Add army loading support
IBBoard <dev@ibboard.co.uk>
parents:
104
diff
changeset
|
844 |
b5ae022ce7b8
Re #54: Add army loading support
IBBoard <dev@ibboard.co.uk>
parents:
104
diff
changeset
|
845 foreach (INonNativeWarFoundryFactory factory in nonNativeFactories) |
b5ae022ce7b8
Re #54: Add army loading support
IBBoard <dev@ibboard.co.uk>
parents:
104
diff
changeset
|
846 { |
b5ae022ce7b8
Re #54: Add army loading support
IBBoard <dev@ibboard.co.uk>
parents:
104
diff
changeset
|
847 if (factory.CanHandleFileAsArmy(file)) |
b5ae022ce7b8
Re #54: Add army loading support
IBBoard <dev@ibboard.co.uk>
parents:
104
diff
changeset
|
848 { |
b5ae022ce7b8
Re #54: Add army loading support
IBBoard <dev@ibboard.co.uk>
parents:
104
diff
changeset
|
849 loadingFactory = factory; |
b5ae022ce7b8
Re #54: Add army loading support
IBBoard <dev@ibboard.co.uk>
parents:
104
diff
changeset
|
850 break; |
b5ae022ce7b8
Re #54: Add army loading support
IBBoard <dev@ibboard.co.uk>
parents:
104
diff
changeset
|
851 } |
b5ae022ce7b8
Re #54: Add army loading support
IBBoard <dev@ibboard.co.uk>
parents:
104
diff
changeset
|
852 } |
b5ae022ce7b8
Re #54: Add army loading support
IBBoard <dev@ibboard.co.uk>
parents:
104
diff
changeset
|
853 |
b5ae022ce7b8
Re #54: Add army loading support
IBBoard <dev@ibboard.co.uk>
parents:
104
diff
changeset
|
854 if (loadingFactory == null) |
b5ae022ce7b8
Re #54: Add army loading support
IBBoard <dev@ibboard.co.uk>
parents:
104
diff
changeset
|
855 { |
b5ae022ce7b8
Re #54: Add army loading support
IBBoard <dev@ibboard.co.uk>
parents:
104
diff
changeset
|
856 foreach (INativeWarFoundryFactory factory in factories) |
b5ae022ce7b8
Re #54: Add army loading support
IBBoard <dev@ibboard.co.uk>
parents:
104
diff
changeset
|
857 { |
b5ae022ce7b8
Re #54: Add army loading support
IBBoard <dev@ibboard.co.uk>
parents:
104
diff
changeset
|
858 if (factory.CanHandleFileAsArmy(file)) |
b5ae022ce7b8
Re #54: Add army loading support
IBBoard <dev@ibboard.co.uk>
parents:
104
diff
changeset
|
859 { |
b5ae022ce7b8
Re #54: Add army loading support
IBBoard <dev@ibboard.co.uk>
parents:
104
diff
changeset
|
860 loadingFactory = factory; |
b5ae022ce7b8
Re #54: Add army loading support
IBBoard <dev@ibboard.co.uk>
parents:
104
diff
changeset
|
861 break; |
b5ae022ce7b8
Re #54: Add army loading support
IBBoard <dev@ibboard.co.uk>
parents:
104
diff
changeset
|
862 } |
b5ae022ce7b8
Re #54: Add army loading support
IBBoard <dev@ibboard.co.uk>
parents:
104
diff
changeset
|
863 } |
b5ae022ce7b8
Re #54: Add army loading support
IBBoard <dev@ibboard.co.uk>
parents:
104
diff
changeset
|
864 } |
b5ae022ce7b8
Re #54: Add army loading support
IBBoard <dev@ibboard.co.uk>
parents:
104
diff
changeset
|
865 |
b5ae022ce7b8
Re #54: Add army loading support
IBBoard <dev@ibboard.co.uk>
parents:
104
diff
changeset
|
866 return loadingFactory; |
b5ae022ce7b8
Re #54: Add army loading support
IBBoard <dev@ibboard.co.uk>
parents:
104
diff
changeset
|
867 } |
0 | 868 } |
869 } |