SteamInventory.Items (because it's nice and noob friendly)

This commit is contained in:
Garry Newman 2019-05-07 21:01:42 +01:00
parent a020474856
commit 060af634d7
2 changed files with 45 additions and 1 deletions

View File

@ -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] [TestMethod]
public async Task GetExchanges() public async Task GetExchanges()
{ {

View File

@ -35,11 +35,19 @@ internal static void Shutdown()
internal static void InstallEvents() 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 => LoadDefinitions() );
SteamInventoryDefinitionUpdate_t.Install( x => OnServerDefinitionsUpdated(), true ); 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<int> OnInventoryUpdated; public static event Action<int> OnInventoryUpdated;
public static event Action OnDefinitionsUpdated; public static event Action OnDefinitionsUpdated;
public static event Action OnServerDefinitionsUpdated; public static event Action OnServerDefinitionsUpdated;
@ -147,6 +155,11 @@ public static async Task<InventoryDef[]> GetDefinitionsWithPricesAsync()
return defs.Select( x => new InventoryDef( x ) ).ToArray(); return defs.Select( x => new InventoryDef( x ) ).ToArray();
} }
/// <summary>
/// We will try to keep this list of your items automatically up to date.
/// </summary>
public static InventoryItem[] Items { get; internal set; }
public static InventoryDef[] Definitions { get; internal set; } public static InventoryDef[] Definitions { get; internal set; }
static Dictionary<int, InventoryDef> _defMap; static Dictionary<int, InventoryDef> _defMap;
@ -164,6 +177,18 @@ internal static InventoryDef[] GetDefinitions()
return defs.Select( x => new InventoryDef( x ) ).ToArray(); return defs.Select( x => new InventoryDef( x ) ).ToArray();
} }
/// <summary>
/// Update the list of Items[]
/// </summary>
public static bool GetAllItems()
{
var sresult = default( SteamInventoryResult_t );
return Internal.GetAllItems( ref sresult );
}
/// <summary>
/// Get all items and return the InventoryResult
/// </summary>
public static async Task<InventoryResult?> GetAllItemsAsync() public static async Task<InventoryResult?> GetAllItemsAsync()
{ {
var sresult = default( SteamInventoryResult_t ); var sresult = default( SteamInventoryResult_t );