# HG changeset patch # User IBBoard # Date 1261427855 0 # Node ID 6083010a005c2c59aa506c4b309d1da16e7f6f84 # Parent ece26f6a62f397e45ba5af85332efd7dc93974e5 Re #223: Use translations within the API * Update requirements to use translations * Remove duplicate classes diff -r ece26f6a62f3 -r 6083010a005c IBBoard.WarFoundry.API.csproj --- 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 @@ - - - diff -r ece26f6a62f3 -r 6083010a005c api/Requirements/RequirementAND.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 @@ /// 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; diff -r ece26f6a62f3 -r 6083010a005c api/Requirements/RequirementOR.cs --- 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 @@ /// 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; diff -r ece26f6a62f3 -r 6083010a005c api/Requirements/UnitExcludesRequirement.cs --- 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) { diff -r ece26f6a62f3 -r 6083010a005c api/Requirements/UnitExclusion.cs --- 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 description for UnitMaxNumberRequirement. - /// - 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 - /// Summary description for UnitMaxNumberRequirement. - /// - 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); } - } - } -} diff -r ece26f6a62f3 -r 6083010a005c api/Requirements/UnitMinNumberReached.cs --- 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 description for UnitMaxNumberRequirement. - /// - 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"; } - } - } -} diff -r ece26f6a62f3 -r 6083010a005c api/Requirements/UnitRequirementMaxNumber.cs --- 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) diff -r ece26f6a62f3 -r 6083010a005c api/Requirements/UnitRequirementMinNumber.cs --- 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) diff -r ece26f6a62f3 -r 6083010a005c api/Requirements/UnitRequiresAtLeastRequirement.cs --- 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 @@ /// 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