Skip to content

Commit 8695fe2

Browse files
authored
Merge pull request #157 from TaloDev/develop
Release 0.47.0
2 parents 95dafa0 + 48a9360 commit 8695fe2

File tree

13 files changed

+289
-12
lines changed

13 files changed

+289
-12
lines changed

.github/workflows/claude-code-review.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,5 +54,5 @@ jobs:
5454
5555
# See https://github.com/anthropics/claude-code-action/blob/main/docs/usage.md
5656
# or https://docs.anthropic.com/en/docs/claude-code/sdk#command-line for available options
57-
claude_args: '--allowed-tools "Bash(gh issue view:*),Bash(gh search:*),Bash(gh issue list:*),Bash(gh pr comment:*),Bash(gh pr diff:*),Bash(gh pr view:*),Bash(gh pr list:*)"'
57+
claude_args: '--model sonnet --allowed-tools "Bash(gh issue view:*),Bash(gh search:*),Bash(gh issue list:*),Bash(gh pr comment:*),Bash(gh pr diff:*),Bash(gh pr view:*),Bash(gh pr list:*)"'
5858
use_sticky_comment: true

Assets/Talo Game Services/Talo/Runtime/APIs/BaseAPI.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace TaloGameServices
99
public class BaseAPI
1010
{
1111
// automatically updated with a pre-commit hook
12-
private const string ClientVersion = "0.46.0";
12+
private const string ClientVersion = "0.47.0";
1313

1414
protected string baseUrl;
1515

Assets/Talo Game Services/Talo/Runtime/APIs/ChannelsAPI.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,5 +348,34 @@ public async Task SetStorageProps(int channelId, params (string, string)[] propT
348348
OnChannelStoragePropsFailedToSet?.Invoke(res.channel, res.failedProps);
349349
}
350350
}
351+
352+
public async Task<ChannelStorageProp[]> ListStorageProps(int channelId, string[] propKeys, bool bustCache = false)
353+
{
354+
Talo.IdentityCheck();
355+
356+
if (!bustCache)
357+
{
358+
return await _storageManager.ListProps(channelId, propKeys);
359+
}
360+
361+
var queryParams = propKeys.Length > 0
362+
? "?" + string.Join("&", propKeys.Select((key) => $"propKeys={key}"))
363+
: "";
364+
365+
var uri = new Uri($"{baseUrl}/{channelId}/storage/list{queryParams}");
366+
var json = await Call(uri, "GET");
367+
368+
var res = JsonUtility.FromJson<ChannelStoragePropsListResponse>(json);
369+
if (res.props != null)
370+
{
371+
foreach (var prop in res.props)
372+
{
373+
_storageManager.UpsertProp(channelId, prop);
374+
}
375+
return res.props;
376+
}
377+
378+
return Array.Empty<ChannelStorageProp>();
379+
}
351380
}
352381
}

Assets/Talo Game Services/Talo/Runtime/APIs/LeaderboardsAPI.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ public class GetEntriesOptions
1313
public bool includeArchived = false;
1414
public string propKey = "";
1515
public string propValue = "";
16+
public string startDate = "";
17+
public string endDate = "";
1618

