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 wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/API/EventListeningWarFoundryLoader.cs	Sun Feb 27 19:44:08 2011 +0000
@@ -0,0 +1,87 @@
+using System;
+using IBBoard.WarFoundry.API.Factories;
+using System.Collections.Generic;
+using IBBoard.WarFoundry.API.Objects;
+
+namespace IBBoard.WarFoundry.API
+{
+	public class EventListeningWarFoundryLoader : AbstractWarFoundryLoader
+	{
+		private IDictionary<string, GameSystem> gameSystems;
+		private IDictionary<string, Race> races;
+		private IDictionary<string, Army> armies;
+
+		public EventListeningWarFoundryLoader()
+		{
+			gameSystems = new Dictionary<string, GameSystem>();
+			races = new Dictionary<string, Race>();
+			armies = new Dictionary<string, Army>();
+		}
+		
+		public override void RegisterFactory (INativeWarFoundryFactory factory)
+		{
+			base.RegisterFactory (factory);
+			factory.GameSystemLoaded+= DoStoreGameSystem;
+			factory.RaceLoaded+= DoStoreRace;
+		}
+		
+		protected override GameSystem GetExistingSystemForSystem (GameSystem system)
+		{
+			throw new System.NotImplementedException();
+		}
+		
+		
+		protected override void DoStoreGameSystem (GameSystem system)
+		{
+			gameSystems.Add(system.ID, system);
+		}
+		
+		
+		protected override void DoStoreRace (Race race)
+		{
+			races.Add(race.ID, race);
+		}
+		
+		
+		public override GameSystem[] GetGameSystems ()
+		{
+			throw new System.NotImplementedException();
+		}
+		
+		
+		public override GameSystem GetGameSystem (string systemID)
+		{
+			return DictionaryUtils.GetValue(gameSystems, systemID);
+		}
+		
+		
+		protected override void RemoveGameSystem (GameSystem system)
+		{
+			throw new System.NotImplementedException();
+		}
+		
+		
+		public override Race[] GetRaces (GameSystem system)
+		{
+			throw new System.NotImplementedException();
+		}
+		
+		
+		public override Race GetRace (GameSystem system, string raceID)
+		{
+			return GetRace(system, raceID, "");
+		}
+		
+		
+		public override Race GetRace (GameSystem system, string raceID, string raceSubID)
+		{
+			return DictionaryUtils.GetValue(races, raceID);
+		}
+		
+		
+		protected override void RemoveRace (Race race)
+		{
+			throw new System.NotImplementedException();
+		}
+	}
+}
--- a/API/Factories/Xml/WarFoundryXmlFactoryTests.cs	Sat Feb 26 20:15:38 2011 +0000
+++ b/API/Factories/Xml/WarFoundryXmlFactoryTests.cs	Sun Feb 27 19:44:08 2011 +0000
@@ -13,7 +13,11 @@
 		[Test()]
 		public void TestFactoryHandlesMultipleFilesWithOldNamesInOneSystemZip()
 		{
-			ICollection<IWarFoundryObject> objs = WarFoundryXmlFactory.GetFactory().CreateObjectsFromFile(new FileInfo("testdata/multifile-zips/Test.system"));
+			EventListeningWarFoundryLoader loader = new EventListeningWarFoundryLoader ();
+			WarFoundryLoader.SetDefault(loader);
+			WarFoundryXmlFactory factory = WarFoundryXmlFactory.GetFactory ();
+			loader.RegisterFactory(factory);
+			ICollection<IWarFoundryObject> objs = factory.CreateObjectsFromFile(new FileInfo("testdata/multifile-zips/Test.system"));
 			Assert.That(objs, Has.Count(2));
 			int raceCount = 0;
 			int systemCount = 0;
--- a/IBBoard.WarFoundry.API.Tests.csproj	Sat Feb 26 20:15:38 2011 +0000
+++ b/IBBoard.WarFoundry.API.Tests.csproj	Sun Feb 27 19:44:08 2011 +0000
@@ -89,6 +89,7 @@
     <Compile Include="API\AbstractWarFoundryLoaderTests.cs" />
     <Compile Include="API\Objects\GameSystemTest.cs" />
     <Compile Include="API\Factories\Xml\WarFoundryXmlFactoryTests.cs" />
+    <Compile Include="API\EventListeningWarFoundryLoader.cs" />
   </ItemGroup>
   <ItemGroup>
     <None Include="app.config" />