-
Notifications
You must be signed in to change notification settings - Fork 25
Godot 4 AWS Plugin v 1.0.0 #66
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
timjbruce
wants to merge
3
commits into
aws-solutions-library-samples:main
Choose a base branch
from
timjbruce:GodotPlugin
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
GodotSample/BackendFeatures/AmazonGameLiftIntegration/AmazonGameLiftIntegration.gd.uid
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
uid://bj1uupijq8a0p |
16 changes: 12 additions & 4 deletions
16
GodotSample/BackendFeatures/AmazonGameLiftIntegration/AmazonGameLiftIntegration.tscn
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,16 @@ | ||
[gd_scene load_steps=2 format=3 uid="uid://d2rykx55ylfax"] | ||
[gd_scene load_steps=4 format=3 uid="uid://d2rykx55ylfax"] | ||
|
||
[ext_resource type="Script" path="res://BackendFeatures/AmazonGameLiftIntegration/AmazonGameLiftIntegration.gd" id="1_f5d5y"] | ||
[ext_resource type="Script" uid="uid://bj1uupijq8a0p" path="res://BackendFeatures/AmazonGameLiftIntegration/AmazonGameLiftIntegration.gd" id="1_f5d5y"] | ||
[ext_resource type="Script" uid="uid://dxp7lgvaxrjry" path="res://addons/AWSGameSDK/scripts/AWSAuthorization.gd" id="2_6och4"] | ||
[ext_resource type="Script" uid="uid://c1iyo651ktydf" path="res://addons/AWSGameSDK/scripts/AWSBackend.gd" id="3_tqorc"] | ||
|
||
[node name="Node2D" type="Node2D"] | ||
|
||
[node name="Test" type="Node" parent="."] | ||
script = ExtResource("1_f5d5y") | ||
|
||
[node name="AWSGameSDKAuth" type="Node" parent="."] | ||
script = ExtResource("2_6och4") | ||
metadata/_custom_type_script = "uid://dxp7lgvaxrjry" | ||
|
||
[node name="AWSGameSDKBackend" type="Node" parent="."] | ||
script = ExtResource("3_tqorc") | ||
metadata/_custom_type_script = "uid://c1iyo651ktydf" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,48 +2,170 @@ | |
|
||
The AWS Game Backend Framework Godot 4 SDK provides integrations to the custom identity component, managed refreshing of access tokens, helper methods for calling custom backend features, and samples for integrating with different game platforms. | ||
|
||
# SDK Overview | ||
# SDK Overview - Now a Godot Plugin | ||
|
||
## Initializing the SDK | ||
The AWS Game SDK has been updated to now be installed and used as a plugin in Godot 4.x. | ||
|
||
The AWS Game SDK has to be configured in your Godot 4 project in _Project Settings -> Autoload_ with the name _AwsGameSdk_. | ||
To begin using the plugin, copy the ./addons/AWSGameSDK directory to your projects ./addons directory. It should appear as it does in the picture below. | ||
|
||
The Initializing and accessing the AWS Game SDK within Godot 4 (see the Godot 4 Integration Samples for sample code): | ||
 | ||
|
||
Next, go to Project -> Project Settings... from your menu and enable the AWS Games SDK plugin by checking the checkbox. | ||
|
||
 | ||
|
||
## Adding nodes for the AWS for Games SDK to your scenes | ||
|
||
The AWS Game SDK contains two components that can be added to your projects. These are `AWSGameSDKAuth` and `AWSGameSDKBackend`. The AWSGameSDKAuth component allows you to login as guest, refresh your access token, and link accounts to Facebook, Apple, Google Play, and Steam via an API endpoint. The AWSGameSDKBackend component allows you to make calls to a backend endpoint to save and retrieve player data. You can add the necessary nodes to an appropriate scene for your project. The AWSGameSDKBackend requires the AWSGameSDKAuth component, as access tokens are required to save and retrieve data. These components can be added by adding child nodes to your scene. | ||
|
||
 | ||
|
||
Once added, your scene tree should look similar to this. | ||
|
||
 | ||
|
||
The plugin also uses signals. This removes the need to register callbacks and you can setup appropriate listeners to features enabled via the plugin. | ||
|
||
## Initializing the SDK and Login | ||
|
||
Initialization of the SDKs has been moved to property sheets to make it easier for developers to make calls. | ||
|
||
To complete setup of the AWSGameSDKAuth component, highlight the component in your scene tree and view the properties in the Inspector window. Update the `Login Endpoint` value with your API Gateway Login Endpoint, as shown below. | ||
|
||
 | ||
