changeset 419:71fceea2725b

Code tidy-up - remove warnings * Add missing GetHashcode() implementations * Remove unused exception variables * Use unused event * Remove dead code * Properly override some methods
author IBBoard <dev@ibboard.co.uk>
date Sun, 25 Sep 2011 20:52:27 +0100
parents 6798a59c1b49
children 22561233df69
files API/AbstractWarFoundryLoader.cs API/Exporters/WarFoundryXMLWithXSLExporter.cs API/Factories/Xml/WarFoundryXmlFactory.cs API/Factories/Xml/WarFoundryXmlFactoryUtils.cs API/Objects/GameSystem.cs API/Objects/Race.cs API/Objects/Requirement/AbstractRequirement.cs API/Objects/Requirement/RequiresAtLeastNUnitsRequirement.cs API/Objects/Requirement/RequiresNoMoreThanNOfUnitTypeRequirement.cs API/Objects/Requirement/UnitRequiresNoMoreThanNOfUnitTypeRequirement.cs API/Objects/UnitType.cs
diffstat 11 files changed, 67 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/API/AbstractWarFoundryLoader.cs	Sat Sep 24 11:59:39 2011 +0100
+++ b/API/AbstractWarFoundryLoader.cs	Sun Sep 25 20:52:27 2011 +0100
@@ -129,6 +129,7 @@
 		/// </returns>
 		public List<FileLoadFailure> LoadFiles()
 		{
+			OnFileLoadingStarted();
 			PrepareForFileLoad();
 			Dictionary<FileInfo, IWarFoundryFactory> loadableRaces = new Dictionary<FileInfo, IWarFoundryFactory>();
 			Dictionary<FileInfo, IWarFoundryFactory> loadableGameSystems = new Dictionary<FileInfo, IWarFoundryFactory>();
@@ -140,6 +141,14 @@
 			return failedLoads;
 		}
 
+		private void OnFileLoadingStarted()
+		{
+			if (FileLoadingStarted != null)
+			{
+				FileLoadingStarted();
+			}
+		}
+
 		private void OnFileLoadingFinished(List<FileLoadFailure> failures)
 		{
 			if (FileLoadingFinished != null)
--- a/API/Exporters/WarFoundryXMLWithXSLExporter.cs	Sat Sep 24 11:59:39 2011 +0100
+++ b/API/Exporters/WarFoundryXMLWithXSLExporter.cs	Sun Sep 25 20:52:27 2011 +0100
@@ -132,15 +132,7 @@
                         armyEquipmentItem.SetAttribute("name", equip.Name);
 
                         int armyEquipAmount = 0;
-
-                        if (UnitEquipmentUtil.GetEquipmentAmount(uni, equip) == null)
-                        {
-                            armyEquipAmount = 0;
-                        }
-                        else
-                        {
-                            armyEquipAmount = (int)UnitEquipmentUtil.GetEquipmentAmount(uni, equip);
-                        }
+						armyEquipAmount = (int)UnitEquipmentUtil.GetEquipmentAmount(uni, equip);
                         
                         if (UnitEquipmentUtil.GetEquipmentAmountIsRatio(uni, equip))
                         {
--- a/API/Factories/Xml/WarFoundryXmlFactory.cs	Sat Sep 24 11:59:39 2011 +0100
+++ b/API/Factories/Xml/WarFoundryXmlFactory.cs	Sun Sep 25 20:52:27 2011 +0100
@@ -167,7 +167,7 @@
 			{
 				raceFactory.CompleteLoading(race);
 			}
-			catch (InvalidFileException ex)
+			catch (InvalidFileException)
 			{
 				WarFoundryLoader.GetDefault().RemoveRace(race);
 				throw;
@@ -180,7 +180,7 @@
 			{
 				gameSystemFactory.CompleteLoading(system);
 			}
-			catch (InvalidFileException ex)
+			catch (InvalidFileException)
 			{
 				WarFoundryLoader.GetDefault().RemoveGameSystem(system);
 				throw;
--- a/API/Factories/Xml/WarFoundryXmlFactoryUtils.cs	Sat Sep 24 11:59:39 2011 +0100
+++ b/API/Factories/Xml/WarFoundryXmlFactoryUtils.cs	Sun Sep 25 20:52:27 2011 +0100
@@ -98,15 +98,15 @@
 			{
 				cache.Add(xmlNamespace, schemaLocation);
 			}
-			catch (IOException ex)
+			catch (IOException)
 			{
 				//TODO: Warn on schema failure
 			}
-			catch (XmlSchemaException ex)
+			catch (XmlSchemaException)
 			{
 				//TODO: Warn on schema failure
 			}
-			catch (XmlException ex)
+			catch (XmlException)
 			{
 				//TODO: Warn on schema failure
 			}
--- a/API/Objects/GameSystem.cs	Sat Sep 24 11:59:39 2011 +0100
+++ b/API/Objects/GameSystem.cs	Sun Sep 25 20:52:27 2011 +0100
@@ -238,7 +238,19 @@
 
 		public override int GetHashCode()
 		{
-			return ID.GetHashCode() + Name.GetHashCode() + (RawCategories != null ? RawCategories.GetHashCode() : 0) + warnOnError.GetHashCode();
+			return ID.GetHashCode() + Name.GetHashCode() + GetCategoryHash() + warnOnError.GetHashCode();
+		}
+
+		private int GetCategoryHash()
+		{
+			int hash = 0;
+
+			foreach (Category cat in RawCategories.Values)
+			{
+				hash += cat.ID.GetHashCode();
+			}
+
+			return hash;
 		}
 
 		public bool UnitTypeMaxed(UnitType unitType, Army army)
--- a/API/Objects/Race.cs	Sat Sep 24 11:59:39 2011 +0100
+++ b/API/Objects/Race.cs	Sun Sep 25 20:52:27 2011 +0100
@@ -60,6 +60,11 @@
 			}
 		}
 
+		public override int GetHashCode()
+		{
+			return ID.GetHashCode() + SubID.GetHashCode() + GameSystem.GetHashCode() + ArmyDefaultName.GetHashCode();
+		}
+
 		public string SubID
 		{
 			get { return subID; }
--- a/API/Objects/Requirement/AbstractRequirement.cs	Sat Sep 24 11:59:39 2011 +0100
+++ b/API/Objects/Requirement/AbstractRequirement.cs	Sun Sep 25 20:52:27 2011 +0100
@@ -24,6 +24,8 @@
 			}
 		}
 
+		public override abstract int GetHashCode();
+
 		/// <summary>
 		/// Type-specific equality checking - must be implemented by each class
 		/// </summary>
--- a/API/Objects/Requirement/RequiresAtLeastNUnitsRequirement.cs	Sat Sep 24 11:59:39 2011 +0100
+++ b/API/Objects/Requirement/RequiresAtLeastNUnitsRequirement.cs	Sun Sep 25 20:52:27 2011 +0100
@@ -39,6 +39,18 @@
 			}
 		}
 
