mirror of
https://github.com/Facepunch/Facepunch.Steamworks.git
synced 2024-12-26 22:55:55 +03:00
SteamInventory.Items (because it's nice and noob friendly)
This commit is contained in:
parent
a020474856
commit
060af634d7
@ -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()
|
||||||
{
|
{
|
||||||
|
@ -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 );
|
||||||
|
Loading…
Reference in New Issue
Block a user