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. |
cd ./work
conda create -n pyenv310_gdscript_sdk python=3.10
conda activate pyenv310_gdscript_sdk
pip install -r requirements.txt
scons
-
Copy PlayFabSDK folder to GodotEngine project folder.
-
Added res://PlayFabSDK/PlayFab.gd to AutoLoad under the name PlayFab.
-
Added res://PlayFabSDK/PlayFabSettings.gd to AutoLoad under the name PlayFabSettings.
-
Create testTitleData.json to GodotEngine project folder.
Caution
|
|
{
"TitleId": "*****",
"developerSecretKey": "********",
"userEmail": "****@****.***"
}
Or, it can be embedded directly in the program as follows.
PlayFabSettings.TitleId = "00000"
PlayFabSettings.DeveloperSecretKey = "XXXXXXXX"
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())
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")
)
- 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.
- 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.
See below for specific uses of the API.