Skip to content
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

Godot 4 AWS Plugin v 1.0.0 #66

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
439 changes: 0 additions & 439 deletions GodotSample/AWSGameSDK/AWSGameSDK.gd

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uid://bj1uupijq8a0p
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[gd_scene load_steps=2 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"]

[node name="Node2D" type="Node2D"]

Expand Down
166 changes: 135 additions & 31 deletions GodotSample/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,48 +2,156 @@

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):
![Godot4 Folder Structure with AWS Games SDK Plugin](images_readme/folder_structure.png)

Next, go to Project -> Project Settings... from your menu and enable the AWS Games SDK plugin by checking the checkbox.

![AWS for Games SDK Plugin enabled for a Godot project](images_readme/project_settings.png)

## 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 retrrieve data. These components can be added by adding child nodes to your scene.

![Adding AWSGameSDK nodes to your Godot scene](images_readme/add_aws_nodes_to_your_scene.png)

Once added, your scene tree should look similar to this.

![A Godot scene with nodes added for AWSGameSDKAuth and AWSGameSDKBackend](images_readme/scene_tree_with_plugins.png)

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.

![Setting your authentication endpoint property for the AWSGameSDKAuth component](images_readme/setting_auth_endpoint.png)

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.

![Setting your backend endpoint property for the AWSGameSDKAuth component](images_readme/setting_backend_endpoint.png)

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
# 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)
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
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)
```

## Adding the SDK to an existing project
Supported signals are:

To add the SDK to an existing project:
```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.

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)
```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
```

# Godot 4 Integration Samples

Expand Down Expand Up @@ -95,7 +203,3 @@ 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)
```




33 changes: 23 additions & 10 deletions GodotSample/Samples/FacebookLogin/FacebookLogin.gd
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,22 @@

extends Node

# TODO: Add the login endpoint here
const login_endpoint = "https://YOURENDPOINT.execute-api.us-east-1.amazonaws.com/prod/"

var aws_game_sdk
@onready var aws_games_sdk_auth = get_node("AWSGameSDKAuth")


# Called when the node enters the scene tree for the first time.
func _ready():

#init sdk and setup signal listeners
aws_games_sdk_auth.init()
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.fb_link.conect(on_link_facebook_id_response)
aws_games_sdk_auth.fb_login.conect(on_login_with_facebook_response)
aws_games_sdk_auth.aws_sdk_error.connect(_on_aws_sdk_error)
#login
aws_games_sdk_auth.login()
# 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)
Expand All @@ -19,30 +27,35 @@ func _ready():
self.aws_game_sdk.login_as_new_guest_user(self.login_as_guest_callback)

# Called on any login or token refresh failures
func on_login_error(message):
func _on_login_error(message):
print("Login error: " + message)


func _on_aws_sdk_error(message):
print("AWS SDK error: ", message)


# Receives a UserInfo object after successful guest login
func login_as_guest_callback(user_info):
func _on_login_success():
print("Received guest login info.")
print(user_info)
print(aws_games_sdk_auth.user_info)

# Try linking Facebook ID to existing user
# NOTE: You'll need to use a community Facebook integration such as https://github.com/DrMoriarty/godot-facebook
# Once you've logged in with Facebook, send the access_token and user_id here
self.aws_game_sdk.link_facebook_id_to_current_user("AcceessTokenHere", "UserIdHere", self.on_link_facebook_id_response)

func on_link_facebook_id_response(user_info):
func on_link_facebook_id_response():
print("Received Facebook ID linking info")
print(user_info)
print(aws_games_sdk_auth.user_info.to_string())

# Let's now try to login with Facebook acccess token directly to access the same user
self.aws_game_sdk.login_with_facebook_access_token("AccessTokenHere", "UserIdHere", self.on_login_with_facebook_response)


func on_login_with_facebook_response(user_info):
func on_login_with_facebook_response():
print("Received Facebook ID login info")
print(user_info)
print(aws_games_sdk_auth.user_info.to_string())

# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
Expand Down
1 change: 1 addition & 0 deletions GodotSample/Samples/FacebookLogin/FacebookLogin.gd.uid
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uid://cno7al5g886tr
11 changes: 7 additions & 4 deletions GodotSample/Samples/FacebookLogin/FacebookLogin.tscn
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
[gd_scene load_steps=2 format=3 uid="uid://qknp5wwmrjlu"]
[gd_scene load_steps=3 format=3 uid="uid://qknp5wwmrjlu"]

[ext_resource type="Script" path="res://Samples/FacebookLogin/FacebookLogin.gd" id="1_gobne"]
[ext_resource type="Script" uid="uid://cno7al5g886tr" path="res://Samples/FacebookLogin/FacebookLogin.gd" id="1_gobne"]
[ext_resource type="Script" uid="uid://dxp7lgvaxrjry" path="res://addons/AWSGameSDK/scripts/AWSAuthorization.gd" id="2_jnwcp"]

[node name="Node2D" type="Node2D"]

[node name="Test" type="Node" parent="."]
script = ExtResource("1_gobne")

[node name="AWSGameSDKAuth" type="Node" parent="."]
script = ExtResource("2_jnwcp")
metadata/_custom_type_script = "uid://dxp7lgvaxrjry"
Loading