changeset 229:6083010a005c

Re #223: Use translations within the API * Update requirements to use translations * Remove duplicate classes
author IBBoard <dev@ibboard.co.uk>
date Mon, 21 Dec 2009 20:37:35 +0000
parents ece26f6a62f3
children 73da8d13ce69
files IBBoard.WarFoundry.API.csproj api/Requirements/RequirementAND.cs api/Requirements/RequirementOR.cs api/Requirements/UnitExcludesRequirement.cs api/Requirements/UnitExclusion.cs api/Requirements/UnitMaxNumberReached.cs api/Requirements/UnitMinNumberReached.cs api/Requirements/UnitRequirementMaxNumber.cs api/Requirements/UnitRequirementMinNumber.cs api/Requirements/UnitRequiresAtLeastRequirement.cs
diffstat 10 files changed, 40 insertions(+), 157 deletions(-) [+]
line wrap: on
line diff
--- a/IBBoard.WarFoundry.API.csproj	Sun Dec 20 20:59:28 2009 +0000
+++ b/IBBoard.WarFoundry.API.csproj	Mon Dec 21 20:37:35 2009 +0000
@@ -88,9 +88,6 @@
     <Compile Include="api\Requirements\RequirementAND.cs" />
     <Compile Include="api\Requirements\RequirementOR.cs" />
     <Compile Include="api\Requirements\UnitExcludesRequirement.cs" />
-    <Compile Include="api\Requirements\UnitExclusion.cs" />
-    <Compile Include="api\Requirements\UnitMaxNumberReached.cs" />
-    <Compile Include="api\Requirements\UnitMinNumberReached.cs" />
     <Compile Include="api\Requirements\UnitRequirement.cs" />
     <Compile Include="api\Requirements\UnitRequirementItem.cs" />
     <Compile Include="api\Requirements\UnitRequirementMaxNumber.cs" />
