Round off some edges with ItemDefinitions

This commit is contained in:
Garry Newman 2019-05-01 14:03:37 +01:00
parent 157d0d676e
commit 994cdee49e

View File

@ -33,30 +33,26 @@ internal static void Shutdown()
internal static void InstallEvents() internal static void InstallEvents()
{ {
SteamInventoryFullUpdate_t.Install( x => OnInventoryUpdated?.Invoke( x.Handle ) ); SteamInventoryFullUpdate_t.Install( x => OnInventoryUpdated?.Invoke( x.Handle ) );
SteamInventoryDefinitionUpdate_t.Install( x => DefinitionsUpdated() ); SteamInventoryDefinitionUpdate_t.Install( x => LoadDefinitions() );
} }
public static event Action<int> OnInventoryUpdated; public static event Action<int> OnInventoryUpdated;
public static event Action OnDefinitionsUpdated; public static event Action OnDefinitionsUpdated;
internal static int defUpdateCount = 0; static void LoadDefinitions()
internal static void DefinitionsUpdated()
{ {
Definitions = GetDefinitions(); Definitions = GetDefinitions();
if ( Definitions != null ) if ( Definitions == null )
return;
_defMap = new Dictionary<int, InventoryDef>();
foreach ( var d in Definitions )
{ {
_defMap = new Dictionary<int, InventoryDef>(); _defMap[d.Id] = d;
foreach ( var d in Definitions )
{
_defMap[d.Id] = d;
}
} }
defUpdateCount++;
OnDefinitionsUpdated?.Invoke(); OnDefinitionsUpdated?.Invoke();
} }
@ -68,16 +64,33 @@ internal static void DefinitionsUpdated()
/// </summary> /// </summary>
public static void LoadItemDefinitions() public static void LoadItemDefinitions()
{ {
// If they're null, try to load them immediately
// my hunch is that this loads a disk cached version
// but waiting for LoadItemDefinitions downloads a new copy
// from Steam's servers. So this will give us immediate data
// where as Steam's inventory servers could be slow/down
if ( Definitions == null )
{
LoadDefinitions();
}
Internal.LoadItemDefinitions(); Internal.LoadItemDefinitions();
} }
/// <summary> /// <summary>
/// Will call LoadItemDefinitions and wait until Definitions is not null /// Will call LoadItemDefinitions and wait until Definitions is not null
/// </summary> /// </summary>
public static async Task<bool> WaitForDefinitions( float timeoutSeconds = 10 ) public static async Task<bool> WaitForDefinitions( float timeoutSeconds = 30 )
{ {
if ( Definitions != null )
return true;
LoadDefinitions();
LoadItemDefinitions(); LoadItemDefinitions();
if ( Definitions != null )
return true;
var sw = Stopwatch.StartNew(); var sw = Stopwatch.StartNew();
while ( Definitions == null ) while ( Definitions == null )