Mercurial > repos > IBBoard.WarFoundry.API
annotate api/Factories/AbstractWarFoundryFactory.cs @ 95:6c6cfe5594fc
Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
* Create new "equipment selection" objects to track equipment selection amounts and cost
* Create ratio version
* Creat absolute amount version
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sun, 09 Aug 2009 10:34:09 +0000 |
parents | e5ea6bfcde83 |
children | 2f3cafb69799 |
rev | line source |
---|---|
15 | 1 // This file (AbstractWarFoundryFactory.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2009 IBBoard. |
0 | 2 // |
15 | 3 // The file and the library/program it is in are licensed under the GNU LGPL license, either version 3 of the License or (at your option) any later version. Please see COPYING.LGPL for more information and the full license. |
0 | 4 |
5 using System; | |
6 using System.IO; | |
7 using System.Collections.Generic; | |
8 using IBBoard.WarFoundry.API.Objects; | |
9 | |
10 namespace IBBoard.WarFoundry.API.Factories | |
11 { | |
12 public abstract class AbstractWarFoundryFactory<FILE_TYPE> : IWarFoundryFactory | |
8
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
13 { |
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
14 public virtual void CompleteLoading(IWarFoundryStagedLoadObject obj) |
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
15 { |
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
16 //Default to doing nothing as this will probably be standard for non-native factories and some native factories |
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
17 } |
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
18 |
0 | 19 public bool CanHandleFileFormat (FileInfo file) |
20 { | |
14
0770e5cbba7c
Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
21 FILE_TYPE typedFile = GetFileAsSupportedType(file); |
0770e5cbba7c
Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
22 return typedFile != null && CheckCanHandleFileFormat(typedFile); |
0770e5cbba7c
Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
23 } |
0770e5cbba7c
Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
24 |
0770e5cbba7c
Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
25 public bool CanHandleFileAsRace(FileInfo file) |
0770e5cbba7c
Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
26 { |
0770e5cbba7c
Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
27 FILE_TYPE typedFile = GetFileAsSupportedType(file); |
0770e5cbba7c
Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
28 return typedFile != null && CheckCanHandleFileAsRace(typedFile); |
0770e5cbba7c
Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
29 } |
0770e5cbba7c
Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
30 |
0770e5cbba7c
Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
31 public bool CanHandleFileAsGameSystem(FileInfo file) |
0770e5cbba7c
Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
32 { |
0770e5cbba7c
Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
33 FILE_TYPE typedFile = GetFileAsSupportedType(file); |
0770e5cbba7c
Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
34 return typedFile != null && CheckCanHandleFileAsGameSystem(typedFile); |
0770e5cbba7c
Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
35 } |
0770e5cbba7c
Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
36 |
0770e5cbba7c
Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
37 public bool CanHandleFileAsArmy(FileInfo file) |
0770e5cbba7c
Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
38 { |
0770e5cbba7c
Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
39 FILE_TYPE typedFile = GetFileAsSupportedType(file); |
0770e5cbba7c
Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
40 return typedFile != null && CheckCanHandleFileAsArmy(typedFile); |
0 | 41 } |
42 | |
43 /// <summary> | |
44 /// Converts the <see cref="FileInfo"/> object in to the appropriate type for this class so that it can perform its checks. If no conversion is required (the test can be performed on a <see cref="FileInfo"/> object) the object should be returned with no modification. | |
28 | 45 /// If the file is not of supported type the <code>null</code> should be returned. |
0 | 46 /// </summary> |
47 /// <param name="file"> | |
48 /// A <see cref="FileInfo"/> to get the supported source object from. | |
49 /// </param> | |
50 /// <returns> | |
51 /// An object of type <see cref="FILE_TYPE"/> that has been converted from the input <see cref="FileInfo"/> object, or <code>null</code> if the conversion cannot be made. | |
52 /// </returns> | |
53 protected abstract FILE_TYPE GetFileAsSupportedType(FileInfo file); | |
54 | |
55 /// <summary> | |
56 /// Checks whether the factory thinks it can load data from the file in its paramaterised type. | |
57 /// </summary> | |
58 /// <param name="file"> | |
59 /// An object of the converted <see cref="FILE_TYPE"/> to check support for | |
60 /// </param> | |
61 /// <returns> | |
62 /// <code>true</code> if the factory thinks it can support the file, else <code>false</code> | |
63 /// </returns> | |
64 protected abstract bool CheckCanHandleFileFormat(FILE_TYPE file); | |
14
0770e5cbba7c
Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
65 |
0770e5cbba7c
Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
66 /// <summary> |
0770e5cbba7c
Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
67 /// Checks whether the factory thinks it can load data from the file in its paramaterised type as a Race object. |
0770e5cbba7c
Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
68 /// </summary> |
0770e5cbba7c
Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
69 /// <param name="file"> |
0770e5cbba7c
Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
70 /// An object of the converted <see cref="FILE_TYPE"/> to check support for |
0770e5cbba7c
Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
71 /// </param> |
0770e5cbba7c
Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
72 /// <returns> |
0770e5cbba7c
Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
73 /// <code>true</code> if the factory thinks it can support the file as a Race, else <code>false</code> |
0770e5cbba7c
Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
74 /// </returns> |
0770e5cbba7c
Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
75 protected abstract bool CheckCanHandleFileAsRace(FILE_TYPE file); |
0770e5cbba7c
Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
76 |
0770e5cbba7c
Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
77 /// <summary> |
0770e5cbba7c
Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
78 /// Checks whether the factory thinks it can load data from the file in its paramaterised type as a GameSystem object. |
0770e5cbba7c
Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
79 /// </summary> |
0770e5cbba7c
Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
80 /// <param name="file"> |
0770e5cbba7c
Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
81 /// An object of the converted <see cref="FILE_TYPE"/> to check support for |
0770e5cbba7c
Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
82 /// </param> |
0770e5cbba7c
Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
83 /// <returns> |
0770e5cbba7c
Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
84 /// <code>true</code> if the factory thinks it can support the file as a GameSystem, else <code>false</code> |
0770e5cbba7c
Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
85 /// </returns> |
0770e5cbba7c
Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
86 protected abstract bool CheckCanHandleFileAsGameSystem(FILE_TYPE file); |
0770e5cbba7c
Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
87 |
0770e5cbba7c
Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
88 /// <summary> |
0770e5cbba7c
Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
89 /// Checks whether the factory thinks it can load data from the file in its paramaterised type as an Army object. |
0770e5cbba7c
Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
90 /// </summary> |
0770e5cbba7c
Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
91 /// <param name="file"> |
0770e5cbba7c
Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
92 /// An object of the converted <see cref="FILE_TYPE"/> to check support for |
0770e5cbba7c
Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
93 /// </param> |
0770e5cbba7c
Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
94 /// <returns> |
0770e5cbba7c
Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
95 /// <code>true</code> if the factory thinks it can support the file as a Army, else <code>false</code> |
0770e5cbba7c
Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
96 /// </returns> |
0770e5cbba7c
Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
97 protected abstract bool CheckCanHandleFileAsArmy(FILE_TYPE file); |
0770e5cbba7c
Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
98 |
0 | 99 |
100 public ICollection<IWarFoundryObject> CreateObjectsFromFile(FileInfo file) | |
101 { | |
102 return DoCreateObjectsFromFile(GetFileAsSupportedType(file)); | |
103 } | |
104 | |
105 /// <summary> | |
106 /// Reads the data from the supplied converted <see cref="FILE_TYPE"/> object and returns it as a collection of loadable objects. | |
107 /// </summary> | |
108 /// <param name="file"> | |
109 /// An object of the converted <see cref="FILE_TYPE"/> for the file to load data from | |
110 /// </param> | |
111 /// <returns> | |
112 /// A <see cref="ICollection`1"/> of <see cref="IWarFoundryObject"/>s that were loaded from the file object | |
113 /// </returns> | |
114 protected abstract ICollection<IWarFoundryObject> DoCreateObjectsFromFile(FILE_TYPE file); | |
115 } | |
116 } |