Skip to content

Commit

Permalink
Merge pull request #86 from TaloDev/playground-interactivity
Browse files Browse the repository at this point in the history
Make playground more interactive, add better messaging
  • Loading branch information
tudddorrr authored Oct 24, 2024
2 parents fac9f81 + 3329868 commit 725390e
Show file tree
Hide file tree
Showing 18 changed files with 177 additions and 623 deletions.
549 changes: 43 additions & 506 deletions Assets/Samples/Playground/Scenes/Playground.unity

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions Assets/Samples/Playground/Scripts/Events/TrackEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ public async void OnButtonClick()

private async Task Track()
{
if (string.IsNullOrEmpty(eventName))
{
ResponseMessage.SetText("eventName not set on TrackEventButton");
return;
}

try
{
await Talo.Events.Track(eventName, props.Select((prop) => (prop.key, prop.value)).ToArray());
Expand Down
43 changes: 0 additions & 43 deletions Assets/Samples/Playground/Scripts/Events/TrackLevelUpEvent.cs

This file was deleted.

11 changes: 0 additions & 11 deletions Assets/Samples/Playground/Scripts/Events/TrackLevelUpEvent.cs.meta

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ private async Task FetchCategories()
else
{
var mapped = categories.Select((c) => $"{c.name} ({c.internalName})");
ResponseMessage.SetText($"Categories: " + string.Join(',', mapped));
ResponseMessage.SetText($"Categories: " + string.Join(", ", mapped));
}
}
}
21 changes: 18 additions & 3 deletions Assets/Samples/Playground/Scripts/Feedback/SendFeedback.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,28 @@
using UnityEngine;
using TaloGameServices;
using System;

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

