diff --git a/Facepunch.Steamworks.Test/InventoryTest.cs b/Facepunch.Steamworks.Test/InventoryTest.cs index 5c78829..593af1d 100644 --- a/Facepunch.Steamworks.Test/InventoryTest.cs +++ b/Facepunch.Steamworks.Test/InventoryTest.cs @@ -61,7 +61,7 @@ namespace Steamworks foreach ( var item in items ) { - Console.WriteLine( $"{item.Id} / {item.DefId} / {item.Quantity} " ); + Console.WriteLine( $"{item.Id} / {item.DefId} / {item.Quantity} / {item.Def.Name} " ); foreach ( var prop in item.Properties ) { diff --git a/Facepunch.Steamworks/SteamInventory.cs b/Facepunch.Steamworks/SteamInventory.cs index f08df22..ba3aa87 100644 --- a/Facepunch.Steamworks/SteamInventory.cs +++ b/Facepunch.Steamworks/SteamInventory.cs @@ -40,6 +40,17 @@ namespace Steamworks internal static void DefinitionsUpdated() { Definitions = GetDefinitions(); + + if ( Definitions != null ) + { + _defMap = new Dictionary(); + + foreach ( var d in Definitions ) + { + _defMap[d.Id] = d; + } + } + defUpdateCount++; OnDefinitionsUpdated?.Invoke(); @@ -76,6 +87,14 @@ namespace Steamworks return true; } + internal static InventoryDef FindDefinition( InventoryDefId defId ) + { + if ( _defMap.TryGetValue( defId, out var val ) ) + return val; + + return null; + } + public static string Currency { get; internal set; } public static async Task GetDefinitionsWithPricesAsync() @@ -103,6 +122,7 @@ namespace Steamworks } public static InventoryDef[] Definitions { get; internal set; } + public static Dictionary _defMap; internal static InventoryDef[] GetDefinitions() { diff --git a/Facepunch.Steamworks/Structs/InventoryDef.cs b/Facepunch.Steamworks/Structs/InventoryDef.cs index fbda5ac..e384619 100644 --- a/Facepunch.Steamworks/Structs/InventoryDef.cs +++ b/Facepunch.Steamworks/Structs/InventoryDef.cs @@ -4,7 +4,7 @@ using Steamworks.Data; namespace Steamworks { - public struct InventoryDef + public class InventoryDef { internal InventoryDefId _id; diff --git a/Facepunch.Steamworks/Structs/InventoryItem.cs b/Facepunch.Steamworks/Structs/InventoryItem.cs index 83d4794..1643c5b 100644 --- a/Facepunch.Steamworks/Structs/InventoryItem.cs +++ b/Facepunch.Steamworks/Structs/InventoryItem.cs @@ -18,6 +18,8 @@ namespace Steamworks public int Quantity => _quantity; + public InventoryDef Def => SteamInventory.FindDefinition( DefId ); + /// /// Only available if the result set was created with the getproperties diff --git a/Facepunch.Steamworks/Structs/InventoryResult.cs b/Facepunch.Steamworks/Structs/InventoryResult.cs index 9b804af..62eb875 100644 --- a/Facepunch.Steamworks/Structs/InventoryResult.cs +++ b/Facepunch.Steamworks/Structs/InventoryResult.cs @@ -21,7 +21,7 @@ namespace Steamworks while ( _result == Result.Pending ) { _result = SteamInventory.Internal.GetResultStatus( _id ); - Task.Delay( 10 ); + await Task.Delay( 10 ); } return _result == Result.OK || _result == Result.Expired;