changeset 353:65fccdd51aec

Re #27: Unit requirements * Add initial requirement handler class * Add method to get requirements for army (currently falls back to Race)
author IBBoard <dev@ibboard.co.uk>
date Sun, 17 Apr 2011 20:08:43 +0000
parents 7ef9656651b5
children 47acc63cf529
files API/Objects/Army.cs API/Objects/Requirement/RequirementHandler.cs IBBoard.WarFoundry.API.csproj
diffstat 3 files changed, 42 insertions(+), 1 deletions(-) [+]
line diff
     1.1 --- a/API/Objects/Army.cs	Sat Apr 16 19:46:27 2011 +0000
     1.2 +++ b/API/Objects/Army.cs	Sun Apr 17 20:08:43 2011 +0000
     1.3 @@ -11,6 +11,7 @@
     1.4  using IBBoard.WarFoundry.API.Factories;
     1.5  using IBBoard.WarFoundry.API.Requirements;
     1.6  using ICSharpCode.SharpZipLib.Zip;
     1.7 +using IBBoard.WarFoundry.API.Objects.Requirement;
     1.8  
     1.9  namespace IBBoard.WarFoundry.API.Objects
    1.10  {
    1.11 @@ -277,5 +278,10 @@
    1.12  		{
    1.13  			OnFailedRequirement(val);
    1.14  		}
    1.15 +
    1.16 +		public ICollection<IRequirement> GetRequirements ()
    1.17 +		{
    1.18 +			return Race.GetRequirements();
    1.19 +		}
    1.20  	}
    1.21  }
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/API/Objects/Requirement/RequirementHandler.cs	Sun Apr 17 20:08:43 2011 +0000
     2.3 @@ -0,0 +1,34 @@
     2.4 +// This file (RequirementHandler.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2011 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 +using System;
     2.8 +
     2.9 +namespace IBBoard.WarFoundry.API.Objects.Requirement
    2.10 +{
    2.11 +	/// <summary>
    2.12 +	/// The requirement handler that tests the validity of armies.
    2.13 +	/// </summary>
    2.14 +	public class RequirementHandler
    2.15 +	{
    2.16 +		private RequirementHandler()
    2.17 +		{
    2.18 +		}
    2.19 +
    2.20 +		public static Validation ValidateArmy (Army army)
    2.21 +		{
    2.22 +			Validation result = Validation.Passed;
    2.23 +
    2.24 +			foreach (IRequirement requirement in army.GetRequirements())
    2.25 +			{
    2.26 +				if (!Validates.AsOkay(requirement.ValidatesArmy(army)))
    2.27 +				{
    2.28 +					result = Validation.Failed;
    2.29 +					break;
    2.30 +				}
    2.31 +			}
    2.32 +
    2.33 +			return result;
    2.34 +		}
    2.35 +	}
    2.36 +}
    2.37 +
     3.1 --- a/IBBoard.WarFoundry.API.csproj	Sat Apr 16 19:46:27 2011 +0000
     3.2 +++ b/IBBoard.WarFoundry.API.csproj	Sun Apr 17 20:08:43 2011 +0000
     3.3 @@ -1,4 +1,4 @@
     3.4 -<?xml version="1.0" encoding="utf-8"?>
     3.5 +<?xml version="1.0" encoding="utf-8"?>
     3.6  <Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5">
     3.7    <PropertyGroup>
     3.8      <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
     3.9 @@ -192,6 +192,7 @@
    3.10      <Compile Include="API\Objects\Requirement\Validation.cs" />
    3.11      <Compile Include="API\Objects\Requirement\UnitRequiresNoMoreThanNOfUnitTypeRequirement.cs" />
    3.12      <Compile Include="API\Objects\Requirement\IRequirement.cs" />
    3.13 +    <Compile Include="API\Objects\Requirement\RequirementHandler.cs" />
    3.14    </ItemGroup>
    3.15    <ItemGroup>
    3.16      <Reference Include="System.Xml" />