Skip to content

Commit

Permalink
Several additions and refactors
Browse files Browse the repository at this point in the history
Add player functionality to demo project
Refactor friend package to player package
Some other small refactors everywhere

Signed-off-by: Jacob Ibáñez Sánchez <jacobibanez@jacobibanez.com>
  • Loading branch information
Iakobs committed Dec 19, 2023
1 parent c82edcd commit 4f9d5ee
Show file tree
Hide file tree
Showing 22 changed files with 740 additions and 218 deletions.
2 changes: 1 addition & 1 deletion plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ tasks.dokkaHtmlPartial {

dokkaSourceSets.configureEach {
perPackageOption {
matchingRegex.set(".*friends|.*signin")
matchingRegex.set(".*signin")
suppress.set(true)
}
}
Expand Down
1 change: 1 addition & 0 deletions plugin/demo/project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ GodotPlayGameServices="*res://addons/GodotPlayGameServices/autoloads/godot_play_
SignInClient="*res://addons/GodotPlayGameServices/autoloads/sign_in_client.gd"
AchievementsClient="*res://addons/GodotPlayGameServices/autoloads/achievements_client.gd"
LeaderboardsClient="*res://addons/GodotPlayGameServices/autoloads/leaderboards_client.gd"
PlayersClient="*res://addons/GodotPlayGameServices/autoloads/players_client.gd"

[display]

Expand Down
4 changes: 4 additions & 0 deletions plugin/demo/scenes/MainMenu.gd
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ extends Control

@onready var achievements_button: Button = %Achievements
@onready var leaderboards_button: Button = %Leaderboards
@onready var players_button: Button = %Players

func _ready() -> void:
achievements_button.pressed.connect(func():
Expand All @@ -10,3 +11,6 @@ func _ready() -> void:
leaderboards_button.pressed.connect(func():
get_tree().change_scene_to_file("res://scenes/leaderboards/Leaderboards.tscn")
)
players_button.pressed.connect(func():
get_tree().change_scene_to_file("res://scenes/players/Players.tscn")
)
7 changes: 7 additions & 0 deletions plugin/demo/scenes/MainMenu.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,10 @@ custom_minimum_size = Vector2(500, 200)
layout_mode = 2
theme = ExtResource("2_aajnr")
text = "Leaderboads"

[node name="Players" type="Button" parent="MarginContainer/VBoxContainer"]
unique_name_in_owner = true
custom_minimum_size = Vector2(500, 200)
layout_mode = 2
theme = ExtResource("2_aajnr")
text = "Players"
4 changes: 2 additions & 2 deletions plugin/demo/scenes/achievements/AchievementDisplay.gd
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ func _set_up_display() -> void:
id_label.text = achievement.achievement_id
name_label.text = achievement.achievement_name
description_label.text = achievement.description
type_label.text = AchievementsClient.Type.keys()[achievement.type]
state_label.text = AchievementsClient.State.keys()[achievement.state]
type_label.text = AchievementsClient.Type.find_key(achievement.type)
state_label.text = AchievementsClient.State.find_key(achievement.state)
xp_value_label.text = str(achievement.xp_value)

if achievement.type == AchievementsClient.Type.TYPE_INCREMENTAL:
Expand Down
27 changes: 27 additions & 0 deletions plugin/demo/scenes/players/FriendDisplay.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
extends Control

@onready var id_label: Label = %IdLabel
@onready var name_label: Label = %NameLabel
@onready var title_label: Label = %TitleLabel
@onready var status_label: Label = %StatusLabel
@onready var level_label: Label = %LevelLabel
@onready var xp_label: Label = %XpLabel

@onready var compare_button: Button = %CompareButton

var friend: PlayersClient.Player

func _ready() -> void:
if friend:
_set_up_display()
compare_button.pressed.connect(func():
PlayersClient.compare_profile_with(friend.player_id)
)

func _set_up_display() -> void:
id_label.text = friend.player_id
name_label.text = friend.display_name
title_label.text = friend.title
status_label.text = PlayersClient.PlayerFriendStatus.find_key(friend.friend_status)
level_label.text = str(friend.level_info.current_level.level_number)
xp_label.text = str(friend.level_info.current_xp_total)
148 changes: 148 additions & 0 deletions plugin/demo/scenes/players/FriendDisplay.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
[gd_scene load_steps=3 format=3 uid="uid://cipu5ch2lo1ne"]

[ext_resource type="Theme" uid="uid://bmm3mvq11y045" path="res://theme.tres" id="1_ylrpt"]
[ext_resource type="Script" path="res://scenes/players/FriendDisplay.gd" id="2_nfjqs"]

[node name="FriendDisplay" type="PanelContainer"]
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
mouse_filter = 1
theme = ExtResource("1_ylrpt")
script = ExtResource("2_nfjqs")

[node name="MarginContainer" type="MarginContainer" parent="."]
layout_mode = 2
theme_override_constants/margin_left = 25
theme_override_constants/margin_top = 25
theme_override_constants/margin_right = 25
theme_override_constants/margin_bottom = 25

[node name="VBoxContainer" type="VBoxContainer" parent="MarginContainer"]
layout_mode = 2
theme_override_constants/separation = 25

[node name="Id" type="HBoxContainer" parent="MarginContainer/VBoxContainer"]
layout_mode = 2

[node name="Label" type="Label" parent="MarginContainer/VBoxContainer/Id"]
layout_mode = 2
text = "ID:"

[node name="IdLabel" type="Label" parent="MarginContainer/VBoxContainer/Id"]
unique_name_in_owner = true
layout_mode = 2
size_flags_horizontal = 3
text_overrun_behavior = 3

[node name="Name" type="HBoxContainer" parent="MarginContainer/VBoxContainer"]
layout_mode = 2

[node name="Label" type="Label" parent="MarginContainer/VBoxContainer/Name"]
layout_mode = 2
text = "Name:"

[node name="NameLabel" type="Label" parent="MarginContainer/VBoxContainer/Name"]
unique_name_in_owner = true
layout_mode = 2
size_flags_horizontal = 3
text_overrun_behavior = 3

[node name="Title" type="HBoxContainer" parent="MarginContainer/VBoxContainer"]
layout_mode = 2

[node name="Label" type="Label" parent="MarginContainer/VBoxContainer/Title"]
layout_mode = 2
text = "Title:"

[node name="TitleLabel" type="Label" parent="MarginContainer/VBoxContainer/Title"]
unique_name_in_owner = true
layout_mode = 2

[node name="Status" type="HBoxContainer" parent="MarginContainer/VBoxContainer"]
layout_mode = 2

[node name="Label" type="Label" parent="MarginContainer/VBoxContainer/Status"]
layout_mode = 2
text = "Status:"

[node name="StatusLabel" type="Label" parent="MarginContainer/VBoxContainer/Status"]
unique_name_in_owner = true
layout_mode = 2

[node name="Level" type="HBoxContainer" parent="MarginContainer/VBoxContainer"]
layout_mode = 2

[node name="Label" type="Label" parent="MarginContainer/VBoxContainer/Level"]
layout_mode = 2
text = "Level:"

[node name="LevelLabel" type="Label" parent="MarginContainer/VBoxContainer/Level"]
unique_name_in_owner = true
layout_mode = 2

[node name="Xp" type="HBoxContainer" parent="MarginContainer/VBoxContainer"]
layout_mode = 2

[node name="Label" type="Label" parent="MarginContainer/VBoxContainer/Xp"]
layout_mode = 2
text = "XP:"

[node name="XpLabel" type="Label" parent="MarginContainer/VBoxContainer/Xp"]
unique_name_in_owner = true
layout_mode = 2

[node name="HSeparator" type="HSeparator" parent="MarginContainer/VBoxContainer"]
layout_mode = 2

[node name="Compare" type="VBoxContainer" parent="MarginContainer/VBoxContainer"]
layout_mode = 2
theme_override_constants/separation = 25

[node name="CompareButton" type="Button" parent="MarginContainer/VBoxContainer/Compare"]
unique_name_in_owner = true
layout_mode = 2
theme = ExtResource("1_ylrpt")
text = "Compare"
text_overrun_behavior = 3

[node name="HSeparator2" type="HSeparator" parent="MarginContainer/VBoxContainer"]
visible = false
layout_mode = 2

[node name="Variants" type="VBoxContainer" parent="MarginContainer/VBoxContainer"]
visible = false
layout_mode = 2
theme_override_constants/separation = 25

[node name="TimeSpan" type="VBoxContainer" parent="MarginContainer/VBoxContainer/Variants"]
layout_mode = 2

[node name="Label" type="Label" parent="MarginContainer/VBoxContainer/Variants/TimeSpan"]
layout_mode = 2
text = "Time Span"

[node name="TimeSpan" type="OptionButton" parent="MarginContainer/VBoxContainer/Variants/TimeSpan"]
unique_name_in_owner = true
layout_mode = 2

[node name="Collection" type="VBoxContainer" parent="MarginContainer/VBoxContainer/Variants"]
layout_mode = 2

[node name="Label" type="Label" parent="MarginContainer/VBoxContainer/Variants/Collection"]
layout_mode = 2
text = "Collection"

[node name="Collection" type="OptionButton" parent="MarginContainer/VBoxContainer/Variants/Collection"]
unique_name_in_owner = true
layout_mode = 2

[node name="ShowVariant" type="Button" parent="MarginContainer/VBoxContainer/Variants"]
unique_name_in_owner = true
layout_mode = 2
theme = ExtResource("1_ylrpt")
disabled = true
text = "Show Leaderboard Variant"
text_overrun_behavior = 3
25 changes: 25 additions & 0 deletions plugin/demo/scenes/players/Players.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
extends Control

@onready var back_button: Button = %Back

@onready var friends_display: VBoxContainer = %FriendsDisplay

var _friends_cache: Array[PlayersClient.Player] = []
var _friend_display := preload("res://scenes/players/FriendDisplay.tscn")

func _ready() -> void:
if _friends_cache.is_empty():
PlayersClient.load_friends(10, true, true)
PlayersClient.friends_loaded.connect(
func cache_and_display(friends: Array[PlayersClient.Player]):
_friends_cache = friends
if not _friends_cache.is_empty() and friends_display.get_child_count() == 0:
for friend: PlayersClient.Player in _friends_cache:
var container := _friend_display.instantiate() as Control
container.friend = friend
friends_display.add_child(container)
)

back_button.pressed.connect(func():
get_tree().change_scene_to_file("res://scenes/MainMenu.tscn")
)
70 changes: 70 additions & 0 deletions plugin/demo/scenes/players/Players.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
[gd_scene load_steps=3 format=3 uid="uid://ewhiun7ljryy"]

[ext_resource type="Theme" uid="uid://bmm3mvq11y045" path="res://theme.tres" id="1_i7feq"]
[ext_resource type="Script" path="res://scenes/players/Players.gd" id="2_xda1v"]

[node name="Players" type="Control"]
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
theme = ExtResource("1_i7feq")
script = ExtResource("2_xda1v")

[node name="MarginContainer" type="MarginContainer" parent="."]
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
theme_override_constants/margin_left = 50
theme_override_constants/margin_top = 150
theme_override_constants/margin_right = 50
theme_override_constants/margin_bottom = 50

[node name="VBoxContainer" type="VBoxContainer" parent="MarginContainer"]
layout_mode = 2
theme_override_constants/separation = 50

[node name="NavBar" type="HBoxContainer" parent="MarginContainer/VBoxContainer"]
layout_mode = 2

[node name="Back" type="Button" parent="MarginContainer/VBoxContainer/NavBar"]
unique_name_in_owner = true
layout_mode = 2
theme = ExtResource("1_i7feq")
text = "Back"

[node name="ScrollContainer" type="ScrollContainer" parent="MarginContainer/VBoxContainer"]
layout_mode = 2
size_flags_vertical = 3
horizontal_scroll_mode = 0

[node name="VBoxContainer" type="VBoxContainer" parent="MarginContainer/VBoxContainer/ScrollContainer"]
layout_mode = 2
size_flags_horizontal = 3
size_flags_vertical = 3
theme_override_constants/separation = 25

[node name="ShowAchievements" type="Button" parent="MarginContainer/VBoxContainer/ScrollContainer/VBoxContainer"]
unique_name_in_owner = true
visible = false
custom_minimum_size = Vector2(500, 200)
layout_mode = 2
theme = ExtResource("1_i7feq")
text = "Show Achievements"

[node name="Label" type="Label" parent="MarginContainer/VBoxContainer/ScrollContainer/VBoxContainer"]
layout_mode = 2
text = "Friends"
horizontal_alignment = 1

[node name="FriendsDisplay" type="VBoxContainer" parent="MarginContainer/VBoxContainer/ScrollContainer/VBoxContainer"]
unique_name_in_owner = true
layout_mode = 2
size_flags_horizontal = 3
size_flags_vertical = 3
theme_override_constants/separation = 25
Loading

0 comments on commit 4f9d5ee

Please sign in to comment.