aws-solutions-library-samples / guidance-for-custom-game-backend-hosting-on-aws

The AWS Game Backend Framework allows you to integrate your game clients with AWS backend services, with secure scalable identity management and authentication, and integrations to commonly used game platform identity providers and game engines.
https://aws.amazon.com/solutions/guidance/custom-game-backend-hosting-on-aws/
MIT No Attribution
35 stars 18 forks source link

Support for await keyword in the Godot SDK #58

Open treepumpkin opened 1 week ago

treepumpkin commented 1 week ago

Godot 4 introduced the await keyword for coroutines, it would be nice to use it in this SDK, too. Here is an example with the login_as_new_guest_user call.

Current SDK usage:

func _ready():

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

    # Log in as new guest user first
    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):
    print("Login error: " + message)

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

    # Try linking Steam ID to existing user
    # NOTE: You need to use the Godot Steamworks SDK (https://godotsteam.com/) to integrate with Steam
    #       Use the GetAuthTicketForWebAPI to get the steam auth token (https://godotsteam.com/functions/users/#getauthticketforwebapi)
    self.aws_game_sdk.link_steam_id_to_current_user("YourTokenHere", self.on_link_steam_id_response)

Desired SDK usage (same pattern as in W4 Cloud's SDK )

func _ready():

    # Get the SDK and Init
    self.aws_game_sdk = get_node("/root/AwsGameSdk")

    var res = await self.aws_game_sdk.login_as_new_guest_user().async()

    if res.is_error():
        print("Error!:" + res.as_error())
        return

    print("Received guest login info.")
    print(res.get_data())

    # Try linking Steam ID to existing user
    # NOTE: You need to use the Godot Steamworks SDK (https://godotsteam.com/) to integrate with Steam
    #       Use the GetAuthTicketForWebAPI to get the steam auth token (https://godotsteam.com/functions/users/#getauthticketforwebapi)
    res = await aws_game_sdk.link_steam_id_to_current_user("YourTokenHere").async()
juhoaws commented 1 week ago

Interesting, thank you for pointing this out. Does the await here yield the execution back and return to this function only after the response comes in? Quick look at the docs it looks like that's the case. The other thing I'd need to investigate is the async() call for a method, is that something that needs to be implemented on the method level?

If you're interested in working on a pull request on this, we'd be happy to include that! But completely fine if not, we'll keep it in the issues then and try to come back to this at a later point