mirror of
https://github.com/Facepunch/Facepunch.Steamworks.git
synced 2025-01-14 15:48:06 +03:00
InventoryDef and Recpie IEquatable
This commit is contained in:
parent
208af219d2
commit
cf2bc51c54
@ -5,7 +5,7 @@ using Steamworks.Data;
|
|||||||
|
|
||||||
namespace Steamworks
|
namespace Steamworks
|
||||||
{
|
{
|
||||||
public class InventoryDef
|
public class InventoryDef : IEquatable<InventoryDef>
|
||||||
{
|
{
|
||||||
internal InventoryDefId _id;
|
internal InventoryDefId _id;
|
||||||
internal Dictionary<string, string> _properties;
|
internal Dictionary<string, string> _properties;
|
||||||
@ -220,5 +220,21 @@ namespace Steamworks
|
|||||||
return _recContaining;
|
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>
|
/// <summary>
|
||||||
/// A structured description of an item exchange
|
/// A structured description of an item exchange
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public struct InventoryRecipe
|
public struct InventoryRecipe : IEquatable<InventoryRecipe>
|
||||||
{
|
{
|
||||||
public struct Ingredient
|
public struct Ingredient
|
||||||
{
|
{
|
||||||
@ -70,11 +70,14 @@ namespace Steamworks
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public Ingredient[] Ingredients;
|
public Ingredient[] Ingredients;
|
||||||
|
|
||||||
|
public string Source;
|
||||||
|
|
||||||
internal static InventoryRecipe FromString( string part, InventoryDef Result )
|
internal static InventoryRecipe FromString( string part, InventoryDef Result )
|
||||||
{
|
{
|
||||||
var r = new InventoryRecipe
|
var r = new InventoryRecipe
|
||||||
{
|
{
|
||||||
Result = Result
|
Result = Result,
|
||||||
|
Source = part
|
||||||
};
|
};
|
||||||
|
|
||||||
var parts = part.Split( new[] { ',' }, StringSplitOptions.RemoveEmptyEntries );
|
var parts = part.Split( new[] { ',' }, StringSplitOptions.RemoveEmptyEntries );
|
||||||
@ -87,5 +90,15 @@ namespace Steamworks
|
|||||||
{
|
{
|
||||||
return Ingredients.Any( x => x.DefinitionId == inventoryDef.Id );
|
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…
x
Reference in New Issue
Block a user