Skip to content

Commit 5e22ff5

Browse files
authored
Merge pull request #72 from TaloDev/develop
Release 0.21.0
2 parents b222a90 + 3ae47eb commit 5e22ff5

File tree

8 files changed

+135
-46
lines changed

8 files changed

+135
-46
lines changed

Assets/Samples/LeaderboardsDemo/Scenes/LeaderboardsDemo.unity

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ NavMeshSettings:
104104
serializedVersion: 2
105105
m_ObjectHideFlags: 0
106106
m_BuildSettings:
107-
serializedVersion: 2
107+
serializedVersion: 3
108108
agentTypeID: 0
109109
agentRadius: 0.5
110110
agentHeight: 2
@@ -117,7 +117,7 @@ NavMeshSettings:
117117
cellSize: 0.16666667
118118
manualTileSize: 0
119119
tileSize: 256
120-
accuratePlacement: 0
120+
buildHeightMesh: 0
121121
maxJobWorkers: 0
122122
preserveTilesOutsideBounds: 0
123123
debug:
@@ -164,13 +164,13 @@ Transform:
164164
m_PrefabInstance: {fileID: 0}
165165
m_PrefabAsset: {fileID: 0}
166166
m_GameObject: {fileID: 373737617}
167+
serializedVersion: 2
167168
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
168169
m_LocalPosition: {x: 0, y: 0, z: 0}
169170
m_LocalScale: {x: 1, y: 1, z: 1}
170171
m_ConstrainProportionsScale: 0
171172
m_Children: []
172173
m_Father: {fileID: 0}
173-
m_RootOrder: 1
174174
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
175175
--- !u!114 &373737620
176176
MonoBehaviour:
@@ -184,7 +184,7 @@ MonoBehaviour:
184184
m_Script: {fileID: 11500000, guid: 5d32f5ae2f5f7495cb77f079a21c54b0, type: 3}
185185
m_Name:
186186
m_EditorClassIdentifier:
187-
leaderboardName: uniq
187+
leaderboardName: test-leaderboard
188188
--- !u!1 &497470367
189189
GameObject:
190190
m_ObjectHideFlags: 0
@@ -225,9 +225,17 @@ Camera:
225225
m_projectionMatrixMode: 1
226226
m_GateFitMode: 2
227227
m_FOVAxisMode: 0
228+
m_Iso: 200
229+
m_ShutterSpeed: 0.005
230+
m_Aperture: 16
231+
m_FocusDistance: 10
232+
m_FocalLength: 50
233+
m_BladeCount: 5
234+
m_Curvature: {x: 2, y: 11}
235+
m_BarrelClipping: 0.25
236+
m_Anamorphism: 0
228237
m_SensorSize: {x: 36, y: 24}
229238
m_LensShift: {x: 0, y: 0}
230-
m_FocalLength: 50
231239
m_NormalizedViewPortRect:
232240
serializedVersion: 2
233241
x: 0
@@ -261,11 +269,17 @@ Transform:
261269
m_PrefabInstance: {fileID: 0}
262270
m_PrefabAsset: {fileID: 0}
263271
m_GameObject: {fileID: 497470367}
272+
serializedVersion: 2
264273
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
265274
m_LocalPosition: {x: 0, y: 0, z: -10}
266275
m_LocalScale: {x: 1, y: 1, z: 1}
267276
m_ConstrainProportionsScale: 0
268277
m_Children: []
269278
m_Father: {fileID: 0}
270-
m_RootOrder: 0
271279
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
280+
--- !u!1660057539 &9223372036854775807
281+
SceneRoots:
282+
m_ObjectHideFlags: 0
283+
m_Roots:
284+
- {fileID: 497470370}
285+
- {fileID: 373737619}

Assets/Samples/LeaderboardsDemo/Scripts/LeaderboardUIController.cs

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ public class LeaderboardUIController : MonoBehaviour
1212
private VisualElement root;
1313
private ListView entriesList;
1414
private Label infoLabel;
15-
private List<LeaderboardEntry> entries = new ();
1615