1719
public string ToQueryString()
1820
{
@@ -21,6 +23,8 @@ public string ToQueryString()
2123
if (includeArchived) query["withDeleted"] = "1";
2224
if (!string.IsNullOrEmpty(propKey)) query["propKey"] = propKey;
2325
if (!string.IsNullOrEmpty(propValue)) query["propValue"] = propValue;
26+
if (!string.IsNullOrEmpty(startDate)) query["startDate"] = startDate;
27+
if (!string.IsNullOrEmpty(endDate)) query["endDate"] = endDate;
2428

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

Assets/Talo Game Services/Talo/Runtime/Entities/LeaderboardEntry.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,37 @@
11
using System;
2+
using UnityEngine;
23

34
namespace TaloGameServices
45
{
6+
public enum LeaderboardSortMode
7+
{
8+
DESC,
9+
ASC
10+
}
11+
512
[Serializable]
613
public class LeaderboardEntry: EntityWithProps
714
{
815
public int id;
916
public int position;
1017
public float score;
1118
public PlayerAlias playerAlias;
19+
public string createdAt;
1220
public string updatedAt;
1321
public string deletedAt;
22+
public string leaderboardName;
23+
public string leaderboardInternalName;
24+
[SerializeField] internal string leaderboardSortMode;
25+
26+
public LeaderboardSortMode LeaderboardSortMode
27+
{
28+
get
29+
{
30+
return leaderboardSortMode.ToLower() == "asc"
31+
? LeaderboardSortMode.ASC
32+
: LeaderboardSortMode.DESC;
33+
}
34+
}
1435

1536
public override string ToString()
1637
{
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using System;
2+
3+
namespace TaloGameServices
4+
{
5+
[Serializable]
6+
public class ChannelStoragePropsListResponse
7+
{
8+
public ChannelStorageProp[] props;
9+
}
10+
}

Assets/Talo Game Services/Talo/Runtime/Responses/ChannelStoragePropsListResponse.cs.meta

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Talo Game Services/Talo/Runtime/Utils/ChannelStorageManager.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,32 @@ public void DeleteProp(int channelId, string propKey)
4242
var key = $"{channelId}:{propKey}";
4343
_currentProps.Remove(key);
4444
}
45+
46+
public async Task<ChannelStorageProp[]> ListProps(int channelId, string[] propKeys)
47+
{
48+
var results = new List<ChannelStorageProp>();
49+
var keysToFetch = new List<string>();
50+
51+
foreach (var propKey in propKeys)
52+
{
53+
var cacheKey = $"{channelId}:{propKey}";
54+
if (_currentProps.TryGetValue(cacheKey, out var cachedProp))
55+
{
56+
results.Add(cachedProp);
57+
}
58+
else
59+
{
60+
keysToFetch.Add(propKey);
61+
}
62+
}
63+
64+
if (keysToFetch.Count > 0)
65+
{
66+
var fetchedProps = await Talo.Channels.ListStorageProps(channelId, keysToFetch.ToArray(), true);
67+
results.AddRange(fetchedProps);
68+
}
69+
70+
return results.ToArray();
71+
}
4572
}
4673
}

Assets/Talo Game Services/Talo/Runtime/Utils/LeaderboardEntriesManager.cs

Lines changed: 50 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Collections.Generic;
1+
using System;
2+
using System.Collections.Generic;
23

34
namespace TaloGameServices
45
{
@@ -21,24 +22,64 @@ public void UpsertEntry(string internalName, LeaderboardEntry entry)
2122
{
2223
_currentEntries[internalName] = new List<LeaderboardEntry>();
2324
}
24-
else
25+
26+
var entries = _currentEntries[internalName];
27+
28+
// ensure there isn't an existing entry
29+
entries.RemoveAll((e) => e.id == entry.id);
30+
31+
int insertPosition = FindInsertPosition(entries, entry);
32+
entries.Insert(insertPosition, entry);
33+
34+
for (int idx = 0; idx < entries.Count; idx++)
2535
{
26-
_currentEntries[internalName].RemoveAll(e => e.id == entry.id);
36+
entries[idx].position = idx;
2737
}
38+
}
2839

29-
if (entry.position >= _currentEntries[internalName].Count)
40+
private int FindInsertPosition(List<LeaderboardEntry> entries, LeaderboardEntry newEntry)
41+
{
42+
if (entries.Count == 0)
3043
{
31-
_currentEntries[internalName].Add(entry);
44+
return 0;
3245
}
33-
else
46+
47+
int left = 0;
48+
int right = entries.Count;
49+
50+
while (left < right)
3451
{
35-
_currentEntries[internalName].Insert(entry.position, entry);
52+
int mid = left + (right - left) / 2;
53+
if (CompareEntries(newEntry, entries[mid]))
54+
{
55+
right = mid;
56+
}
57+
else
58+
{
59+
left = mid + 1;
60+
}
3661
}
3762

38-
for (int idx = entry.position; idx < _currentEntries[internalName].Count; idx++)
63+
return left;
64+
}
65+
66+
private bool CompareEntries(LeaderboardEntry a, LeaderboardEntry b)
67+
{
68+
// first compare by score based on sort mode
69+
if (a.score != b.score)
3970
{
40-
_currentEntries[internalName][idx].position = idx;
71+
if (a.LeaderboardSortMode == LeaderboardSortMode.ASC)
72+
{
73+
return a.score < b.score;
74+
}
75+
else
76+
{
77+
return a.score > b.score;
78+
}
4179
}
80+
81+
// if scores are equal, earlier entries win
82+
return DateTime.Parse(a.createdAt) < DateTime.Parse(b.createdAt);
4283
}
4384
}
4485
}

Assets/Talo Game Services/Talo/Tests/LeaderboardsAPI.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)