diff --git a/CHANGELOG.md b/CHANGELOG.md index c89608d..875a78a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/plugin/demo/scenes/players/PlayerDisplay.gd b/plugin/demo/scenes/players/PlayerDisplay.gd index 8ad4f88..837c97d 100644 --- a/plugin/demo/scenes/players/PlayerDisplay.gd +++ b/plugin/demo/scenes/players/PlayerDisplay.gd @@ -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: @@ -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 diff --git a/plugin/demo/scenes/players/Players.gd b/plugin/demo/scenes/players/Players.gd index 91a7e02..83ed503 100644 --- a/plugin/demo/scenes/players/Players.gd +++ b/plugin/demo/scenes/players/Players.gd @@ -9,14 +9,14 @@ 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) @@ -24,15 +24,15 @@ 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]): + 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 diff --git a/plugin/demo/scenes/snapshots/Snapshots.gd b/plugin/demo/scenes/snapshots/Snapshots.gd index 2352a00..f23a04a 100644 --- a/plugin/demo/scenes/snapshots/Snapshots.gd +++ b/plugin/demo/scenes/snapshots/Snapshots.gd @@ -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 diff --git a/plugin/export_scripts_template/autoloads/achievements_client.gd b/plugin/export_scripts_template/autoloads/achievements_client.gd index 80b45aa..1b8a50b 100644 --- a/plugin/export_scripts_template/autoloads/achievements_client.gd +++ b/plugin/export_scripts_template/autoloads/achievements_client.gd @@ -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. @@ -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 diff --git a/plugin/export_scripts_template/autoloads/events_client.gd b/plugin/export_scripts_template/autoloads/events_client.gd index 355886f..8cb8c59 100644 --- a/plugin/export_scripts_template/autoloads/events_client.gd +++ b/plugin/export_scripts_template/autoloads/events_client.gd @@ -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. @@ -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 diff --git a/plugin/export_scripts_template/autoloads/leaderboards_client.gd b/plugin/export_scripts_template/autoloads/leaderboards_client.gd index 08cd664..4e4af0b 100644 --- a/plugin/export_scripts_template/autoloads/leaderboards_client.gd +++ b/plugin/export_scripts_template/autoloads/leaderboards_client.gd @@ -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. @@ -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 diff --git a/plugin/export_scripts_template/autoloads/players_client.gd b/plugin/export_scripts_template/autoloads/players_client.gd index f957df1..7eb7cd5 100644 --- a/plugin/export_scripts_template/autoloads/players_client.gd +++ b/plugin/export_scripts_template/autoloads/players_client.gd @@ -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 { @@ -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. @@ -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 @@ -132,23 +132,23 @@ 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 @@ -156,9 +156,9 @@ class Player: 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 @@ -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) @@ -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: @@ -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 diff --git a/plugin/export_scripts_template/autoloads/snapshots_client.gd b/plugin/export_scripts_template/autoloads/snapshots_client.gd index 6faaad3..9ef8fdb 100644 --- a/plugin/export_scripts_template/autoloads/snapshots_client.gd +++ b/plugin/export_scripts_template/autoloads/snapshots_client.gd @@ -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. @@ -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 diff --git a/plugin/export_scripts_template/plugin.cfg b/plugin/export_scripts_template/plugin.cfg index bf4ae5b..8429339 100644 --- a/plugin/export_scripts_template/plugin.cfg +++ b/plugin/export_scripts_template/plugin.cfg @@ -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"