mirror of
https://github.com/Facepunch/Facepunch.Steamworks.git
synced 2024-12-27 07:05:50 +03:00
InventoryDef and Recpie IEquatable
This commit is contained in:
parent
208af219d2
commit
cf2bc51c54
@ -5,7 +5,7 @@
|
||||
|
||||
namespace Steamworks
|
||||
{
|
||||
public class InventoryDef
|
||||
public class InventoryDef : IEquatable<InventoryDef>
|
||||
{
|
||||
internal InventoryDefId _id;
|
||||
internal Dictionary<string, string> _properties;
|
||||
@ -220,5 +220,21 @@ public InventoryRecipe[] GetRecipesContainingThis()
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -9,7 +9,7 @@ namespace Steamworks
|
||||
/// <summary>
|
||||
/// A structured description of an item exchange
|
||||
/// </summary>
|
||||
public struct InventoryRecipe
|
||||
public struct InventoryRecipe : IEquatable<InventoryRecipe>
|
||||
{
|
||||
public struct Ingredient
|
||||
{
|
||||
@ -70,11 +70,14 @@ internal static Ingredient FromString( string part )
|
||||
/// </summary>
|
||||
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 @@ internal bool ContainsIngredient( InventoryDef inventoryDef )
|
||||
{
|
||||
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();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user