mirror of
https://github.com/Facepunch/Facepunch.Steamworks.git
synced 2025-01-23 20:17:58 +03:00
Calls on an unresolved leaderboard are deferred
Applies to: * AddScore( bool onlyIfBeatsOldScore, int score, params int[] subscores ) * AddScore( bool onlyIfBeatsOldScore, int score, int[] subscores = null, AddScoreCallback onSuccess = null, FailureCallback onFailure = null ) * AttachRemoteFile( RemoteFile file, AttachRemoteFileCallback onSuccess = null, FailureCallback onFailure = null ) * FetchScores( RequestType RequestType, int start, int end, FetchScoresCallback onSuccess, FailureCallback onFailure = null )
This commit is contained in:
parent
7eb4a88cee
commit
1c04459cdb
@ -35,6 +35,8 @@ namespace Facepunch.Steamworks
|
|||||||
internal ulong BoardId;
|
internal ulong BoardId;
|
||||||
internal Client client;
|
internal Client client;
|
||||||
|
|
||||||
|
private readonly Queue<Action> _onCreated = new Queue<Action>();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The results from the last query. Can be null.
|
/// The results from the last query. Can be null.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -77,21 +79,45 @@ namespace Facepunch.Steamworks
|
|||||||
client = null;
|
client = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void DispatchOnCreatedCallbacks()
|
||||||
|
{
|
||||||
|
while ( _onCreated.Count > 0 )
|
||||||
|
{
|
||||||
|
_onCreated.Dequeue()();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool DeferOnCreated( Action onValid, FailureCallback onFailure = null )
|
||||||
|
{
|
||||||
|
if ( IsValid || IsError ) return false;
|
||||||
|
|
||||||
|
_onCreated.Enqueue( () =>
|
||||||
|
{
|
||||||
|
if ( IsValid ) onValid();
|
||||||
|
else onFailure?.Invoke( Callbacks.Result.Fail );
|
||||||
|
} );
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
internal void OnBoardCreated( LeaderboardFindResult_t result, bool error )
|
internal void OnBoardCreated( LeaderboardFindResult_t result, bool error )
|
||||||
{
|
{
|
||||||
if ( error || ( result.LeaderboardFound == 0 ) )
|
if ( error || ( result.LeaderboardFound == 0 ) )
|
||||||
{
|
{
|
||||||
IsError = true;
|
IsError = true;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
BoardId = result.SteamLeaderboard;
|
|
||||||
|
|
||||||
if ( IsValid )
|
|
||||||
{
|
{
|
||||||
Name = client.native.userstats.GetLeaderboardName( BoardId );
|
BoardId = result.SteamLeaderboard;
|
||||||
TotalEntries = client.native.userstats.GetLeaderboardEntryCount( BoardId );
|
|
||||||
|
if ( IsValid )
|
||||||
|
{
|
||||||
|
Name = client.native.userstats.GetLeaderboardName( BoardId );
|
||||||
|
TotalEntries = client.native.userstats.GetLeaderboardEntryCount( BoardId );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DispatchOnCreatedCallbacks();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -103,7 +129,8 @@ namespace Facepunch.Steamworks
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public bool AddScore( bool onlyIfBeatsOldScore, int score, params int[] subscores )
|
public bool AddScore( bool onlyIfBeatsOldScore, int score, params int[] subscores )
|
||||||
{
|
{
|
||||||
if ( !IsValid ) return false;
|
if ( IsError ) return false;
|
||||||
|
if ( !IsValid ) return DeferOnCreated( () => AddScore( onlyIfBeatsOldScore, score, subscores ) );
|
||||||
|
|
||||||
var flags = LeaderboardUploadScoreMethod.ForceUpdate;
|
var flags = LeaderboardUploadScoreMethod.ForceUpdate;
|
||||||
if ( onlyIfBeatsOldScore ) flags = LeaderboardUploadScoreMethod.KeepBest;
|
if ( onlyIfBeatsOldScore ) flags = LeaderboardUploadScoreMethod.KeepBest;
|
||||||
@ -142,7 +169,8 @@ namespace Facepunch.Steamworks
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public bool AddScore( bool onlyIfBeatsOldScore, int score, int[] subscores = null, AddScoreCallback onSuccess = null, FailureCallback onFailure = null )
|
public bool AddScore( bool onlyIfBeatsOldScore, int score, int[] subscores = null, AddScoreCallback onSuccess = null, FailureCallback onFailure = null )
|
||||||
{
|
{
|
||||||
if ( !IsValid ) return false;
|
if ( IsError ) return false;
|
||||||
|
if ( !IsValid ) return DeferOnCreated( () => AddScore( onlyIfBeatsOldScore, score, subscores, onSuccess, onFailure ), onFailure );
|
||||||
|
|
||||||
if ( subscores == null ) subscores = new int[0];
|
if ( subscores == null ) subscores = new int[0];
|
||||||
|
|
||||||
@ -182,7 +210,8 @@ namespace Facepunch.Steamworks
|
|||||||
/// <returns>True if the file attachment process has started</returns>
|
/// <returns>True if the file attachment process has started</returns>
|
||||||
public bool AttachRemoteFile( RemoteFile file, AttachRemoteFileCallback onSuccess = null, FailureCallback onFailure = null )
|
public bool AttachRemoteFile( RemoteFile file, AttachRemoteFileCallback onSuccess = null, FailureCallback onFailure = null )
|
||||||
{
|
{
|
||||||
if ( !IsValid ) return false;
|
if ( IsError ) return false;
|
||||||
|
if ( !IsValid ) return DeferOnCreated( () => AttachRemoteFile( file, onSuccess, onFailure ), onFailure );
|
||||||
|
|
||||||
if ( file.IsShared )
|
if ( file.IsShared )
|
||||||
{
|
{
|
||||||
@ -260,7 +289,8 @@ namespace Facepunch.Steamworks
|
|||||||
/// <returns>Returns true if we have started the query</returns>
|
/// <returns>Returns true if we have started the query</returns>
|
||||||
public bool FetchScores( RequestType RequestType, int start, int end, FetchScoresCallback onSuccess, FailureCallback onFailure = null )
|
public bool FetchScores( RequestType RequestType, int start, int end, FetchScoresCallback onSuccess, FailureCallback onFailure = null )
|
||||||
{
|
{
|
||||||
if ( !IsValid ) return false;
|
if ( IsError ) return false;
|
||||||
|
if ( !IsValid ) return DeferOnCreated( () => FetchScores( RequestType, start, end, onSuccess, onFailure ), onFailure );
|
||||||
|
|
||||||
client.native.userstats.DownloadLeaderboardEntries( BoardId, (LeaderboardDataRequest) RequestType, start, end, ( result, error ) =>
|
client.native.userstats.DownloadLeaderboardEntries( BoardId, (LeaderboardDataRequest) RequestType, start, end, ( result, error ) =>
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user