Skip to content

Commit 400a8ae

Browse files
authored
Merge pull request #41 from TaloDev/develop
Release 0.11.0
2 parents f45a530 + 1b27f1e commit 400a8ae

File tree

12 files changed

+198
-92
lines changed

12 files changed

+198
-92
lines changed

Assets/Scripts/Players/IdentifyPlayer.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ public class IdentifyPlayer : MonoBehaviour
99

1010
private void Start()
1111
{
12+
Talo.Players.OnIdentified += async (player) =>
13+
{
14+
await Talo.Saves.GetSaves();
15+
};
16+
1217
Talo.Saves.OnSavesLoaded += () =>
1318
{
1419
if (Talo.Saves.All.Length > 0)
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using System;
2+
using System.Linq;
3+
4+
namespace TaloGameServices
5+
{
6+
public class LiveConfig
7+
{
8+
private Prop[] props;
9+
10+
public LiveConfig(Prop[] props)
11+
{
12+
this.props = props;
13+
}
14+
15+
public T GetProp<T>(string key, T fallback = default(T))
16+
{
17+
Prop prop = props.First((prop) => prop.key == key);
18+
return ((T)Convert.ChangeType(prop.key, typeof(T))) ?? fallback;
19+
}
20+
}
21+
}

Packages/com.trytalo.talo/Runtime/Entities/LiveConfig.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: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using System;
2+
using UnityEngine;
3+
4+
namespace TaloGameServices
5+
{
6+
public class GameConfigAPI : BaseAPI
7+
{
8+
public event Action<LiveConfig> OnLiveConfigLoaded;
9+
10+
public GameConfigAPI(TaloManager manager) : base(manager, "game-config") { }
11+
12+
public async void Get()
13+
{
14+
var uri = new Uri(baseUrl);
15+
var json = await Call(uri, "GET");
16+
var res = JsonUtility.FromJson<GameConfigResponse>(json);
17+
18+
Talo.LiveConfig = new LiveConfig(res.config);
19+
OnLiveConfigLoaded?.Invoke(Talo.LiveConfig);
20+
}
21+
}
22+
}

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

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ namespace TaloGameServices
66
{
77
public class PlayersAPI : BaseAPI
88
{
9+
public event Action<Player> OnIdentified;
10+
911
public PlayersAPI(TaloManager manager) : base(manager, "players") { }
1012

1113
public async Task Identify(string service, string identifier)
@@ -16,15 +18,7 @@ public async Task Identify(string service, string identifier)
1618
var res = JsonUtility.FromJson<PlayersIdentifyResponse>(json);
1719

1820
Talo.CurrentAlias = res.alias;
19-
20-
try
21-
{
22-
await Talo.Saves.GetSaves();
23-
}
24-
catch (Exception err)
25-
{
26-
Debug.LogError(err.Message);
27-
}
21+
OnIdentified?.Invoke(Talo.CurrentPlayer);
2822
}
2923

3024
public async void Update()
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
namespace TaloGameServices
2+
{
3+
[System.Serializable]
4+
public class GameConfigResponse
5+
{
6+
public Prop[] config;
7+
}
8+
}

Packages/com.trytalo.talo/Runtime/Responses/GameConfigResponse.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: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
using System;
2-
using TaloGameServices;
32
using UnityEngine;
43

5-
public class StatsAPI : BaseAPI
4+
namespace TaloGameServices
65
{
7-
public StatsAPI(TaloManager manager) : base(manager, "game-stats") { }
8-
9-
public async void Track(string internalName, float change = 1f)
6+
public class StatsAPI : BaseAPI
107
{
11-
Talo.IdentityCheck();
8+
public StatsAPI(TaloManager manager) : base(manager, "game-stats") { }
9+
10+
public async void Track(string internalName, float change = 1f)
11+
{
12+
Talo.IdentityCheck();
1213

13-
var uri = new Uri(baseUrl + $"/{internalName}");
14-
var content = JsonUtility.ToJson(new StatsPutRequest(change));
14+
var uri = new Uri(baseUrl + $"/{internalName}");
15+
var content = JsonUtility.ToJson(new StatsPutRequest(change));
1516

16-
await Call(uri, "PUT", content);
17+
await Call(uri, "PUT", content);
18+
}
1719
}
1820
}

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

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ public class Talo
1010
private static LeaderboardsAPI _leaderboards;
1111
private static SavesAPI _saves;
1212
private static StatsAPI _stats;
13+
private static GameConfigAPI _gameConfig;
1314

1415
private static PlayerAlias _currentAlias;
1516

@@ -29,6 +30,20 @@ public static Player CurrentPlayer
2930
set => _currentAlias.player = value;
3031
}
3132

33+
private static LiveConfig _liveConfig;
34+
35+
public static LiveConfig LiveConfig
36+
{
37+
get {
38+
if (_liveConfig == null)
39+
{
40+
throw new Exception("Live config needs to be inited first - use Talo.GameConfig.Get() to fetch it");
41+
}
42+
return _liveConfig;
43+
}
44+
set => _liveConfig = value;
45+
}
46+
3247
public static EventsAPI Events
3348
{
3449
get => _events;
@@ -54,12 +69,17 @@ public static StatsAPI Stats
5469
get => _stats;
5570
}
5671

72+
public static GameConfigAPI GameConfig
73+
{
74+
get => _gameConfig;
75+
}
76+
5777
static Talo()
5878
{
5979
var settings = Resources.Load<TaloSettings>("Talo Settings");
6080
if (!settings)
6181
{
62-
Debug.LogError("'Talo Settings' asset not found in Resources folder. Create one using the Create menu > Talo > Settings Asset");
82+
Debug.LogError("A 'Talo Settings' asset was not found in the Resources folder. Create one using the Create menu > Talo > Settings Asset");
6383
return;
6484
}
6585

@@ -71,6 +91,7 @@ static Talo()
7191
_leaderboards = new LeaderboardsAPI(manager);
7292
_saves = new SavesAPI(manager);
7393
_stats = new StatsAPI(manager);
94+
_gameConfig = new GameConfigAPI(manager);
7495
}
7596

7697
public static bool HasIdentity()

0 commit comments

Comments
 (0)