changeset 89:90dee8d781ee

Re #253: Allow multiple data files in a single zip * Add and use loader that just listens to events to capture new objects and does nothing else
author IBBoard <dev@ibboard.co.uk>
date Sun, 27 Feb 2011 19:44:08 +0000
parents 31fd34f7d7cf
children 5d19fee8e9dc
files API/EventListeningWarFoundryLoader.cs API/Factories/Xml/WarFoundryXmlFactoryTests.cs IBBoard.WarFoundry.API.Tests.csproj
diffstat 3 files changed, 93 insertions(+), 1 deletions(-) [+]
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/API/EventListeningWarFoundryLoader.cs	Sun Feb 27 19:44:08 2011 +0000
     1.3 @@ -0,0 +1,87 @@
     1.4 +using System;
     1.5 +using IBBoard.WarFoundry.API.Factories;
     1.6 +using System.Collections.Generic;
     1.7 +using IBBoard.WarFoundry.API.Objects;
     1.8 +
     1.9 +namespace IBBoard.WarFoundry.API
    1.10 +{
    1.11 +	public class EventListeningWarFoundryLoader : AbstractWarFoundryLoader
    1.12 +	{
    1.13 +		private IDictionary<string, GameSystem> gameSystems;
    1.14 +		private IDictionary<string, Race> races;
    1.15 +		private IDictionary<string, Army> armies;
    1.16 +
    1.17 +		public EventListeningWarFoundryLoader()
    1.18 +		{
    1.19 +			gameSystems = new Dictionary<string, GameSystem>();
    1.20 +			races = new Dictionary<string, Race>();
    1.21 +			armies = new Dictionary<string, Army>();
    1.22 +		}
    1.23 +		
    1.24 +		public override void RegisterFactory (INativeWarFoundryFactory factory)
    1.25 +		{
    1.26 +			base.RegisterFactory (factory);
    1.27 +			factory.GameSystemLoaded+= DoStoreGameSystem;
    1.28 +			factory.RaceLoaded+= DoStoreRace;
    1.29 +		}
    1.30 +		
    1.31 +		protected override GameSystem GetExistingSystemForSystem (GameSystem system)
    1.32 +		{
    1.33 +			throw new System.NotImplementedException();
    1.34 +		}
    1.35 +		
    1.36 +		
    1.37 +		protected override void DoStoreGameSystem (GameSystem system)
    1.38 +		{
    1.39 +			gameSystems.Add(system.ID, system);
    1.40 +		}
    1.41 +		
    1.42 +		
    1.43 +		protected override void DoStoreRace (Race race)
    1.44 +		{
    1.45 +			races.Add(race.ID, race);
    1.46 +		}
    1.47 +		
    1.48 +		
    1.49 +		public override GameSystem[] GetGameSystems ()
    1.50 +		{
    1.51 +			throw new System.NotImplementedException();
    1.52 +		}
    1.53 +		
    1.54 +		
    1.55 +		public override GameSystem GetGameSystem (string systemID)
    1.56 +		{
    1.57 +			return DictionaryUtils.GetValue(gameSystems, systemID);
    1.58 +		}
    1.59 +		
    1.60 +		
    1.61 +		protected override void RemoveGameSystem (GameSystem system)
    1.62 +		{
    1.63 +			throw new System.NotImplementedException();
    1.64 +		}
    1.65 +		
    1.66 +		
    1.67 +		public override Race[] GetRaces (GameSystem system)
    1.68 +		{
    1.69 +			throw new System.NotImplementedException();
    1.70 +		}
    1.71 +		
    1.72 +		
    1.73 +		public override Race GetRace (GameSystem system, string raceID)
    1.74 +		{
    1.75 +			return GetRace(system, raceID, "");
    1.76 +		}
    1.77 +		
    1.78 +		
    1.79 +		public override Race GetRace (GameSystem system, string raceID, string raceSubID)
    1.80 +		{
    1.81 +			return DictionaryUtils.GetValue(races, raceID);
    1.82 +		}
    1.83 +		
    1.84 +		
    1.85 +		protected override void RemoveRace (Race race)
    1.86 +		{
    1.87 +			throw new System.NotImplementedException();
    1.88 +		}
    1.89 +	}
    1.90 +}
     2.1 --- a/API/Factories/Xml/WarFoundryXmlFactoryTests.cs	Sat Feb 26 20:15:38 2011 +0000
     2.2 +++ b/API/Factories/Xml/WarFoundryXmlFactoryTests.cs	Sun Feb 27 19:44:08 2011 +0000
     2.3 @@ -13,7 +13,11 @@
     2.4  		[Test()]
     2.5  		public void TestFactoryHandlesMultipleFilesWithOldNamesInOneSystemZip()
     2.6  		{
     2.7 -			ICollection<IWarFoundryObject> objs = WarFoundryXmlFactory.GetFactory().CreateObjectsFromFile(new FileInfo("testdata/multifile-zips/Test.system"));
     2.8 +			EventListeningWarFoundryLoader loader = new EventListeningWarFoundryLoader ();
     2.9 +			WarFoundryLoader.SetDefault(loader);
    2.10 +			WarFoundryXmlFactory factory = WarFoundryXmlFactory.GetFactory ();
    2.11 +			loader.RegisterFactory(factory);
    2.12 +			ICollection<IWarFoundryObject> objs = factory.CreateObjectsFromFile(new FileInfo("testdata/multifile-zips/Test.system"));
    2.13  			Assert.That(objs, Has.Count(2));
    2.14  			int raceCount = 0;
    2.15  			int systemCount = 0;
     3.1 --- a/IBBoard.WarFoundry.API.Tests.csproj	Sat Feb 26 20:15:38 2011 +0000
     3.2 +++ b/IBBoard.WarFoundry.API.Tests.csproj	Sun Feb 27 19:44:08 2011 +0000
     3.3 @@ -89,6 +89,7 @@
     3.4      <Compile Include="API\AbstractWarFoundryLoaderTests.cs" />
     3.5      <Compile Include="API\Objects\GameSystemTest.cs" />
     3.6      <Compile Include="API\Factories\Xml\WarFoundryXmlFactoryTests.cs" />
     3.7 +    <Compile Include="API\EventListeningWarFoundryLoader.cs" />
     3.8    </ItemGroup>
     3.9    <ItemGroup>
    3.10      <None Include="app.config" />