Skip to content

MizunagiKB/PlayFab_GDScriptSdk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

48 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PlayFab_GDScriptSdk README

About

This program is an unofficial implementation for using Microsoft PlayFab from the GDScript(Godot Engine).

Caution
Currently, only Godot 3.5 or higher is supported.
Godot 4 is not supported.

This program can be used as-is by incorporating it into a Godot project.

This program is automatically generated based on the API_Specs published by PlayFab.

If you want to customize the generated content, you can use the following to generate it on your own.

Note
See the README.md at PlayFab_GDScriptTemplate for easy generation instructions.

Build

cd ./work
conda create -n pyenv310_gdscript_sdk python=3.10
conda activate pyenv310_gdscript_sdk
pip install -r requirements.txt
scons

Usage

  1. Copy PlayFabSDK folder to GodotEngine project folder.

  2. Added res://PlayFabSDK/PlayFab.gd to AutoLoad under the name PlayFab.

  3. Added res://PlayFabSDK/PlayFabSettings.gd to AutoLoad under the name PlayFabSettings.

  4. Create testTitleData.json to GodotEngine project folder.

Caution
  • The testTitleData.json is intended for testing purposes.

  • The developerSecretKey is intended for use by the server. Please ensure that it is not included in programs intended for clients.

{
    "TitleId": "*****",
    "developerSecretKey": "********",
    "userEmail": "****@****.***"
}

Or, it can be embedded directly in the program as follows.

PlayFabSettings.TitleId = "00000"
PlayFabSettings.DeveloperSecretKey = "XXXXXXXX"

API Call

The API is called by PlayFab . {{category}} . {{API name}}.

To call the RegisterPlayFabUser function, write as follows.

PlayFab.Client.RegisterPlayFabUser(...)

The parameters required to call the API are specified in the Dictionary.

var dict_request = {
    "TitleId": "00000",
    "Username": "USERNAME",
    "Password": "********"
}

PlayFab.Client.LoginWithPlayFab(dict_request)

If you do not want to deal directly with Dictionary, you can use the data model.

var o_request := PlayFab.ClientDataModels.PFLoginWithPlayFabRequest.new()
o_request.TitleId = "00000"
o_request.Username = "USERNAME"
o_request.Password = "********"


PlayFab.Client.LoginWithPlayFab(o_request.get_dict())

Result

Use funcref to get the results.

# callback function
func _request_completed(
    h_request: int,
    response_code: int,
    headers,
    json_parse_result: JSONParseResult
    ):
    if json_parse_result.error == OK:
        # DataModel can also be used.
        if json_parse_result.result.code == 200:
            var res := PlayFab.ClientDataModels.PFLoginResult.new(json_parse_result.result.data)
        else:
            var res := PlayFab.ErrorDataModels.PFApiErrorWrapper.new(json_parse_result.result)

# on function call
func _on_btn_login_pressed():

    var o_request := PlayFab.ClientDataModels.PFLoginWithPlayFabRequest.new()
    o_request.TitleId = "00000"
    o_request.Username = "USERNAME"
    o_request.Password = "********"

    PlayFab.Client.RegisterPlayFabUser(
        o_request.get_dict(),
        funcref(self, "_request_completed")
    )

Useful functions

PlayFab.is_valid()

Check to see if you can call PlayFab from GDScript.

PlayFab.reset()

Resets the current state and returns it to its initial state.<br>(Any information or requests in communication will be discarded.)

PlayFab.get_status()

Returns the current communication status. HTTPClient.get_status information can be obtained from the data.

PlayFab.status_ntoa()

get_status the information into readable information.

PlayFab.request_queue_size()

Returns the number of waiting requests.

Operating Specifications

DataModel has not been fully tested.
The DateTime type is treated as a string.

Be careful when handling DateTime as there is no correct DateTime to handle as JSON.

Names are different in some places to prevent reserved words from colliding.
  • The property named OS is renamed OperatingSystem.

  • All data model names are prefixed with PF.
    ex) GetFileMetadata to PFGetFileMetadata

API calls are serialized.

API calls are made in the order in which they are registered and are not processed in parallel.

Multiple accounts cannot be used at the same time.

Only one person can log in within a single program. This is because only one EntityToken or ClientSessionTicket is stored in PlayFabSettings.gd.

PlayFab API Reference

See below for specific uses of the API.

Releases

No releases published

Packages

No packages published