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 diff
     1.1 --- a/api/Factories/Xml/WarFoundryXmlGameSystemFactory.cs	Mon Jan 24 16:42:43 2011 +0000
     1.2 +++ b/api/Factories/Xml/WarFoundryXmlGameSystemFactory.cs	Mon Jan 24 16:43:31 2011 +0000
     1.3 @@ -1,99 +1,107 @@
     1.4 -//  This file (WarFoundryXmlGameSystemFactory.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2009 IBBoard
     1.5 -// 
     1.6 -// 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.
     1.7 -
     1.8 -using System;
     1.9 -using System.Collections.Generic;
    1.10 -using System.IO;
    1.11 -using System.Xml;
    1.12 -using ICSharpCode.SharpZipLib.Zip;
    1.13 -using IBBoard.Xml;
    1.14 -using IBBoard.WarFoundry.API.Objects;
    1.15 -
    1.16 -namespace IBBoard.WarFoundry.API.Factories.Xml
    1.17 -{
    1.18 -	/// <summary>
    1.19 -	/// A sub-factory specifically for loading GameSystems from WarFoundry XML files
    1.20 -	/// </summary>
    1.21 -	public class WarFoundryXmlGameSystemFactory : AbstractStagedLoadedSubFactory
    1.22 -	{	
    1.23 -		private Dictionary<GameSystem, XmlDocument> extraData = new Dictionary<GameSystem, XmlDocument>();
    1.24 -		
    1.25 -		public WarFoundryXmlGameSystemFactory(WarFoundryXmlFactory factory) : base(factory)
    1.26 -		{
    1.27 -		}
    1.28 -		
    1.29 -		private void StoreExtraData(GameSystem wfObject, XmlElement elem)
    1.30 -		{
    1.31 -			extraData[wfObject] = elem.OwnerDocument;
    1.32 -		}
    1.33 -	
    1.34 -		private XmlDocument GetExtraData(GameSystem obj)
    1.35 -		{
    1.36 -			XmlDocument extra = null;
    1.37 -			extraData.TryGetValue(obj, out extra);			
    1.38 -			return extra;
    1.39 -		}
    1.40 -		
    1.41 -		public GameSystem CreateSystemFromElement(ZipFile file, XmlElement elem)
    1.42 -		{
    1.43 -			string id = elem.GetAttribute("id");
    1.44 -			string name = elem.GetAttribute("name");
    1.45 -			GameSystem system = new GameSystem(id, name, mainFactory);
    1.46 -            int defaultarmysize = XmlTools.GetIntValueFromAttribute(elem,"defaultArmySize");
    1.47 -            system.SystemArmyDefaultSize = defaultarmysize;
    1.48 -			StoreExtraData(system, elem);
    1.49 -			return system;
    1.50 -		}		
    1.51 -		
    1.52 -		public void CompleteLoading(GameSystem system)
    1.53 -		{
    1.54 -			if (!WarFoundryXmlFactoryUtils.CanCompleteLoading(system))
    1.55 -			{
    1.56 -				return;
    1.57 -			}
    1.58 -			
    1.59 -			system.SetAsLoading();			
    1.60 -			XmlDocument extraData = GetExtraData(system);
    1.61 -			LoadCategoriesForSystem(system, extraData);
    1.62 -			XmlElement statsElem = WarFoundryXmlFactoryUtils.SelectSingleElement(extraData, "/system:system/system:sysStatsList");
    1.63 -			string defaultStatsID = statsElem.GetAttribute("defaultStats");
    1.64 -			LoadSystemStatsForSystem(system, extraData);
    1.65 -			system.StandardSystemStatsID = defaultStatsID;
    1.66 -			XmlElement systemElement = WarFoundryXmlFactoryUtils.SelectSingleElement(extraData, "/system:system");
    1.67 -			system.WarnOnError = XmlTools.GetBoolValueFromAttribute(systemElement, "warn");
    1.68 -			system.AllowAllies = XmlTools.GetBoolValueFromAttribute(systemElement, "allowAllies");
    1.69 -			system.SetAsFullyLoaded();
    1.70 -		}
    1.71 -
    1.72 -		
    1.73 -		private void LoadCategoriesForSystem(GameSystem system, XmlNode elem)
    1.74 -		{
    1.75 -			foreach (XmlElement cat in WarFoundryXmlFactoryUtils.SelectNodes(elem, "/system:system/system:categories/cat:cat"))
    1.76 -			{
    1.77 -				system.AddCategory(CreateCategoryFromElement(cat));
    1.78 -			}
    1.79 -		}	
    1.80 -		
    1.81 -		private void LoadSystemStatsForSystem(GameSystem system, XmlNode elem)
    1.82 -		{
    1.83 -			foreach (XmlElement stats in WarFoundryXmlFactoryUtils.SelectNodes(elem, "/system:system/system:sysStatsList/system:sysStats"))
    1.84 -			{
    1.85 -				SystemStats sysStats = CreateSystemStatsFromElement(stats);
    1.86 -				system.AddSystemStats(sysStats);
    1.87 -			}
    1.88 -		}
    1.89 -		
    1.90 -		private SystemStats CreateSystemStatsFromElement(XmlElement elem)
    1.91 -		{
    1.92 -			SystemStats sysStats = new SystemStats(elem.GetAttribute("id"));
    1.93 -			
    1.94 -			foreach (XmlElement slot in WarFoundryXmlFactoryUtils.SelectNodes(elem, "system:sysStat"))
    1.95 -			{
    1.96 -				sysStats.AddStatSlot(slot.GetAttribute("name"));
    1.97 -			}
    1.98 -
    1.99 -			return sysStats;
   1.100 -		}	
   1.101 -	}
   1.102 -}
   1.103 +//  This file (WarFoundryXmlGameSystemFactory.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2009 IBBoard
   1.104 +// 
   1.105 +// 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.
   1.106 +
   1.107 +using System;
   1.108 +using System.Collections.Generic;
   1.109 +using System.IO;
   1.110 +using System.Xml;
   1.111 +using ICSharpCode.SharpZipLib.Zip;
   1.112 +using IBBoard.Xml;
   1.113 +using IBBoard.WarFoundry.API.Objects;
   1.114 +
   1.115 +namespace IBBoard.WarFoundry.API.Factories.Xml
   1.116 +{
   1.117 +	/// <summary>
   1.118 +	/// A sub-factory specifically for loading GameSystems from WarFoundry XML files
   1.119 +	/// </summary>
   1.120 +	public class WarFoundryXmlGameSystemFactory : AbstractStagedLoadedSubFactory
   1.121 +	{	
   1.122 +		private Dictionary<GameSystem, XmlDocument> extraData = new Dictionary<GameSystem, XmlDocument>();
   1.123 +		
   1.124 +		public WarFoundryXmlGameSystemFactory(WarFoundryXmlFactory factory) : base(factory)
   1.125 +		{
   1.126 +		}
   1.127 +		
   1.128 +		private void StoreExtraData(GameSystem wfObject, XmlElement elem)
   1.129 +		{
   1.130 +			extraData[wfObject] = elem.OwnerDocument;
   1.131 +		}
   1.132 +	
   1.133 +		private XmlDocument GetExtraData(GameSystem obj)
   1.134 +		{
   1.135 +			XmlDocument extra = null;
   1.136 +			extraData.TryGetValue(obj, out extra);			
   1.137 +			return extra;
   1.138 +		}
   1.139 +		
   1.140 +		public GameSystem CreateSystemFromElement(ZipFile file, XmlElement elem)
   1.141 +		{
   1.142 +			string id = elem.GetAttribute("id");
   1.143 +			string name = elem.GetAttribute("name");
   1.144 +			GameSystem system = new GameSystem(id, name, mainFactory);
   1.145 +            int defaultarmysize = XmlTools.GetIntValueFromAttribute(elem, "defaultArmySize");
   1.146 +            system.SystemArmyDefaultSize =  defaultarmysize;
   1.147 +            string defaultptsabbreviationsing = elem.GetAttribute("defaultPtsAbbreviationSingular");
   1.148 +            system.SystemPtsAbbrevSingle = defaultptsabbreviationsing;
   1.149 +            string defaultPtsabbreviationplur = elem.GetAttribute("defaultPtsAbbreviationPlural");
   1.150 +            system.SystemPtsAbbrevPlural = defaultPtsabbreviationplur;
   1.151 +            string defaultPtsnamesing = elem.GetAttribute("defaultPtsNameSingular");
   1.152 +            system.SystemPtsNameSingle = defaultPtsnamesing;
   1.153 +            string defaultPtsnameplur = elem.GetAttribute("defaultPtsNamePlural");
   1.154 +            system.SystemPtsNamePlural = defaultPtsnameplur;
   1.155 +			StoreExtraData(system, elem);
   1.156 +			return system;
   1.157 +		}		
   1.158 +		
   1.159 +		public void CompleteLoading(GameSystem system)
   1.160 +		{
   1.161 +			if (!WarFoundryXmlFactoryUtils.CanCompleteLoading(system))
   1.162 +			{
   1.163 +				return;
   1.164 +			}
   1.165 +			
   1.166 +			system.SetAsLoading();			
   1.167 +			XmlDocument extraData = GetExtraData(system);
   1.168 +			LoadCategoriesForSystem(system, extraData);
   1.169 +			XmlElement statsElem = WarFoundryXmlFactoryUtils.SelectSingleElement(extraData, "/system:system/system:sysStatsList");
   1.170 +			string defaultStatsID = statsElem.GetAttribute("defaultStats");
   1.171 +			LoadSystemStatsForSystem(system, extraData);
   1.172 +			system.StandardSystemStatsID = defaultStatsID;
   1.173 +			XmlElement systemElement = WarFoundryXmlFactoryUtils.SelectSingleElement(extraData, "/system:system");
   1.174 +			system.WarnOnError = XmlTools.GetBoolValueFromAttribute(systemElement, "warn");
   1.175 +			system.AllowAllies = XmlTools.GetBoolValueFromAttribute(systemElement, "allowAllies");
   1.176 +			system.SetAsFullyLoaded();
   1.177 +		}
   1.178 +
   1.179 +		
   1.180 +		private void LoadCategoriesForSystem(GameSystem system, XmlNode elem)
   1.181 +		{
   1.182 +			foreach (XmlElement cat in WarFoundryXmlFactoryUtils.SelectNodes(elem, "/system:system/system:categories/cat:cat"))
   1.183 +			{
   1.184 +				system.AddCategory(CreateCategoryFromElement(cat));
   1.185 +			}
   1.186 +		}	
   1.187 +		
   1.188 +		private void LoadSystemStatsForSystem(GameSystem system, XmlNode elem)
   1.189 +		{
   1.190 +			foreach (XmlElement stats in WarFoundryXmlFactoryUtils.SelectNodes(elem, "/system:system/system:sysStatsList/system:sysStats"))
   1.191 +			{
   1.192 +				SystemStats sysStats = CreateSystemStatsFromElement(stats);
   1.193 +				system.AddSystemStats(sysStats);
   1.194 +			}
   1.195 +		}
   1.196 +		
   1.197 +		private SystemStats CreateSystemStatsFromElement(XmlElement elem)
   1.198 +		{
   1.199 +			SystemStats sysStats = new SystemStats(elem.GetAttribute("id"));
   1.200 +			
   1.201 +			foreach (XmlElement slot in WarFoundryXmlFactoryUtils.SelectNodes(elem, "system:sysStat"))
   1.202 +			{
   1.203 +				sysStats.AddStatSlot(slot.GetAttribute("name"));
   1.204 +			}
   1.205 +
   1.206 +			return sysStats;
   1.207 +		}	
   1.208 +	}
   1.209 +}
   1.210 \ No newline at end of file