changeset 376:e50682387d63

Re #353: Handle unloaded units being referenced outside factory * Remove inheritance prior to creation of more generalised sub-factory inheritance * Create helper class that contains the only common code from old inheritance to keep duplication down
author IBBoard <dev@ibboard.co.uk>
date Sat, 02 Jul 2011 19:58:28 +0000
parents d9bf78a8f517
children c3b0b28bad48
files API/Factories/Requirement/UnitRequiresAtLeastNUnitsRequirementFactory.cs API/Factories/Xml/AbstractStagedLoadedSubFactory.cs API/Factories/Xml/CategoryLoader.cs API/Factories/Xml/WarFoundryXmlGameSystemFactory.cs API/Factories/Xml/WarFoundryXmlRaceFactory.cs IBBoard.WarFoundry.API.csproj
diffstat 6 files changed, 41 insertions(+), 45 deletions(-) [+]
line diff
     1.1 --- a/API/Factories/Requirement/UnitRequiresAtLeastNUnitsRequirementFactory.cs	Sat Jul 02 15:10:17 2011 +0000
     1.2 +++ b/API/Factories/Requirement/UnitRequiresAtLeastNUnitsRequirementFactory.cs	Sat Jul 02 19:58:28 2011 +0000
     1.3 @@ -43,7 +43,7 @@
     1.4  					{
     1.5  						req.AddUnitTypeRequirement(unitType, Int32.Parse(amount));
     1.6  					}
     1.7 -					catch (FormatException ex)
     1.8 +					catch (FormatException)
     1.9  					{
    1.10  						throw new InvalidRequirementException(String.Format("Invalid amount '{0}' for unit type '{1}' for 'Requires at least N units' requirement", amount, unitID));
    1.11  					}
     2.1 --- a/API/Factories/Xml/AbstractStagedLoadedSubFactory.cs	Sat Jul 02 15:10:17 2011 +0000
     2.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.3 @@ -1,33 +0,0 @@
     2.4 -//  This file (AbstractStagedLoadedSubFactory.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2009 IBBoard
     2.5 -// 
     2.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.
     2.7 -
     2.8 -using System;
     2.9 -using System.Xml;
    2.10 -using IBBoard.Xml;
    2.11 -using IBBoard.WarFoundry.API.Objects;
    2.12 -
    2.13 -namespace IBBoard.WarFoundry.API.Factories.Xml
    2.14 -{
    2.15 -	public class AbstractStagedLoadedSubFactory
    2.16 -	{
    2.17 -		protected WarFoundryXmlFactory mainFactory;
    2.18 -		
    2.19 -		protected AbstractStagedLoadedSubFactory(WarFoundryXmlFactory factory)
    2.20 -		{
    2.21 -			mainFactory = factory;
    2.22 -		}
    2.23 -		
    2.24 -		protected Category CreateCategoryFromElement(XmlElement elem)
    2.25 -		{
    2.26 -			string id = elem.GetAttribute("id");
    2.27 -			string name = elem.GetAttribute("name");
    2.28 -			Category cat = new Category(id, name);
    2.29 -			cat.MaximumPercentage = XmlTools.GetIntValueFromAttribute(elem, "maxPercentage");
    2.30 -			cat.MinimumPercentage = XmlTools.GetIntValueFromAttribute(elem, "minPercentage");
    2.31 -			cat.MaximumPoints = XmlTools.GetIntValueFromAttribute(elem, "maxPoints");
    2.32 -			cat.MinimumPoints = XmlTools.GetIntValueFromAttribute(elem, "minPoints");
    2.33 -			return cat;
    2.34 -		}	
    2.35 -	}
    2.36 -}
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/API/Factories/Xml/CategoryLoader.cs	Sat Jul 02 19:58:28 2011 +0000
     3.3 @@ -0,0 +1,26 @@
     3.4 +// This file (CategoryLoader.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2011 IBBoard
     3.5 +// 
     3.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.
     3.7 +using System;
     3.8 +using IBBoard.WarFoundry.API.Objects;
     3.9 +using IBBoard.Xml;
    3.10 +using System.Xml;
    3.11 +
    3.12 +namespace IBBoard.WarFoundry.API.Factories.Xml
    3.13 +{
    3.14 +	public class CategoryLoader
    3.15 +	{
    3.16 +		public static Category CreateFromElement(XmlElement elem)
    3.17 +		{
    3.18 +			string id = elem.GetAttribute("id");
    3.19 +			string name = elem.GetAttribute("name");
    3.20 +			Category cat = new Category(id, name);
    3.21 +			cat.MaximumPercentage = XmlTools.GetIntValueFromAttribute(elem, "maxPercentage");
    3.22 +			cat.MinimumPercentage = XmlTools.GetIntValueFromAttribute(elem, "minPercentage");
    3.23 +			cat.MaximumPoints = XmlTools.GetIntValueFromAttribute(elem, "maxPoints");
    3.24 +			cat.MinimumPoints = XmlTools.GetIntValueFromAttribute(elem, "minPoints");
    3.25 +			return cat;
    3.26 +		}
    3.27 +	}
    3.28 +}
    3.29 +
     4.1 --- a/API/Factories/Xml/WarFoundryXmlGameSystemFactory.cs	Sat Jul 02 15:10:17 2011 +0000
     4.2 +++ b/API/Factories/Xml/WarFoundryXmlGameSystemFactory.cs	Sat Jul 02 19:58:28 2011 +0000
     4.3 @@ -15,12 +15,14 @@
     4.4  	/// <summary>
     4.5  	/// A sub-factory specifically for loading GameSystems from WarFoundry XML files
     4.6  	/// </summary>
     4.7 -	public class WarFoundryXmlGameSystemFactory : AbstractStagedLoadedSubFactory
     4.8 +	public class WarFoundryXmlGameSystemFactory
     4.9  	{	
    4.10 -		private Dictionary<GameSystem, XmlDocument> extraData = new Dictionary<GameSystem, XmlDocument>();
    4.11 +		private Dictionary<GameSystem, XmlDocument> extraData = new Dictionary<GameSystem, XmlDocument>();
    4.12 +		private WarFoundryXmlFactory mainFactory;
    4.13  		
    4.14 -		public WarFoundryXmlGameSystemFactory(WarFoundryXmlFactory factory) : base(factory)
    4.15 -		{
    4.16 +		public WarFoundryXmlGameSystemFactory(WarFoundryXmlFactory factory)
    4.17 +		{
    4.18 +			this.mainFactory = factory;
    4.19  		}
    4.20  		
    4.21  		private void StoreExtraData(GameSystem wfObject, XmlElement elem)
    4.22 @@ -74,7 +76,7 @@
    4.23  		{
    4.24  			foreach (XmlElement cat in WarFoundryXmlFactoryUtils.SelectNodes(elem, "/system:system/system:categories/cat:cat"))
    4.25  			{
    4.26 -				system.AddCategory(CreateCategoryFromElement(cat));
    4.27 +				system.AddCategory(CategoryLoader.CreateFromElement(cat));
    4.28  			}
    4.29  		}	
    4.30  		
     5.1 --- a/API/Factories/Xml/WarFoundryXmlRaceFactory.cs	Sat Jul 02 15:10:17 2011 +0000
     5.2 +++ b/API/Factories/Xml/WarFoundryXmlRaceFactory.cs	Sat Jul 02 19:58:28 2011 +0000
     5.3 @@ -20,14 +20,15 @@
     5.4  	/// <summary>
     5.5  	/// A sub-factory for loading WarFoundry Race XML files
     5.6  	/// </summary>
     5.7 -	public class WarFoundryXmlRaceFactory : AbstractStagedLoadedSubFactory
     5.8 +	public class WarFoundryXmlRaceFactory
     5.9  	{
    5.10  		private Dictionary<Race, XmlDocument> extraData = new Dictionary<Race, XmlDocument>();
    5.11 -		private WarFoundryXmlLimitParser limitParser = new WarFoundryXmlLimitParser();
    5.12 +		private WarFoundryXmlLimitParser limitParser = new WarFoundryXmlLimitParser();
    5.13 +		private WarFoundryXmlFactory mainFactory;
    5.14  		
    5.15 -		public WarFoundryXmlRaceFactory(WarFoundryXmlFactory factory) : base (factory)
    5.16 +		public WarFoundryXmlRaceFactory(WarFoundryXmlFactory factory)
    5.17  		{
    5.18 -			//Do nothing special
    5.19 +			this.mainFactory = factory;
    5.20  		}
    5.21  		
    5.22  		private void StoreExtraData(Race wfObject, XmlElement elem)
    5.23 @@ -102,7 +103,7 @@
    5.24  
    5.25  		private Category CreateCategoryFromElement(XmlElement elem, Race parentRace)
    5.26  		{
    5.27 -			Category cat = CreateCategoryFromElement(elem);
    5.28 +			Category cat = CategoryLoader.CreateFromElement(elem);
    5.29  			parentRace.AddCategory(cat);
    5.30  			return cat;
    5.31  		}
     6.1 --- a/IBBoard.WarFoundry.API.csproj	Sat Jul 02 15:10:17 2011 +0000
     6.2 +++ b/IBBoard.WarFoundry.API.csproj	Sat Jul 02 19:58:28 2011 +0000
     6.3 @@ -146,7 +146,6 @@
     6.4      <Compile Include="API\Factories\Xml\WarFoundryXmlRaceFactory.cs" />
     6.5      <Compile Include="API\Factories\Xml\WarFoundryXmlArmyFactory.cs" />
     6.6      <Compile Include="API\Factories\Xml\WarFoundryXmlFactoryUtils.cs" />
     6.7 -    <Compile Include="API\Factories\Xml\AbstractStagedLoadedSubFactory.cs" />
     6.8      <Compile Include="API\Objects\InvalidContainershipException.cs" />
     6.9      <Compile Include="API\Objects\CompositeEquipmentItem.cs" />
    6.10      <Compile Include="API\Objects\AbstractUnitEquipmentItemSelection.cs" />
    6.11 @@ -181,6 +180,7 @@
    6.12      <Compile Include="API\Objects\Requirement\AbstractRequirement.cs" />
    6.13      <Compile Include="API\Factories\Requirement\UnitRequiresAtLeastNUnitsRequirementFactory.cs" />
    6.14      <Compile Include="API\Factories\Requirement\InvalidRequirementException.cs" />
    6.15 +    <Compile Include="API\Factories\Xml\CategoryLoader.cs" />
    6.16    </ItemGroup>
    6.17    <ItemGroup>
    6.18      <Reference Include="System.Xml" />