Mercurial > repos > IBDev-IBBoard.WarFoundry.API
comparison API/Factories/AbstractNonNativeFileExtensionWarFoundryFactory.cs @ 337:3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
no-open-ticket
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sun, 03 Apr 2011 18:50:32 +0000 |
parents | |
children | cbeee87dc2d3 |
comparison
equal
deleted
inserted
replaced
336:3631c1493c7f | 337:3c4a6403a88c |
---|---|
1 // This file (AbstractNonNativeFileExtensionWarFoundryFactory.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2007, 2008, 2009 IBBoard. | |
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. | |
4 | |
5 using System; | |
6 using System.Collections.Generic; | |
7 using System.IO; | |
8 using IBBoard.Logging; | |
9 using IBBoard.WarFoundry.API.Objects; | |
10 | |
11 namespace IBBoard.WarFoundry.API.Factories | |
12 { | |
13 public abstract class AbstractNonNativeFileExtensionWarFoundryFactory : AbstractNonNativeWarFoundryFactory<FileInfo> | |
14 { | |
15 protected abstract string ArmyFileExtension { get; } | |
16 protected abstract string RaceFileExtension { get; } | |
17 protected abstract string GameSystemFileExtension { get; } | |
18 | |
19 protected override bool CheckCanHandleFileFormat (FileInfo file) | |
20 { | |
21 return CheckCanHandleFileAsArmy(file) || CheckCanHandleFileAsRace(file) || CheckCanHandleFileAsGameSystem(file); | |
22 } | |
23 | |
24 protected override bool CheckCanHandleFileAsArmy(FileInfo file) | |
25 { | |
26 return ArmyFileExtension!=null && file.Name.ToLower().EndsWith(ArmyFileExtension); | |
27 } | |
28 | |
29 protected override bool CheckCanHandleFileAsRace(FileInfo file) | |
30 { | |
31 return RaceFileExtension!=null && file.Name.ToLower().EndsWith(RaceFileExtension); | |
32 } | |
33 | |
34 protected override bool CheckCanHandleFileAsGameSystem(FileInfo file) | |
35 { | |
36 return GameSystemFileExtension!=null && file.Name.ToLower().EndsWith(GameSystemFileExtension); | |
37 } | |
38 | |
39 protected override FileInfo GetFileAsSupportedType (FileInfo file) | |
40 { | |
41 return file; | |
42 } | |
43 | |
44 protected abstract Army CreateArmyFromFile(FileInfo file); | |
45 protected abstract Race CreateRaceFromFile(FileInfo file); | |
46 protected abstract GameSystem CreateGameSystemFromFile(FileInfo file); | |
47 | |
48 protected override ICollection<IWarFoundryObject> DoCreateObjectsFromFile (FileInfo file) | |
49 { | |
50 IWarFoundryObject obj = null; | |
51 | |
52 if (CheckCanHandleFileAsGameSystem(file)) | |
53 { | |
54 GameSystem gameSystem = CreateGameSystemFromFile (file); | |
55 OnGameSystemLoaded(gameSystem); | |
56 obj = gameSystem; | |
57 } | |
58 else if (CheckCanHandleFileAsRace(file)) | |
59 { | |
60 Race race = CreateRaceFromFile (file); | |
61 OnRaceLoaded(race); | |
62 obj = race; | |
63 } | |
64 else if (CheckCanHandleFileAsArmy(file)) | |
65 { | |
66 Army army = CreateArmyFromFile (file); | |
67 OnArmyLoaded(army); | |
68 obj = army; | |
69 } | |
70 else | |
71 { | |
72 LogNotifier.Warn(GetType(), "Failed trying to create from "+file.FullName+" - not a Race, Army or GameSystem"); | |
73 } | |
74 | |
75 ICollection<IWarFoundryObject> objects = new List<IWarFoundryObject>(); | |
76 | |
77 if (obj != null) | |
78 { | |
79 objects.Add(obj); | |
80 } | |
81 | |
82 return objects; | |
83 } | |
84 } | |
85 } |