changeset 371:bfdb95906075

Re #351: Add extensible requirement handling method * First refactor of extensible requirement creation * Needs to return different types of factory * Needs to handle unit types that are currently not loaded
author IBBoard <dev@ibboard.co.uk>
date Mon, 13 Jun 2011 19:44:39 +0000
parents 077e9be48438
children 2f8b2467ba99
files API/Factories/Requirement/UnitRequiresAtLeastNUnitsRequirementFactory.cs API/Factories/Xml/WarFoundryXmlRaceFactory.cs IBBoard.WarFoundry.API.csproj
diffstat 3 files changed, 37 insertions(+), 6 deletions(-) [+]
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/API/Factories/Requirement/UnitRequiresAtLeastNUnitsRequirementFactory.cs	Mon Jun 13 19:44:39 2011 +0000
     1.3 @@ -0,0 +1,24 @@
     1.4 +// This file (UnitRequiresAtLeastNUnitsRequirementFactory.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2011 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 +using System;
     1.8 +using IBBoard.WarFoundry.API.Objects;
     1.9 +using IBBoard.WarFoundry.API.Objects.Requirement;
    1.10 +
    1.11 +namespace IBBoard.WarFoundry.API.Factories.Requirement
    1.12 +{
    1.13 +	public class UnitRequiresAtLeastNUnitsRequirementFactory
    1.14 +	{
    1.15 +		public UnitRequiresAtLeastNUnitsRequirementFactory()
    1.16 +		{
    1.17 +			//Do nothing special
    1.18 +		}
    1.19 +
    1.20 +		public UnitRequiresAtLeastNUnitsRequirement CreateRequirement (UnitType type, string data)
    1.21 +		{
    1.22 +			UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(type);
    1.23 +			return req;
    1.24 +		}
    1.25 +	}
    1.26 +}
    1.27 +
     2.1 --- a/API/Factories/Xml/WarFoundryXmlRaceFactory.cs	Mon Jun 13 15:15:04 2011 +0000
     2.2 +++ b/API/Factories/Xml/WarFoundryXmlRaceFactory.cs	Mon Jun 13 19:44:39 2011 +0000
     2.3 @@ -12,7 +12,8 @@
     2.4  using IBBoard.CustomMath;
     2.5  using ICSharpCode.SharpZipLib.Zip;
     2.6  using IBBoard.WarFoundry.API.Objects;
     2.7 -using IBBoard.WarFoundry.API.Objects.Requirement;
     2.8 +using IBBoard.WarFoundry.API.Objects.Requirement;
     2.9 +using IBBoard.WarFoundry.API.Factories.Requirement;
    2.10  
    2.11  namespace IBBoard.WarFoundry.API.Factories.Xml
    2.12  {
    2.13 @@ -373,19 +374,24 @@
    2.14  		}
    2.15  
    2.16  		private void LoadRequirementsForUnitType(XmlElement elem, UnitType type)
    2.17 -		{
    2.18 -			//TODO: Handle requirements more extensibly
    2.19 +		{
    2.20  			foreach (XmlElement extraData in WarFoundryXmlFactoryUtils.SelectNodes(elem, "race:requirements/race:requirement"))
    2.21  			{
    2.22  				string name = extraData.GetAttribute("requirementName");
    2.23 -				if (name == "RequiresAtLeastNUnits") {
    2.24 +				UnitRequiresAtLeastNUnitsRequirementFactory reqFactory = GetRequirementFactory(name);
    2.25 +
    2.26 +				if (reqFactory != null) {
    2.27  					string data = WarFoundryXmlFactoryUtils.SelectSingleElement(extraData, "race:data").InnerText;
    2.28 -					UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(type);
    2.29 -					req.AddUnitTypeRequirement(GetUnitTypeFromDocument(elem.OwnerDocument, data, type.Race));
    2.30 +					UnitRequiresAtLeastNUnitsRequirement req = reqFactory.CreateRequirement(type, data);
    2.31  					type.AddRequirement(req);
    2.32  				}
    2.33  			}
    2.34  		}
    2.35 +
    2.36 +		UnitRequiresAtLeastNUnitsRequirementFactory GetRequirementFactory (string name)
    2.37 +		{
    2.38 +			return new UnitRequiresAtLeastNUnitsRequirementFactory();
    2.39 +		}
    2.40  		
    2.41  		private void LoadExtraDataForUnitType(XmlElement elem, UnitType type)
    2.42  		{
     3.1 --- a/IBBoard.WarFoundry.API.csproj	Mon Jun 13 15:15:04 2011 +0000
     3.2 +++ b/IBBoard.WarFoundry.API.csproj	Mon Jun 13 19:44:39 2011 +0000
     3.3 @@ -179,6 +179,7 @@
     3.4      <Compile Include="API\Objects\Requirement\IRequirement.cs" />
     3.5      <Compile Include="API\Objects\Requirement\RequirementHandler.cs" />
     3.6      <Compile Include="API\Objects\Requirement\AbstractRequirement.cs" />
     3.7 +    <Compile Include="API\Factories\Requirement\UnitRequiresAtLeastNUnitsRequirementFactory.cs" />
     3.8    </ItemGroup>
     3.9    <ItemGroup>
    3.10      <Reference Include="System.Xml" />