Mercurial > repos > IBDev-IBBoard.WarFoundry.API
diff 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 |
line wrap: on
line diff
--- a/api/Factories/AbstractWarFoundryFactory.cs Sat Feb 26 20:15:12 2011 +0000 +++ b/api/Factories/AbstractWarFoundryFactory.cs Sun Feb 27 15:54:13 2011 +0000 @@ -11,12 +11,18 @@ { public abstract class AbstractWarFoundryFactory<FILE_TYPE> : IWarFoundryFactory { + public event SingleArgMethodInvoker<GameSystem> GameSystemLoaded; + + public event SingleArgMethodInvoker<Race> RaceLoaded; + + public event SingleArgMethodInvoker<Army> ArmyLoaded; + public virtual void CompleteLoading(IWarFoundryStagedLoadObject obj) { //Pretend we've fully loaded, as this will probably be standard for non-native factories and some native factories obj.SetAsFullyLoaded(); } - + public bool CanHandleFileFormat (FileInfo file) { FILE_TYPE typedFile = GetFileAsSupportedType(file); @@ -138,6 +144,7 @@ /// <summary> /// Reads the data from the supplied converted <see cref="FILE_TYPE"/> object and returns it as a collection of loadable objects. + /// In addition, the method fires the appropriate XxxLoaded event for each object created for asynchronous use. /// </summary> /// <param name="file"> /// An object of the converted <see cref="FILE_TYPE"/> for the file to load data from @@ -146,5 +153,29 @@ /// A <see cref="ICollection`1"/> of <see cref="IWarFoundryObject"/>s that were loaded from the file object /// </returns> protected abstract ICollection<IWarFoundryObject> DoCreateObjectsFromFile(FILE_TYPE file); + + protected void OnGameSystemLoaded(GameSystem system) + { + if (GameSystemLoaded != null) + { + GameSystemLoaded(system); + } + } + + protected void OnRaceLoaded(Race race) + { + if (RaceLoaded != null) + { + RaceLoaded(race); + } + } + + protected void OnArmyLoaded(Army army) + { + if (ArmyLoaded != null) + { + ArmyLoaded(army); + } + } } }