Create/Get leaderboard

This commit is contained in:
Garry Newman 2019-04-17 08:40:58 +01:00
parent d2a3e0b1da
commit e5a89b0550
8 changed files with 90 additions and 24 deletions

View File

@ -0,0 +1,20 @@
namespace Steamworks.Data
{
public enum LeaderboardDisplay : int
{
/// <summary>
/// The score is just a simple numerical value
/// </summary>
Numeric = 1,
/// <summary>
/// The score represents a time, in seconds
/// </summary>
TimeSeconds = 2,
/// <summary>
/// The score represents a time, in milliseconds
/// </summary>
TimeMilliSeconds = 3,
}
}

View File

@ -0,0 +1,15 @@
namespace Steamworks.Data
{
public enum LeaderboardSort : int
{
/// <summary>
/// The top-score is the lowest number
/// </summary>
Ascending = 1,
/// <summary>
/// The top-score is the highest number
/// </summary>
Descending = 2,
}
}

View File

@ -323,11 +323,11 @@ internal bool ResetAllStats( [MarshalAs( UnmanagedType.U1 )] bool bAchievementsT
#region FunctionMeta
[UnmanagedFunctionPointer( CallingConvention.ThisCall )]
private delegate SteamAPICall_t FindOrCreateLeaderboardDelegate( IntPtr self, string pchLeaderboardName, LeaderboardSortMethod eLeaderboardSortMethod, LeaderboardDisplayType eLeaderboardDisplayType );
private delegate SteamAPICall_t FindOrCreateLeaderboardDelegate( IntPtr self, string pchLeaderboardName, LeaderboardSort eLeaderboardSortMethod, LeaderboardDisplay eLeaderboardDisplayType );
private FindOrCreateLeaderboardDelegate FindOrCreateLeaderboardDelegatePointer;
#endregion
internal async Task<LeaderboardFindResult_t?> FindOrCreateLeaderboard( string pchLeaderboardName, LeaderboardSortMethod eLeaderboardSortMethod, LeaderboardDisplayType eLeaderboardDisplayType )
internal async Task<LeaderboardFindResult_t?> FindOrCreateLeaderboard( string pchLeaderboardName, LeaderboardSort eLeaderboardSortMethod, LeaderboardDisplay eLeaderboardDisplayType )
{
return await (new Result<LeaderboardFindResult_t>( FindOrCreateLeaderboardDelegatePointer( Self, pchLeaderboardName, eLeaderboardSortMethod, eLeaderboardDisplayType ) )).GetResult();
}
@ -367,22 +367,22 @@ internal int GetLeaderboardEntryCount( SteamLeaderboard_t hSteamLeaderboard )
#region FunctionMeta
[UnmanagedFunctionPointer( CallingConvention.ThisCall )]
private delegate LeaderboardSortMethod GetLeaderboardSortMethodDelegate( IntPtr self, SteamLeaderboard_t hSteamLeaderboard );
private delegate LeaderboardSort GetLeaderboardSortMethodDelegate( IntPtr self, SteamLeaderboard_t hSteamLeaderboard );
private GetLeaderboardSortMethodDelegate GetLeaderboardSortMethodDelegatePointer;
#endregion
internal LeaderboardSortMethod GetLeaderboardSortMethod( SteamLeaderboard_t hSteamLeaderboard )
internal LeaderboardSort GetLeaderboardSortMethod( SteamLeaderboard_t hSteamLeaderboard )
{
return GetLeaderboardSortMethodDelegatePointer( Self, hSteamLeaderboard );
}
#region FunctionMeta
[UnmanagedFunctionPointer( CallingConvention.ThisCall )]
private delegate LeaderboardDisplayType GetLeaderboardDisplayTypeDelegate( IntPtr self, SteamLeaderboard_t hSteamLeaderboard );
private delegate LeaderboardDisplay GetLeaderboardDisplayTypeDelegate( IntPtr self, SteamLeaderboard_t hSteamLeaderboard );
private GetLeaderboardDisplayTypeDelegate GetLeaderboardDisplayTypeDelegatePointer;
#endregion
internal LeaderboardDisplayType GetLeaderboardDisplayType( SteamLeaderboard_t hSteamLeaderboard )
internal LeaderboardDisplay GetLeaderboardDisplayType( SteamLeaderboard_t hSteamLeaderboard )
{
return GetLeaderboardDisplayTypeDelegatePointer( Self, hSteamLeaderboard );
}

View File

@ -904,24 +904,9 @@ internal enum LeaderboardDataRequest : int
//
// ELeaderboardSortMethod
//
internal enum LeaderboardSortMethod : int
{
None = 0,
Ascending = 1,
Descending = 2,
}
//
// ELeaderboardDisplayType
//
internal enum LeaderboardDisplayType : int
{
None = 0,
Numeric = 1,
TimeSeconds = 2,
TimeMilliSeconds = 3,
}
//
// ELeaderboardUploadScoreMethod
//

View File

@ -101,5 +101,33 @@ public static bool RequestCurrentStats()
{
return Internal.RequestCurrentStats();
}
/// <summary>
/// Gets a leaderboard by name, it will create it if it's not yet created.
/// Leaderboards created with this function will not automatically show up in the Steam Community.
/// You must manually set the Community Name field in the App Admin panel of the Steamworks website.
/// As such it's generally recommended to prefer creating the leaderboards in the App Admin panel on
/// the Steamworks website and using FindLeaderboard unless you're expected to have a large amount of
/// dynamically created leaderboards.
/// </summary>
public static async Task<Leaderboard?> FindOrCreateLeaderboard( string name, LeaderboardSort sort, LeaderboardDisplay display )
{
var result = await Internal.FindOrCreateLeaderboard( name, sort, display );
if ( !result.HasValue || result.Value.LeaderboardFound == 0 )
return null;
return new Leaderboard { Id = result.Value.SteamLeaderboard };
}
public static async Task<Leaderboard?> FindLeaderboard( string name )
{
var result = await Internal.FindLeaderboard( name );
if ( !result.HasValue || result.Value.LeaderboardFound == 0 )
return null;
return new Leaderboard { Id = result.Value.SteamLeaderboard };
}
}
}

View File

@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace Steamworks.Data
{
public struct Leaderboard
{
internal SteamLeaderboard_t Id;
}
}

View File

@ -18,9 +18,9 @@ public static string ConvertType( string type )
type = type.Replace( "FriendRelationship", "Relationship" );
type = type.Replace( "BeginAuthSessionResult", "BeginAuthResult" );
type = type.Replace( "PublishedFileId_t", "PublishedFileId" );
type = type.Replace( "PublishedFileId_t", "PublishedFileId" );
type = type.Replace( "LeaderboardSortMethod", "LeaderboardSort" );
type = type.Replace( "LeaderboardDisplayType", "LeaderboardDisplay" );
return type;
}
@ -28,6 +28,8 @@ public static string ConvertType( string type )
public static bool ShouldCreate( string type )
{
if ( type == "SteamId" ) return false;
if ( type == "LeaderboardSort" ) return false;
if ( type == "LeaderboardDisplay" ) return false;
return true;

View File

@ -27,6 +27,9 @@ private void Enums()
name = Cleanup.ConvertType( name );
if ( !Cleanup.ShouldCreate( name ) )
continue;
StartBlock( $"{Cleanup.Expose( name )} enum {name} : int" );
{
//