diff --git a/OpenRA.Game/Input/Hotkey.cs b/OpenRA.Game/Input/Hotkey.cs index e8f4334eab..61729dec70 100644 --- a/OpenRA.Game/Input/Hotkey.cs +++ b/OpenRA.Game/Input/Hotkey.cs @@ -9,9 +9,11 @@ */ #endregion +using System; + namespace OpenRA { - public struct Hotkey + public struct Hotkey : IEquatable { public static Hotkey Invalid = new Hotkey(Keycode.UNKNOWN, Modifiers.None); public bool IsValid() @@ -74,6 +76,11 @@ namespace OpenRA public override int GetHashCode() { return Key.GetHashCode() ^ Modifiers.GetHashCode(); } + public bool Equals(Hotkey other) + { + return other == this; + } + public override bool Equals(object obj) { var o = obj as Hotkey?; diff --git a/OpenRA.Game/Primitives/Color.cs b/OpenRA.Game/Primitives/Color.cs index 6e9b24b16e..8a11ae84f8 100644 --- a/OpenRA.Game/Primitives/Color.cs +++ b/OpenRA.Game/Primitives/Color.cs @@ -15,7 +15,7 @@ using OpenRA.Scripting; namespace OpenRA.Primitives { - public struct Color : IScriptBindable + public struct Color : IEquatable, IScriptBindable { readonly long argb; @@ -200,6 +200,11 @@ namespace OpenRA.Primitives public byte G { get { return (byte)(argb >> 8); } } public byte B { get { return (byte)argb; } } + public bool Equals(Color other) + { + return this == other; + } + public override bool Equals(object obj) { if (!(obj is Color)) diff --git a/OpenRA.Game/Primitives/Pair.cs b/OpenRA.Game/Primitives/Pair.cs index c9d31c6998..22392cba19 100644 --- a/OpenRA.Game/Primitives/Pair.cs +++ b/OpenRA.Game/Primitives/Pair.cs @@ -66,17 +66,5 @@ namespace OpenRA.Primitives public static class Pair { public static Pair New(T t, U u) { return new Pair(t, u); } - - static Pair() - { - Pair.Ucomparer = new ColorEqualityComparer(); - } - - // avoid the default crappy one - class ColorEqualityComparer : IEqualityComparer - { - public bool Equals(Color x, Color y) { return x.ToArgb() == y.ToArgb(); } - public int GetHashCode(Color obj) { return obj.GetHashCode(); } - } } } diff --git a/OpenRA.Game/Primitives/Rectangle.cs b/OpenRA.Game/Primitives/Rectangle.cs index 165b0a0ddc..bb9be803b3 100644 --- a/OpenRA.Game/Primitives/Rectangle.cs +++ b/OpenRA.Game/Primitives/Rectangle.cs @@ -13,7 +13,7 @@ using System; namespace OpenRA.Primitives { - public struct Rectangle + public struct Rectangle : IEquatable { // TODO: Make these readonly: this will require a lot of changes to the UI logic public int X; @@ -76,6 +76,11 @@ namespace OpenRA.Primitives return Contains(pt.X, pt.Y); } + public bool Equals(Rectangle other) + { + return this == other; + } + public override bool Equals(object obj) { if (!(obj is Rectangle)) diff --git a/OpenRA.Game/Primitives/Size.cs b/OpenRA.Game/Primitives/Size.cs index 3a5b26c11d..03d501c014 100644 --- a/OpenRA.Game/Primitives/Size.cs +++ b/OpenRA.Game/Primitives/Size.cs @@ -13,7 +13,7 @@ using System; namespace OpenRA.Primitives { - public struct Size + public struct Size : IEquatable { public readonly int Width; public readonly int Height; @@ -46,6 +46,11 @@ namespace OpenRA.Primitives public bool IsEmpty { get { return Width == 0 && Height == 0; } } + public bool Equals(Size other) + { + return this == other; + } + public override bool Equals(object obj) { if (!(obj is Size)) diff --git a/OpenRA.Game/Primitives/float3.cs b/OpenRA.Game/Primitives/float3.cs index 3d12f4db5d..b738843731 100644 --- a/OpenRA.Game/Primitives/float3.cs +++ b/OpenRA.Game/Primitives/float3.cs @@ -9,6 +9,7 @@ */ #endregion +using System; using System.Diagnostics.CodeAnalysis; using System.Runtime.InteropServices; @@ -16,7 +17,7 @@ namespace OpenRA { [SuppressMessage("StyleCop.CSharp.NamingRules", "SA1300:ElementMustBeginWithUpperCaseLetter", Justification = "Mimic a built-in type alias.")] [StructLayout(LayoutKind.Sequential)] - public struct float3 + public struct float3 : IEquatable { public readonly float X, Y, Z; public float2 XY { get { return new float2(X, Y); } } @@ -47,6 +48,11 @@ namespace OpenRA public static bool operator !=(float3 me, float3 other) { return !(me == other); } public override int GetHashCode() { return X.GetHashCode() ^ Y.GetHashCode() ^ Z.GetHashCode(); } + public bool Equals(float3 other) + { + return other == this; + } + public override bool Equals(object obj) { var o = obj as float3?;