Files

75 lines
2.4 KiB
GDScript

extends Node
@onready var loading_screen = $LoadingScreen
@onready var auth_screen = $AuthScreen
@onready var hub_screen = $HubScreen
@onready var dungeon_scene = $DungeonScene
@onready var death_screen = $DeathScreen
var _manifest_requested: bool = false
func _ready():
print("[Main] _ready called")
_show_screen("LOADING")
call_deferred("_setup_signals")
call_deferred("_start_loading")
func _start_loading():
# Connect to server and start asset download
if not Network.is_socket_connected():
print("[Main] Connecting to server...")
Network.connect_to_server()
await Network.connected
print("[Main] Connected! Calling check_for_updates...")
UpdateManager.check_for_updates()
func _setup_signals():
print("[Main] _setup_signals called")
if GameState:
print("[Main] GameState found, connecting state_changed signal...")
GameState.state_changed.connect(_on_state_changed)
print("[Main] Signal connected successfully")
else:
print("[Main] ERROR: GameState autoload not found!")
func _on_state_changed(new_state: String):
print("[Main] _on_state_changed received: ", new_state)
_show_screen(new_state)
func _show_screen(state: String):
print("[Main] _show_screen called with: ", state)
# Transitional states (portal exit, dungeon cleared) show the loading screen
# while waiting for the server to send HUB_STATE.
var is_transitioning = state == "PORTALUSED" or state == "DUNGEONCLEARED"
if loading_screen:
_set_screen_visible(loading_screen, state == "LOADING" or is_transitioning)
print("[Main] LoadingScreen visible: ", state == "LOADING" or is_transitioning)
if auth_screen:
_set_screen_visible(auth_screen, state == "AUTH")
print("[Main] AuthScreen visible: ", state == "AUTH")
if hub_screen:
_set_screen_visible(hub_screen, state == "HUB")
print("[Main] HubScreen visible: ", state == "HUB")
if dungeon_scene:
_set_screen_visible(dungeon_scene, state == "PLAYING")
print("[Main] DungeonScene visible: ", state == "PLAYING")
if death_screen:
_set_screen_visible(death_screen, state == "DEAD")
print("[Main] DeathScreen visible: ", state == "DEAD")
func _set_screen_visible(node: Node, is_visible: bool):
if node == null:
return
if node is CanvasLayer:
node.visible = is_visible
elif node is CanvasItem:
node.visible = is_visible
else:
node.set_process(is_visible)
node.set_physics_process(is_visible)
for child in node.get_children():
_set_screen_visible(child, is_visible)