mirror of
https://github.com/Facepunch/Facepunch.Steamworks.git
synced 2024-12-25 06:05:46 +03:00
Create/Get leaderboard
This commit is contained in:
parent
d2a3e0b1da
commit
e5a89b0550
20
Facepunch.Steamworks/Enum/LeaderboardDisplay.cs
Normal file
20
Facepunch.Steamworks/Enum/LeaderboardDisplay.cs
Normal 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,
|
||||
}
|
||||
}
|
15
Facepunch.Steamworks/Enum/LeaderboardSort.cs
Normal file
15
Facepunch.Steamworks/Enum/LeaderboardSort.cs
Normal 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,
|
||||
}
|
||||
}
|
@ -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 );
|
||||
}
|
||||
|
@ -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
|
||||
//
|
||||
|
@ -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 };
|
||||
}
|
||||
|
||||
}
|
||||
}
|
13
Facepunch.Steamworks/Structs/Leaderboard.cs
Normal file
13
Facepunch.Steamworks/Structs/Leaderboard.cs
Normal 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;
|
||||
}
|
||||
}
|
@ -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;
|
||||
|
@ -27,6 +27,9 @@ private void Enums()
|
||||
|
||||
name = Cleanup.ConvertType( name );
|
||||
|
||||
if ( !Cleanup.ShouldCreate( name ) )
|
||||
continue;
|
||||
|
||||
StartBlock( $"{Cleanup.Expose( name )} enum {name} : int" );
|
||||
{
|
||||
//
|
||||
|
Loading…
Reference in New Issue
Block a user