Skip to content

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
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

timjbruce
Copy link

Issue #, if available:

Description of changes:

  1. Moved AWSGameSDK to the addons folder and created a plugin that contains 2 components - Auth and Backend. Separated the two features into their own components so we can work on adding additional features (webscokets, analytics, etc) to the plugin without affecting core functionality.

  2. Auth component changes/updates

  • Removed callbacks for the more Godot-style using signals. This impacts the API for each of the calls, removing the need to pass a callback.
  • Moved file load and save save_game.dat functionality to the plugin. These steps are now in the plugin to simplify the integration for developers.
  • Changed Login api to just use login. The plugin will determine login as new or existing guest account, based on the save_gaeme.dat file loading and valid.
  • Removed the need to pass tokens to each request. Token is now read from user_info that is local to the Auth component.
  • Changed token refresh to use a timer. This reduces CPU for the code to work in a game.
  • Updated private methods and signals to have _ in front of their name. This should help to avoid issues where developers use private methods by mistake.
  • Added export variable for login_endpoint, allowing developers to configure this using a property page versus code updates.

3/ Backend component changes/updates

  • Created new backend_set_request and backend_get_request methods to signify the action developers want to take. This encapsulates the URI for the developer with the goal of simplifying development.
  • Added get_response_data method, to actively retrieve any responses from the backend versus passing as part of a signal.
  • Added export variables for backend_endpoint, get_player_data_URI, set_player_data_URI, and post_player_data_URI. This allows developers to set these via a property page versus code updates.

4/ Updated the samples to use the new plugin and methods. Also updated the readme to help developers add the plugin and configure it within their project.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@armandocv armandocv requested review from armandocv and juhoaws March 27, 2025 18:08
Copy link
Contributor

@armandocv armandocv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for submitting this PR. Your contribution is appreciated. I have reviewed your changes and left some comments for your consideration. Please take a moment to review these suggestions and make any necessary adjustments.

Comment on lines +11 to +12
add_autoload_singleton(AUTOLOAD_NAME, "res://addons/AWSGameSDK/AWSAuthorization.gd")
add_autoload_singleton(AUTOLOAD_NAME, "res://addons/AWSGameSDK/AWSBackend.gd")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The _enable_plugin() function attempts to register two autoload singletons with the same name. This would cause a conflict as only one can be registered with a given name.

Recommended solution: Register only one autoload singleton or use different names for each:

func _enable_plugin():
    add_autoload_singleton(AUTOLOAD_NAME_AUTH, "res://addons/AWSGameSDK/scripts/AWSAuthorization.gd")
    add_autoload_singleton(AUTOLOAD_NAME_BACKEND, "res://addons/AWSGameSDK/scripts/AWSBackend.gd")

func _enable_plugin():
add_autoload_singleton(AUTOLOAD_NAME, "res://addons/AWSGameSDK/AWSAuthorization.gd")
add_autoload_singleton(AUTOLOAD_NAME, "res://addons/AWSGameSDK/AWSBackend.gd")

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The plugin doesn't properly register the custom node types to make them available in the editor

Recommended solution:
Add proper node registration in the plugin script:

@tool
extends EditorPlugin

const AUTOLOAD_NAME_AUTH = "AWSGameSDKAuth"
const AUTOLOAD_NAME_BACKEND = "AWSGameSDKBackend"

func _enter_tree():
    # Register custom node types
    add_custom_type("AWSGameSDKAuth", "Node", preload("res://addons/AWSGameSDK/scripts/AWSAuthorization.gd"), preload("res://addons/AWSGameSDK/icon.png"))
    add_custom_type("AWSGameSDKBackend", "Node", preload("res://addons/AWSGameSDK/scripts/AWSBackend.gd"), preload("res://addons/AWSGameSDK/icon.png"))

func _exit_tree():
    # Remove custom node types
    remove_custom_type("AWSGameSDKAuth")
    remove_custom_type("AWSGameSDKBackend")

func _enable_plugin():
    add_autoload_singleton(AUTOLOAD_NAME_AUTH, "res://addons/AWSGameSDK/scripts/AWSAuthorization.gd")
    add_autoload_singleton(AUTOLOAD_NAME_BACKEND, "res://addons/AWSGameSDK/scripts/AWSBackend.gd")

func _disable_plugin():
    remove_autoload_singleton(AUTOLOAD_NAME_AUTH)
    remove_autoload_singleton(AUTOLOAD_NAME_BACKEND)


# trigger error if we didn't get a proper response code
if(response_code >= 400):
error_string = json_string
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When an HTTP request fails with a response code >= 400, it sets error_string but doesn't emit any signal:

Recommended solution: Emit an error signal when HTTP requests fail:

if(response_code >= 400):
    error_string = json_string
    aws_login_error.emit("HTTP Error: " + str(response_code) + " - " + json_string)
    return

var error = json.parse(json_string)

# trigger error if we didn't get a proper response code
if(response_code >= 400):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When an HTTP request fails with a response code >= 400, it sets error_string but doesn't emit any signal.

Recommended solution: Emit an error signal when HTTP requests fail:

if(response_code >= 400):
    error_string = json_string
    aws_login_error.emit("HTTP Error: " + str(response_code) + " - " + json_string)
    return



func login():
if user_info.user_id == "" or user_info.guest_secret == "":
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The login() function doesn't check if user_info is null before accessing its properties.

Recommended solution: Add null check before accessing properties:

func login():
    if user_info == null:
        user_info = UserInfo.new()
        _login_as_new_guest()
    elif user_info.user_id == "" or user_info.guest_secret == "":
        _login_as_new_guest()
    else:
        _login_as_guest()

aws_sdk_error.emit("Error making backend request")


func _backend_reqeust_completed(result, response_code, headers, body):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo in function name: _backend_reqeust_completed

print("AWS Game SDK initialized")


func _make_auth_http_request(url: String, method: HTTPClient.Method = HTTPClient.METHOD_GET, form_data: Dictionary = {}) -> void:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function declares a form_data parameter but doesn't use it.

func login_with_facebook_access_token(facebook_access_token, facebook_user_id)
```

Supported signals are:
Copy link
Contributor

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:

## Signal Reference

### AWSGameSDKAuth Signals
- `aws_login_success`: Emitted when login is successful. No parameters.
- `aws_login_error(message: String)`: Emitted when login fails. Provides an error message.
- `aws_sdk_error(message: String)`: Emitted when a general SDK error occurs. Provides an error message.
- `steam_link`: Emitted when Steam account linking is successful.
- `steam_login`: Emitted when Steam login is successful.
- `fb_link`: Emitted when Facebook account linking is successful.
- `fb_login`: Emitted when Facebook login is successful.
- `apple_link`: Emitted when Apple account linking is successful.
- `apple_login`: Emitted when Apple login is successful.
- `goog_link`: Emitted when Google Play account linking is successful.
- `goog_login`: Emitted when Google Play login is successful.

### AWSGameSDKBackend Signals
- `aws_backend_request_successful`: Emitted when a backend request completes successfully.
- `aws_sdk_error(message: String)`: Emitted when a backend request fails. Provides an error message.

```

## Adding the SDK to an existing project
# Migrating from prior version
Copy link
Contributor

Choose a reason for hiding this comment

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

@@ -0,0 +1,97 @@
# AWS Game Backend Framework Godot 4 SDK
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file appears to be outdated documentation that was included in the PR version by mistake.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants