Mercurial > repos > IBDev-IBBoard.WarFoundry.API
annotate api/Factories/AbstractWarFoundryFactory.cs @ 218:a1a6b527cd70
Re #226
* Fix missing "using" import caused by r419
no-open-ticket
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sat, 28 Nov 2009 16:22:11 +0000 |
parents | 3e287b6b5244 |
children | f00a57369aaa |
rev | line source |
---|---|
104
2f3cafb69799
Re #121: Migrate to AGPL license
IBBoard <dev@ibboard.co.uk>
parents:
28
diff
changeset
|
1 // This file (AbstractWarFoundryFactory.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2007, 2008, 2009 IBBoard. |
0 | 2 // |
104
2f3cafb69799
Re #121: Migrate to AGPL license
IBBoard <dev@ibboard.co.uk>
parents:
28
diff
changeset
|
3 // The file and the library/program it is in are licensed and distributed, without warranty, under the GNU Affero GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license. |
0 | 4 |
5 using System; | |
6 using System.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 { |
120
fcbc3beea498
* Change default factory behaviour to pretend it has loaded files without changing anything
IBBoard <dev@ibboard.co.uk>
parents:
104
diff
changeset
|
16 //Pretend we've fully loaded, as this will probably be standard for non-native factories and some native factories |
fcbc3beea498
* Change default factory behaviour to pretend it has loaded files without changing anything
IBBoard <dev@ibboard.co.uk>
parents:
104
diff
changeset
|
17 obj.SetAsFullyLoaded(); |
8
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
18 } |
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
19 |
0 | 20 public bool CanHandleFileFormat (FileInfo file) |
21 { | |
200 | 22 FILE_TYPE typedFile = GetFileAsSupportedType(file); |
23 bool canHandle = typedFile != null && CheckCanHandleFileFormat(typedFile); | |
24 | |
25 if (typedFile != null) | |
26 { | |
27 CleanUpFileAsSupportedType(typedFile); | |
28 } | |
29 | |
151
1d13820b3d96
Fixes #176: Bug when saving recently edited army
IBBoard <dev@ibboard.co.uk>
parents:
120
diff
changeset
|
30 return canHandle; |
14
0770e5cbba7c
Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
31 } |
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 public bool CanHandleFileAsRace(FileInfo file) |
0770e5cbba7c
Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
34 { |
200 | 35 FILE_TYPE typedFile = GetFileAsSupportedType(file); |
36 bool canHandle = typedFile != null && CheckCanHandleFileAsRace(typedFile); | |
37 | |
38 if (typedFile != null) | |
39 { | |
40 CleanUpFileAsSupportedType(typedFile); | |
41 } | |
42 | |
151
1d13820b3d96
Fixes #176: Bug when saving recently edited army
IBBoard <dev@ibboard.co.uk>
parents:
120
diff
changeset
|
43 return canHandle; |
14
0770e5cbba7c
Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
44 } |
0770e5cbba7c
Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
45 |
0770e5cbba7c
Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
46 public bool CanHandleFileAsGameSystem(FileInfo file) |
0770e5cbba7c
Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
47 { |
200 | 48 FILE_TYPE typedFile = GetFileAsSupportedType(file); |
49 bool canHandle = typedFile != null && CheckCanHandleFileAsGameSystem(typedFile); | |
50 | |
51 if (typedFile != null) | |
52 { | |
53 CleanUpFileAsSupportedType(typedFile); | |
54 } | |
55 | |
151
1d13820b3d96
Fixes #176: Bug when saving recently edited army
IBBoard <dev@ibboard.co.uk>
parents:
120
diff
changeset
|
56 return canHandle; |
14
0770e5cbba7c
Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
57 } |
0770e5cbba7c
Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
58 |
0770e5cbba7c
Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
59 public bool CanHandleFileAsArmy(FileInfo file) |
0770e5cbba7c
Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
60 { |
0770e5cbba7c
Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
61 FILE_TYPE typedFile = GetFileAsSupportedType(file); |
200 | 62 bool canHandle = typedFile != null && CheckCanHandleFileAsArmy(typedFile); |
63 | |
64 if (typedFile != null) | |
65 { | |
66 CleanUpFileAsSupportedType(typedFile); | |
67 } | |
68 | |
151
1d13820b3d96
Fixes #176: Bug when saving recently edited army
IBBoard <dev@ibboard.co.uk>
parents:
120
diff
changeset
|
69 return canHandle; |
200 | 70 } |
71 | |
72 protected virtual void CleanUpFileAsSupportedType(FILE_TYPE typedFile) | |
73 { | |
74 //Do nothing by default | |
0 | 75 } |
76 | |
77 /// <summary> | |
78 /// 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 | 79 /// If the file is not of supported type the <code>null</code> should be returned. |
0 | 80 /// </summary> |
81 /// <param name="file"> | |
82 /// A <see cref="FileInfo"/> to get the supported source object from. | |
83 /// </param> | |
84 /// <returns> | |
85 /// 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. | |
86 /// </returns> | |
87 protected abstract FILE_TYPE GetFileAsSupportedType(FileInfo file); | |
88 | |
89 /// <summary> | |
90 /// Checks whether the factory thinks it can load data from the file in its paramaterised type. | |
91 /// </summary> | |
92 /// <param name="file"> | |
93 /// An object of the converted <see cref="FILE_TYPE"/> to check support for | |
94 /// </param> | |
95 /// <returns> | |
96 /// <code>true</code> if the factory thinks it can support the file, else <code>false</code> | |
97 /// </returns> | |
98 protected abstract bool CheckCanHandleFileFormat(FILE_TYPE file); | |
14
0770e5cbba7c
Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
99 |
0770e5cbba7c
Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
100 /// <summary> |
0770e5cbba7c
Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
101 /// 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
|
102 /// </summary> |
0770e5cbba7c
Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
103 /// <param name="file"> |
0770e5cbba7c
Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
104 /// 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
|
105 /// </param> |
0770e5cbba7c
Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
106 /// <returns> |
0770e5cbba7c
Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
107 /// <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
|
108 /// </returns> |
0770e5cbba7c
Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
109 protected abstract bool CheckCanHandleFileAsRace(FILE_TYPE file); |
0770e5cbba7c
Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
110 |
0770e5cbba7c
Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
111 /// <summary> |
0770e5cbba7c
Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
112 /// 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
|
113 /// </summary> |
0770e5cbba7c
Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
114 /// <param name="file"> |
0770e5cbba7c
Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
115 /// 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
|
116 /// </param> |
0770e5cbba7c
Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
117 /// <returns> |
0770e5cbba7c
Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
118 /// <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
|
119 /// </returns> |
0770e5cbba7c
Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
120 protected abstract bool CheckCanHandleFileAsGameSystem(FILE_TYPE file); |
0770e5cbba7c
Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
121 |
0770e5cbba7c
Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
122 /// <summary> |
0770e5cbba7c
Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
123 /// 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
|
124 /// </summary> |
0770e5cbba7c
Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
125 /// <param name="file"> |
0770e5cbba7c
Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
126 /// 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
|
127 /// </param> |
0770e5cbba7c
Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
128 /// <returns> |
0770e5cbba7c
Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
129 /// <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
|
130 /// </returns> |
0770e5cbba7c
Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
131 protected abstract bool CheckCanHandleFileAsArmy(FILE_TYPE file); |
0770e5cbba7c
Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
132 |
0 | 133 |
134 public ICollection<IWarFoundryObject> CreateObjectsFromFile(FileInfo file) | |
135 { | |
136 return DoCreateObjectsFromFile(GetFileAsSupportedType(file)); | |
137 } | |
138 | |
139 /// <summary> | |
140 /// Reads the data from the supplied converted <see cref="FILE_TYPE"/> object and returns it as a collection of loadable objects. | |
141 /// </summary> | |
142 /// <param name="file"> | |
143 /// An object of the converted <see cref="FILE_TYPE"/> for the file to load data from | |
144 /// </param> | |
145 /// <returns> | |
146 /// A <see cref="ICollection`1"/> of <see cref="IWarFoundryObject"/>s that were loaded from the file object | |
147 /// </returns> | |
148 protected abstract ICollection<IWarFoundryObject> DoCreateObjectsFromFile(FILE_TYPE file); | |
149 } | |
150 } |