Skip to content

Commit 584903f

Browse files
authored
Merge pull request #26 from TaloDev/develop
Release 0.6.0
2 parents 81bb72b + fbd9d5b commit 584903f

File tree

10 files changed

+78
-32
lines changed

10 files changed

+78
-32
lines changed

Assets/Scripts/Events/TrackEvent.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public void OnButtonClick()
1414
Track();
1515
}
1616

17-
private void Track()
17+
private async void Track()
1818
{
1919
try
2020
{
@@ -24,7 +24,7 @@ private void Track()
2424

2525
if (flushImmediately)
2626
{
27-
Talo.Events.Flush();
27+
await Talo.Events.Flush();
2828

2929
ResponseMessage.SetText($"{eventName} tracked and events flushed");
3030
}

Assets/Scripts/Leaderboards/GetLeaderboardEntries.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ private async void FetchEntries()
1818
try
1919
{
2020
int score = UnityEngine.Random.Range(0, 10000);
21-
LeaderboardEntry[] entries = await Talo.Leaderboards.GetEntries(internalName, page);
21+
LeaderboardEntriesResponse res = await Talo.Leaderboards.GetEntries(internalName, page);
22+
LeaderboardEntry[] entries = res.entries;
2223

2324
if (entries.Length == 0)
2425
{

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

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,19 +45,24 @@ public async Task Flush()
4545
Talo.IdentityCheck();
4646

4747
var eventsToSend = queue.ToArray();
48-
queue.Clear();
48+
49+
if (eventsToSend.Length > 0)
50+
{
51+
queue.Clear();
4952

50-
var uri = new Uri(baseUrl);
51-
var content = JsonUtility.ToJson(new EventsPostRequest(eventsToSend));
53+
var uri = new Uri(baseUrl);
54+
var content = JsonUtility.ToJson(new EventsPostRequest(eventsToSend));
5255

53-
try
54-
{
55-
await Call(uri, "POST", content);
56-
}
57-
catch (Exception err)
58-
{
59-
Debug.LogError(err.Message);
60-
queue.AddRange(eventsToSend);
56+
try
57+
{
58+
await Call(uri, "POST", content);
59+
manager.ResetFlushTimer();
60+
}
61+
catch (Exception err)
62+
{
63+
Debug.LogError(err.Message);
64+
queue.AddRange(eventsToSend);
65+
}
6166
}
6267
}
6368
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ public class LeaderboardsAPI : BaseAPI
88
{
99
public LeaderboardsAPI(TaloManager manager) : base(manager, "leaderboards") { }
1010

11-
public async Task<LeaderboardEntry[]> GetEntries(string internalName, int page)
11+
public async Task<LeaderboardEntriesResponse> GetEntries(string internalName, int page)
1212
{
1313
var uri = new Uri(baseUrl + $"/{internalName}/entries?page={page}");
1414

1515
var json = await Call(uri, "GET");
1616
var res = JsonUtility.FromJson<LeaderboardEntriesResponse>(json);
17-
return res.entries;
17+
return res;
1818
}
1919

2020
public async Task<LeaderboardEntry[]> GetEntriesForCurrentPlayer(string leaderboardInternalName, int page)

Packages/com.trytalo.talo/Runtime/Responses/LeaderboardEntriesResponse.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,7 @@
44
public class LeaderboardEntriesResponse
55
{
66
public LeaderboardEntry[] entries;
7+
public int count;
8+
public bool isLastPage;
79
}
810
}

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

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -64,18 +64,12 @@ public async Task<GameSave[]> GetSaves(SaveMode mode = SaveMode.BOTH)
6464

6565
if (mode != SaveMode.OFFLINE_ONLY)
6666
{
67-
try
68-
{
69-
var uri = new Uri(baseUrl + $"?aliasId={Talo.CurrentAlias.id}");
67+
var uri = new Uri(baseUrl + $"?aliasId={Talo.CurrentAlias.id}");
7068

71-
var json = await Call(uri, "GET");
72-
var res = JsonUtility.FromJson<SavesIndexResponse>(json);
69+
var json = await Call(uri, "GET");
70+
var res = JsonUtility.FromJson<SavesIndexResponse>(json);
7371

74-
saves.AddRange(res.saves);
75-
} catch
76-
{
77-
Debug.LogWarning("Failed to load online saves");
78-
}
72+
saves.AddRange(res.saves);
7973
}
8074

8175
_allSaves = saves;

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,7 @@ static Talo()
6363
return;
6464
}
6565

66-
var go = new GameObject("Talo Manager");
67-
var manager = go.AddComponent<TaloManager>();
66+
var manager = new GameObject("Talo Manager").AddComponent<TaloManager>();
6867
manager.settings = settings;
6968

7069
_events = new EventsAPI(manager);
@@ -74,9 +73,14 @@ static Talo()
7473
_stats = new StatsAPI(manager);
7574
}
7675

76+
public static bool HasIdentity()
77+
{
78+
return CurrentAlias != null;
79+
}
80+
7781
public static void IdentityCheck()
7882
{
79-
if (CurrentAlias == null)
83+
if (!HasIdentity())
8084
{
8185
throw new Exception("You need to identify a player using Talo.Identify() before doing this.");
8286
}

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

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,52 @@ public class TaloManager : MonoBehaviour
66
{
77
public TaloSettings settings;
88

9+
private float tmrFlush;
10+
911
private void Awake()
1012
{
1113
DontDestroyOnLoad(gameObject);
1214
}
1315

14-
private async void OnApplicationQuit()
16+
private void OnApplicationQuit()
17+
{
18+
DoFlush();
19+
}
20+
21+
private void OnApplicationFocus(bool hasFocus)
22+
{
23+
if (!hasFocus) DoFlush();
24+
}
25+
26+
private void OnApplicationPause(bool isPaused)
27+
{
28+
if (isPaused) DoFlush();
29+
}
30+
31+
private async void DoFlush()
32+
{
33+
if (Talo.HasIdentity())
34+
{
35+
await Talo.Events.Flush();
36+
}
37+
}
38+
39+
private void Update()
40+
{
41+
if (Application.platform == RuntimePlatform.WebGLPlayer)
42+
{
43+
tmrFlush += Time.deltaTime;
44+
if (tmrFlush >= settings.webGLEventFlushRate)
45+
{
46+
DoFlush();
47+
tmrFlush = 0;
48+
}
49+
}
50+
}
51+
52+
public void ResetFlushTimer()
1553
{
16-
await Talo.Events.Flush();
54+
tmrFlush = 0;
1755
}
1856
}
1957
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,7 @@ public class TaloSettings : ScriptableObject
77
{
88
public string accessKey;
99
public string apiUrl = "https://api.trytalo.com/v1";
10+
[Tooltip("How often in seconds events are flushed in a WebGL build, see the docs for more info")]
11+
public float webGLEventFlushRate = 30f;
1012
}
1113
}

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.6.0-pre.0",
3+
"version": "0.6.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 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",
66
"unity": "2019.1",

0 commit comments

Comments
 (0)