Inventory item def

This commit is contained in:
Garry Newman 2019-04-29 11:21:59 +01:00
parent 1625268f5d
commit b74d45814a
5 changed files with 25 additions and 3 deletions

View File

@ -61,7 +61,7 @@ public async Task GetAllItems()
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 )
{

View File

@ -40,6 +40,17 @@ internal static void InstallEvents()
internal static void DefinitionsUpdated()
{
Definitions = GetDefinitions();
if ( Definitions != null )
{
_defMap = new Dictionary<int, InventoryDef>();
foreach ( var d in Definitions )
{
_defMap[d.Id] = d;
}
}
defUpdateCount++;
OnDefinitionsUpdated?.Invoke();
@ -76,6 +87,14 @@ public static async Task<bool> WaitForDefinitions( float timeoutSeconds = 10 )
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<InventoryDef[]> GetDefinitionsWithPricesAsync()
@ -103,6 +122,7 @@ public static async Task<InventoryDef[]> GetDefinitionsWithPricesAsync()
}
public static InventoryDef[] Definitions { get; internal set; }
public static Dictionary<int, InventoryDef> _defMap;
internal static InventoryDef[] GetDefinitions()
{

View File

@ -4,7 +4,7 @@
namespace Steamworks
{
public struct InventoryDef
public class InventoryDef
{
internal InventoryDefId _id;

View File

@ -18,6 +18,8 @@ public struct InventoryItem
public int Quantity => _quantity;
public InventoryDef Def => SteamInventory.FindDefinition( DefId );
/// <summary>
/// Only available if the result set was created with the getproperties

View File

@ -21,7 +21,7 @@ internal async Task<bool> WaitUntilReadyAsync()
while ( _result == Result.Pending )
{
_result = SteamInventory.Internal.GetResultStatus( _id );
Task.Delay( 10 );
await Task.Delay( 10 );
}
return _result == Result.OK || _result == Result.Expired;