comparison API/Factories/AbstractWarFoundryFactory.cs @ 482:1ed2f3ab5e35

Re #419: Remove assumptions of a file-based install * Swap API to using new "loadable object" and "loadable object source" wrappers to allow file-based or memory-based loading
author IBBoard <dev@ibboard.co.uk>
date Sat, 07 Jul 2012 21:01:32 +0100
parents 3c4a6403a88c
children
comparison
equal deleted inserted replaced
481:81f32062c9fa 482:1ed2f3ab5e35
4 4
5 using System; 5 using System;
6 using System.IO; 6 using System.IO;
7 using System.Collections.Generic; 7 using System.Collections.Generic;
8 using IBBoard.WarFoundry.API.Objects; 8 using IBBoard.WarFoundry.API.Objects;
9 using IBBoard.WarFoundry.API.Loading;
9 10
10 namespace IBBoard.WarFoundry.API.Factories 11 namespace IBBoard.WarFoundry.API.Factories
11 { 12 {
12 public abstract class AbstractWarFoundryFactory<FILE_TYPE> : IWarFoundryFactory 13 public abstract class AbstractWarFoundryFactory<FILE_TYPE> : IWarFoundryFactory
13 { 14 {
21 { 22 {
22 //Pretend we've fully loaded, as this will probably be standard for non-native factories and some native factories 23 //Pretend we've fully loaded, as this will probably be standard for non-native factories and some native factories
23 obj.SetAsFullyLoaded(); 24 obj.SetAsFullyLoaded();
24 } 25 }
25 26
26 public bool CanHandleFileFormat (FileInfo file) 27 public bool CanHandleFileFormat(ILoadableObject file)
27 { 28 {
28 FILE_TYPE typedFile = GetFileAsSupportedType(file); 29 FILE_TYPE typedFile = GetFileAsSupportedType(file);
29 bool canHandle = typedFile != null && CheckCanHandleFileFormat(typedFile); 30 bool canHandle = typedFile != null && CheckCanHandleFileFormat(typedFile);
30 31
31 if (typedFile != null) 32 if (typedFile != null)
34 } 35 }
35 36
36 return canHandle; 37 return canHandle;
37 } 38 }
38 39
39 public bool CanHandleFileAsRace(FileInfo file) 40 public bool CanHandleFileAsRace(ILoadableObject file)
40 { 41 {
41 FILE_TYPE typedFile = GetFileAsSupportedType(file); 42 FILE_TYPE typedFile = GetFileAsSupportedType(file);
42 bool canHandle = typedFile != null && CheckCanHandleFileAsRace(typedFile); 43 bool canHandle = typedFile != null && CheckCanHandleFileAsRace(typedFile);
43 44
44 if (typedFile != null) 45 if (typedFile != null)
47 } 48 }
48 49
49 return canHandle; 50 return canHandle;
50 } 51 }
51 52
52 public bool CanHandleFileAsGameSystem(FileInfo file) 53 public bool CanHandleFileAsGameSystem(ILoadableObject file)
53 { 54 {
54 FILE_TYPE typedFile = GetFileAsSupportedType(file); 55 FILE_TYPE typedFile = GetFileAsSupportedType(file);
55 bool canHandle = typedFile != null && CheckCanHandleFileAsGameSystem(typedFile); 56 bool canHandle = typedFile != null && CheckCanHandleFileAsGameSystem(typedFile);
56 57
57 if (typedFile != null) 58 if (typedFile != null)
60 } 61 }
61 62
62 return canHandle; 63 return canHandle;
63 } 64 }
64 65
65 public bool CanHandleFileAsArmy(FileInfo file) 66 public bool CanHandleFileAsArmy(ILoadableObject file)
66 { 67 {
67 FILE_TYPE typedFile = GetFileAsSupportedType(file); 68 FILE_TYPE typedFile = GetFileAsSupportedType(file);
68 bool canHandle = typedFile != null && CheckCanHandleFileAsArmy(typedFile); 69 bool canHandle = typedFile != null && CheckCanHandleFileAsArmy(typedFile);
69 70
70 if (typedFile != null) 71 if (typedFile != null)
79 { 80 {
80 //Do nothing by default 81 //Do nothing by default
81 } 82 }
82 83
83 /// <summary> 84 /// <summary>
84 /// 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. 85 /// Converts the <see cref="ILoadableObject"/> 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="ILoadableObject"/> object) the object should be returned with no modification.
85 /// If the file is not of supported type the <code>null</code> should be returned. 86 /// If the file is not of supported type the <code>null</code> should be returned.
86 /// </summary> 87 /// </summary>
87 /// <param name="file"> 88 /// <param name="file">
88 /// A <see cref="FileInfo"/> to get the supported source object from. 89 /// A <see cref="ILoadableObject"/> to get the supported source object from.
89 /// </param> 90 /// </param>
90 /// <returns> 91 /// <returns>
91 /// 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. 92 /// An object of type <see cref="FILE_TYPE"/> that has been converted from the input <see cref="ILoadableObject"/> object, or <code>null</code> if the conversion cannot be made.
92 /// </returns> 93 /// </returns>
93 protected abstract FILE_TYPE GetFileAsSupportedType(FileInfo file); 94 protected abstract FILE_TYPE GetFileAsSupportedType(ILoadableObject file);
94 95
95 /// <summary> 96 /// <summary>
96 /// Checks whether the factory thinks it can load data from the file in its paramaterised type. 97 /// Checks whether the factory thinks it can load data from the file in its paramaterised type.
97 /// </summary> 98 /// </summary>
98 /// <param name="file"> 99 /// <param name="file">
135 /// <code>true</code> if the factory thinks it can support the file as a Army, else <code>false</code> 136 /// <code>true</code> if the factory thinks it can support the file as a Army, else <code>false</code>
136 /// </returns> 137 /// </returns>
137 protected abstract bool CheckCanHandleFileAsArmy(FILE_TYPE file); 138 protected abstract bool CheckCanHandleFileAsArmy(FILE_TYPE file);
138 139
139 140
140 public ICollection<IWarFoundryObject> CreateObjectsFromFile(FileInfo file) 141 public ICollection<IWarFoundryObject> CreateObjectsFromFile(ILoadableObject file)
141 { 142 {
142 return DoCreateObjectsFromFile(GetFileAsSupportedType(file)); 143 return DoCreateObjectsFromFile(GetFileAsSupportedType(file));
143 } 144 }
144 145
145 /// <summary> 146 /// <summary>