diff --git a/Facepunch.Steamworks/Structs/InventoryDef.cs b/Facepunch.Steamworks/Structs/InventoryDef.cs index 45e6028..f438873 100644 --- a/Facepunch.Steamworks/Structs/InventoryDef.cs +++ b/Facepunch.Steamworks/Structs/InventoryDef.cs @@ -5,7 +5,7 @@ using Steamworks.Data; namespace Steamworks { - public class InventoryDef + public class InventoryDef : IEquatable { internal InventoryDefId _id; internal Dictionary _properties; @@ -220,5 +220,21 @@ namespace Steamworks return _recContaining; } + public static bool operator ==( InventoryDef a, InventoryDef b ) + { + if ( Object.ReferenceEquals( a, null ) ) + return Object.ReferenceEquals( b, null ); + + return a.Equals( b ); + } + public static bool operator !=( InventoryDef a, InventoryDef b ) => !(a == b); + public override bool Equals( object p ) => this.Equals( (InventoryDef)p ); + public override int GetHashCode() => Id.GetHashCode(); + public bool Equals( InventoryDef p ) + { + if ( p == null ) return false; + return p.Id == Id; + } + } } \ No newline at end of file diff --git a/Facepunch.Steamworks/Structs/InventoryRecipe.cs b/Facepunch.Steamworks/Structs/InventoryRecipe.cs index 03384e8..1305eb8 100644 --- a/Facepunch.Steamworks/Structs/InventoryRecipe.cs +++ b/Facepunch.Steamworks/Structs/InventoryRecipe.cs @@ -9,7 +9,7 @@ namespace Steamworks /// /// A structured description of an item exchange /// - public struct InventoryRecipe + public struct InventoryRecipe : IEquatable { public struct Ingredient { @@ -70,11 +70,14 @@ namespace Steamworks /// public Ingredient[] Ingredients; + public string Source; + internal static InventoryRecipe FromString( string part, InventoryDef Result ) { var r = new InventoryRecipe { - Result = Result + Result = Result, + Source = part }; var parts = part.Split( new[] { ',' }, StringSplitOptions.RemoveEmptyEntries ); @@ -87,5 +90,15 @@ namespace Steamworks { return Ingredients.Any( x => x.DefinitionId == inventoryDef.Id ); } + + public static bool operator ==( InventoryRecipe a, InventoryRecipe b ) => a.GetHashCode() == b.GetHashCode(); + public static bool operator !=( InventoryRecipe a, InventoryRecipe b ) => a.GetHashCode() != b.GetHashCode(); + public override bool Equals( object p ) => this.Equals( (InventoryRecipe)p ); + public override int GetHashCode() + { + return Source.GetHashCode(); + } + + public bool Equals( InventoryRecipe p ) => p.GetHashCode() == GetHashCode(); } } \ No newline at end of file