--- a/api/Requirements/RequirementAND.cs	Sun Dec 20 20:59:28 2009 +0000
+++ b/api/Requirements/RequirementAND.cs	Mon Dec 21 20:37:35 2009 +0000
@@ -14,17 +14,7 @@
 	/// </summary>
 	public class RequirementAND : AbstractRequirement
 	{
-		private static string and;
-
-		static RequirementAND()
-		{
-			and = Translation.GetTranslation("requirement_and", true);
-
-			if (and == null)
-			{
-				and = "{0}; and {1}";
-			}
-		}
+		private static string and = Translation.GetTranslation("requirementAND", "{0} and {1}");
 
 		private AbstractRequirement reqA, reqB;
 
--- a/api/Requirements/RequirementOR.cs	Sun Dec 20 20:59:28 2009 +0000
+++ b/api/Requirements/RequirementOR.cs	Mon Dec 21 20:37:35 2009 +0000
@@ -14,17 +14,7 @@
 	/// </summary>
 	public class RequirementOR : AbstractRequirement
 	{
-		private static string or;
-
-		static RequirementOR()
-		{
-			or = Translation.GetTranslation("requirement_or", true);
-
-			if (or == null)
-			{
-				or = "{0} or {1}";
-			}
-		}
+		private static string or = Translation.GetTranslation("requirementOR", "{0} or {1}");
 
 		private AbstractRequirement reqA, reqB;
 
--- a/api/Requirements/UnitExcludesRequirement.cs	Sun Dec 20 20:59:28 2009 +0000
+++ b/api/Requirements/UnitExcludesRequirement.cs	Mon Dec 21 20:37:35 2009 +0000
@@ -4,7 +4,9 @@
 
 using System;
 using System.Collections.Generic;
+using System.Text;
 using IBBoard.WarFoundry.API.Objects;
+using IBBoard.Lang;
 
 namespace IBBoard.WarFoundry.API.Requirements
 {
@@ -24,9 +26,22 @@
 		{
 			get 
 			{
-				return "Some units are already included that excluded this unit";
+				string otherUnits = GetOtherUnitTypeNames();
+				return Translation.GetTranslation("requirementUnitExcludesDescription", "{0} can only be taken if none of the following are taken: {1}", unitType.Name, otherUnits);
 			}
 		}
+		
+		private string GetOtherUnitTypeNames()
+		{
+			StringBuilder sb = new StringBuilder();
+			
+			foreach (UnitRequirementItem req in excludingTypes)
+			{
+				sb.Append(req.UnitType.Name);
+			}
+			
+			return sb.ToString();
+		}
 
 		protected override AbstractFailedRequirement CanAddToArmy(Army army, UnitType type)
 		{		
--- a/api/Requirements/UnitExclusion.cs	Sun Dec 20 20:59:28 2009 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,45 +0,0 @@
-// This file (UnitExclusion.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2008, 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.Text;
-using IBBoard.WarFoundry.API.Objects;
-
-namespace IBBoard.WarFoundry.API.Requirements
-{
-	/// <summary>
-	/// Summary description for UnitMaxNumberRequirement.
-	/// </summary>
-	public class UnitExclusion : FailedUnitRequirement
-	{
-		private string unitList;
-		private UnitType type;
-
-		public UnitExclusion(UnitRequirement req, UnitType unitType, UnitType[] excludingTypes) : base(req)
-		{
-			type = unitType;
-
-			if (excludingTypes.Length > 1)
-			{
-				StringBuilder sb = new StringBuilder(excludingTypes[0].Name);
-
-				for (int i = 1; i<excludingTypes.Length; i++)
-				{
-					sb.Append(", "+excludingTypes[i].Name);
-				}
-
-				unitList = sb.ToString();
-			}
-			else
-			{
-				unitList = excludingTypes[0].Name;
-			}
-		}
-
-		public override string Description
-		{
-			get { return "The army cannot have any of the following units to include a unit of type "+type.Name+": "+unitList; }
-		}
-	}
-}
--- a/api/Requirements/UnitMaxNumberReached.cs	Sun Dec 20 20:59:28 2009 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,29 +0,0 @@
-// This file (UnitMaxNumberReached.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2008, 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 IBBoard;
-using IBBoard.Lang;
-using IBBoard.WarFoundry.API.Objects;
-
-namespace IBBoard.WarFoundry.API.Requirements
-{
-	/// <summary>
-	/// Summary description for UnitMaxNumberRequirement.
-	/// </summary>
-	public class UnitMaxNumberReached : FailedUnitRequirement
-	{
-		private UnitType type;
-
-		public UnitMaxNumberReached(UnitType unitType, UnitRequirementMaxNumber requirement) : base(requirement)
-		{
-			type = unitType;
-		}
-
-		public override string Description
-		{
-			get { return String.Format(Translation.GetTranslation("ErrorUnitMaxNumberReached", "The maximum number of units of type \"{0}\" has already been reached or exceeded."), type.Name); }
-		}
-	}
-}
--- a/api/Requirements/UnitMinNumberReached.cs	Sun Dec 20 20:59:28 2009 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,27 +0,0 @@
-// This file (UnitMinNumberReached.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2008, 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 IBBoard.WarFoundry.API.Objects;
-
-namespace IBBoard.WarFoundry.API.Requirements
-{
-	/// <summary>
-	/// Summary description for UnitMaxNumberRequirement.
-	/// </summary>
-	public class UnitMinNumberReached : FailedUnitRequirement
-	{
-		private UnitType type;
-
-		public UnitMinNumberReached(UnitType unitType, UnitRequirementMinNumber requirement) : base(requirement)
-		{
-			type = unitType;
-		}
-
-		public override string Description
-		{
-			get { return "The minimum number of units of type "+type.Name+" is not currently met"; }
-		}
-	}
-}
--- a/api/Requirements/UnitRequirementMaxNumber.cs	Sun Dec 20 20:59:28 2009 +0000
+++ b/api/Requirements/UnitRequirementMaxNumber.cs	Mon Dec 21 20:37:35 2009 +0000
@@ -3,6 +3,7 @@
 // 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 IBBoard.Lang;
 using IBBoard.WarFoundry.API.Objects;
 
 namespace IBBoard.WarFoundry.API.Requirements
@@ -18,7 +19,7 @@
 		
 		public override string Description
 		{
-			get { return "You may only include up to "+maxUnitCount+" "+unitType.Name+" units in an army"; }
+			get { return Translation.GetTranslation("requirementUnitMaxNumber", "an army can contain up to {0} units of type {1}", maxUnitCount, unitType.Name); }
 		}
 		
 		protected override AbstractFailedRequirement CanAddToArmy (Army army, UnitType type)
--- a/api/Requirements/UnitRequirementMinNumber.cs	Sun Dec 20 20:59:28 2009 +0000
+++ b/api/Requirements/UnitRequirementMinNumber.cs	Mon Dec 21 20:37:35 2009 +0000
@@ -3,6 +3,7 @@
 // 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 IBBoard.Lang;
 using IBBoard.WarFoundry.API.Objects;
 
 namespace IBBoard.WarFoundry.API.Requirements
@@ -18,7 +19,7 @@
 		
 		public override string Description
 		{
-			get { return "You must include at least "+minUnitCount+" "+unitType.Name+" units in an army"; }
+			get { return Translation.GetTranslation("requirementUnitMinNumber", "you must include at least {0} of {1} in an army", minUnitCount, unitType.Name); }
 		}
 		
 		protected override AbstractFailedRequirement CanAddToArmy(Army army, UnitType type)
--- a/api/Requirements/UnitRequiresAtLeastRequirement.cs	Sun Dec 20 20:59:28 2009 +0000
+++ b/api/Requirements/UnitRequiresAtLeastRequirement.cs	Mon Dec 21 20:37:35 2009 +0000
@@ -5,6 +5,7 @@
 using System;
 using System.Collections.Generic;
 using System.Text;
+using IBBoard.Lang;
 using IBBoard.WarFoundry.API;
 using IBBoard.WarFoundry.API.Objects;
 
@@ -15,48 +16,37 @@
 	/// </summary>
 	public class UnitRequiresAtLeastRequirement : UnitRequirement
 	{
-		private UnitType[] requiredTypes;
-		private int[] requiredCounts;
+		private UnitRequirementItem[] requiredTypes;
 		private String unitList;
 
-		public UnitRequiresAtLeastRequirement(UnitType type, UnitType requiredUnitType) : this(type, new UnitType[]{requiredUnitType}, new int[]{1})
+		public UnitRequiresAtLeastRequirement(UnitType type, UnitType requiredUnitType) : this(type, new UnitRequirementItem[]{new UnitRequirementItem(requiredUnitType)})
 		{
 		}
 		
-		public UnitRequiresAtLeastRequirement(UnitType type, UnitType[] requiredUnitTypes, int[] minNumsRequired) : base(type)
-		{
-			if (requiredUnitTypes.Length != minNumsRequired.Length)
-			{
-				throw new ArgumentException("List of required unit types and list of number of units required must be equal");
-			}
-			else if (requiredUnitTypes.Length == 1)
-			{
-				throw new ArgumentException("List of required unit types must not be empty");
-			}
-			
+		public UnitRequiresAtLeastRequirement(UnitType type, UnitRequirementItem[] requiredUnitTypes) : base(type)
+		{			
 			requiredTypes = requiredUnitTypes;
-			requiredCounts = minNumsRequired;
-
-			if (requiredTypes.Length > 1)
+			bool first = true;
+			
+			foreach (UnitRequirementItem req in requiredTypes)
 			{
-				StringBuilder sb = new StringBuilder(requiredCounts[0]+" x "+requiredTypes[0].Name);
-
-				for (int i = 1; i<requiredTypes.Length; i++)
+				string reqString = Translation.GetTranslation("requirementUnitTypeAtLeastSingle", "{1} {0}", req.UnitType.Name, req.Amount);
+				
+				if (first)
 				{
-					sb.Append(", "+requiredCounts[i]+" x "+requiredTypes[i].Name);
+					first = false;
+					unitList = reqString;
 				}
-
-				unitList = sb.ToString();
-			}
-			else
-			{
-				unitList = requiredTypes[0].Name;
+				else
+				{
+					unitList = Translation.GetTranslation("requirementUnitTypeAtLeastJoiner", "{0}, {1}", unitList, reqString);
+				}
 			}
 		}
 
 		public override string Description
 		{
-			get { return "The army must include at least the following units to include a unit of type "+unitType.Name+": "+unitList; }
+			get { return Translation.GetTranslation("requirementUnitTypeAtLeast", "the army must include at least the following units to include a unit of type {0}: {1}", unitType.Name, unitList); }
 		}
 
 		protected override AbstractFailedRequirement CanRemoveFromArmy(Army army, UnitType type)