Skip to content

Move Twitch initialization from scenario scene to game startup #332

@saebyn

Description

@saebyn

Problem

Currently, the Twitch setup, authentication check, and welcome message are performed in Stages/Game/main/main.gd inside _ready(), which runs every time a scenario is loaded. This means:

  • Twitch setup is re-run on each scenario load, which is unnecessary and potentially disruptive.
  • The welcome message (if configured) is sent every time a scenario starts, rather than once when the game is launched.
  • Twitch authentication state is not managed at the application level, leading to possible repeated setup attempts.

Relevant Code

File: Stages/Game/main/main.gd, lines 77–96

# Check if twitch integration is enabled and then set it up if so
if SettingsManager.twitch_enabled:
    MyLogger.info("Main", "Twitch integration enabled - setting up Twitch connection")
    var setup_successful: bool = await Twitch.setup()

    if setup_successful:
        MyLogger.info("Main", "Twitch setup successful")
        var me = await Twitch.get_current_user()
        MyLogger.info("Main", "Twitch authenticated as %s (ID: %s)" % [me.display_name, me.id])

        if SettingsManager.twitch_welcome_message != "":
            Twitch.chat(SettingsManager.twitch_welcome_message)

        Twitch.api.unauthenticated.connect(_on_twitch_unauthenticated)
    else:
        # display a message to the user if Twitch setup failed, but don't disable the game features since Twitch is optional
        MyLogger.error("Main", "Twitch setup failed - Twitch features will be unavailable")
        ui.call_deferred("show_problem_message", "Twitch integration failed to set up. Twitch features will be unavailable. Please check the logs for more details.")

Proposed Solution

Move the Twitch initialization logic to an earlier, application-level point — such as the main menu scene or an autoloaded system (e.g., GameManager) — so that:

  1. Twitch setup runs once when the game is launched, not per-scenario.
  2. The welcome message is sent once at game startup.
  3. The unauthenticated signal handler is connected at the application level, with UI feedback routed appropriately regardless of which scene is active.
  4. Twitch connection status is available globally so the main menu or HUD can reflect it.

Considerations

  • The ui reference in main.gd is a MainUI node; error/status messages would need to be surfaced differently if Twitch init moves out of the scenario scene.
  • GameManager (already autoloaded) could be a good home for this logic, emitting a signal like twitch_status_changed that any scene can subscribe to.
  • Alternatively, a dedicated TwitchManager autoload could handle connection lifecycle.
  • Care should be taken to avoid re-connecting the unauthenticated signal multiple times across scene reloads.
  • The TwitchCommand nodes in the Main scene and their signals and handlers will also need to move.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    Status

    Backlog

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions