Skip to content

Commit b3c0b95

Browse files
authored
Merge pull request #19 from TaloDev/develop
Release 0.5.0
2 parents 13386a1 + 01c37e7 commit b3c0b95

File tree

11 files changed

+498
-3
lines changed

11 files changed

+498
-3
lines changed

Assets/Scenes/Playground.unity

Lines changed: 380 additions & 0 deletions
Large diffs are not rendered by default.

Assets/Scripts/Stats.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.

Assets/Scripts/Stats/TrackStat.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using System;
2+
using UnityEngine;
3+
using TaloGameServices;
4+
5+
public class TrackStat : MonoBehaviour
6+
{
7+
public string statInternalName;
8+
public float change = 1;
9+
10+
public void OnButtonClick()
11+
{
12+
Track();
13+
}
14+
15+
private void Track()
16+
{
17+
try
18+
{
19+
Talo.Stats.Track(statInternalName, change);
20+
21+
ResponseMessage.SetText($"{statInternalName} changed by {change}");
22+
}
23+
catch (Exception err)
24+
{
25+
ResponseMessage.SetText(err.Message);
26+
throw err;
27+
}
28+
}
29+
}

Assets/Scripts/Stats/TrackStat.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.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
namespace TaloGameServices
2+
{
3+
public class StatsPutRequest
4+
{
5+
public float change;
6+
public int aliasId;
7+
8+
public StatsPutRequest(float change)
9+
{
10+
this.change = change;
11+
aliasId = Talo.CurrentAlias.id;
12+
}
13+
}
14+
}

Packages/com.trytalo.talo/Runtime/Requests/StatsPutRequest.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.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using System;
2+
using System.Net.Http;
3+
using System.Text;
4+
using TaloGameServices;
5+
using UnityEngine;
6+
7+
public class StatsAPI : BaseAPI
8+
{
9+
public StatsAPI(TaloSettings settings, HttpClient client) : base(settings, client, "game-stats") { }
10+
11+
public async void Track(string internalName, float change = 1f)
12+
{
13+
Talo.IdentityCheck();
14+
15+
var req = new HttpRequestMessage();
16+
req.Method = HttpMethod.Post;
17+
req.RequestUri = new Uri(baseUrl + $"/{internalName}");
18+
19+
string content = JsonUtility.ToJson(new StatsPutRequest(change));
20+
req.Content = new StringContent(content, Encoding.UTF8, "application/json");
21+
22+
await Call(req);
23+
}
24+
}

Packages/com.trytalo.talo/Runtime/StatsAPI.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/Runtime/Talo.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ public class Talo
1212
private static PlayersAPI _players;
1313
private static LeaderboardsAPI _leaderboards;
1414
private static SavesAPI _saves;
15+
private static StatsAPI _stats;
1516

1617
private static PlayerAlias _currentAlias;
1718

@@ -51,6 +52,11 @@ public static SavesAPI Saves
5152
get => _saves;
5253
}
5354

55+
public static StatsAPI Stats
56+
{
57+
get => _stats;
58+
}
59+
5460
static Talo()
5561
{
5662
var settings = Resources.Load<TaloSettings>("Talo Settings");
@@ -64,6 +70,7 @@ static Talo()
6470
_players = new PlayersAPI(settings, client);
6571
_leaderboards = new LeaderboardsAPI(settings, client);
6672
_saves = new SavesAPI(settings, client);
73+
_stats = new StatsAPI(settings, client);
6774
}
6875

6976
public static void IdentityCheck()

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.4.0",
3+
"version": "0.5.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)