public async void OnButtonClick()
{
await Talo.Feedback.Send(internalName, feedbackComment);
ResponseMessage.SetText($"Feedback sent for {internalName}: {feedbackComment}");
if (string.IsNullOrEmpty(categoryInternalName) || string.IsNullOrEmpty(feedbackComment))
{
ResponseMessage.SetText("categoryInternalName or feedbackComment not set on SendFeedbackButton");
return;
}

try
{
await Talo.Feedback.Send(categoryInternalName, feedbackComment);
ResponseMessage.SetText($"Feedback sent for {categoryInternalName}: {feedbackComment}");
}
catch (Exception err)
{
ResponseMessage.SetText(err.Message);
throw err;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

public class GetLeaderboardEntries : MonoBehaviour
{
public string internalName;
public int page;
public string leaderboardInternalName;
public int page = 0;

public async void OnButtonClick()
{
Expand All @@ -16,10 +16,16 @@ public async void OnButtonClick()

private async Task FetchEntries()
{
if (string.IsNullOrEmpty(leaderboardInternalName))
{
ResponseMessage.SetText("leaderboardInternalName not set on GetLeaderboardEntriesButton");
return;
}

try
{
int score = UnityEngine.Random.Range(0, 10000);
LeaderboardEntriesResponse res = await Talo.Leaderboards.GetEntries(internalName, page);
LeaderboardEntriesResponse res = await Talo.Leaderboards.GetEntries(leaderboardInternalName, page);
LeaderboardEntry[] entries = res.entries;

if (entries.Length == 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

public class PostLeaderboardEntry : MonoBehaviour
{
public string internalName;
public string leaderboardInternalName;

public async void OnButtonClick()
{
Expand All @@ -14,10 +14,16 @@ public async void OnButtonClick()

private async Task PostEntry()
{
if (string.IsNullOrEmpty(leaderboardInternalName))
{
ResponseMessage.SetText("leaderboardInternalName not set on AddEntryButton");
return;
}

try
{
int score = UnityEngine.Random.Range(0, 10000);
(LeaderboardEntry entry, bool updated) = await Talo.Leaderboards.AddEntry(internalName, score);
(LeaderboardEntry entry, bool updated) = await Talo.Leaderboards.AddEntry(leaderboardInternalName, score);

ResponseMessage.SetText($"Entry with score {score} added, position is {entry.position}, it was {(updated ? "" : "not")} updated");
}
Expand Down
19 changes: 0 additions & 19 deletions Assets/Samples/Playground/Scripts/Players/DeleteHealthProp.cs

This file was deleted.

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

public class DeleteHealthProp : MonoBehaviour
{
public string key;

public async void OnButtonClick()
{
await DeleteProp();
}

private async Task DeleteProp()
{
if (string.IsNullOrEmpty(key))
{
ResponseMessage.SetText("key not set on DeletePropButton");
return;
}

try
{
await Talo.CurrentPlayer.DeleteProp(key);
ResponseMessage.SetText($"{key} deleted");
}
catch (Exception err)
{
ResponseMessage.SetText(err.Message);
throw err;
}
}
}
21 changes: 10 additions & 11 deletions Assets/Samples/Playground/Scripts/Players/GetGroup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,18 @@ public async void OnButtonClick()
{
if (string.IsNullOrEmpty(groupId))
{
ResponseMessage.SetText("groupId not set on 'Get group' button");
ResponseMessage.SetText("groupId not set on GetGroupButton");
return;
}
else

try
{
var group = await Talo.PlayerGroups.Get(groupId);
ResponseMessage.SetText($"{group.name} has {group.count} player(s)");
}
catch (Exception e)
{
try
{
var group = await Talo.PlayerGroups.Get(groupId);
ResponseMessage.SetText($"{group.name} has {group.count} player(s)");
}
catch (Exception e)
{
ResponseMessage.SetText(e.Message);
}
ResponseMessage.SetText(e.Message);
}
}
}
8 changes: 7 additions & 1 deletion Assets/Samples/Playground/Scripts/Players/IdentifyPlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ public async void OnButtonClick()

private async Task Identify()
{
if (string.IsNullOrEmpty(service) || string.IsNullOrEmpty(identifier))
{
ResponseMessage.SetText("service or identifier not set on IdentifyButton");
return;
}

try
{
await Talo.Players.Identify(service, identifier);
Expand All @@ -37,7 +43,7 @@ private void OnIdentified(Player player)
if (panel != null)
{
ResponseMessage.SetText("Identified!");
panel.GetComponent<Image>().color = new Color(135 / 255f, 1f, 135 / 255f);
panel.GetComponent<Image>().color = new Color(120 / 255f, 230 / 255f, 160 / 255f);
}
}
}
21 changes: 0 additions & 21 deletions Assets/Samples/Playground/Scripts/Players/SetHealthProp.cs

This file was deleted.

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

public class SetProp : MonoBehaviour
{
public string key, value;

public async void OnButtonClick()
{
await UpdateProp();
}

private async Task UpdateProp()
{
if (string.IsNullOrEmpty(key) || string.IsNullOrEmpty(value))
{
ResponseMessage.SetText("key or value not set on SetPropButton");
return;
}

try
{
await Talo.CurrentPlayer.SetProp(key, value);
ResponseMessage.SetText($"{key} set to {value}");
}
catch (System.Exception err)
{
ResponseMessage.SetText(err.Message);
throw err;
}
}
}
6 changes: 6 additions & 0 deletions Assets/Samples/Playground/Scripts/Stats/TrackStat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ public void OnButtonClick()

private async void Track()
{
if (string.IsNullOrEmpty(statInternalName))
{
ResponseMessage.SetText("statInternalName not set on TrackStatButton");
return;
}

try
{
await Talo.Stats.Track(statInternalName, change);
Expand Down
4 changes: 2 additions & 2 deletions Packages/com.trytalo.talo/Runtime/APIs/FeedbackAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ public async Task<FeedbackCategory[]> GetCategories()
return res.feedbackCategories;
}

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

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

await Call(uri, "POST", content);
Expand Down

0 comments on commit 725390e

Please sign in to comment.