Mercurial > repos > IBDev-IBBoard.WarFoundry.API
comparison api/Factories/AbstractWarFoundryFactory.cs @ 313:f00a57369aaa
Re #253: Allow multiple data files in a single zip
* Add event-based mechanism to allow GameSystem to be registered before Race is loaded from a single zip
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sun, 27 Feb 2011 15:54:13 +0000 |
parents | 3e287b6b5244 |
children |
comparison
equal
deleted
inserted
replaced
312:3854c26073c4 | 313:f00a57369aaa |
---|---|
9 | 9 |
10 namespace IBBoard.WarFoundry.API.Factories | 10 namespace IBBoard.WarFoundry.API.Factories |
11 { | 11 { |
12 public abstract class AbstractWarFoundryFactory<FILE_TYPE> : IWarFoundryFactory | 12 public abstract class AbstractWarFoundryFactory<FILE_TYPE> : IWarFoundryFactory |
13 { | 13 { |
14 public event SingleArgMethodInvoker<GameSystem> GameSystemLoaded; | |
15 | |
16 public event SingleArgMethodInvoker<Race> RaceLoaded; | |
17 | |
18 public event SingleArgMethodInvoker<Army> ArmyLoaded; | |
19 | |
14 public virtual void CompleteLoading(IWarFoundryStagedLoadObject obj) | 20 public virtual void CompleteLoading(IWarFoundryStagedLoadObject obj) |
15 { | 21 { |
16 //Pretend we've fully loaded, as this will probably be standard for non-native factories and some native factories | 22 //Pretend we've fully loaded, as this will probably be standard for non-native factories and some native factories |
17 obj.SetAsFullyLoaded(); | 23 obj.SetAsFullyLoaded(); |
18 } | 24 } |
19 | 25 |
20 public bool CanHandleFileFormat (FileInfo file) | 26 public bool CanHandleFileFormat (FileInfo file) |
21 { | 27 { |
22 FILE_TYPE typedFile = GetFileAsSupportedType(file); | 28 FILE_TYPE typedFile = GetFileAsSupportedType(file); |
23 bool canHandle = typedFile != null && CheckCanHandleFileFormat(typedFile); | 29 bool canHandle = typedFile != null && CheckCanHandleFileFormat(typedFile); |
24 | 30 |
136 return DoCreateObjectsFromFile(GetFileAsSupportedType(file)); | 142 return DoCreateObjectsFromFile(GetFileAsSupportedType(file)); |
137 } | 143 } |
138 | 144 |
139 /// <summary> | 145 /// <summary> |
140 /// Reads the data from the supplied converted <see cref="FILE_TYPE"/> object and returns it as a collection of loadable objects. | 146 /// Reads the data from the supplied converted <see cref="FILE_TYPE"/> object and returns it as a collection of loadable objects. |
147 /// In addition, the method fires the appropriate XxxLoaded event for each object created for asynchronous use. | |
141 /// </summary> | 148 /// </summary> |
142 /// <param name="file"> | 149 /// <param name="file"> |
143 /// An object of the converted <see cref="FILE_TYPE"/> for the file to load data from | 150 /// An object of the converted <see cref="FILE_TYPE"/> for the file to load data from |
144 /// </param> | 151 /// </param> |
145 /// <returns> | 152 /// <returns> |
146 /// A <see cref="ICollection`1"/> of <see cref="IWarFoundryObject"/>s that were loaded from the file object | 153 /// A <see cref="ICollection`1"/> of <see cref="IWarFoundryObject"/>s that were loaded from the file object |
147 /// </returns> | 154 /// </returns> |
148 protected abstract ICollection<IWarFoundryObject> DoCreateObjectsFromFile(FILE_TYPE file); | 155 protected abstract ICollection<IWarFoundryObject> DoCreateObjectsFromFile(FILE_TYPE file); |
156 | |
157 protected void OnGameSystemLoaded(GameSystem system) | |
158 { | |
159 if (GameSystemLoaded != null) | |
160 { | |
161 GameSystemLoaded(system); | |
162 } | |
163 } | |
164 | |
165 protected void OnRaceLoaded(Race race) | |
166 { | |
167 if (RaceLoaded != null) | |
168 { | |
169 RaceLoaded(race); | |
170 } | |
171 } | |
172 | |
173 protected void OnArmyLoaded(Army army) | |
174 { | |
175 if (ArmyLoaded != null) | |
176 { | |
177 ArmyLoaded(army); | |
178 } | |
179 } | |
149 } | 180 } |
150 } | 181 } |