Skip to content

Commit

Permalink
Merge pull request #66 from TaloDev/develop
Browse files Browse the repository at this point in the history
Release 0.18.0
  • Loading branch information
tudddorrr authored Jun 13, 2024
2 parents ed7838a + e158ee7 commit 9f60dc0
Show file tree
Hide file tree
Showing 30 changed files with 1,956 additions and 143 deletions.
702 changes: 648 additions & 54 deletions Assets/Samples/Playground/Scenes/Playground.unity

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions Assets/Samples/Playground/Scripts/Feedback.meta

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

27 changes: 27 additions & 0 deletions Assets/Samples/Playground/Scripts/Feedback/GetCategories.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using UnityEngine;
using TaloGameServices;
using System.Threading.Tasks;
using System.Linq;

public class GetCategories : MonoBehaviour
{
public async void OnButtonClick()
{
await FetchCategories();
}

private async Task FetchCategories()
{
var categories = await Talo.Feedback.GetCategories();

if (categories.Length == 0)
{
ResponseMessage.SetText("No categories found. Create some in the Talo dashboard!");
}
else
{
var mapped = categories.Select((c) => $"{c.name} ({c.internalName})");
ResponseMessage.SetText($"Categories: " + string.Join(',', mapped));
}
}
}
11 changes: 11 additions & 0 deletions Assets/Samples/Playground/Scripts/Feedback/GetCategories.cs.meta

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

13 changes: 13 additions & 0 deletions Assets/Samples/Playground/Scripts/Feedback/SendFeedback.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using UnityEngine;
using TaloGameServices;

