Skip to content

Commit

Permalink
Add load current player method to demo project
Browse files Browse the repository at this point in the history
Signed-off-by: Jacob Ibáñez Sánchez <jacobibanez@jacobibanez.com>
  • Loading branch information
Iakobs committed Dec 20, 2023
1 parent f311286 commit fd859db
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
10 changes: 10 additions & 0 deletions plugin/demo/scenes/players/Players.gd
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,22 @@ extends Control
@onready var search_button: Button = %SearchButton
@onready var search_display: VBoxContainer = %SearchDisplay

@onready var current_player_display: VBoxContainer = %CurrentPlayerDisplay

@onready var friends_display: VBoxContainer = %FriendsDisplay

var _current_player: PlayersClient.Player
var _friends_cache: Array[PlayersClient.Player] = []
var _player_display := preload("res://scenes/players/PlayerDisplay.tscn")

func _ready() -> void:
if not _current_player:
PlayersClient.load_current_player(true)
PlayersClient.current_player_loaded.connect(func(current_player: PlayersClient.Player):
var container := _player_display.instantiate() as Control
container.player = current_player
current_player_display.add_child(container)
)
if _friends_cache.is_empty():
PlayersClient.load_friends(10, true, true)
PlayersClient.friends_loaded.connect(
Expand Down
17 changes: 17 additions & 0 deletions plugin/demo/scenes/players/Players.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,23 @@ layout_mode = 2
[node name="HSeparator" type="HSeparator" parent="MarginContainer/VBoxContainer/ScrollContainer/ScrollChild"]
layout_mode = 2

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

[node name="Label" type="Label" parent="MarginContainer/VBoxContainer/ScrollContainer/ScrollChild/CurrentPlayer"]
layout_mode = 2
text = "Current Player"
horizontal_alignment = 1

[node name="CurrentPlayerDisplay" type="VBoxContainer" parent="MarginContainer/VBoxContainer/ScrollContainer/ScrollChild/CurrentPlayer"]
unique_name_in_owner = true
layout_mode = 2
theme_override_constants/separation = 25

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

[node name="Friends" type="VBoxContainer" parent="MarginContainer/VBoxContainer/ScrollContainer/ScrollChild"]
layout_mode = 2
theme_override_constants/separation = 25
Expand Down
23 changes: 23 additions & 0 deletions plugin/export_scripts_template/autoloads/players_client.gd
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ signal friends_loaded(friends: Array[Player])
## [param player]: The selected player.
signal player_searched(player: Player)

## Signal emitted after calling the [method load_current_player] method.[br]
## [br]
## [param current_player]: The currently signed-in player, or null if there where
## any errors loading the player.
signal current_player_loaded(current_player: Player)

## Friends list visibility statuses.
enum FriendsListVisibilityStatus {
FEATURE_UNAVAILABLE = 3, ## The friends list is currently unavailable for the game.
Expand Down Expand Up @@ -48,6 +54,10 @@ func _connect_signals() -> void:
var safe_dictionary := GodotPlayGameServices.json_marshaller.safe_parse_dictionary(friend_json)
player_searched.emit(Player.new(safe_dictionary))
)
GodotPlayGameServices.android_plugin.currentPlayerLoaded.connect(func(friend_json: String):
var safe_dictionary := GodotPlayGameServices.json_marshaller.safe_parse_dictionary(friend_json)
current_player_loaded.emit(Player.new(safe_dictionary))
)

## Use this method and subscribe to the emitted signal to receive the list of friends
## for the current player.[br]
Expand Down Expand Up @@ -109,6 +119,19 @@ func search_player() -> void:
if GodotPlayGameServices.android_plugin:
GodotPlayGameServices.android_plugin.searchPlayer()

## Use this method and subscribe to the emitted signal to receive the currently
## signed in player.[br]
## [br]
## The method emits the [signal current_player_loaded] signal.[br]
## [br]
## [param force_reload]: If true, this call will clear any locally cached
## data and attempt to fetch the latest data from the server. Send it set to [code]true[/code]
## the first time, and [code]false[/code] in subsequent calls, or when you want
## to clear the cache.
func load_current_player(force_reload: bool) -> void:
if GodotPlayGameServices.android_plugin:
GodotPlayGameServices.android_plugin.loadCurrentPlayer(force_reload)

## Player information.
class Player:
var banner_image_landscape_uri: String ## Banner image of the player in landscape.
Expand Down

0 comments on commit fd859db

Please sign in to comment.