changeset 300:c7b765f9575f

Re #99: added points name system to system load procedure
author snowblizz
date Mon, 24 Jan 2011 16:43:31 +0000
parents 25c47b7ecc99
children 4219d79f262f
files api/Factories/Xml/WarFoundryXmlGameSystemFactory.cs
diffstat 1 files changed, 107 insertions(+), 99 deletions(-) [+]
line wrap: on
line diff
--- a/api/Factories/Xml/WarFoundryXmlGameSystemFactory.cs	Mon Jan 24 16:42:43 2011 +0000
+++ b/api/Factories/Xml/WarFoundryXmlGameSystemFactory.cs	Mon Jan 24 16:43:31 2011 +0000
@@ -1,99 +1,107 @@
-//  This file (WarFoundryXmlGameSystemFactory.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2009 IBBoard
-// 
-// 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.
-
-using System;
-using System.Collections.Generic;
-using System.IO;
-using System.Xml;
-using ICSharpCode.SharpZipLib.Zip;
-using IBBoard.Xml;
-using IBBoard.WarFoundry.API.Objects;
-
-namespace IBBoard.WarFoundry.API.Factories.Xml
-{
-	/// <summary>
-	/// A sub-factory specifically for loading GameSystems from WarFoundry XML files
-	/// </summary>
-	public class WarFoundryXmlGameSystemFactory : AbstractStagedLoadedSubFactory
-	{	
-		private Dictionary<GameSystem, XmlDocument> extraData = new Dictionary<GameSystem, XmlDocument>();
-		
-		public WarFoundryXmlGameSystemFactory(WarFoundryXmlFactory factory) : base(factory)
-		{
-		}
-		
-		private void StoreExtraData(GameSystem wfObject, XmlElement elem)
-		{
-			extraData[wfObject] = elem.OwnerDocument;
-		}
-	
-		private XmlDocument GetExtraData(GameSystem obj)
-		{
-			XmlDocument extra = null;
-			extraData.TryGetValue(obj, out extra);			
-			return extra;
-		}
-		
-		public GameSystem CreateSystemFromElement(ZipFile file, XmlElement elem)
-		{
-			string id = elem.GetAttribute("id");
-			string name = elem.GetAttribute("name");
-			GameSystem system = new GameSystem(id, name, mainFactory);
-            int defaultarmysize = XmlTools.GetIntValueFromAttribute(elem,"defaultArmySize");
-            system.SystemArmyDefaultSize = defaultarmysize;
-			StoreExtraData(system, elem);
-			return system;
-		}		
-		
-		public void CompleteLoading(GameSystem system)
-		{
-			if (!WarFoundryXmlFactoryUtils.CanCompleteLoading(system))
-			{
-				return;
-			}
-			
-			system.SetAsLoading();			
-			XmlDocument extraData = GetExtraData(system);
-			LoadCategoriesForSystem(system, extraData);
-			XmlElement statsElem = WarFoundryXmlFactoryUtils.SelectSingleElement(extraData, "/system:system/system:sysStatsList");
-			string defaultStatsID = statsElem.GetAttribute("defaultStats");
-			LoadSystemStatsForSystem(system, extraData);
-			system.StandardSystemStatsID = defaultStatsID;
-			XmlElement systemElement = WarFoundryXmlFactoryUtils.SelectSingleElement(extraData, "/system:system");
-			system.WarnOnError = XmlTools.GetBoolValueFromAttribute(systemElement, "warn");
-			system.AllowAllies = XmlTools.GetBoolValueFromAttribute(systemElement, "allowAllies");
-			system.SetAsFullyLoaded();
-		}
-
-		
-		private void LoadCategoriesForSystem(GameSystem system, XmlNode elem)
-		{
-			foreach (XmlElement cat in WarFoundryXmlFactoryUtils.SelectNodes(elem, "/system:system/system:categories/cat:cat"))
-			{
-				system.AddCategory(CreateCategoryFromElement(cat));
-			}
-		}	
-		
-		private void LoadSystemStatsForSystem(GameSystem system, XmlNode elem)
-		{
-			foreach (XmlElement stats in WarFoundryXmlFactoryUtils.SelectNodes(elem, "/system:system/system:sysStatsList/system:sysStats"))
-			{
-				SystemStats sysStats = CreateSystemStatsFromElement(stats);
-				system.AddSystemStats(sysStats);
-			}
-		}
-		
-		private SystemStats CreateSystemStatsFromElement(XmlElement elem)
-		{
-			SystemStats sysStats = new SystemStats(elem.GetAttribute("id"));
-			
-			foreach (XmlElement slot in WarFoundryXmlFactoryUtils.SelectNodes(elem, "system:sysStat"))
-			{
-				sysStats.AddStatSlot(slot.GetAttribute("name"));
-			}
-
-			return sysStats;
-		}	
-	}
-}
+//  This file (WarFoundryXmlGameSystemFactory.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2009 IBBoard
+// 
+// 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.
+
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Xml;
+using ICSharpCode.SharpZipLib.Zip;
+using IBBoard.Xml;
+using IBBoard.WarFoundry.API.Objects;
+
+namespace IBBoard.WarFoundry.API.Factories.Xml
+{
+	/// <summary>
+	/// A sub-factory specifically for loading GameSystems from WarFoundry XML files
+	/// </summary>
+	public class WarFoundryXmlGameSystemFactory : AbstractStagedLoadedSubFactory
+	{	
+		private Dictionary<GameSystem, XmlDocument> extraData = new Dictionary<GameSystem, XmlDocument>();
+		
+		public WarFoundryXmlGameSystemFactory(WarFoundryXmlFactory factory) : base(factory)
+		{
+		}
+		
+		private void StoreExtraData(GameSystem wfObject, XmlElement elem)
+		{
+			extraData[wfObject] = elem.OwnerDocument;
+		}
+	
+		private XmlDocument GetExtraData(GameSystem obj)
+		{
+			XmlDocument extra = null;
+			extraData.TryGetValue(obj, out extra);			
+			return extra;
+		}
+		
+		public GameSystem CreateSystemFromElement(ZipFile file, XmlElement elem)
+		{
+			string id = elem.GetAttribute("id");
+			string name = elem.GetAttribute("name");
+			GameSystem system = new GameSystem(id, name, mainFactory);
+            int defaultarmysize = XmlTools.GetIntValueFromAttribute(elem, "defaultArmySize");
+            system.SystemArmyDefaultSize =  defaultarmysize;
+            string defaultptsabbreviationsing = elem.GetAttribute("defaultPtsAbbreviationSingular");
+            system.SystemPtsAbbrevSingle = defaultptsabbreviationsing;
+            string defaultPtsabbreviationplur = elem.GetAttribute("defaultPtsAbbreviationPlural");
+            system.SystemPtsAbbrevPlural = defaultPtsabbreviationplur;
+            string defaultPtsnamesing = elem.GetAttribute("defaultPtsNameSingular");
+            system.SystemPtsNameSingle = defaultPtsnamesing;
+            string defaultPtsnameplur = elem.GetAttribute("defaultPtsNamePlural");
+            system.SystemPtsNamePlural = defaultPtsnameplur;
+			StoreExtraData(system, elem);
+			return system;
+		}		
+		
+		public void CompleteLoading(GameSystem system)
+		{
+			if (!WarFoundryXmlFactoryUtils.CanCompleteLoading(system))
+			{
+				return;
+			}
+			
+			system.SetAsLoading();			
+			XmlDocument extraData = GetExtraData(system);
+			LoadCategoriesForSystem(system, extraData);
+			XmlElement statsElem = WarFoundryXmlFactoryUtils.SelectSingleElement(extraData, "/system:system/system:sysStatsList");
+			string defaultStatsID = statsElem.GetAttribute("defaultStats");
+			LoadSystemStatsForSystem(system, extraData);
+			system.StandardSystemStatsID = defaultStatsID;
+			XmlElement systemElement = WarFoundryXmlFactoryUtils.SelectSingleElement(extraData, "/system:system");
+			system.WarnOnError = XmlTools.GetBoolValueFromAttribute(systemElement, "warn");
+			system.AllowAllies = XmlTools.GetBoolValueFromAttribute(systemElement, "allowAllies");
+			system.SetAsFullyLoaded();
+		}
+
+		
+		private void LoadCategoriesForSystem(GameSystem system, XmlNode elem)
+		{
+			foreach (XmlElement cat in WarFoundryXmlFactoryUtils.SelectNodes(elem, "/system:system/system:categories/cat:cat"))
+			{
+				system.AddCategory(CreateCategoryFromElement(cat));
+			}
+		}	
+		
+		private void LoadSystemStatsForSystem(GameSystem system, XmlNode elem)
+		{
+			foreach (XmlElement stats in WarFoundryXmlFactoryUtils.SelectNodes(elem, "/system:system/system:sysStatsList/system:sysStats"))
+			{
+				SystemStats sysStats = CreateSystemStatsFromElement(stats);
+				system.AddSystemStats(sysStats);
+			}
+		}
+		
+		private SystemStats CreateSystemStatsFromElement(XmlElement elem)
+		{
+			SystemStats sysStats = new SystemStats(elem.GetAttribute("id"));
+			
+			foreach (XmlElement slot in WarFoundryXmlFactoryUtils.SelectNodes(elem, "system:sysStat"))
+			{
+				sysStats.AddStatSlot(slot.GetAttribute("name"));
+			}
+
+			return sysStats;
+		}	
+	}
+}
\ No newline at end of file