annotate api/WarFoundryLoader.cs @ 226:c931684f9024

Re #234: Invalid data file doesn't stop load * Add internal methods to remove game systems or races that fail to load * Add error handling on XML CompleteLoading so that game system or race is removed, but make sure not to affect error
author IBBoard <dev@ibboard.co.uk>
date Sat, 19 Dec 2009 15:40:50 +0000
parents 721891008b5c
children a36a0e9cc05d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
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
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;
144
721891008b5c Fixes #22: Add functionality to get failed file loads and reason
IBBoard <dev@ibboard.co.uk>
parents: 141
diff changeset
43 public delegate void FileLoadingCompleteDelegate(List<FileLoadFailure> failures);
721891008b5c Fixes #22: Add functionality to get failed file loads and reason
IBBoard <dev@ibboard.co.uk>
parents: 141
diff changeset
44 public event MethodInvoker FileLoadingStarted;
721891008b5c Fixes #22: Add functionality to get failed file loads and reason
IBBoard <dev@ibboard.co.uk>
parents: 141
diff changeset
45 public event FileLoadingCompleteDelegate FileLoadingFinished;
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
46
144
721891008b5c Fixes #22: Add functionality to get failed file loads and reason
IBBoard <dev@ibboard.co.uk>
parents: 141
diff changeset
47 private WarFoundryLoader()
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
48 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
49 directories = new List<DirectoryInfo>();
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
50 factories = new List<INativeWarFoundryFactory>();
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
51 nonNativeFactories = new List<INonNativeWarFoundryFactory>();
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
52 loadedObjects = new Dictionary<IWarFoundryFactory,SimpleSet<IWarFoundryObject>>();
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
53 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
54
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
55 /// <summary>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
56 /// 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
57 /// </summary>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
58 /// <param name="directory">
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
59 /// 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
60 /// </param>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
61 public void AddLoadDirectory(DirectoryInfo directory)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
62 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
63 if (!directories.Contains(directory))
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 directories.Add(directory);
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
66 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
67 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
68
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
69 /// <summary>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
70 /// 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
71 /// </summary>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
72 /// <param name="directory">
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
73 /// A <see cref="DirectoryInfo"/>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
74 /// </param>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
75 public void RemoveLoadDirectory(DirectoryInfo directory)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
76 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
77 if (directories.Contains(directory))
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 directories.Remove(directory);
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
80 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
81 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
82
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
83 /// <summary>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
84 /// 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
85 /// </summary>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
86 /// <param name="factory">
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
87 /// 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
88 /// </param>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
89 public void RegisterFactory(INativeWarFoundryFactory factory)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
90 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
91 if (!factories.Contains(factory))
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 factories.Add(factory);
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
94 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
95 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
96
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
97 /// <summary>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
98 /// 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
99 /// </summary>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
100 /// <param name="factory">
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
101 /// 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
102 /// </param>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
103 public void UnregisterFactory(INativeWarFoundryFactory factory)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
104 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
105 if (factories.Contains(factory))
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 factories.Remove(factory);
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
108 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
109 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
110
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
111 /// <summary>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
112 /// 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
113 /// </summary>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
114 /// <param name="factory">
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
115 /// 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
116 /// </param>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
117 public void RegisterNonNativeFactory(INonNativeWarFoundryFactory factory)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
118 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
119 if (!nonNativeFactories.Contains(factory))
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 nonNativeFactories.Add(factory);
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
122 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
123 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
124
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
125 /// <summary>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
126 /// 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
127 /// </summary>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
128 /// <param name="factory">
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
129 /// 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
130 /// </param>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
131 public void UnregisterNonNativeFactory(INonNativeWarFoundryFactory factory)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
132 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
133 if (nonNativeFactories.Contains(factory))
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 nonNativeFactories.Remove(factory);
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
136 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
137 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
138
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
139 /// <summary>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
140 /// Loads all of the data files in the registered directories.
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
141 /// </summary>
14
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
142 /// <returns>
141
32b774f24017 Re #22 - Get errored file loading
IBBoard <dev@ibboard.co.uk>
parents: 114
diff changeset
143 /// A <see cref="List"/> of <see cref="FileLoadFailure"/> for files that failed to load
14
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
144 /// </returns>
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
145 public List<FileLoadFailure> LoadFiles()
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
146 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
147 LogNotifier.Debug(GetType(), "Load files");
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
148 PrepareForFileLoad();
14
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
149 Dictionary<FileInfo, IWarFoundryFactory> loadableRaces = new Dictionary<FileInfo, IWarFoundryFactory>();
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
150 Dictionary<FileInfo, IWarFoundryFactory> loadableGameSystems = new Dictionary<FileInfo, IWarFoundryFactory>();
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
151 List<FileLoadFailure> failedLoads = FillLoadableFiles(loadableRaces, loadableGameSystems);
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
152 failedLoads.AddRange(LoadGameSystems(loadableGameSystems));
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
153 failedLoads.AddRange(LoadRaces(loadableRaces));
144
721891008b5c Fixes #22: Add functionality to get failed file loads and reason
IBBoard <dev@ibboard.co.uk>
parents: 141
diff changeset
154 OnFileLoadingFinished(failedLoads);
14
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
155 return failedLoads;
0
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
144
721891008b5c Fixes #22: Add functionality to get failed file loads and reason
IBBoard <dev@ibboard.co.uk>
parents: 141
diff changeset
158 private void OnFileLoadingFinished(List<FileLoadFailure> failures)
721891008b5c Fixes #22: Add functionality to get failed file loads and reason
IBBoard <dev@ibboard.co.uk>
parents: 141
diff changeset
159 {
721891008b5c Fixes #22: Add functionality to get failed file loads and reason
IBBoard <dev@ibboard.co.uk>
parents: 141
diff changeset
160 if (FileLoadingFinished!=null)
721891008b5c Fixes #22: Add functionality to get failed file loads and reason
IBBoard <dev@ibboard.co.uk>
parents: 141
diff changeset
161 {
721891008b5c Fixes #22: Add functionality to get failed file loads and reason
IBBoard <dev@ibboard.co.uk>
parents: 141
diff changeset
162 FileLoadingFinished(failures);
721891008b5c Fixes #22: Add functionality to get failed file loads and reason
IBBoard <dev@ibboard.co.uk>
parents: 141
diff changeset
163 }
721891008b5c Fixes #22: Add functionality to get failed file loads and reason
IBBoard <dev@ibboard.co.uk>
parents: 141
diff changeset
164 }
721891008b5c Fixes #22: Add functionality to get failed file loads and reason
IBBoard <dev@ibboard.co.uk>
parents: 141
diff changeset
165
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
166 protected void PrepareForFileLoad()
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
167 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
168 //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
169 systemsTable = new Dictionary<string,GameSystem>();
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
170 racesTable = new Dictionary<string,Dictionary<string,Dictionary<string,Race>>>();
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
171 }
14
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
172
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
173 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
174 {
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
175 List<FileLoadFailure> fails = new List<FileLoadFailure>();
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 foreach (DirectoryInfo directory in directories)
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 if (directory.Exists)
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 List<FileLoadFailure> directoryFails = FillLoadableFilesForDirectory(loadableRaces, loadableGameSystems, directory);
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
182 fails.AddRange(directoryFails);
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 else
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 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
187 }
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
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
190 return fails;
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
191 }
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 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
194 {
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
195 List<FileLoadFailure> fails = new List<FileLoadFailure>();
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
196 LogNotifier.Debug(GetType(), "Load from "+directory.FullName);
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
197
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
198 foreach (FileInfo file in directory.GetFiles())
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
199 {
27
e7de5c96f5c2 Re #44 - Fix API tests
IBBoard <dev@ibboard.co.uk>
parents: 23
diff changeset
200 IWarFoundryFactory factory = GetGameSystemLoadingFactoryForFile(file);
14
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
201
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
202 if (factory != null)
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
203 {
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
204 loadableGameSystems.Add(file, factory);
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
205 }
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
206 else
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
207 {
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
208 factory = GetRaceLoadingFactoryForFile(file);
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
209
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
210 if (factory!=null)
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 loadableRaces.Add(file, factory);
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 else
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
215 {
30
92cf25b0493b Re #32 - Migrate to using Schemas
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
216 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
217 fails.Add(failure);
92cf25b0493b Re #32 - Migrate to using Schemas
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
218 LogNotifier.Info(GetType(), failure.Message);
14
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
219 }
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 }
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 return fails;
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
27
e7de5c96f5c2 Re #44 - Fix API tests
IBBoard <dev@ibboard.co.uk>
parents: 23
diff changeset
226 private IWarFoundryFactory GetGameSystemLoadingFactoryForFile(FileInfo file)
14
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 IWarFoundryFactory loadingFactory = null;
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 foreach (INonNativeWarFoundryFactory factory in nonNativeFactories)
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 if (factory.CanHandleFileAsGameSystem(file))
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 loadingFactory = factory;
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
235 break;
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
236 }
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
237 }
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 if (loadingFactory == null)
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 foreach (INativeWarFoundryFactory factory in factories)
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
242 {
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
243 if (factory.CanHandleFileAsGameSystem(file))
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 loadingFactory = factory;
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
246 break;
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
247 }
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 }
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 return loadingFactory;
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
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
254 private IWarFoundryFactory GetRaceLoadingFactoryForFile(FileInfo file)
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 IWarFoundryFactory loadingFactory = null;
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 foreach (INonNativeWarFoundryFactory factory in nonNativeFactories)
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 if (factory.CanHandleFileAsRace(file))
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 loadingFactory = factory;
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
263 break;
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
264 }
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
265 }
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 if (loadingFactory == null)
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 foreach (INativeWarFoundryFactory factory in factories)
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
270 {
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
271 if (factory.CanHandleFileAsRace(file))
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 loadingFactory = factory;
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
274 break;
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
275 }
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
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
279 return loadingFactory;
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
280 }
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
281
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
282 private List<FileLoadFailure> LoadGameSystems(Dictionary<FileInfo, IWarFoundryFactory> gameSystemFiles)
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 List<FileLoadFailure> fails = new List<FileLoadFailure>();
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
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
287 foreach (FileInfo file in gameSystemFiles.Keys)
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
288 {
23
f9846f896df3 Re #32 - Migrate WarFoundry files to using Schemas
IBBoard <dev@ibboard.co.uk>
parents: 20
diff changeset
289 FileLoadFailure failure = null;
f9846f896df3 Re #32 - Migrate WarFoundry files to using Schemas
IBBoard <dev@ibboard.co.uk>
parents: 20
diff changeset
290
14
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
291 try
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
292 {
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
293 bool loaded = LoadObject(file, gameSystemFiles[file]);
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
294
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
295 if (!loaded)
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
296 {
41
422ddd5fedd1 Re #48 - Require schemas to validate
IBBoard <dev@ibboard.co.uk>
parents: 30
diff changeset
297 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
298 }
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
299 }
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
300 catch (Exception ex)
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
301 {
30
92cf25b0493b Re #32 - Migrate to using Schemas
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
302 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
303 }
f9846f896df3 Re #32 - Migrate WarFoundry files to using Schemas
IBBoard <dev@ibboard.co.uk>
parents: 20
diff changeset
304
f9846f896df3 Re #32 - Migrate WarFoundry files to using Schemas
IBBoard <dev@ibboard.co.uk>
parents: 20
diff changeset
305 if (failure!=null)
f9846f896df3 Re #32 - Migrate WarFoundry files to using Schemas
IBBoard <dev@ibboard.co.uk>
parents: 20
diff changeset
306 {
f9846f896df3 Re #32 - Migrate WarFoundry files to using Schemas
IBBoard <dev@ibboard.co.uk>
parents: 20
diff changeset
307 fails.Add(failure);
41
422ddd5fedd1 Re #48 - Require schemas to validate
IBBoard <dev@ibboard.co.uk>
parents: 30
diff changeset
308 LogNotifier.Warn(GetType(), failure.Message, failure.Exception);
14
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 }
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
311
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
312 return fails;
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
313 }
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
314
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
315 private List<FileLoadFailure> LoadRaces(Dictionary<FileInfo, IWarFoundryFactory> raceFiles)
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
316 {
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
317 List<FileLoadFailure> fails = new List<FileLoadFailure>();
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
318
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
319 foreach (FileInfo file in raceFiles.Keys)
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
320 {
23
f9846f896df3 Re #32 - Migrate WarFoundry files to using Schemas
IBBoard <dev@ibboard.co.uk>
parents: 20
diff changeset
321 FileLoadFailure failure = null;
f9846f896df3 Re #32 - Migrate WarFoundry files to using Schemas
IBBoard <dev@ibboard.co.uk>
parents: 20
diff changeset
322
14
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
323 try
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
324 {
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
325 bool loaded = LoadObject(file, raceFiles[file]);
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
326
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
327 if (!loaded)
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
328 {
23
f9846f896df3 Re #32 - Migrate WarFoundry files to using Schemas
IBBoard <dev@ibboard.co.uk>
parents: 20
diff changeset
329 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
330 }
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
331 }
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
332 catch (Exception ex)
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
333 {
30
92cf25b0493b Re #32 - Migrate to using Schemas
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
334 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
335 }
f9846f896df3 Re #32 - Migrate WarFoundry files to using Schemas
IBBoard <dev@ibboard.co.uk>
parents: 20
diff changeset
336
f9846f896df3 Re #32 - Migrate WarFoundry files to using Schemas
IBBoard <dev@ibboard.co.uk>
parents: 20
diff changeset
337 if (failure!=null)
f9846f896df3 Re #32 - Migrate WarFoundry files to using Schemas
IBBoard <dev@ibboard.co.uk>
parents: 20
diff changeset
338 {
f9846f896df3 Re #32 - Migrate WarFoundry files to using Schemas
IBBoard <dev@ibboard.co.uk>
parents: 20
diff changeset
339 fails.Add(failure);
30
92cf25b0493b Re #32 - Migrate to using Schemas
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
340 LogNotifier.Warn(GetType(), failure.Message, failure.Exception);
14
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 }
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
343
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
344 return fails;
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
345 }
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 private bool LoadObject(FileInfo file, IWarFoundryFactory factory)
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
348 {
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
349 bool loaded = false;
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 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
352 ICollection<IWarFoundryObject> objects = factory.CreateObjectsFromFile(file);
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
353
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
354 if (objects.Count > 0)
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
355 {
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
356 AddLoadedObjects(objects, factory);
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
357 loaded = true;
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
358 }
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
359
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
360 return loaded;
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
361 }
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
362
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
363
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
364 /// <summary>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
365 /// 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
366 /// </summary>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
367 /// <param name="file">
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
368 /// 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
369 /// </param>
14
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
370 /// <returns>
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
371 /// 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
372 /// </returns>
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
373 public ICollection<IWarFoundryObject> LoadFile(FileInfo file)
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
374 {
19
57451981545c Re #10 and re #11 - Refactor code and document code
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
375 ICollection<IWarFoundryObject> objs = null;
14
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
376 IWarFoundryFactory loadFactory = null;
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
377
19
57451981545c Re #10 and re #11 - Refactor code and document code
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
378 try
57451981545c Re #10 and re #11 - Refactor code and document code
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
379 {
57451981545c Re #10 and re #11 - Refactor code and document code
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
380 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
381
57451981545c Re #10 and re #11 - Refactor code and document code
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
382 if (objs == null)
57451981545c Re #10 and re #11 - Refactor code and document code
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
383 {
57451981545c Re #10 and re #11 - Refactor code and document code
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
384 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
385 }
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 catch (InvalidFileException ex)
57451981545c Re #10 and re #11 - Refactor code and document code
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
388 {
20
b7c93a5821cd * Remove unnecessary project dependency
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
389 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
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 if (objs!=null)
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 AddLoadedObjects(objs, loadFactory);
57451981545c Re #10 and re #11 - Refactor code and document code
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
395 }
57451981545c Re #10 and re #11 - Refactor code and document code
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
396 else
57451981545c Re #10 and re #11 - Refactor code and document code
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
397 {
57451981545c Re #10 and re #11 - Refactor code and document code
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
398 objs = new List<IWarFoundryObject>();
57451981545c Re #10 and re #11 - Refactor code and document code
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
399 }
57451981545c Re #10 and re #11 - Refactor code and document code
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
400
57451981545c Re #10 and re #11 - Refactor code and document code
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
401 return objs;
57451981545c Re #10 and re #11 - Refactor code and document code
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
402 }
57451981545c Re #10 and re #11 - Refactor code and document code
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
403
57451981545c Re #10 and re #11 - Refactor code and document code
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
404 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
405 {
57451981545c Re #10 and re #11 - Refactor code and document code
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
406 ICollection<IWarFoundryObject> objs = null;
57451981545c Re #10 and re #11 - Refactor code and document code
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
407 loadFactory = null;
57451981545c Re #10 and re #11 - Refactor code and document code
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
408
14
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
409 if (nonNativeFactories.Count > 0)
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 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
412
14
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
413 foreach (INonNativeWarFoundryFactory factory in nonNativeFactories)
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 bool canLoad = factory.CanHandleFileFormat(file);
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
416 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
417
14
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
418 if (canLoad)
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 objs = factory.CreateObjectsFromFile(file);
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
421
14
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
422 if (objs!=null)
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
423 {
14
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
424 loadFactory = factory;
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
425 break;
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
426 }
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
427 }
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
428 }
14
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
429 }
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
430
19
57451981545c Re #10 and re #11 - Refactor code and document code
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
431 return objs;
57451981545c Re #10 and re #11 - Refactor code and document code
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
432 }
57451981545c Re #10 and re #11 - Refactor code and document code
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
433
57451981545c Re #10 and re #11 - Refactor code and document code
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
434 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
435 {
57451981545c Re #10 and re #11 - Refactor code and document code
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
436 ICollection<IWarFoundryObject> objs = null;
57451981545c Re #10 and re #11 - Refactor code and document code
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
437 loadFactory = null;
57451981545c Re #10 and re #11 - Refactor code and document code
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
438
57451981545c Re #10 and re #11 - Refactor code and document code
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
439 if (factories.Count > 0)
14
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
440 {
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
441 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
442
14
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
443 foreach (INativeWarFoundryFactory factory in factories)
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
444 {
14
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
445 if (factory.CanHandleFileFormat(file))
0
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 objs = factory.CreateObjectsFromFile(file);
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
448
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
449 if (objs!=null)
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
450 {
14
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
451 loadFactory = factory;
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
452 break;
0
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 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
455 }
14
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
456 }
19
57451981545c Re #10 and re #11 - Refactor code and document code
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
457
14
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
458 return objs;
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
459 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
460
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
461 private void AddLoadedObjects(ICollection<IWarFoundryObject> loadedObjs, IWarFoundryFactory factory)
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 SimpleSet<IWarFoundryObject> objs;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
464 loadedObjects.TryGetValue(factory, out objs);
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
465
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
466 if (objs == null)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
467 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
468 objs = new SimpleSet<IWarFoundryObject>();
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
469 loadedObjects.Add(factory, objs);
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
470 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
471
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
472 objs.AddRange(loadedObjs);
14
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
473 StoreObjects(loadedObjs);
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
474 }
14
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
475
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
476 private void StoreObjects(ICollection<IWarFoundryObject> loadedObjects)
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
477 {
14
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
478 foreach (IWarFoundryObject loadedObject in loadedObjects)
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
479 {
14
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
480 if (loadedObject is GameSystem)
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
481 {
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
482 StoreGameSystem((GameSystem)loadedObject);
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
483 }
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
484 else if (loadedObject is Race)
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
485 {
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
486 StoreRace((Race)loadedObject);
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
487 }
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
488 }
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
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
491 protected void StoreGameSystem(GameSystem system)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
492 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
493 string sysid = system.ID.ToLower();
82
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 41
diff changeset
494
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 41
diff changeset
495 if (systemsTable.ContainsKey(sysid))
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
496 {
102
c85ea8988455 Re #123: Rollcall plugin won't re-add Game System on reload
IBBoard <dev@ibboard.co.uk>
parents: 82
diff changeset
497 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
498
c85ea8988455 Re #123: Rollcall plugin won't re-add Game System on reload
IBBoard <dev@ibboard.co.uk>
parents: 82
diff changeset
499 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
500 {
c85ea8988455 Re #123: Rollcall plugin won't re-add Game System on reload
IBBoard <dev@ibboard.co.uk>
parents: 82
diff changeset
501 //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
502 //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
503 }
82
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 41
diff changeset
504 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 41
diff changeset
505 else
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 41
diff changeset
506 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 41
diff changeset
507 systemsTable.Add(sysid, (GameSystem)system);
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
508 }
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
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
511 protected void StoreRace(Race race)
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 Dictionary<string, Dictionary<string, Race>> systemRaces;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
514
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
515 if (race.GameSystem == null)
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 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
518 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
519
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
520 string systemID = race.GameSystem.ID.ToLower();
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
521 racesTable.TryGetValue(systemID, out systemRaces);
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 (systemRaces==null)
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 systemRaces = new Dictionary<string,Dictionary<string,Race>>();
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
526 racesTable.Add(systemID, systemRaces);
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
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
529 Dictionary<string, Race> subRaces;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
530 systemRaces.TryGetValue(race.ID.ToLower(), out subRaces);
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 if (subRaces==null)
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 subRaces = new Dictionary<string,Race>();
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
535 systemRaces.Add(race.ID.ToLower(), subRaces);
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
536 }
102
c85ea8988455 Re #123: Rollcall plugin won't re-add Game System on reload
IBBoard <dev@ibboard.co.uk>
parents: 82
diff changeset
537
c85ea8988455 Re #123: Rollcall plugin won't re-add Game System on reload
IBBoard <dev@ibboard.co.uk>
parents: 82
diff changeset
538 string subID = race.SubID.ToLower();
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
539
102
c85ea8988455 Re #123: Rollcall plugin won't re-add Game System on reload
IBBoard <dev@ibboard.co.uk>
parents: 82
diff changeset
540 if (subRaces.ContainsKey(subID))
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
541 {
102
c85ea8988455 Re #123: Rollcall plugin won't re-add Game System on reload
IBBoard <dev@ibboard.co.uk>
parents: 82
diff changeset
542 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
543
c85ea8988455 Re #123: Rollcall plugin won't re-add Game System on reload
IBBoard <dev@ibboard.co.uk>
parents: 82
diff changeset
544 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
545 {
c85ea8988455 Re #123: Rollcall plugin won't re-add Game System on reload
IBBoard <dev@ibboard.co.uk>
parents: 82
diff changeset
546 //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
547 //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
548 }
0
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 else
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
551 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
552 subRaces.Add(race.SubID.ToLower(), race);
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
553 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
554 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
555
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
556 /// <summary>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
557 /// 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
558 /// </summary>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
559 /// <returns>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
560 /// 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
561 /// </returns>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
562 public GameSystem[] GetGameSystems()
82
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 41
diff changeset
563 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 41
diff changeset
564 if (systemsTable==null)
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 41
diff changeset
565 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 41
diff changeset
566 LoadFiles();
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
567 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
568
14
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
569 return DictionaryUtils.ToArray<string, GameSystem>(systemsTable);
82
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 41
diff changeset
570 }
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
571
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
572 /// <summary>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
573 /// Gets a single <see cref="GameSystem"/> with a given ID.
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
574 /// </summary>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
575 /// <param name="systemID">
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
576 /// 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
577 /// </param>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
578 /// <returns>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
579 /// The <see cref="GameSystem"/> with the given ID, or <code>null</code> if one doesn't exist.
82
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 41
diff changeset
580 /// </returns>
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 41
diff changeset
581 public GameSystem GetGameSystem(string systemID)
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 41
diff changeset
582 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 41
diff changeset
583 if (systemsTable==null)
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 41
diff changeset
584 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 41
diff changeset
585 LoadFiles();
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
586 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
587
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
588 GameSystem system;
82
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 41
diff changeset
589 systemsTable.TryGetValue(systemID.ToLower(), out system);
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 41
diff changeset
590 return system;
226
c931684f9024 Re #234: Invalid data file doesn't stop load
IBBoard <dev@ibboard.co.uk>
parents: 144
diff changeset
591 }
c931684f9024 Re #234: Invalid data file doesn't stop load
IBBoard <dev@ibboard.co.uk>
parents: 144
diff changeset
592
c931684f9024 Re #234: Invalid data file doesn't stop load
IBBoard <dev@ibboard.co.uk>
parents: 144
diff changeset
593 /// <summary>
c931684f9024 Re #234: Invalid data file doesn't stop load
IBBoard <dev@ibboard.co.uk>
parents: 144
diff changeset
594 /// Removes a loaded <see cref="GameSystem"/>. Used when a GameSystem fails to complete loading
c931684f9024 Re #234: Invalid data file doesn't stop load
IBBoard <dev@ibboard.co.uk>
parents: 144
diff changeset
595 /// </summary>
c931684f9024 Re #234: Invalid data file doesn't stop load
IBBoard <dev@ibboard.co.uk>
parents: 144
diff changeset
596 /// <param name="system">The GameSystem to remove</param>
c931684f9024 Re #234: Invalid data file doesn't stop load
IBBoard <dev@ibboard.co.uk>
parents: 144
diff changeset
597 internal void RemoveGameSystem(GameSystem system)
c931684f9024 Re #234: Invalid data file doesn't stop load
IBBoard <dev@ibboard.co.uk>
parents: 144
diff changeset
598 {
c931684f9024 Re #234: Invalid data file doesn't stop load
IBBoard <dev@ibboard.co.uk>
parents: 144
diff changeset
599 systemsTable.Remove(system.ID.ToLower());
82
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 41
diff changeset
600 }
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
601
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
602 /// <summary>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
603 /// 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
604 /// </summary>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
605 /// <param name="system">
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
606 /// The <see cref="GameSystem"/> to get the available races for.
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
607 /// </param>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
608 /// <returns>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
609 /// An array of <see cref="Race"/>s for the <see cref="GameSystem"/>
82
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 41
diff changeset
610 /// </returns>
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 41
diff changeset
611 public Race[] GetRaces(GameSystem system)
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 41
diff changeset
612 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 41
diff changeset
613 return GetRaces(system.ID);
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 41
diff changeset
614 }
0
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 /// <summary>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
617 /// 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
618 /// </summary>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
619 /// <param name="systemID">
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
620 /// 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
621 /// </param>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
622 /// <returns>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
623 /// An array of <see cref="Race"/>s for the specified game system
82
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 41
diff changeset
624 /// </returns>
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 41
diff changeset
625 public Race[] GetRaces(string systemID)
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 41
diff changeset
626 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 41
diff changeset
627 if (racesTable==null)
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 41
diff changeset
628 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 41
diff changeset
629 LoadFiles();
0
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
82
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 41
diff changeset
632 systemID = systemID.ToLower();
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
633 Dictionary<string, Dictionary<string, Race>> system;
82
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 41
diff changeset
634 racesTable.TryGetValue(systemID, out system);
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 41
diff changeset
635
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 41
diff changeset
636 if (system==null)
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 41
diff changeset
637 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 41
diff changeset
638 return new Race[0];
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 41
diff changeset
639 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 41
diff changeset
640
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 41
diff changeset
641 int count = 0;
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 41
diff changeset
642
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 41
diff changeset
643 foreach (Dictionary<string, Race> racesDict in system.Values)
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 41
diff changeset
644 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 41
diff changeset
645 count+= racesDict.Count;
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 41
diff changeset
646 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 41
diff changeset
647
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 41
diff changeset
648 Race[] races = new Race[count];
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 41
diff changeset
649 int i = 0;
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 41
diff changeset
650
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 41
diff changeset
651 foreach (string raceID in system.Keys)
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 41
diff changeset
652 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 41
diff changeset
653 foreach (string raceSubId in system[raceID].Keys)
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 41
diff changeset
654 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 41
diff changeset
655 races[i++] = GetRace(systemID, raceID, raceSubId);
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 41
diff changeset
656 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 41
diff changeset
657 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 41
diff changeset
658
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 41
diff changeset
659 return races;
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 41
diff changeset
660 }
0
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 /// <summary>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
663 /// 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
664 /// </summary>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
665 /// <param name="system">
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
666 /// The <see cref="GameSystem"/> that the race is part of.
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
667 /// </param>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
668 /// <param name="raceID">
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
669 /// 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
670 /// </param>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
671 /// <returns>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
672 /// A <see cref="Race"/> with the specified ID from the <see cref="GameSystem"/>, or <code>null</code> if one doesn't exist.
82
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 41
diff changeset
673 /// </returns>
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 41
diff changeset
674 public Race GetRace(GameSystem system, string raceID)
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 41
diff changeset
675 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 41
diff changeset
676 return GetRace(system.ID, raceID);
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 41
diff changeset
677 }
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
678
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
679 /// <summary>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
680 /// 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
681 /// </summary>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
682 /// <param name="systemID">
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
683 /// 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
684 /// </param>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
685 /// <param name="raceID">
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
686 /// 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
687 /// </param>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
688 /// <returns>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
689 /// 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
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 41
diff changeset
690 /// </returns>
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 41
diff changeset
691 public Race GetRace(string systemID, string raceID)
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 41
diff changeset
692 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 41
diff changeset
693 return GetRace(systemID, raceID, "");
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 41
diff changeset
694 }
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
695
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
696 /// <summary>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
697 /// 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
698 /// </summary>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
699 /// <param name="system">
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
700 /// The <see cref="GameSystem"/> that the race is part of.
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
701 /// </param>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
702 /// <param name="raceID">
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
703 /// 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
704 /// </param>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
705 /// <param name="raceSubID">
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
706 /// A <see cref="System.String"/>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
707 /// </param>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
708 /// <returns>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
709 /// A <see cref="Race"/>
82
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 41
diff changeset
710 /// </returns>
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 41
diff changeset
711 public Race GetRace(GameSystem system, string raceID, string raceSubID)
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 41
diff changeset
712 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 41
diff changeset
713 return GetRace(system.ID, raceID, raceSubID);
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 41
diff changeset
714 }
0
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 /// <summary>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
717 /// 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
718 /// </summary>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
719 /// <param name="systemID">
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
720 /// 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
721 /// </param>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
722 /// <param name="raceID">
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
723 /// 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
724 /// </param>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
725 /// <param name="raceSubID">
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
726 /// A <see cref="System.String"/>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
727 /// </param>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
728 /// <returns>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
729 /// A <see cref="Race"/>
82
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 41
diff changeset
730 /// </returns>
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 41
diff changeset
731 public Race GetRace(string systemID, string raceID, string raceSubID)
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 41
diff changeset
732 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 41
diff changeset
733 if (racesTable==null)
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 41
diff changeset
734 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 41
diff changeset
735 LoadFiles();
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
736 }
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 Race race = null;
226
c931684f9024 Re #234: Invalid data file doesn't stop load
IBBoard <dev@ibboard.co.uk>
parents: 144
diff changeset
739
c931684f9024 Re #234: Invalid data file doesn't stop load
IBBoard <dev@ibboard.co.uk>
parents: 144
diff changeset
740 Dictionary<string, Race> subraces = GetRaceTable(systemID, raceID);
c931684f9024 Re #234: Invalid data file doesn't stop load
IBBoard <dev@ibboard.co.uk>
parents: 144
diff changeset
741
c931684f9024 Re #234: Invalid data file doesn't stop load
IBBoard <dev@ibboard.co.uk>
parents: 144
diff changeset
742 if (subraces != null)
c931684f9024 Re #234: Invalid data file doesn't stop load
IBBoard <dev@ibboard.co.uk>
parents: 144
diff changeset
743 {
c931684f9024 Re #234: Invalid data file doesn't stop load
IBBoard <dev@ibboard.co.uk>
parents: 144
diff changeset
744 subraces.TryGetValue(raceSubID.ToLower(), out race);
0
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
226
c931684f9024 Re #234: Invalid data file doesn't stop load
IBBoard <dev@ibboard.co.uk>
parents: 144
diff changeset
747 return race;
c931684f9024 Re #234: Invalid data file doesn't stop load
IBBoard <dev@ibboard.co.uk>
parents: 144
diff changeset
748 }
c931684f9024 Re #234: Invalid data file doesn't stop load
IBBoard <dev@ibboard.co.uk>
parents: 144
diff changeset
749
c931684f9024 Re #234: Invalid data file doesn't stop load
IBBoard <dev@ibboard.co.uk>
parents: 144
diff changeset
750 private Dictionary<string, Race> GetRaceTable(string systemID, string raceID)
c931684f9024 Re #234: Invalid data file doesn't stop load
IBBoard <dev@ibboard.co.uk>
parents: 144
diff changeset
751 {
c931684f9024 Re #234: Invalid data file doesn't stop load
IBBoard <dev@ibboard.co.uk>
parents: 144
diff changeset
752 Dictionary<string, Dictionary<string, Race>> races;
c931684f9024 Re #234: Invalid data file doesn't stop load
IBBoard <dev@ibboard.co.uk>
parents: 144
diff changeset
753 racesTable.TryGetValue(systemID.ToLower(), out races);
c931684f9024 Re #234: Invalid data file doesn't stop load
IBBoard <dev@ibboard.co.uk>
parents: 144
diff changeset
754 Dictionary<string, Race> subraces = null;
c931684f9024 Re #234: Invalid data file doesn't stop load
IBBoard <dev@ibboard.co.uk>
parents: 144
diff changeset
755
c931684f9024 Re #234: Invalid data file doesn't stop load
IBBoard <dev@ibboard.co.uk>
parents: 144
diff changeset
756 if (races != null)
c931684f9024 Re #234: Invalid data file doesn't stop load
IBBoard <dev@ibboard.co.uk>
parents: 144
diff changeset
757 {
c931684f9024 Re #234: Invalid data file doesn't stop load
IBBoard <dev@ibboard.co.uk>
parents: 144
diff changeset
758 races.TryGetValue(raceID.ToLower(), out subraces);
c931684f9024 Re #234: Invalid data file doesn't stop load
IBBoard <dev@ibboard.co.uk>
parents: 144
diff changeset
759 }
c931684f9024 Re #234: Invalid data file doesn't stop load
IBBoard <dev@ibboard.co.uk>
parents: 144
diff changeset
760
c931684f9024 Re #234: Invalid data file doesn't stop load
IBBoard <dev@ibboard.co.uk>
parents: 144
diff changeset
761 return subraces;
c931684f9024 Re #234: Invalid data file doesn't stop load
IBBoard <dev@ibboard.co.uk>
parents: 144
diff changeset
762 }
c931684f9024 Re #234: Invalid data file doesn't stop load
IBBoard <dev@ibboard.co.uk>
parents: 144
diff changeset
763
c931684f9024 Re #234: Invalid data file doesn't stop load
IBBoard <dev@ibboard.co.uk>
parents: 144
diff changeset
764 internal void RemoveRace(Race race)
c931684f9024 Re #234: Invalid data file doesn't stop load
IBBoard <dev@ibboard.co.uk>
parents: 144
diff changeset
765 {
c931684f9024 Re #234: Invalid data file doesn't stop load
IBBoard <dev@ibboard.co.uk>
parents: 144
diff changeset
766 Dictionary<string, Race> subraces = GetRaceTable(race.GameSystem.ID, race.ID);
c931684f9024 Re #234: Invalid data file doesn't stop load
IBBoard <dev@ibboard.co.uk>
parents: 144
diff changeset
767
c931684f9024 Re #234: Invalid data file doesn't stop load
IBBoard <dev@ibboard.co.uk>
parents: 144
diff changeset
768 if (subraces != null)
c931684f9024 Re #234: Invalid data file doesn't stop load
IBBoard <dev@ibboard.co.uk>
parents: 144
diff changeset
769 {
c931684f9024 Re #234: Invalid data file doesn't stop load
IBBoard <dev@ibboard.co.uk>
parents: 144
diff changeset
770 subraces.Remove(race.SubID.ToLower());
c931684f9024 Re #234: Invalid data file doesn't stop load
IBBoard <dev@ibboard.co.uk>
parents: 144
diff changeset
771 }
82
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 41
diff changeset
772 }
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
773
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
774 /// <summary>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
775 /// 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
776 /// </summary>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
777 /// <returns>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
778 /// An array of <see cref="System.String"/>s representing the IDs of the game systems.
82
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 41
diff changeset
779 /// </returns>
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 41
diff changeset
780 public string[] GetGameSystemIDs()
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 41
diff changeset
781 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 41
diff changeset
782 if (systemsTable==null)
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 41
diff changeset
783 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 41
diff changeset
784 LoadFiles();
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 41
diff changeset
785 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 41
diff changeset
786
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 41
diff changeset
787 string[] keys = new string[systemsTable.Keys.Count];
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 41
diff changeset
788 int i = 0;
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 41
diff changeset
789
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 41
diff changeset
790 foreach (string key in systemsTable.Keys)
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 41
diff changeset
791 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 41
diff changeset
792 keys[i++] = key;
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 41
diff changeset
793 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 41
diff changeset
794
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 41
diff changeset
795 return keys;
0
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 /// <summary>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
799 /// 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
800 /// </summary>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
801 /// <param name="system">
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
802 /// The <see cref="GameSystem"/> to get the available races for.
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
803 /// </param>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
804 /// <returns>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
805 /// 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
806 /// </returns>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
807 public string[] GetSystemRaceIDs(GameSystem system)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
808 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
809 return GetSystemRaceIDs(system.ID);
82
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 41
diff changeset
810 }
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
811
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
812 /// <summary>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
813 /// 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
814 /// </summary>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
815 /// <param name="systemID">
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
816 /// 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
817 /// </param>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
818 /// <returns>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
819 /// An array of <see cref="System.String"/>s representing the IDs of the races of the specified game system.
82
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 41
diff changeset
820 /// </returns>
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 41
diff changeset
821 public string[] GetSystemRaceIDs(string systemID)
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 41
diff changeset
822 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 41
diff changeset
823 if (racesTable == null)
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 41
diff changeset
824 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 41
diff changeset
825 LoadFiles();
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 41
diff changeset
826 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 41
diff changeset
827
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 41
diff changeset
828 Dictionary<string, Dictionary<string, Race>> races = racesTable[systemID.ToLower()];
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 41
diff changeset
829
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 41
diff changeset
830 if (races==null)
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 41
diff changeset
831 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 41
diff changeset
832 return new string[0];
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 41
diff changeset
833 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 41
diff changeset
834 else
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 41
diff changeset
835 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 41
diff changeset
836 string[] keys = new string[races.Keys.Count];
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 41
diff changeset
837 int i = 0;
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 41
diff changeset
838
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 41
diff changeset
839 foreach (string key in races.Keys)
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 41
diff changeset
840 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 41
diff changeset
841 keys[i++] = key;
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 41
diff changeset
842 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 41
diff changeset
843
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 41
diff changeset
844 return keys;
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 41
diff changeset
845 }
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
846 }
111
b5ae022ce7b8 Re #54: Add army loading support
IBBoard <dev@ibboard.co.uk>
parents: 104
diff changeset
847
b5ae022ce7b8 Re #54: Add army loading support
IBBoard <dev@ibboard.co.uk>
parents: 104
diff changeset
848 public Army LoadArmy(FileInfo file)
b5ae022ce7b8 Re #54: Add army loading support
IBBoard <dev@ibboard.co.uk>
parents: 104
diff changeset
849 {
112
863518044d38 Re #54: Add Army support to WarFoundryFactory
IBBoard <dev@ibboard.co.uk>
parents: 111
diff changeset
850 IWarFoundryFactory factory = GetArmyLoadingFactoryForFile(file);
111
b5ae022ce7b8 Re #54: Add army loading support
IBBoard <dev@ibboard.co.uk>
parents: 104
diff changeset
851 Army loadedArmy = null;
b5ae022ce7b8 Re #54: Add army loading support
IBBoard <dev@ibboard.co.uk>
parents: 104
diff changeset
852
112
863518044d38 Re #54: Add Army support to WarFoundryFactory
IBBoard <dev@ibboard.co.uk>
parents: 111
diff changeset
853 if (factory != null)
111
b5ae022ce7b8 Re #54: Add army loading support
IBBoard <dev@ibboard.co.uk>
parents: 104
diff changeset
854 {
112
863518044d38 Re #54: Add Army support to WarFoundryFactory
IBBoard <dev@ibboard.co.uk>
parents: 111
diff changeset
855 ICollection<IWarFoundryObject> objs = factory.CreateObjectsFromFile(file);
863518044d38 Re #54: Add Army support to WarFoundryFactory
IBBoard <dev@ibboard.co.uk>
parents: 111
diff changeset
856
863518044d38 Re #54: Add Army support to WarFoundryFactory
IBBoard <dev@ibboard.co.uk>
parents: 111
diff changeset
857 if (objs.Count == 1)
111
b5ae022ce7b8 Re #54: Add army loading support
IBBoard <dev@ibboard.co.uk>
parents: 104
diff changeset
858 {
112
863518044d38 Re #54: Add Army support to WarFoundryFactory
IBBoard <dev@ibboard.co.uk>
parents: 111
diff changeset
859 foreach (IWarFoundryObject obj in objs)
111
b5ae022ce7b8 Re #54: Add army loading support
IBBoard <dev@ibboard.co.uk>
parents: 104
diff changeset
860 {
112
863518044d38 Re #54: Add Army support to WarFoundryFactory
IBBoard <dev@ibboard.co.uk>
parents: 111
diff changeset
861 if (obj is Army)
863518044d38 Re #54: Add Army support to WarFoundryFactory
IBBoard <dev@ibboard.co.uk>
parents: 111
diff changeset
862 {
863518044d38 Re #54: Add Army support to WarFoundryFactory
IBBoard <dev@ibboard.co.uk>
parents: 111
diff changeset
863 loadedArmy = (Army) obj;
863518044d38 Re #54: Add Army support to WarFoundryFactory
IBBoard <dev@ibboard.co.uk>
parents: 111
diff changeset
864 }
111
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 }
b5ae022ce7b8 Re #54: Add army loading support
IBBoard <dev@ibboard.co.uk>
parents: 104
diff changeset
867 }
b5ae022ce7b8 Re #54: Add army loading support
IBBoard <dev@ibboard.co.uk>
parents: 104
diff changeset
868
b5ae022ce7b8 Re #54: Add army loading support
IBBoard <dev@ibboard.co.uk>
parents: 104
diff changeset
869 return loadedArmy;
b5ae022ce7b8 Re #54: Add army loading support
IBBoard <dev@ibboard.co.uk>
parents: 104
diff changeset
870 }
b5ae022ce7b8 Re #54: Add army loading support
IBBoard <dev@ibboard.co.uk>
parents: 104
diff changeset
871
b5ae022ce7b8 Re #54: Add army loading support
IBBoard <dev@ibboard.co.uk>
parents: 104
diff changeset
872 private IWarFoundryFactory GetArmyLoadingFactoryForFile(FileInfo file)
b5ae022ce7b8 Re #54: Add army loading support
IBBoard <dev@ibboard.co.uk>
parents: 104
diff changeset
873 {
b5ae022ce7b8 Re #54: Add army loading support
IBBoard <dev@ibboard.co.uk>
parents: 104
diff changeset
874 IWarFoundryFactory loadingFactory = null;
b5ae022ce7b8 Re #54: Add army loading support
IBBoard <dev@ibboard.co.uk>
parents: 104
diff changeset
875
b5ae022ce7b8 Re #54: Add army loading support
IBBoard <dev@ibboard.co.uk>
parents: 104
diff changeset
876 foreach (INonNativeWarFoundryFactory factory in nonNativeFactories)
b5ae022ce7b8 Re #54: Add army loading support
IBBoard <dev@ibboard.co.uk>
parents: 104
diff changeset
877 {
b5ae022ce7b8 Re #54: Add army loading support
IBBoard <dev@ibboard.co.uk>
parents: 104
diff changeset
878 if (factory.CanHandleFileAsArmy(file))
b5ae022ce7b8 Re #54: Add army loading support
IBBoard <dev@ibboard.co.uk>
parents: 104
diff changeset
879 {
b5ae022ce7b8 Re #54: Add army loading support
IBBoard <dev@ibboard.co.uk>
parents: 104
diff changeset
880 loadingFactory = factory;
b5ae022ce7b8 Re #54: Add army loading support
IBBoard <dev@ibboard.co.uk>
parents: 104
diff changeset
881 break;
b5ae022ce7b8 Re #54: Add army loading support
IBBoard <dev@ibboard.co.uk>
parents: 104
diff changeset
882 }
b5ae022ce7b8 Re #54: Add army loading support
IBBoard <dev@ibboard.co.uk>
parents: 104
diff changeset
883 }
b5ae022ce7b8 Re #54: Add army loading support
IBBoard <dev@ibboard.co.uk>
parents: 104
diff changeset
884
b5ae022ce7b8 Re #54: Add army loading support
IBBoard <dev@ibboard.co.uk>
parents: 104
diff changeset
885 if (loadingFactory == null)
b5ae022ce7b8 Re #54: Add army loading support
IBBoard <dev@ibboard.co.uk>
parents: 104
diff changeset
886 {
b5ae022ce7b8 Re #54: Add army loading support
IBBoard <dev@ibboard.co.uk>
parents: 104
diff changeset
887 foreach (INativeWarFoundryFactory factory in factories)
b5ae022ce7b8 Re #54: Add army loading support
IBBoard <dev@ibboard.co.uk>
parents: 104
diff changeset
888 {
b5ae022ce7b8 Re #54: Add army loading support
IBBoard <dev@ibboard.co.uk>
parents: 104
diff changeset
889 if (factory.CanHandleFileAsArmy(file))
b5ae022ce7b8 Re #54: Add army loading support
IBBoard <dev@ibboard.co.uk>
parents: 104
diff changeset
890 {
b5ae022ce7b8 Re #54: Add army loading support
IBBoard <dev@ibboard.co.uk>
parents: 104
diff changeset
891 loadingFactory = factory;
b5ae022ce7b8 Re #54: Add army loading support
IBBoard <dev@ibboard.co.uk>
parents: 104
diff changeset
892 break;
b5ae022ce7b8 Re #54: Add army loading support
IBBoard <dev@ibboard.co.uk>
parents: 104
diff changeset
893 }
b5ae022ce7b8 Re #54: Add army loading support
IBBoard <dev@ibboard.co.uk>
parents: 104
diff changeset
894 }
b5ae022ce7b8 Re #54: Add army loading support
IBBoard <dev@ibboard.co.uk>
parents: 104
diff changeset
895 }
b5ae022ce7b8 Re #54: Add army loading support
IBBoard <dev@ibboard.co.uk>
parents: 104
diff changeset
896
b5ae022ce7b8 Re #54: Add army loading support
IBBoard <dev@ibboard.co.uk>
parents: 104
diff changeset
897 return loadingFactory;
226
c931684f9024 Re #234: Invalid data file doesn't stop load
IBBoard <dev@ibboard.co.uk>
parents: 144
diff changeset
898 }
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
899 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
900 }