+		public override int GetHashCode()
+		{
+			int hash = 0;
+
+			foreach (UnitCountRequirementData req in requiredTypes)
+			{
+				hash += req.UnitType.GetHashCode();
+			}
+
+			return hash;
+		}
+
 		/// <summary>
 		/// Checks whether the supplied WarFoundryObject can be added to the supplied army.
 		/// </summary>
--- a/API/Objects/Requirement/RequiresNoMoreThanNOfUnitTypeRequirement.cs	Sat Sep 24 11:59:39 2011 +0100
+++ b/API/Objects/Requirement/RequiresNoMoreThanNOfUnitTypeRequirement.cs	Sun Sep 25 20:52:27 2011 +0100
@@ -120,6 +120,18 @@
 			return Collections.Collections.AreEqual(limitedTypes, other.limitedTypes);
 		}
 
+		public override int GetHashCode()
+		{
+			int hash = 0;
+
+			foreach (UnitCountRequirementData limit in limitedTypes)
+			{
+				hash += limit.UnitType.GetHashCode();
+			}
+
+			return hash;
+		}
+
 		protected string FailureStringPrefix { get; set; }
 
 		protected override string GetValidationFailedMessage (Army army)
--- a/API/Objects/Requirement/UnitRequiresNoMoreThanNOfUnitTypeRequirement.cs	Sat Sep 24 11:59:39 2011 +0100
+++ b/API/Objects/Requirement/UnitRequiresNoMoreThanNOfUnitTypeRequirement.cs	Sun Sep 25 20:52:27 2011 +0100
@@ -38,19 +38,19 @@
 		}
 
 
-		private bool IsApplicable(WarFoundryObject toObject, Army toArmy)
+		protected override bool IsApplicable(WarFoundryObject toObject, Army toArmy)
 		{
 			return IsApplicable(toArmy) || IsApplicable(toObject);
 		}
 
 
-		private bool IsApplicable(Army toArmy)
+		protected override bool IsApplicable(Army toArmy)
 		{
 			return toArmy.GetUnitTypeCount(requirementOnType) > 0;
 		}
 
 
-		private bool IsApplicable(WarFoundryObject toObject)
+		protected override bool IsApplicable(WarFoundryObject toObject)
 		{
 			return requirementOnType.Equals(toObject) || (toObject is Unit && requirementOnType.Equals(((Unit)toObject).UnitType));
 		}
--- a/API/Objects/UnitType.cs	Sat Sep 24 11:59:39 2011 +0100
+++ b/API/Objects/UnitType.cs	Sun Sep 25 20:52:27 2011 +0100
@@ -69,6 +69,11 @@
 			}
 		}
 
+		public override int GetHashCode()
+		{
+			return Race.GetHashCode() + ID.GetHashCode() + Name.GetHashCode();
+		}
+
 		public GameSystem GameSystem
 		{
 			get { return Race.GameSystem; }