1716
private async void Start()
1817
{
@@ -38,14 +37,6 @@ private async void OnPostClick()
3837
var score = Random.Range(0, 100);
3938
(LeaderboardEntry entry, bool updated) = await Talo.Leaderboards.AddEntry(leaderboardName, score);
4039

41-
var idx = entries.FindIndex((existingEntry) => existingEntry.playerAlias.id == entry.playerAlias.id);
42-
if (idx != -1)
43-
{
44-
entries.RemoveAt(idx);
45-
}
46-
47-
entries.Insert(entry.position, entry);
48-
4940
infoLabel.text = $"You scored {score}.";
5041
if (updated) infoLabel.text += " Your highscore was updated!";
5142

@@ -54,7 +45,7 @@ private async void OnPostClick()
5445

5546
private void HandleListVisibility()
5647
{
57-
if (entries.Count == 0)
48+
if (Talo.Leaderboards.GetCachedEntries(leaderboardName).Count == 0)
5849
{
5950
infoLabel.text = "There are currently no entries";
6051
}
@@ -72,8 +63,6 @@ private async Task LoadEntries()
7263
do
7364
{
7465
var res = await Talo.Leaderboards.GetEntries(leaderboardName, page);
75-
entries.AddRange(res.entries);
76-
7766
page++;
7867
done = res.isLastPage;
7968
} while (!done);
@@ -89,6 +78,8 @@ private async Task LoadEntries()
8978
return label;
9079
};
9180

81+
var entries = Talo.Leaderboards.GetCachedEntries(leaderboardName);
82+
9283
entriesList.bindItem = (e, i) =>
9384
{
9485
e.Q<Label>().text = $"{i+1}. {entries[i].playerAlias.identifier} - {entries[i].score}";

Packages/com.trytalo.talo/Runtime/LeaderboardsAPI.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,40 @@
11
using System;
2+
using System.Collections.Generic;
23
using System.Threading.Tasks;
34
using UnityEngine;
45

56
namespace TaloGameServices
67
{
78
public class LeaderboardsAPI : BaseAPI
89
{
10+
private LeaderboardEntriesManager _entriesManager = new();
11+
912
public LeaderboardsAPI(TaloManager manager) : base(manager, "v1/leaderboards") { }
1013

14+
public List<LeaderboardEntry> GetCachedEntries(string internalName)
15+
{
16+
return _entriesManager.GetEntries(internalName);
17+
}
18+
19+
public List<LeaderboardEntry> GetCachedEntriesForCurrentPlayer(string internalName)
20+
{
21+
Talo.IdentityCheck();
22+
23+
return _entriesManager.GetEntries(internalName).FindAll(e => e.playerAlias.id == Talo.CurrentAlias.id);
24+
}
25+
1126
public async Task<LeaderboardEntriesResponse> GetEntries(string internalName, int page)
1227
{
1328
var uri = new Uri(baseUrl + $"/{internalName}/entries?page={page}");
1429

1530
var json = await Call(uri, "GET");
1631
var res = JsonUtility.FromJson<LeaderboardEntriesResponse>(json);
32+
33+
foreach (var entry in res.entries)
34+
{
35+
_entriesManager.UpsertEntry(internalName, entry);
36+
}
37+
1738
return res;
1839
}
1940

@@ -38,6 +59,8 @@ public async Task<LeaderboardEntriesResponse> GetEntriesForCurrentPlayer(string
3859
var json = await Call(uri, "POST", content);
3960
var res = JsonUtility.FromJson<LeaderboardEntryResponse>(json);
4061

62+
_entriesManager.UpsertEntry(internalName, res.entry);
63+
4164
return (res.entry, res.updated);
4265
}
4366
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
using System.Collections.Generic;
2+
3+
namespace TaloGameServices
4+
{
5+
public class LeaderboardEntriesManager
6+
{
7+
private Dictionary<string, List<LeaderboardEntry>> _currentEntries = new Dictionary<string, List<LeaderboardEntry>>();
8+
9+
public List<LeaderboardEntry> GetEntries(string internalName)
10+
{
11+
if (_currentEntries.ContainsKey(internalName))
12+
{
13+
return _currentEntries[internalName];
14+
}
15+
return new List<LeaderboardEntry>();
16+
}
17+
18+
public void UpsertEntry(string internalName, LeaderboardEntry entry)
19+
{
20+
if (!_currentEntries.ContainsKey(internalName))
21+
{
22+
_currentEntries[internalName] = new List<LeaderboardEntry>();
23+
}
24+
else
25+
{
26+
_currentEntries[internalName].RemoveAll(e => e.id == entry.id);
27+
}
28+
29+
_currentEntries[internalName].Insert(entry.position, entry);
30+
31+
for (int idx = entry.position; idx < _currentEntries[internalName].Count; idx++)
32+
{
33+
_currentEntries[internalName][idx].position = idx;
34+
}
35+
}
36+
}
37+
}

Packages/com.trytalo.talo/Runtime/Utils/LeaderboardEntriesManager.cs.meta

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

Packages/com.trytalo.talo/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "com.trytalo.talo",
3-
"version": "0.20.0",
3+
"version": "0.21.0",
44
"displayName": "Talo Game Services",
55
"description": "Talo (https://trytalo.com) is an open-source game backend with services designed to help you build games faster. You can currently:\n\n- Identify and authenticate players\n- Store persistent data across players\n- Track events (levelling up, finding loot, etc)\n- Display high scores with leaderboards\n- Store and load player saves\n- Load game config options and flags from the cloud\n- Get feedback directly from your players",
66
"unity": "2022.3",

UserSettings/EditorUserSettings.asset

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ EditorUserSettings:
99
value: 5103525351515d5d0c560820477707471715407a787c76352c7b4a6bb3e2646b
1010
flags: 0
1111
RecentlyUsedSceneGuid-1:
12-
value: 515250075c0c595e5f5a5e71122159444e4e4a2f7a7d7f602f284d66b4b76661
12+
value: 5a00005e56575e5a540c5b714377094914151a7c282b22662b2b4963e7b6643c
1313
flags: 0
1414
RecentlyUsedSceneGuid-2:
15-
value: 5a00005e56575e5a540c5b714377094914151a7c282b22662b2b4963e7b6643c
15+
value: 5657050456070d020e58592748775d1510154f2c792c7e657b7a4962e3b5663e
1616
flags: 0
1717
RecentlyUsedSceneGuid-3:
18-
value: 5657050456070d020e58592748775d1510154f2c792c7e657b7a4962e3b5663e
18+
value: 515250075c0c595e5f5a5e71122159444e4e4a2f7a7d7f602f284d66b4b76661
1919
flags: 0
2020
vcSharedLogLevel:
2121
value: 0d5e400f0650

0 commit comments

Comments
 (0)