Skip to content

Player Information

Kopfenheim edited this page Feb 1, 2018 · 2 revisions

Functions and callbacks for obtaining the currently signed in player's information from Google Play Game Services.

Obtaining the player's profile picture

One of the limitations for an Android module for Godot is that basic variable types such as int, boolean, String, etc. are the only types of data that can be passed between the module and the GDScript. This is because that Godot's building system seems to be set up, any Android module can't seem to natively understand what a Vector2, Texture, or a Node is. (There is probably a way to pass in such higher level objects, but I have been unable to figure it out so far)

So, in order to let you use the player's icon that the player has setup in their Play Games account, the module:

  • Asynchronously downloads the player's icon from Google Play Game Services as an Android Bitmap
  • Stores the Bitmap to the app's local storage location as a .png file
  • Sends a callback to your scipt for player sign in and info (i.e. script with the first instanceID passed to init() through instanceIDsStr when initializing the module)
  • The callback includes information about the name of the image and the subfolder in which the image is located inside the user:// directory (see the callback details for _on_play_game_services_player_icon_requested below)

The location in which the module stores the .png file for the player's icon is a subfolder of the user:// directory that can be used in GDScript to access the app's designated local storage location. (Fun fact: On Android, the user:// directory is located at /data/user/0/{your app's package name}/files/)

To easily load the image from storage and use it as a TextureImage (which can be applied as a Texture in Godot), you can create the following function in your script:

func getImageTexture(imageLoc):
	var imgTex = ImageTexture.new()
	imgTex.load(imageLoc)
	return imgTex

and use it within the callbacks as:

func _on_play_game_services_player_icon_requested(id, folder, fileName):
	var fileLoc = "user://" + folder + "/" + fileName
	var texture = getImageTexture(fileLoc)

Functions

  • getCurrentPlayerID()

    Get the unique google ID that identifies the player that is currently signed in to your game
    • Parameters
      • None
    • Returns
      • String A unique google ID for the currently signed in player. This ID remains consistent across all sessions. If it is unavailable then an empty string will be returned
  • getCurrentPlayerDisplayName()

    Get the display name of the player that is currently signed in to your game
    • Parameters
      • None
    • Returns
      • String The display name of the signed in player. If it is unavailable then an empty string will be returned
  • getCurrentPlayerTitle()

    Get the title of the player that is currently signed in to your game
    • Parameters
      • None
    • Returns
      • String The title of the signed in player. If it is unavailable then an empty string will be returned
  • getCurrentPlayerLevel()

    Get the level value player that is currently signed in to your game. This is the level value that appears in the player's profile in the Play Games app
    • Parameters
      • None
    • Returns
      • int The level of the signed in player. If it is unavailable then value of 0 will be returned
  • getCurrentPlayerXP()

    Get the current XP value of the player that is currently signed in to your game. This is the XP value that appears in the player's profile in the Play Games app
    • Parameters
      • None
    • Returns
      • String The XP of the signed in player. This value is actually a long in Android but GDScript doesn't seem to understand what a long is. So, it is converted to a string inside the module just in case the value is somehow larger than the value that GDScript's int can handle. So, you will have to handle the conversion (if needed) on your end.
  • getCurrentPlayerMaxXP()

    Get the maximum XP value represented by the current level of the player (exclusive). This is the XP value that appears in the player's profile in the Play Games app
    • Parameters
      • None
    • Returns
      • String The max XP of the current level of the signed in player. This value is actually a long in Android but GDScript doesn't seem to understand what a long is. So, it is converted to a string inside the module just in case the value is somehow larger than the value that GDScript's int can handle. So, you will have to handle the conversion (if needed) on your end.
  • getCurrentPlayerMinXP()

    Get the minimum XP value needed to attain the current level of the player (inclusive). This is the XP value that appears in the player's profile in the Play Games app
    • Parameters
      • None
    • Returns
      • String The min XP needed to obtain the current level of the signed in player. This value is actually a long in Android but GDScript doesn't seem to understand what a long is. So, it is converted to a string inside the module just in case the value is somehow larger than the value that GDScript's int can handle. So, you will have to handle the conversion (if needed) on your end.
  • requestCurrentPlayerIcon(boolean hiRes)

    Start the asynchronous process of downloading the currently signed inplayer's icon from Google Play Game Services and saving it in the app's local storage.
    • Parameters
      • hiRes: If it is true, then the module will try to download a high-resolution version of the currently signed in player's icon if available or a standard resolution icon if hi-res icon is unavailable. If it is false then the module tries to download the standard resolution icon.
    • Returns
      • boolean It is true if an icon is available for download for the player and the process was started successfully. It is false otherwise.
  • requestCurrentPlayerBanner(boolean portrait)

    Start the asynchronous process of downloading the currently signed inplayer's banner image from Google Play Game Services and saving it in the app's local storage.
    • Parameters
      • portrait: If it is true, then the module will try to download the portrait banner for the currently signed in player. If it is false then the module tries to download the landscape banner.
    • Returns
      • boolean It is true if a banner is available for download for the player and the process was started successfully. It is false otherwise.

Callbacks

Uses the first instance ID passed to init() through instanceIDsStr when initializing the module (i.e. {id for player sign in and info script})

  • _on_play_game_services_player_icon_requested(playerID, folder, fileName)

    Called when the player's icon was successfully loaded and saved to the app's local storage. See the section about "Obtaining the player's profile picture" above for some more info about how to use data within the parameters.
    • String playerID: The unique google ID of currently signed in player for whom the icon was loaded
    • String folder: The subfolder within the user:// directory of Godot within which the image is located
    • String fileName: The name of the .png image
  • _on_play_game_services_player_banner_requested(playerID, folder, fileName)

    Called when the player's banner was successfully loaded and saved to the app's local storage. See the section about "Obtaining the player's profile picture" above for some more info about how to use data within the parameters.
    • String playerID: The unique google ID of currently signed in player for whom the icon was loaded
    • String folder: The subfolder within the user:// directory of Godot within which the image is located
    • String fileName: The name of the .png image