Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions Assets/Talo Game Services/Talo/Runtime/APIs/LeaderboardsAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class GetEntriesOptions
public string propValue = "";
public string startDate = "";
public string endDate = "";
public string aliasService = "";

public string ToQueryString()
{
Expand All @@ -27,22 +28,37 @@ public string ToQueryString()
if (!string.IsNullOrEmpty(propValue)) query["propValue"] = propValue;
if (!string.IsNullOrEmpty(startDate)) query["startDate"] = startDate;
if (!string.IsNullOrEmpty(endDate)) query["endDate"] = endDate;
if (!string.IsNullOrEmpty(aliasService)) query["aliasService"] = aliasService;

return string.Join("&", query.Select((param) => $"{param.Key}={param.Value}"));
}
}

public class GetCachedEntriesOptions
{
public int aliasId = -1;
public string playerId = "";
public string aliasService = "";
}

public class LeaderboardsAPI : BaseAPI
{
private readonly LeaderboardEntriesManager _entriesManager = new();

public LeaderboardsAPI() : base("v1/leaderboards") { }

public List<LeaderboardEntry> GetCachedEntries(string internalName)
public List<LeaderboardEntry> GetCachedEntries(string internalName, GetCachedEntriesOptions options = null)
{
return _entriesManager.GetEntries(internalName);
options ??= new GetCachedEntriesOptions();

return _entriesManager.GetEntries(internalName).FindAll(e =>
(options.aliasId == -1 || e.playerAlias.id == options.aliasId) &&
(string.IsNullOrEmpty(options.playerId) || e.playerAlias.player.id == options.playerId) &&
(string.IsNullOrEmpty(options.aliasService) || e.playerAlias.service == options.aliasService)
);
}

[Obsolete("Use GetCachedEntries(string internalName, GetCachedEntriesOptions options) with the aliasId or playerId option instead.")]
public List<LeaderboardEntry> GetCachedEntriesForCurrentPlayer(string internalName)
{
Talo.IdentityCheck();
Expand Down