diff --git a/HexCell.cs b/HexCell.cs index 626a58d..c63c17f 100644 --- a/HexCell.cs +++ b/HexCell.cs @@ -1,11 +1,25 @@ using System; using System.Diagnostics; using System.Linq; +using System.Runtime.CompilerServices; using Godot; using Array = Godot.Collections.Array; -public class HexCell : Resource, IEquatable +public class HexCell : IEquatable { + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + if (ReferenceEquals(this, obj)) return true; + if (obj.GetType() != this.GetType()) return false; + return Equals((HexCell)obj); + } + + public override int GetHashCode() + { + return _cubeCoords.GetHashCode(); + } + public static readonly Vector2 size = new Vector2(1, Mathf.Sqrt(3) / 2); public static readonly Vector3 DIR_N = new Vector3(0, 1, -1); public static readonly Vector3 DIR_NE = new Vector3(1, 0, -1); @@ -35,6 +49,16 @@ public class HexCell : Resource, IEquatable return CubeCoords == other.CubeCoords; } + + public static bool operator ==(HexCell cellA, HexCell cellB) + { + return Equals(cellA, cellB); + } + + public static bool operator !=(HexCell cellA, HexCell cellB) + { + return !(cellA == cellB); + } public HexCell(Vector3 cubeCoords) { diff --git a/tests/HexCellTests.cs b/tests/HexCellTests.cs index 65a5bd5..9773ce9 100644 --- a/tests/HexCellTests.cs +++ b/tests/HexCellTests.cs @@ -27,9 +27,14 @@ public class HexCellTests : TestClass cellA.AxialCoords = new Vector2(2, 3); cellB.AxialCoords = new Vector2(2, 3); Assert.Equal(cellA, cellB); + bool result = cellA == cellB; + Assert.True(cellA == cellB); + Assert.False(cellA != cellB); cellB.AxialCoords = new Vector2(3, 2); Assert.NotEqual(cellA, cellB); + Assert.False(cellA == cellB); + Assert.True(cellA != cellB); } [Test]