|
||
To complete setup of the AWSGameSDKBackend component, highlight the component in your scene tree and view the properties in the Inspector window. Update the `Backend Endpoint` value with your API Gateway Backend Endpoint, as shown below. You can leave the URIs as default. | ||
|
||
 | ||
|
||
In your scene's code, you will need to set a variable for each of the SDK components you enable | ||
|
||
```python | ||
@onready var aws_games_sdk_auth = get_node("AWSGameSDKAuth") | ||
@onready var aws_games_sdk_backend = get_node("AWSGameSDKBackend") | ||
``` | ||
|
||
Within the `_ready` function, connect your local functions to the signals from the SDK: | ||
|
||
```python | ||
func _ready(): | ||
# Get the SDK and Init | ||
aws_games_sdk_auth.init() #initialize the Auth SDK | ||
aws_games_sdk_auth.aws_login_success.connect(_on_login_success) #handle successful logins | ||
aws_games_sdk_auth.aws_login_error.connect(_on_login_error) #handle login errors | ||
aws_games_sdk_auth.aws_sdk_error.connect(_on_aws_sdk_error) #handle general SDK errors | ||
aws_games_sdk_backend.aws_backend_request_successful.connect(_on_backend_request_success) #handle successful backend requests | ||
aws_games_sdk_backend.aws_sdk_error.connect(_on_aws_sdk_error) #handle errors from backend requests | ||
``` | ||
|
||
To begin the login process, call login on the AWSGameSDKAuth component, as such: | ||
|
||
```python | ||
aws_games_sdk_auth.login() | ||
``` | ||
|
||
Errors for login can be managed with similar functions to those below: | ||
|
||
``` | ||
func _on_login_error(message): | ||
print("Login error: " + message) | ||
|
||
|
||
# Receives a UserInfo object after successful login | ||
func _on_login_success(): | ||
print("Received login success") | ||
``` | ||
|
||
## Set and Get Data from your custom backend | ||
|
||
Setting and getting data to and from your backend uses the AWSGameSDKBackend with the `backend_set_request` and `backend_get_request` functions. Both of these functions use HTTP GET requests. To set data, use the following syntax: | ||
|
||
```python | ||
aws_games_sdk_backend.backend_set_request(aws_games_sdk_auth.get_auth_token(), {"player_name" : "John Doe"}) | ||
``` | ||
|
||
In this case, the auth_token to make the call is retrieved from the aws_games_sdk_auth component and the `player_name` is set to `John Doe`. Multiple values can be set in a single dictionary request. | ||
|
||
To retrieve data, use the following syntax: | ||
|
||
```python | ||
aws_games_sdk_backend.backend_get_request(aws_games_sdk_auth.get_auth_token()) | ||
``` | ||
|
||
This call only requires the auth_token from the aws_games_sdk_auth component. | ||
|
||
Success and errors of both calls are handled through signal connections that were added to the `_ready` function above. A sample success function is as follows: | ||
|
||
```python | ||
# Get the SDK and Init | ||
self.aws_game_sdk = get_node("/root/AwsGameSdk") | ||
self.aws_game_sdk.init(self.login_endpoint, self.on_login_error) | ||
func _on_backend_request_success(): | ||
print("Backend request successful") | ||
print("Data returned from action: ", aws_games_sdk_backend.get_response_data()) | ||
``` | ||
|
||
## SDK Public API | ||
|
||
The public API for the SDK includes the following methods. Most of them will require you to provide a callback for results (see the Godot 4 Integration Samples for sample code): | ||
The public API for the AWSGameSDKAuth component includes the following methods. Most of them will require you to provide a callback for results (see the Godot 4 Integration Samples for sample code): | ||
|
||
```text | ||
func init(login_endpoint, login_error_callback) | ||
func login_as_new_guest_user(login_callback) | ||
func login_as_guest(user_id, guest_secret, login_callback) | ||
func login_with_refresh_token(refresh_token, login_callback = null) | ||
func link_steam_id_to_current_user(steam_token, login_callback_steam) | ||
func login_with_steam_token(steam_token, login_callback) | ||
func link_apple_id_to_current_user(apple_auth_token, login_callback_apple) | ||
func login_with_apple_id_token(apple_auth_token, login_callback) | ||
func link_google_play_id_to_current_user(google_play_auth_token, login_callback_google) | ||
func login_with_google_play_token(google_play_auth_token, login_callback) | ||
func link_facebook_id_to_current_user(facebook_access_token, facebook_user_id, login_callback_facebook) | ||
func login_with_facebook_access_token(facebook_access_token, facebook_user_id, login_callback) | ||
func backend_get_request(url, resource, query_parameters, callback) | ||
func backend_post_request(url, resource, request_body, callback): | ||
func init() | ||
func login() | ||
func login_with_refresh_token() | ||
func get_auth_token() String | ||
func link_steam_id_to_current_user(steam_token) | ||
func login_with_steam_token(steam_token) | ||
func link_apple_id_to_current_user(apple_auth_token) | ||
func login_with_apple_id_token(apple_auth_token) | ||
func link_google_play_id_to_current_user(google_play_auth_token) | ||
func login_with_google_play_token(google_play_auth_token) | ||
func link_facebook_id_to_current_user(facebook_access_token, facebook_user_id) | ||
func login_with_facebook_access_token(facebook_access_token, facebook_user_id) | ||
``` | ||
|
||
Supported signals are: | ||
|
||
```text | ||
aws_login_success | ||
aws_login_error | ||
aws_sdk_error | ||
steam_link | ||
steam_login | ||
fb_link | ||
fb_login | ||
apple_link | ||
apple_login | ||
goog_link | ||
goog_login | ||
```` | ||
|
||
The public API for the AWSGameSDKBackend component includes the following methods. | ||
|
||
```python | ||
func backend_get_request(auth_token) | ||
func backend_set_request(auth_token, query_parameters) | ||
func backend_post_request(auth_token, request_body) | ||
func get_response_data() String | ||
``` | ||
|
||
Supported signals are: | ||
|
||
```text | ||
aws_backend_request_successful | ||
aws_sdk_error | ||
``` | ||
|
||
## Adding the SDK to an existing project | ||
# Migrating from prior version | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Recommended update: Enhance the migration guide with signal connection examples: ## Migrating from Callback-based to Signal-based Approach
When migrating from the previous version's callback-based approach to the new signal-based approach, you'll need to replace callback function registrations with signal connections:
### Old (Callback-based):
```gdscript
self.aws_game_sdk.login_as_new_guest_user(self.login_callback) New (Signal-based):@onready var aws_games_sdk_auth = get_node("AWSGameSDKAuth")
func _ready():
aws_games_sdk_auth.aws_login_success.connect(_on_login_success)
aws_games_sdk_auth.aws_login_error.connect(_on_login_error)
aws_games_sdk_auth.login()
func _on_login_success():
print("Login successful!")
func _on_login_error(message):
print("Login failed: " + message) |
||
|
||
This section describes the actions you will need to take if you had integrated the prior version of this sample with your Godot project. You should take these steps prior to integrating the new plugin. Before you make any changes, it is important to backup your project in case any errors are made. | ||
|
||
## Unregister the AWSGameSDK Autoload | ||
1. Open _Project Settings -> Autoload_ and select the "Globals" tab. | ||
2. Under the "Autoload" tab, uncheck the _AWSGameSDK_ and click "Close." | ||
|
||
To add the SDK to an existing project: | ||
## Remove the AWSGameSDK folder from your project | ||
This step assumes you have not added any folders, functionality, or code to the proir AWSGameSDK or the folder thereof. Highlight the folder in the File System viewer in your Godot project, right click, and choose "Delete." | ||
|
||
1. Drag and drop the folder `AWSGameSDK` to your Godot 4 project | ||
2. Open _Project Settings -> Autoload_, select the script `AWSGameSDK.gd` with the directory search and select _Open_. Make sure the name is _AwsGameSdk_ and select _Add_. | ||
3. Integrate with the SDK from your custom code (see Godot 4 Integration Samples for example integrations) | ||
## Remove the code used to integrate the AWSGameSDK from your code | ||
This code should be highlighted in your project via the Godot IDE. The new plug-in code will operate very similar to the prior version, so it will be good to denote these areas with a comment, such as `#TODO: Add AWSGameSDK Plugin Code Here` while removing the code. | ||
|
||
# Godot 4 Integration Samples | ||
|
||
|
@@ -96,6 +218,3 @@ func link_google_play_id_to_current_user(google_play_auth_token, login_callback_ | |
func login_with_google_play_token(google_play_auth_token, login_callback) | ||
``` | ||
|
||
|
||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Recommended update: Add comprehensive signal documentation: