diff --git a/Facepunch.Steamworks.Test/InventoryTest.cs b/Facepunch.Steamworks.Test/InventoryTest.cs index 578a4c4..f0f9707 100644 --- a/Facepunch.Steamworks.Test/InventoryTest.cs +++ b/Facepunch.Steamworks.Test/InventoryTest.cs @@ -71,6 +71,25 @@ public async Task GetAllItems() } } + [TestMethod] + public async Task Items() + { + SteamInventory.GetAllItems(); + await SteamInventory.WaitForDefinitions(); + + while ( SteamInventory.Items == null ) + { + await Task.Delay( 10 ); + } + + Assert.IsNotNull( SteamInventory.Items ); + + foreach ( var item in SteamInventory.Items ) + { + Console.WriteLine( $"{item.Id} / {item.DefId} / {item.Quantity} / {item.Def.Name}" ); + } + } + [TestMethod] public async Task GetExchanges() { diff --git a/Facepunch.Steamworks/SteamInventory.cs b/Facepunch.Steamworks/SteamInventory.cs index 65ef3bc..94c2a79 100644 --- a/Facepunch.Steamworks/SteamInventory.cs +++ b/Facepunch.Steamworks/SteamInventory.cs @@ -35,11 +35,19 @@ internal static void Shutdown() internal static void InstallEvents() { - SteamInventoryFullUpdate_t.Install( x => OnInventoryUpdated?.Invoke( x.Handle ) ); + SteamInventoryFullUpdate_t.Install( x => InventoryUpdated( x ) ); SteamInventoryDefinitionUpdate_t.Install( x => LoadDefinitions() ); SteamInventoryDefinitionUpdate_t.Install( x => OnServerDefinitionsUpdated(), true ); } + private static void InventoryUpdated( SteamInventoryFullUpdate_t x ) + { + var r = new InventoryResult( x.Handle, false ); + Items = r.GetItems( false ); + + OnInventoryUpdated?.Invoke( x.Handle ); + } + public static event Action OnInventoryUpdated; public static event Action OnDefinitionsUpdated; public static event Action OnServerDefinitionsUpdated; @@ -147,6 +155,11 @@ public static async Task GetDefinitionsWithPricesAsync() return defs.Select( x => new InventoryDef( x ) ).ToArray(); } + /// + /// We will try to keep this list of your items automatically up to date. + /// + public static InventoryItem[] Items { get; internal set; } + public static InventoryDef[] Definitions { get; internal set; } static Dictionary _defMap; @@ -164,6 +177,18 @@ internal static InventoryDef[] GetDefinitions() return defs.Select( x => new InventoryDef( x ) ).ToArray(); } + /// + /// Update the list of Items[] + /// + public static bool GetAllItems() + { + var sresult = default( SteamInventoryResult_t ); + return Internal.GetAllItems( ref sresult ); + } + + /// + /// Get all items and return the InventoryResult + /// public static async Task GetAllItemsAsync() { var sresult = default( SteamInventoryResult_t );