feat: Introduce main game scene script to orchestrate managers, UI, multiplayer, and game mode setup.

This commit is contained in:
Yogi Wiguna
2026-03-25 17:45:42 +08:00
parent c0d52d4136
commit c46e28a69d
+14 -4
View File
@@ -1474,13 +1474,23 @@ func sync_player_goals(player_id: int, goals: Array):
call_deferred("_deferred_set_player_goals", player_id, goals)
func _deferred_set_player_goals(player_id: int, goals: Array):
# Reduce delay to 0.05s for snappier updates (just enough to ensure nodes are in tree)
if not get_node_or_null(str(player_id)):
await get_tree().create_timer(0.1).timeout
# The player node waits 0.5s in its _ready() function before initializing managers.
# We MUST cleanly wait until it finishes creating them, instead of silently aborting.
var player = get_node_or_null(str(player_id))
# Wait until player and its race_manager thoroughly exist
var wait_limit = 2.0 # Safety limit
var waited = 0.0
while (not player or not player.race_manager) and waited < wait_limit:
await get_tree().create_timer(0.1).timeout
waited += 0.1
player = get_node_or_null(str(player_id))
if player and player.race_manager:
player.goals = goals.duplicate()
# UI UPDATE FIX: explicitly refresh local UI upon receiving starting goals
if player_id == multiplayer.get_unique_id() and GameStateManager.local_player_character:
ui_manager.update_playerboard_ui()
@rpc("any_peer", "call_local")