Skip to content

Commit

Permalink
Merge pull request #72 from TaloDev/develop
Browse files Browse the repository at this point in the history
Release 0.21.0
  • Loading branch information
tudddorrr authored Aug 8, 2024
2 parents b222a90 + 3ae47eb commit 5e22ff5
Show file tree
Hide file tree
Showing 8 changed files with 135 additions and 46 deletions.
26 changes: 20 additions & 6 deletions Assets/Samples/LeaderboardsDemo/Scenes/LeaderboardsDemo.unity
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ NavMeshSettings:
serializedVersion: 2
m_ObjectHideFlags: 0
m_BuildSettings:
serializedVersion: 2
serializedVersion: 3
agentTypeID: 0
agentRadius: 0.5
agentHeight: 2
Expand All @@ -117,7 +117,7 @@ NavMeshSettings:
cellSize: 0.16666667
manualTileSize: 0
tileSize: 256
accuratePlacement: 0
buildHeightMesh: 0
maxJobWorkers: 0
preserveTilesOutsideBounds: 0
debug:
Expand Down Expand Up @@ -164,13 +164,13 @@ Transform:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 373737617}
serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &373737620
MonoBehaviour:
Expand All @@ -184,7 +184,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 5d32f5ae2f5f7495cb77f079a21c54b0, type: 3}
m_Name:
m_EditorClassIdentifier:
leaderboardName: uniq
leaderboardName: test-leaderboard
--- !u!1 &497470367
GameObject:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -225,9 +225,17 @@ Camera:
m_projectionMatrixMode: 1
m_GateFitMode: 2
m_FOVAxisMode: 0
m_Iso: 200
m_ShutterSpeed: 0.005
m_Aperture: 16
m_FocusDistance: 10
m_FocalLength: 50
m_BladeCount: 5
m_Curvature: {x: 2, y: 11}
m_BarrelClipping: 0.25
m_Anamorphism: 0
m_SensorSize: {x: 36, y: 24}
m_LensShift: {x: 0, y: 0}
m_FocalLength: 50
m_NormalizedViewPortRect:
serializedVersion: 2
x: 0
Expand Down Expand Up @@ -261,11 +269,17 @@ Transform:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 497470367}
serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: -10}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1660057539 &9223372036854775807
SceneRoots:
m_ObjectHideFlags: 0
m_Roots:
- {fileID: 497470370}
- {fileID: 373737619}
15 changes: 3 additions & 12 deletions Assets/Samples/LeaderboardsDemo/Scripts/LeaderboardUIController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ public class LeaderboardUIController : MonoBehaviour
private VisualElement root;
private ListView entriesList;
private Label infoLabel;
private List<LeaderboardEntry> entries = new ();

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

var idx = entries.FindIndex((existingEntry) => existingEntry.playerAlias.id == entry.playerAlias.id);
if (idx != -1)
{
entries.RemoveAt(idx);
}

entries.Insert(entry.position, entry);

infoLabel.text = $"You scored {score}.";
if (updated) infoLabel.text += " Your highscore was updated!";

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

private void HandleListVisibility()
{
if (entries.Count == 0)
if (Talo.Leaderboards.GetCachedEntries(leaderboardName).Count == 0)
{
infoLabel.text = "There are currently no entries";
}
Expand All @@ -72,8 +63,6 @@ private async Task LoadEntries()
do
{
var res = await Talo.Leaderboards.GetEntries(leaderboardName, page);
entries.AddRange(res.entries);

page++;
done = res.isLastPage;
} while (!done);
Expand All @@ -89,6 +78,8 @@ private async Task LoadEntries()
return label;
};

var entries = Talo.Leaderboards.GetCachedEntries(leaderboardName);

entriesList.bindItem = (e, i) =>
{
e.Q<Label>().text = $"{i+1}. {entries[i].playerAlias.identifier} - {entries[i].score}";
Expand Down
23 changes: 23 additions & 0 deletions Packages/com.trytalo.talo/Runtime/LeaderboardsAPI.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,40 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using UnityEngine;

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

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

public List<LeaderboardEntry> GetCachedEntries(string internalName)
{
return _entriesManager.GetEntries(internalName);
}

public List<LeaderboardEntry> GetCachedEntriesForCurrentPlayer(string internalName)
{
Talo.IdentityCheck();

return _entriesManager.GetEntries(internalName).FindAll(e => e.playerAlias.id == Talo.CurrentAlias.id);
}

public async Task<LeaderboardEntriesResponse> GetEntries(string internalName, int page)
{
var uri = new Uri(baseUrl + $"/{internalName}/entries?page={page}");

var json = await Call(uri, "GET");
var res = JsonUtility.FromJson<LeaderboardEntriesResponse>(json);

foreach (var entry in res.entries)
{
_entriesManager.UpsertEntry(internalName, entry);
}

return res;
}

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

_entriesManager.UpsertEntry(internalName, res.entry);

return (res.entry, res.updated);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using System.Collections.Generic;

namespace TaloGameServices
{
public class LeaderboardEntriesManager
{
private Dictionary<string, List<LeaderboardEntry>> _currentEntries = new Dictionary<string, List<LeaderboardEntry>>();

public List<LeaderboardEntry> GetEntries(string internalName)
{
if (_currentEntries.ContainsKey(internalName))
{
return _currentEntries[internalName];
}
return new List<LeaderboardEntry>();
}

public void UpsertEntry(string internalName, LeaderboardEntry entry)
{
if (!_currentEntries.ContainsKey(internalName))
{
_currentEntries[internalName] = new List<LeaderboardEntry>();
}
else
{
_currentEntries[internalName].RemoveAll(e => e.id == entry.id);
}

_currentEntries[internalName].Insert(entry.position, entry);

for (int idx = entry.position; idx < _currentEntries[internalName].Count; idx++)
{
_currentEntries[internalName][idx].position = idx;
}
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Packages/com.trytalo.talo/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "com.trytalo.talo",
"version": "0.20.0",
"version": "0.21.0",
"displayName": "Talo Game Services",
"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",
"unity": "2022.3",
Expand Down
6 changes: 3 additions & 3 deletions UserSettings/EditorUserSettings.asset
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ EditorUserSettings:
value: 5103525351515d5d0c560820477707471715407a787c76352c7b4a6bb3e2646b
flags: 0
RecentlyUsedSceneGuid-1:
value: 515250075c0c595e5f5a5e71122159444e4e4a2f7a7d7f602f284d66b4b76661
value: 5a00005e56575e5a540c5b714377094914151a7c282b22662b2b4963e7b6643c
flags: 0
RecentlyUsedSceneGuid-2:
value: 5a00005e56575e5a540c5b714377094914151a7c282b22662b2b4963e7b6643c
value: 5657050456070d020e58592748775d1510154f2c792c7e657b7a4962e3b5663e
flags: 0
RecentlyUsedSceneGuid-3:
value: 5657050456070d020e58592748775d1510154f2c792c7e657b7a4962e3b5663e
value: 515250075c0c595e5f5a5e71122159444e4e4a2f7a7d7f602f284d66b4b76661
flags: 0
vcSharedLogLevel:
value: 0d5e400f0650
Expand Down
Loading

0 comments on commit 5e22ff5

Please sign in to comment.