mirror of
https://github.com/Facepunch/Facepunch.Steamworks.git
synced 2025-02-03 01:00:34 +03:00
Added Query.OnResult callback
This commit is contained in:
parent
9f3ecfd66e
commit
15bfd887bd
@ -243,6 +243,41 @@ namespace Facepunch.Steamworks.Test
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void QueryCallback()
|
||||
{
|
||||
using ( var client = new Facepunch.Steamworks.Client( 252490 ) )
|
||||
{
|
||||
Assert.IsTrue( client.IsValid );
|
||||
|
||||
using ( var Query = client.Workshop.CreateQuery() )
|
||||
{
|
||||
var gotCallback = false;
|
||||
|
||||
Query.OnResult = ( q ) =>
|
||||
{
|
||||
Assert.AreEqual( q.Items.Length, 1 );
|
||||
Console.WriteLine( "Query.TotalResults: {0}", q.TotalResults );
|
||||
Console.WriteLine( "Query.Items.Length: {0}", q.Items.Length );
|
||||
|
||||
gotCallback = true;
|
||||
};
|
||||
|
||||
Query.FileId.Add( 751993251 );
|
||||
Query.Run();
|
||||
|
||||
Assert.IsTrue( Query.IsRunning );
|
||||
|
||||
client.UpdateWhile( () => gotCallback == false );
|
||||
|
||||
Assert.IsFalse( Query.IsRunning );
|
||||
Assert.AreEqual( Query.TotalResults, 1 );
|
||||
|
||||
Assert.AreEqual<ulong>( Query.Items[0].Id, 751993251 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void QueryFiles()
|
||||
{
|
||||
|
@ -37,6 +37,11 @@ namespace Facepunch.Steamworks
|
||||
|
||||
public UserQueryType UserQueryType { get; set; } = UserQueryType.Published;
|
||||
|
||||
/// <summary>
|
||||
/// Called when the query finishes
|
||||
/// </summary>
|
||||
public Action<Query> OnResult;
|
||||
|
||||
/// <summary>
|
||||
/// Page starts at 1 !!
|
||||
/// </summary>
|
||||
@ -106,10 +111,10 @@ namespace Facepunch.Steamworks
|
||||
foreach ( var tag in ExcludeTags )
|
||||
workshop.ugc.AddExcludedTag( Handle, tag );
|
||||
|
||||
Callback = workshop.ugc.SendQueryUGCRequest( Handle, OnResult );
|
||||
Callback = workshop.ugc.SendQueryUGCRequest( Handle, ResultCallback );
|
||||
}
|
||||
|
||||
void OnResult( SteamNative.SteamUGCQueryCompleted_t data, bool bFailed )
|
||||
void ResultCallback( SteamNative.SteamUGCQueryCompleted_t data, bool bFailed )
|
||||
{
|
||||
if ( bFailed )
|
||||
throw new System.Exception( "bFailed!" );
|
||||
@ -166,6 +171,11 @@ namespace Facepunch.Steamworks
|
||||
else
|
||||
{
|
||||
Items = _results.ToArray();
|
||||
|
||||
if ( OnResult != null )
|
||||
{
|
||||
OnResult( this );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user