Mercurial > repos > IBBoard.WarFoundry.API
comparison API/WarFoundryLoader.cs @ 379:04f4c2fea356
Re #351: Add extensible requirement handling method
* Extract common IRequirementFactory interface
* Drop back to just returning IRequirement from factory to simplify generics
* Add initial registration of requirement factories
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sat, 23 Jul 2011 19:53:42 +0000 |
parents | 3c4a6403a88c |
children | 1a632b133606 |
comparison
equal
deleted
inserted
replaced
378:ff7f1b319b4e | 379:04f4c2fea356 |
---|---|
1 // This file (WarFoundryLoader.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2007, 2008, 2009 IBBoard. | 1 // This file (WarFoundryLoader.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2007, 2008, 2009 IBBoard. |
2 // | 2 // |
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. | 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. |
4 | |
5 using System; | 4 using System; |
6 using ICSharpCode.SharpZipLib.Zip; | 5 using ICSharpCode.SharpZipLib.Zip; |
6 using System.Collections.Generic; | |
7 using IBBoard.WarFoundry.API.Factories.Requirement; | |
8 using IBBoard.WarFoundry.API.Objects.Requirement; | |
7 | 9 |
8 namespace IBBoard.WarFoundry.API | 10 namespace IBBoard.WarFoundry.API |
9 { | 11 { |
10 public class WarFoundryLoader | 12 public class WarFoundryLoader |
11 { | 13 { |
12 private static AbstractWarFoundryLoader loader; | 14 private static AbstractWarFoundryLoader loader; |
13 | 15 private static Dictionary<string, IRequirementFactory> requirementFactories = new Dictionary<string, IRequirementFactory>(); |
16 | |
14 /// <summary> | 17 /// <summary> |
15 /// Gets the default <see cref="WarFoundryLoader"/> used to load WarFoundry data files. | 18 /// Gets the default <see cref="WarFoundryLoader"/> used to load WarFoundry data files. |
16 /// </summary> | 19 /// </summary> |
17 /// <returns> | 20 /// <returns> |
18 /// The default <see cref="WarFoundryLoader"/> | 21 /// The default <see cref="WarFoundryLoader"/> |
27 return loader; | 30 return loader; |
28 } | 31 } |
29 | 32 |
30 public static void SetDefault(AbstractWarFoundryLoader newLoader) | 33 public static void SetDefault(AbstractWarFoundryLoader newLoader) |
31 { | 34 { |
32 loader = newLoader; | 35 loader = newLoader; |
33 } | 36 } |
34 | 37 |
35 private WarFoundryLoader() | 38 private WarFoundryLoader() |
36 { | 39 { |
37 //Hide constructor | 40 //Hide constructor |
38 } | 41 } |
42 | |
43 public static void RegisterRequirementFactory(IRequirementFactory factory) | |
44 { | |
45 requirementFactories[factory.AppliesToID] = factory; | |
46 } | |
47 | |
48 public static IRequirementFactory GetRequirementFactory(string requirementID) | |
49 { | |
50 return DictionaryUtils.GetValue(requirementFactories, requirementID); | |
51 } | |
39 } | 52 } |
40 } | 53 } |