Skip to content

Commit

Permalink
Rename all Player related class names (new major version)
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 Oct 11, 2024
1 parent dd97d23 commit 054b1cb
Show file tree
Hide file tree
Showing 10 changed files with 54 additions and 43 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
## v2.0.0
### Rename all Player related class names
The Player namespace used in the `PlayersClient` autoload is a very common name for games of all sorts, so I renamed it to be `PlayGamesPlayer` instead. This is a new major version since it breaks backward compatibility, make sure to update your code if you were using a previous version of this plugin.

The GDScript classes and enums renamed are:

* `Player` class turned into `PlayGamesPlayer`
* `PlayerLevelInfo` class turned into `PlayGamesPlayerLevelInfo`
* `PlayerLevel` class turned into `PlayGamesPlayerLevel`
* `PlayerFriendStatus` enum turned into `PlayGamesPlayerFriendStatus`

## v1.8.3
### Return null when Snapshot is not found
Ass suggested by @TheSkyOne in [this issue](https://github.com/Iakobs/godot-play-game-services/issues/38), when calling to `SnapshotClient.load_game()` and the snapshot is not found, the `game_loaded` signal will now return a null, instead of not being emitted at all as before.
Expand Down
4 changes: 2 additions & 2 deletions plugin/demo/scenes/players/PlayerDisplay.gd
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ extends Control
@onready var compare_holder: VBoxContainer = %CompareHolder
@onready var compare_button: Button = %CompareButton

var player: PlayersClient.Player
var player: PlayersClient.PlayGamesPlayer
var is_comparable = false

func _ready() -> void:
Expand All @@ -31,7 +31,7 @@ func _set_up_display() -> void:
id_label.text = player.player_id
name_label.text = player.display_name
title_label.text = player.title
status_label.text = PlayersClient.PlayerFriendStatus.find_key(player.friend_status)
status_label.text = PlayersClient.PlayGamesPlayerFriendStatus.find_key(player.friend_status)
level_label.text = str(player.level_info.current_level.level_number)
xp_label.text = str(player.level_info.current_xp_total)
compare_holder.visible = is_comparable
Expand Down
12 changes: 6 additions & 6 deletions plugin/demo/scenes/players/Players.gd
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,30 @@ extends Control

@onready var friends_display: VBoxContainer = %FriendsDisplay

var _current_player: PlayersClient.Player
var _friends_cache: Array[PlayersClient.Player] = []
var _current_player: PlayersClient.PlayGamesPlayer
var _friends_cache: Array[PlayersClient.PlayGamesPlayer] = []
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):
PlayersClient.current_player_loaded.connect(func(current_player: PlayersClient.PlayGamesPlayer):
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(
func cache_and_display(friends: Array[PlayersClient.Player]):
func cache_and_display(friends: Array[PlayersClient.PlayGamesPlayer]):
_friends_cache = friends
if not _friends_cache.is_empty() and friends_display.get_child_count() == 0:
for friend: PlayersClient.Player in _friends_cache:
for friend: PlayersClient.PlayGamesPlayer in _friends_cache:
var container := _player_display.instantiate() as Control
container.player = friend
friends_display.add_child(container)
)
PlayersClient.player_searched.connect(func(player: PlayersClient.Player):
PlayersClient.player_searched.connect(func(player: PlayersClient.PlayGamesPlayer):
for child in search_display.get_children():
child.queue_free()
var container := _player_display.instantiate() as Control
Expand Down
2 changes: 1 addition & 1 deletion plugin/demo/scenes/snapshots/Snapshots.gd
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func _connect_save_game_data() -> void:
)
SnapshotsClient.game_loaded.connect(
func(snapshot: SnapshotsClient.Snapshot):
if snapshot == null:
if !snapshot:
print("Snapshot not found!")
return

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class Achievement:
var achievement_id: String ## The achievement id.
var achievement_name: String ## The achievement name.
var description: String ## The description of the achievement.
var player: PlayersClient.Player ## The player associated to this achievement.
var player: PlayersClient.PlayGamesPlayer ## The player associated to this achievement.
var type: Type ## The achievement type.
var state: State ## The achievement state.
var xp_value: int ## The XP value of this achievement.
Expand Down Expand Up @@ -140,7 +140,7 @@ class Achievement:
if dictionary.has("achievementId"): achievement_id = dictionary.achievementId
if dictionary.has("name"): achievement_name = dictionary.name
if dictionary.has("description"): description = dictionary.description
if dictionary.has("player"): player = PlayersClient.Player.new(dictionary.player)
if dictionary.has("player"): player = PlayersClient.PlayGamesPlayer.new(dictionary.player)
if dictionary.has("type"): type = Type[dictionary.type]
if dictionary.has("state"): state = State[dictionary.state]
if dictionary.has("xpValue"): xp_value = dictionary.xpValue
Expand Down
4 changes: 2 additions & 2 deletions plugin/export_scripts_template/autoloads/events_client.gd
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class PlayGamesEvent:
var formatted_value: String ## The sum of increments have been made to this event (formatted for the user's locale).
var icon_image_uri: String ## The URI to the event's image icon.
var name: String ## The name of this event.
var player: PlayersClient.Player ## The player information associated with this event.
var player: PlayersClient.PlayGamesPlayer ## The player information associated with this event.
var value: int ## The number of increments this user has made to this event.
var is_visible: bool ## Whether the event should be displayed to the user in any event related UIs.

Expand All @@ -80,7 +80,7 @@ class PlayGamesEvent:
if dictionary.has("formattedValue"): formatted_value = dictionary.formattedValue
if dictionary.has("iconImageUri"): icon_image_uri = dictionary.iconImageUri
if dictionary.has("name"): name = dictionary.name
if dictionary.has("player"): player = PlayersClient.Player.new(dictionary.player)
if dictionary.has("player"): player = PlayersClient.PlayGamesPlayer.new(dictionary.player)
if dictionary.has("value"): value = dictionary.value
if dictionary.has("isVisible"): is_visible = dictionary.isVisible

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ class Score:
var display_score: String ## Formatted string for the score of the player.
var rank: int ## Rank of the player.
var raw_score: int ## Raw score of the player.
var score_holder: PlayersClient.Player ## The player object who holds the score.
var score_holder: PlayersClient.PlayGamesPlayer ## The player object who holds the score.
var score_holder_display_name: String ## Formatted string for the name of the player.
var score_holder_hi_res_image_uri: String ## Hi-res image of the player.
var score_holder_icon_image_uri: String ## Icon image of the player.
Expand All @@ -258,7 +258,7 @@ class Score:
if dictionary.has("displayScore"): display_score = dictionary.displayScore
if dictionary.has("rank"): rank = dictionary.rank
if dictionary.has("rawScore"): raw_score = dictionary.rawScore
if dictionary.has("scoreHolder"): score_holder = PlayersClient.Player.new(dictionary.scoreHolder)
if dictionary.has("scoreHolder"): score_holder = PlayersClient.PlayGamesPlayer.new(dictionary.scoreHolder)
if dictionary.has("scoreHolderDisplayName"): score_holder_display_name = dictionary.scoreHolderDisplayName
if dictionary.has("scoreHolderHiResImageUri"): score_holder_hi_res_image_uri = dictionary.scoreHolderHiResImageUri
if dictionary.has("scoreHolderIconImageUri"): score_holder_icon_image_uri = dictionary.scoreHolderIconImageUri
Expand Down
50 changes: 25 additions & 25 deletions plugin/export_scripts_template/autoloads/players_client.gd
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@ extends Node
## [br]
## [param friends]: An array containing the friends for the current player.
## The array will be empty if there was an error loading the friends list.
signal friends_loaded(friends: Array[Player])
signal friends_loaded(friends: Array[PlayGamesPlayer])

## Signal emitted after selecting a player in the search window opened by the
## [method search_player] method.[br]
## [br]
## [param player]: The selected player.
signal player_searched(player: Player)
signal player_searched(player: PlayGamesPlayer)

## 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)
signal current_player_loaded(current_player: PlayGamesPlayer)

## Friends list visibility statuses.
enum FriendsListVisibilityStatus {
Expand All @@ -31,7 +31,7 @@ enum FriendsListVisibilityStatus {
}

## This player's friend status relative to the currently signed in player.
enum PlayerFriendStatus {
enum PlayGamesPlayerFriendStatus {
FRIEND = 4, ## The currently signed in player and this player are friends.
NO_RELATIONSHIP = 0, ## The currently signed in player is not a friend of this player.
UNKNOWN = -1 ## The currently signed in player's friend status with this player is unknown.
Expand All @@ -44,19 +44,19 @@ func _connect_signals() -> void:
if GodotPlayGameServices.android_plugin:
GodotPlayGameServices.android_plugin.friendsLoaded.connect(func(friends_json: String):
var safe_array := GodotPlayGameServices.json_marshaller.safe_parse_array(friends_json)
var friends: Array[Player] = []
var friends: Array[PlayGamesPlayer] = []
for dictionary: Dictionary in safe_array:
friends.append(Player.new(dictionary))
friends.append(PlayGamesPlayer.new(dictionary))

friends_loaded.emit(friends)
)
GodotPlayGameServices.android_plugin.playerSearched.connect(func(friend_json: String):
var safe_dictionary := GodotPlayGameServices.json_marshaller.safe_parse_dictionary(friend_json)
player_searched.emit(Player.new(safe_dictionary))
player_searched.emit(PlayGamesPlayer.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))
current_player_loaded.emit(PlayGamesPlayer.new(safe_dictionary))
)

## Use this method and subscribe to the emitted signal to receive the list of friends
Expand Down Expand Up @@ -132,33 +132,33 @@ func load_current_player(force_reload: bool) -> void:
if GodotPlayGameServices.android_plugin:
GodotPlayGameServices.android_plugin.loadCurrentPlayer(force_reload)

## Player information.
class Player:
## PlayGamesPlayer information.
class PlayGamesPlayer:
var banner_image_landscape_uri: String ## Banner image of the player in landscape.
var banner_image_portrait_uri: String ## Banner image of the player in portrait.
var friends_list_visibility_status: FriendsListVisibilityStatus ## Visibility status of this player's friend list.
var display_name: String ## The display name of the player.
var hi_res_image_uri: String ## The hi-res image of the player.
var icon_image_uri: String ## The icon image of the player.
var level_info: PlayerLevelInfo ## Information about the player level.
var level_info: PlayGamesPlayerLevelInfo ## Information about the player level.
var player_id: String ## The player id.
var friend_status: PlayerFriendStatus ## The friend status of this player with the signed in player.
var friend_status: PlayGamesPlayerFriendStatus ## The friend status of this player with the signed in player.
var retrieved_timestamp: int ## The timestamp at which this player record was last updated locally.
var title: String ## The title of the player.
var has_hi_res_image: bool ## Whether this player has a hi-res profile image to display.
var has_icon_image: bool ## Whether this player has an icon-size profile image to display.

## Constructor that creates a Player from a [Dictionary] containing the properties.
## Constructor that creates a PlayGamesPlayer from a [Dictionary] containing the properties.
func _init(dictionary: Dictionary) -> void:
if dictionary.has("bannerImageLandscapeUri"): banner_image_landscape_uri = dictionary.bannerImageLandscapeUri
if dictionary.has("bannerImagePortraitUri"): banner_image_portrait_uri = dictionary.bannerImagePortraitUri
if dictionary.has("friendsListVisibilityStatus"): friends_list_visibility_status = FriendsListVisibilityStatus.get(dictionary.friendsListVisibilityStatus)
if dictionary.has("displayName"): display_name = dictionary.displayName
if dictionary.has("hiResImageUri"): hi_res_image_uri = dictionary.hiResImageUri
if dictionary.has("iconImageUri"): icon_image_uri = dictionary.iconImageUri
if dictionary.has("levelInfo"): level_info = PlayerLevelInfo.new(dictionary.levelInfo)
if dictionary.has("levelInfo"): level_info = PlayGamesPlayerLevelInfo.new(dictionary.levelInfo)
if dictionary.has("playerId"): player_id = dictionary.playerId
if dictionary.has("friendStatus"): friend_status = PlayerFriendStatus.get(dictionary.friendStatus)
if dictionary.has("friendStatus"): friend_status = PlayGamesPlayerFriendStatus.get(dictionary.friendStatus)
if dictionary.has("retrievedTimestamp"): retrieved_timestamp = dictionary.retrievedTimestamp
if dictionary.has("title"): title = dictionary.title
if dictionary.has("hasHiResImage"): has_hi_res_image = dictionary.hasHiResImage
Expand All @@ -175,7 +175,7 @@ class Player:
result.append("icon_image_uri: %s" % icon_image_uri)
result.append("level_info: {%s}" % str(level_info))
result.append("player_id: %s" % player_id)
result.append("friend_status: %s" % PlayerFriendStatus.find_key(friend_status))
result.append("friend_status: %s" % PlayGamesPlayerFriendStatus.find_key(friend_status))
result.append("retrieved_timestamp: %s" % retrieved_timestamp)
result.append("title: %s" % title)
result.append("has_hi_res_image: %s" % has_hi_res_image)
Expand All @@ -184,19 +184,19 @@ class Player:
return ", ".join(result)

## The current level information of a player.
class PlayerLevelInfo:
var current_level: PlayerLevel ## The player's current level object.
class PlayGamesPlayerLevelInfo:
var current_level: PlayGamesPlayerLevel ## The player's current level object.
var current_xp_total: int ## The player's current XP value.
var last_level_up_timestamp: int ## The timestamp of the player's last level-up.
var next_level: PlayerLevel ## The player's next level object.
var is_max_level: bool ## True if the player reached the maximum level ([member PlayerLevelInfo.current_level] is the same as [member PlayerLevelInfo.next_level]).
var next_level: PlayGamesPlayerLevel ## The player's next level object.
var is_max_level: bool ## True if the player reached the maximum level ([member PlayGamesPlayerLevelInfo.current_level] is the same as [member PlayGamesPlayerLevelInfo.next_level]).

## Constructor that creates a PlayerLevelInfo from a [Dictionary] containing the properties.
## Constructor that creates a PlayGamesPlayerLevelInfo from a [Dictionary] containing the properties.
func _init(dictionary: Dictionary) -> void:
if dictionary.has("currentLevel"): current_level = PlayerLevel.new(dictionary.currentLevel)
if dictionary.has("currentLevel"): current_level = PlayGamesPlayerLevel.new(dictionary.currentLevel)
if dictionary.has("currentXpTotal"): current_xp_total = dictionary.currentXpTotal
if dictionary.has("lastLevelUpTimestamp"): last_level_up_timestamp = dictionary.lastLevelUpTimestamp
if dictionary.has("nextLevel"): next_level = PlayerLevel.new(dictionary.nextLevel)
if dictionary.has("nextLevel"): next_level = PlayGamesPlayerLevel.new(dictionary.nextLevel)
if dictionary.has("isMaxLevel"): is_max_level = dictionary.isMaxLevel

func _to_string() -> String:
Expand All @@ -211,12 +211,12 @@ class PlayerLevelInfo:
return ", ".join(result)

## The level of a player.
class PlayerLevel:
class PlayGamesPlayerLevel:
var level_number: int ## The number for this level.
var max_xp: int ## The maximum XP value represented by this level, exclusive.
var min_xp: int ## The minimum XP value needed to attain this level, inclusive.

## Constructor that creates a PlayerLevel from a [Dictionary] containing the properties.
## Constructor that creates a PlayGamesPlayerLevel from a [Dictionary] containing the properties.
func _init(dictionary: Dictionary) -> void:
if dictionary.has("levelNumber"): level_number = dictionary.levelNumber
if dictionary.has("maxXp"): max_xp = dictionary.maxXp
Expand Down
4 changes: 2 additions & 2 deletions plugin/export_scripts_template/autoloads/snapshots_client.gd
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ class SnapshotMetadata:
var last_modified_timestamp: int ## The last time this snapshot was modified, in millis since epoch.
var played_time: int ## The played time of this snapshot in milliseconds.
var has_change_pending: bool ## Indicates whether or not this snapshot has any changes pending that have not been uploaded to the server.
var owner: PlayersClient.Player ## The player that owns this snapshot.
var owner: PlayersClient.PlayGamesPlayer ## The player that owns this snapshot.
var game: GameInfo ## The game information associated with this snapshot.
var device_name: String ## The name of the device that wrote this snapshot, if known.
var cover_image_uri: String ## The snapshot cover image.
Expand All @@ -185,7 +185,7 @@ class SnapshotMetadata:
if dictionary.has("lastModifiedTimestamp"): last_modified_timestamp = dictionary.lastModifiedTimestamp
if dictionary.has("playedTime"): played_time = dictionary.playedTime
if dictionary.has("hasChangePending"): has_change_pending = dictionary.hasChangePending
if dictionary.has("owner"): owner = PlayersClient.Player.new(dictionary.owner)
if dictionary.has("owner"): owner = PlayersClient.PlayGamesPlayer.new(dictionary.owner)
if dictionary.has("game"): game = GameInfo.new(dictionary.game)
if dictionary.has("deviceName"): device_name = dictionary.deviceName
if dictionary.has("coverImageUri"): cover_image_uri = dictionary.coverImageUri
Expand Down
2 changes: 1 addition & 1 deletion plugin/export_scripts_template/plugin.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
name="GodotPlayGameServices"
description="A Godot 4.3 plugin for Google Play Game Services"
author="Jacob Ibáñez Sánchez"
version="1.8.3"
version="2.0.0"
script="export_plugin.gd"

0 comments on commit 054b1cb

Please sign in to comment.