public class SendFeedback : MonoBehaviour
{
public string internalName, feedbackComment;

public async void OnButtonClick()
{
await Talo.Feedback.Send(internalName, feedbackComment);
ResponseMessage.SetText($"Feedback sent for {internalName}: {feedbackComment}");
}
}
11 changes: 11 additions & 0 deletions Assets/Samples/Playground/Scripts/Feedback/SendFeedback.cs.meta

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

Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ private async Task FetchEntries()
if (entries.Length == 0)
{
ResponseMessage.SetText($"No entries for page {page}");
} else
}
else
{
ResponseMessage.SetText(string.Join(", ", entries.Select((e) => e.ToString()).ToArray()));
}
Expand Down
3 changes: 2 additions & 1 deletion Assets/Samples/SavesDemo/Scripts/GlobalUIController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ private void OnSaveChosen(GameSave save)
SetDocumentVisibility(savesListUI, DisplayStyle.None);
SetDocumentVisibility(menuUI, DisplayStyle.None);
SetDocumentVisibility(gameUI, DisplayStyle.Flex);
} else
}
else
{
SetDocumentVisibility(gameUI, DisplayStyle.None);
SetDocumentVisibility(menuUI, DisplayStyle.Flex);
Expand Down
16 changes: 16 additions & 0 deletions Packages/com.trytalo.talo/Runtime/Entities/FeedbackCategory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;

namespace TaloGameServices
{
[Serializable]
public class FeedbackCategory
{
public int id;
public string internalName;
public string name;
public string description;
public bool anonymised;
public string createdAt;
public string updatedAt;
}
}

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

25 changes: 15 additions & 10 deletions Packages/com.trytalo.talo/Runtime/Entities/Player.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using UnityEngine;
using System.Linq;
using System;
using System.Threading.Tasks;

using System.Threading.Tasks;

namespace TaloGameServices
{
[Serializable]
Expand All @@ -19,8 +19,8 @@ public override string ToString()

public string GetProp(string key, string fallback = null)
{
Prop prop = props.First((prop) => prop.key == key);
return prop?.key ?? fallback;
Prop prop = props.FirstOrDefault((prop) => prop.key == key);
return prop?.value ?? fallback;
}

public async Task SetProp(string key, string value)
Expand All @@ -45,17 +45,22 @@ public async Task SetProp(string key, string value)

public async Task DeleteProp(string key)
{
Prop prop = props.First((prop) => prop.key == key);
Prop prop = props.FirstOrDefault((prop) => prop.key == key);
if (prop == null) throw new Exception($"Prop with key {key} does not exist");

prop.value = null;

await Talo.Players.Update();
}

public bool IsInGroup(string groupId)
{
return groups.Any((group) => group.id == groupId);
}

public bool IsInGroupID(string groupId)
{
return groups.Any((group) => group.id == groupId);
}

public bool IsInGroupName(string groupName)
{
return groups.Any((group) => group.name == groupName);
}
}
}
3 changes: 2 additions & 1 deletion Packages/com.trytalo.talo/Runtime/Entities/SaveContent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ public SavedObject(LoadableData loadableData)
value = field.Value.ToString(),
type = field.Value.GetType().ToString()
}).ToArray();
} else
}
else
{
data = new SavedObjectData[]
{
Expand Down
8 changes: 4 additions & 4 deletions Packages/com.trytalo.talo/Runtime/EventsAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class EventsAPI : BaseAPI
private List<Event> queue = new List<Event>();
private readonly int minQueueSize = 10;

public EventsAPI(TaloManager manager) : base(manager, "events") { }
public EventsAPI(TaloManager manager) : base(manager, "/v1/events") { }

private string GetWindowMode()
{
Expand Down Expand Up @@ -51,9 +51,9 @@ public async Task Track(string name, params (string, string)[] props)
{
Talo.IdentityCheck();

var ev = new Event
{
name = name
var ev = new Event
{
name = name
};

if (props != null)
Expand Down
30 changes: 30 additions & 0 deletions Packages/com.trytalo.talo/Runtime/FeedbackAPI.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System;
using System.Threading.Tasks;
using UnityEngine;

namespace TaloGameServices
{
public class FeedbackAPI : BaseAPI
{
public FeedbackAPI(TaloManager manager) : base(manager, "/v1/game-feedback") { }

public async Task<FeedbackCategory[]> GetCategories()
{
var uri = new Uri(baseUrl + "/categories");

var json = await Call(uri, "GET");
var res = JsonUtility.FromJson<FeedbackCategoriesResponse>(json);
return res.feedbackCategories;
}

public async Task Send(string internalName, string comment)
{
Talo.IdentityCheck();

var uri = new Uri(baseUrl + $"/categories/{internalName}");
var content = JsonUtility.ToJson(new FeedbackPostRequest() { comment = comment });

await Call(uri, "POST", content);
}
}
}
11 changes: 11 additions & 0 deletions Packages/com.trytalo.talo/Runtime/FeedbackAPI.cs.meta

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/Runtime/GameConfigAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class GameConfigAPI : BaseAPI
{
public event Action<LiveConfig> OnLiveConfigLoaded;

public GameConfigAPI(TaloManager manager) : base(manager, "game-config") { }
public GameConfigAPI(TaloManager manager) : base(manager, "/v1/game-config") { }

public async Task Get()
{
Expand Down
9 changes: 4 additions & 5 deletions Packages/com.trytalo.talo/Runtime/LeaderboardsAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace TaloGameServices
{
public class LeaderboardsAPI : BaseAPI
{
public LeaderboardsAPI(TaloManager manager) : base(manager, "leaderboards") { }
public LeaderboardsAPI(TaloManager manager) : base(manager, "/v1/leaderboards") { }

public async Task<LeaderboardEntriesResponse> GetEntries(string internalName, int page)
{
Expand All @@ -17,16 +17,15 @@ public async Task<LeaderboardEntriesResponse> GetEntries(string internalName, in
return res;
}

public async Task<LeaderboardEntry[]> GetEntriesForCurrentPlayer(string leaderboardInternalName, int page)
public async Task<LeaderboardEntriesResponse> GetEntriesForCurrentPlayer(string internalName, int page)
{
Talo.IdentityCheck();

var uri = new Uri(baseUrl + $"/{leaderboardInternalName}/entries?page={page}&aliasId={Talo.CurrentAlias.id}");
var uri = new Uri(baseUrl + $"/{internalName}/entries?page={page}&aliasId={Talo.CurrentAlias.id}");

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

return res.entries;
return res;
}

public async Task<(LeaderboardEntry, bool)> AddEntry(string internalName, float score)
Expand Down
4 changes: 2 additions & 2 deletions Packages/com.trytalo.talo/Runtime/PlayersAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ namespace TaloGameServices
{
public class PlayersAPI : BaseAPI
{
public event Action<Player> OnIdentified;
public event Action<Player> OnIdentified;

public PlayersAPI(TaloManager manager) : base(manager, "players") { }
public PlayersAPI(TaloManager manager) : base(manager, "/v1/players") { }

public async Task Identify(string service, string identifier)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace TaloGameServices
{
public class FeedbackPostRequest
{
public string comment;
}
}

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace TaloGameServices
{
[System.Serializable]
public class FeedbackCategoriesResponse
{
public FeedbackCategory[] feedbackCategories;
}
}

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

14 changes: 9 additions & 5 deletions Packages/com.trytalo.talo/Runtime/SavesAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public GameSave Current
get => _currentSave;
}

public SavesAPI(TaloManager manager) : base(manager, "game-saves") {
public SavesAPI(TaloManager manager) : base(manager, "/v1/game-saves") {
_fileHandler = Talo.TestMode
? new SavesTestFileHandler()
: new SavesFileHandler();
Expand Down Expand Up @@ -98,7 +98,8 @@ public async Task<GameSave[]> GetSaves()
if (Talo.IsOffline())
{
if (offlineSaves != null) saves.AddRange(offlineSaves);
} else
}
else
{
Talo.IdentityCheck();

Expand Down Expand Up @@ -184,7 +185,8 @@ private void UpdateOfflineSaves(GameSave incomingSave)

offlineContent.saves = offlineContent.saves.Concat(new GameSave[] { incomingSave }).ToArray();
}
} else
}
else
{
// first entry into the saves file
incomingSave.id = -1;
Expand All @@ -208,7 +210,8 @@ public async Task<GameSave> CreateSave(string saveName, string content = null)
content = saveContent,
updatedAt = DateTime.UtcNow.ToString("O")
};
} else
}
else
{
Talo.IdentityCheck();

Expand Down Expand Up @@ -254,7 +257,8 @@ public async Task<GameSave> UpdateSave(int saveId, string newName = "")
if (!string.IsNullOrEmpty(newName)) save.name = newName;
save.content = saveContent;
save.updatedAt = DateTime.UtcNow.ToString("O");
} else
}
else
{
Talo.IdentityCheck();

Expand Down
2 changes: 1 addition & 1 deletion Packages/com.trytalo.talo/Runtime/StatsAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace TaloGameServices
{
public class StatsAPI : BaseAPI
{
public StatsAPI(TaloManager manager) : base(manager, "game-stats") { }
public StatsAPI(TaloManager manager) : base(manager, "/v1/game-stats") { }

public async Task Track(string internalName, float change = 1f)
{
Expand Down
Loading

0 comments on commit 9f60dc0

Please sign in to comment.