Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make playground more interactive, add better messaging #36

Merged
merged 1 commit into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion addons/talo/apis/api.gd
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ class_name TaloAPI extends Node
var client: TaloClient

func _init(base_path: String):
name = "Talo%s" % [base_path]
name = "Talo%s" % base_path
client = TaloClient.new(base_path)
add_child(client)
4 changes: 2 additions & 2 deletions addons/talo/apis/feedback_api.gd
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ func get_categories() -> Array:
_:
return []

func send(internal_name: String, comment: String) -> void:
func send(category_internal_name: String, comment: String) -> void:
if Talo.identity_check() != OK:
return

await client.make_request(HTTPClient.METHOD_POST, "/categories/%s" % internal_name, {
await client.make_request(HTTPClient.METHOD_POST, "/categories/%s" % category_internal_name, {
comment = comment
})
2 changes: 1 addition & 1 deletion addons/talo/apis/player_groups_api.gd
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class_name PlayerGroupsAPI extends TaloAPI

func get_group(group_id: String) -> TaloPlayerGroup:
var res = await client.make_request(HTTPClient.METHOD_GET, "/%s" % [group_id])
var res = await client.make_request(HTTPClient.METHOD_GET, "/%s" % group_id)

match (res.status):
200:
Expand Down
4 changes: 2 additions & 2 deletions addons/talo/apis/saves_api.gd
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func update_save(save: TaloGameSave, new_name: String = "") -> TaloGameSave:
if Talo.identity_check() != OK:
return

var res = await client.make_request(HTTPClient.METHOD_PATCH, "/%s" % [save.id], {
var res = await client.make_request(HTTPClient.METHOD_PATCH, "/%s" % save.id, {
name=save.display_name if new_name.is_empty() else new_name,
content=content
})
Expand All @@ -152,7 +152,7 @@ func delete_save(save: TaloGameSave) -> void:
if Talo.identity_check() != OK:
return

var res = await client.make_request(HTTPClient.METHOD_DELETE, "/%s" % [save.id])
var res = await client.make_request(HTTPClient.METHOD_DELETE, "/%s" % save.id)

match res.status:
_:
Expand Down
2 changes: 1 addition & 1 deletion addons/talo/samples/authentication/scripts/in_game.gd
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ func _ready() -> void:
Talo.players.identified.connect(_on_player_identified)

func _on_player_identified(player: TaloPlayer) -> void:
username.text = "What would you like to do,\n%s?" % [Talo.current_alias.identifier]
username.text = "What would you like to do,\n%s?" % Talo.current_alias.identifier

func _on_change_password_pressed() -> void:
go_to_change_password.emit()
Expand Down
10 changes: 5 additions & 5 deletions addons/talo/samples/leaderboards/scripts/leaderboard.gd
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ func _ready() -> void:

func _set_entry_count():
if entries_container.get_child_count() == 0:
info_label.text = "No entries yet!" if not _entries_error else "Failed loading leaderboard %s. Does it exist?" % [leaderboard_internal_name]
info_label.text = "No entries yet!" if not _entries_error else "Failed loading leaderboard %s. Does it exist?" % leaderboard_internal_name
else:
info_label.text = "%s entries" % [entries_container.get_child_count()]
info_label.text = "%s entries" % entries_container.get_child_count()
if _filter != "All":
info_label.text += " (%s team)" % [_filter]
info_label.text += " (%s team)" % _filter

func _create_entry(entry: TaloLeaderboardEntry) -> void:
var entry_instance = entry_scene.instantiate()
Expand Down Expand Up @@ -82,7 +82,7 @@ func _on_filter_pressed() -> void:
_filter_idx += 1
_filter = _get_next_filter(_filter_idx)

info_label.text = "Filtering on %s" % [filter_button.text.to_lower()]
filter_button.text = "%s team scores" % [_get_next_filter(_filter_idx + 1)]
info_label.text = "Filtering on %s" % filter_button.text.to_lower()
filter_button.text = "%s team scores" % _get_next_filter(_filter_idx + 1)

_build_entries()
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ func _set_score(score: int) -> void:

func _set_team(team: String) -> void:
if not team.is_empty():
text += " (%s team)" % [team]
text += " (%s team)" % team

func set_data(entry: TaloLeaderboardEntry) -> void:
_set_pos(entry.position)
Expand Down
41 changes: 18 additions & 23 deletions addons/talo/samples/playground/playground.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
[ext_resource type="Script" path="res://addons/talo/samples/playground/scripts/identified_state.gd" id="1_qsdrr"]
[ext_resource type="Script" path="res://addons/talo/samples/playground/scripts/identified_label.gd" id="2_ncaxm"]
[ext_resource type="Script" path="res://addons/talo/samples/playground/scripts/response_label.gd" id="3_bdtqj"]
[ext_resource type="Script" path="res://addons/talo/samples/playground/scripts/level_up_button.gd" id="4_vboi8"]
[ext_resource type="Script" path="res://addons/talo/samples/playground/scripts/track_event_button.gd" id="4_vboi8"]
[ext_resource type="Script" path="res://addons/talo/samples/playground/scripts/get_config_button.gd" id="5_blrul"]
[ext_resource type="Script" path="res://addons/talo/samples/playground/scripts/set_health_button.gd" id="5_fpvjp"]
[ext_resource type="Script" path="res://addons/talo/samples/playground/scripts/discover_secret_button.gd" id="5_wpnvd"]
[ext_resource type="Script" path="res://addons/talo/samples/playground/scripts/delete_health_button.gd" id="6_it1yx"]
[ext_resource type="Script" path="res://addons/talo/samples/playground/scripts/set_prop_button.gd" id="5_fpvjp"]
[ext_resource type="Script" path="res://addons/talo/samples/playground/scripts/track_stat_button.gd" id="5_wpnvd"]
[ext_resource type="Script" path="res://addons/talo/samples/playground/scripts/delete_prop_button.gd" id="6_it1yx"]
[ext_resource type="Script" path="res://addons/talo/samples/playground/scripts/toggle_continuity_button.gd" id="6_pvyh2"]
[ext_resource type="Script" path="res://addons/talo/samples/playground/scripts/get_group_button.gd" id="7_5qx11"]
[ext_resource type="Script" path="res://addons/talo/samples/playground/scripts/toggle_network_button.gd" id="7_wsc44"]
Expand Down Expand Up @@ -39,7 +39,7 @@ anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
color = Color(0.980392, 0.392157, 0.470588, 1)
color = Color(1, 0.509804, 0.627451, 1)
script = ExtResource("1_qsdrr")

[node name="MarginContainer" type="MarginContainer" parent="UI"]
Expand All @@ -63,6 +63,7 @@ text = "Player not identified"
script = ExtResource("2_ncaxm")

[node name="ResponseLabel" type="Label" parent="UI/MarginContainer"]
unique_name_in_owner = true
layout_mode = 2
size_flags_horizontal = 0
size_flags_vertical = 8
Expand Down Expand Up @@ -91,17 +92,15 @@ text = "Players"
layout_mode = 2
text = "Identify"
script = ExtResource("1_o53s3")
service = "username"
identifier = "TaloPlayer"

[node name="SetHealthButton" type="Button" parent="UI/MarginContainer/APIs/Players_Continuity/Players"]
[node name="SetPropButton" type="Button" parent="UI/MarginContainer/APIs/Players_Continuity/Players"]
layout_mode = 2
text = "Set health"
text = "Set prop"
script = ExtResource("5_fpvjp")

[node name="DeleteHealthButton" type="Button" parent="UI/MarginContainer/APIs/Players_Continuity/Players"]
[node name="DeletePropButton" type="Button" parent="UI/MarginContainer/APIs/Players_Continuity/Players"]
layout_mode = 2
text = "Delete health"
text = "Delete prop"
script = ExtResource("6_it1yx")

[node name="GetGroupButton" type="Button" parent="UI/MarginContainer/APIs/Players_Continuity/Players"]
Expand Down Expand Up @@ -139,9 +138,9 @@ theme_override_colors/font_color = Color(0, 0, 0, 1)
theme_override_font_sizes/font_size = 20
text = "Events"

[node name="LevelUpButton" type="Button" parent="UI/MarginContainer/APIs/Events"]
[node name="TrackEventButton" type="Button" parent="UI/MarginContainer/APIs/Events"]
layout_mode = 2
text = "Level up"
text = "Track event"
script = ExtResource("4_vboi8")

[node name="Live config" type="VBoxContainer" parent="UI/MarginContainer/APIs"]
Expand Down Expand Up @@ -169,11 +168,10 @@ theme_override_colors/font_color = Color(0, 0, 0, 1)
theme_override_font_sizes/font_size = 20
text = "Stats"

[node name="DiscoverSecretButton" type="Button" parent="UI/MarginContainer/APIs/Stats"]
[node name="TrackStatButton" type="Button" parent="UI/MarginContainer/APIs/Stats"]
layout_mode = 2
text = "Discover secret"
text = "Track stat"
script = ExtResource("5_wpnvd")
stat_name = "secrets-discovered"

[node name="Leaderboards" type="VBoxContainer" parent="UI/MarginContainer/APIs"]
layout_mode = 2
Expand All @@ -189,13 +187,11 @@ text = "Leaderboards"
layout_mode = 2
text = "Get entries"
script = ExtResource("8_8262a")
leaderboard_name = "sed-totam-magni"

[node name="AddEntryButton" type="Button" parent="UI/MarginContainer/APIs/Leaderboards"]
layout_mode = 2
text = "Add entry"
script = ExtResource("9_3705v")
leaderboard_name = "sed-totam-magni"

[node name="Saves" type="VBoxContainer" parent="UI/MarginContainer/APIs"]
layout_mode = 2
Expand Down Expand Up @@ -467,18 +463,17 @@ script = ExtResource("18_vdjyg")
layout_mode = 2
text = "Send feedback"
script = ExtResource("19_2r4rn")
internal_name = "bugs"
feedback_comment = "There is a bug in the game somewhere, go find it"

[connection signal="pressed" from="UI/MarginContainer/APIs/Players_Continuity/Players/IdentifyButton" to="UI/MarginContainer/APIs/Players_Continuity/Players/IdentifyButton" method="_on_pressed"]
[connection signal="pressed" from="UI/MarginContainer/APIs/Players_Continuity/Players/SetHealthButton" to="UI/MarginContainer/APIs/Players_Continuity/Players/SetHealthButton" method="_on_pressed"]
[connection signal="pressed" from="UI/MarginContainer/APIs/Players_Continuity/Players/DeleteHealthButton" to="UI/MarginContainer/APIs/Players_Continuity/Players/DeleteHealthButton" method="_on_pressed"]
[connection signal="pressed" from="UI/MarginContainer/APIs/Players_Continuity/Players/SetPropButton" to="UI/MarginContainer/APIs/Players_Continuity/Players/SetPropButton" method="_on_pressed"]
[connection signal="pressed" from="UI/MarginContainer/APIs/Players_Continuity/Players/DeletePropButton" to="UI/MarginContainer/APIs/Players_Continuity/Players/DeletePropButton" method="_on_pressed"]
[connection signal="pressed" from="UI/MarginContainer/APIs/Players_Continuity/Players/GetGroupButton" to="UI/MarginContainer/APIs/Players_Continuity/Players/GetGroupButton" method="_on_pressed"]
[connection signal="pressed" from="UI/MarginContainer/APIs/Players_Continuity/Continuity/ToggleContinuityButton" to="UI/MarginContainer/APIs/Players_Continuity/Continuity/ToggleContinuityButton" method="_on_pressed"]
[connection signal="pressed" from="UI/MarginContainer/APIs/Players_Continuity/Continuity/ToggleNetworkButton" to="UI/MarginContainer/APIs/Players_Continuity/Continuity/ToggleNetworkButton" method="_on_pressed"]
[connection signal="pressed" from="UI/MarginContainer/APIs/Events/LevelUpButton" to="UI/MarginContainer/APIs/Events/LevelUpButton" method="_on_pressed"]
[connection signal="pressed" from="UI/MarginContainer/APIs/Events/TrackEventButton" to="UI/MarginContainer/APIs/Events/TrackEventButton" method="_on_pressed"]
[connection signal="pressed" from="UI/MarginContainer/APIs/Live config/GetConfigButton" to="UI/MarginContainer/APIs/Live config/GetConfigButton" method="_on_pressed"]
[connection signal="pressed" from="UI/MarginContainer/APIs/Stats/DiscoverSecretButton" to="UI/MarginContainer/APIs/Stats/DiscoverSecretButton" method="_on_pressed"]
[connection signal="pressed" from="UI/MarginContainer/APIs/Stats/TrackStatButton" to="UI/MarginContainer/APIs/Stats/TrackStatButton" method="_on_pressed"]
[connection signal="pressed" from="UI/MarginContainer/APIs/Leaderboards/GetEntriesButton" to="UI/MarginContainer/APIs/Leaderboards/GetEntriesButton" method="_on_pressed"]
[connection signal="pressed" from="UI/MarginContainer/APIs/Leaderboards/AddEntryButton" to="UI/MarginContainer/APIs/Leaderboards/AddEntryButton" method="_on_pressed"]
[connection signal="pressed" from="UI/MarginContainer/APIs/Saves/GetSavesButton" to="UI/MarginContainer/APIs/Saves/GetSavesButton" method="_on_pressed"]
Expand Down
11 changes: 9 additions & 2 deletions addons/talo/samples/playground/scripts/add_entry_button.gd
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
extends Button

@onready var response_label: Label = $"/root/Playground/UI/MarginContainer/ResponseLabel"
@export var leaderboard_name: String

func _on_pressed() -> void:
if Talo.identity_check() != OK:
%ResponseLabel.text = "You need to identify a player first!"
return

if leaderboard_name.is_empty():
%ResponseLabel.text = "leaderboard_name not set on AddEntryButton"
return

var score = RandomNumberGenerator.new().randi_range(1, 50)
var res = await Talo.leaderboards.add_entry(leaderboard_name, score)

if res.size() > 0:
response_label.text = "Added score: %s, new high score: %s" % [score, res[1]]
%ResponseLabel.text = "Added score: %s, new high score: %s" % [score, res[1]]

This file was deleted.

14 changes: 14 additions & 0 deletions addons/talo/samples/playground/scripts/delete_prop_button.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
extends Button

@export var prop_name: String

func _on_pressed() -> void:
if Talo.identity_check() != OK:
%ResponseLabel.text = "You need to identify a player first!"
return

if prop_name.is_empty():
%ResponseLabel.text = "prop_name not set on DeletePropButton"
return

Talo.current_player.delete_prop(prop_name)

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
extends Button

@onready var response_label: Label = $"/root/Playground/UI/MarginContainer/ResponseLabel"

func _on_pressed() -> void:
var categories = await Talo.feedback.get_categories()

if categories.size() == 0:
response_label.text = "No categories found. Create some in the Talo dashboard!"
%ResponseLabel.text = "No categories found. Create some in the Talo dashboard!"
else:
var mapped = categories.map(func (c): return "%s (%s)" % [c.display_name, c.internal_name])
response_label.text = "Categories: " + ", ".join(mapped)
%ResponseLabel.text = "Categories: " + ", ".join(mapped)
9 changes: 7 additions & 2 deletions addons/talo/samples/playground/scripts/get_entries_button.gd
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
extends Button

@onready var response_label: Label = $"/root/Playground/UI/MarginContainer/ResponseLabel"
@export var leaderboard_name: String

func _on_pressed() -> void:
if leaderboard_name.is_empty():
%ResponseLabel.text = "leaderboard_name not set on GetEntriesButton"
return

var res = await Talo.leaderboards.get_entries(leaderboard_name, 0)

if res.size() > 0:
var entries = res[0]
response_label.text = "Received %s entries" % entries.size()
%ResponseLabel.text = "Received %s entries" % entries.size()
else:
%ResponseLabel.text = "No entries found for %s" % leaderboard_name
18 changes: 9 additions & 9 deletions addons/talo/samples/playground/scripts/get_group_button.gd
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
extends Button

@onready var response_label: Label = $"/root/Playground/UI/MarginContainer/ResponseLabel"
@export var group_id: String = ""
@export var group_id: String

func _on_pressed() -> void:
if not group_id.is_empty():
var group = await Talo.player_groups.get_group(group_id)
if group != null:
response_label.text = "%s has %s player(s)" % [group.display_name, group.count]
else:
print_rich("[color=yellow]Group %s not found[/color]" % [group_id])
if group_id.is_empty():
%ResponseLabel.text = "group_id not set on GetGroupButton"
return

var group = await Talo.player_groups.get_group(group_id)
if group != null:
%ResponseLabel.text = "%s has %s player(s)" % [group.display_name, group.count]
else:
print_rich("[color=yellow]group_id not set on GetGroupButton[/color]")
%ResponseLabel.text = "Group %s not found" % group_id
2 changes: 1 addition & 1 deletion addons/talo/samples/playground/scripts/identified_state.gd
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ func _ready() -> void:
Talo.players.identified.connect(_on_identified)

func _on_identified(_player: TaloPlayer) -> void:
color = Color(0.0, 190.0 / 255.0, 130.0 / 255.0)
color = Color(120.0 / 255.0, 230.0 / 255.0, 160.0 / 255.0)
6 changes: 5 additions & 1 deletion addons/talo/samples/playground/scripts/identify_button.gd
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
extends Button

@export var service: String
@export var service: String = "username"
@export var identifier: String

func _on_pressed():
if service.is_empty() or identifier.is_empty():
%ResponseLabel.text = "service or identifier not set on IdentifyButton"
return

Talo.players.identify(service, identifier)
10 changes: 0 additions & 10 deletions addons/talo/samples/playground/scripts/level_up_button.gd

This file was deleted.

16 changes: 11 additions & 5 deletions addons/talo/samples/playground/scripts/send_feedback_button.gd
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
extends Button

@export var internal_name: String
@export var category_name: String
@export var feedback_comment: String

@onready var response_label: Label = $"/root/Playground/UI/MarginContainer/ResponseLabel"

func _on_pressed() -> void:
await Talo.feedback.send(internal_name, feedback_comment)
response_label.text = "Feedback sent for %s: %s" % [internal_name, feedback_comment]
if Talo.identity_check() != OK:
%ResponseLabel.text = "You need to identify a player first!"
return

if category_name.is_empty() or feedback_comment.is_empty():
%ResponseLabel.text = "category_name or feedback_comment not set on SendFeedbackButton"
return

await Talo.feedback.send(category_name, feedback_comment)
%ResponseLabel.text = "Feedback sent for %s: %s" % [category_name, feedback_comment]
7 changes: 0 additions & 7 deletions addons/talo/samples/playground/scripts/set_health_button.gd

This file was deleted.

15 changes: 15 additions & 0 deletions addons/talo/samples/playground/scripts/set_prop_button.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
extends Button

@export var prop_name: String
@export var prop_value: String

func _on_pressed() -> void:
if Talo.identity_check() != OK:
%ResponseLabel.text = "You need to identify a player first!"
return

if prop_name.is_empty() or prop_value.is_empty():
%ResponseLabel.text = "prop_name or prop_value not set on SetPropButton"
return

Talo.current_player.set_prop(prop_name, prop_value)
Loading