Fix error overflowing

This commit is contained in:
2025-11-19 18:58:23 +01:00
parent 9ae32ca6a9
commit 8f641ab36e
3 changed files with 20 additions and 2 deletions

View File

@ -106,7 +106,7 @@ func _notification(what):
NOTIFICATION_WM_WINDOW_FOCUS_IN: NOTIFICATION_WM_WINDOW_FOCUS_IN:
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED) Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
NOTIFICATION_EXIT_TREE: NOTIFICATION_EXIT_TREE:
print("PlayerController %s exited tree" % multiplayer.get_unique_id()) print("PlayerController exited tree")
NOTIFICATION_ENTER_TREE: NOTIFICATION_ENTER_TREE:
print("PlayerController %s entered tree" % multiplayer.get_unique_id()) print("PlayerController %s entered tree" % multiplayer.get_unique_id())

View File

@ -41,6 +41,7 @@ func close_connection():
multiplayer.multiplayer_peer = null multiplayer.multiplayer_peer = null
print("Connection closed.") print("Connection closed.")
_disconnect_signals() _disconnect_signals()
GameManager.reset_game_state()
func setup_connections(): func setup_connections():
if not multiplayer.peer_connected.is_connected(on_peer_connected): if not multiplayer.peer_connected.is_connected(on_peer_connected):
@ -85,3 +86,4 @@ func on_connected_to_server() -> void:
func on_server_disconnected() -> void: func on_server_disconnected() -> void:
print("Disconnected from server.") print("Disconnected from server.")
get_tree().change_scene_to_file("res://main.tscn") get_tree().change_scene_to_file("res://main.tscn")
GameManager.reset_game_state()

View File

@ -27,7 +27,13 @@ func _ready():
return return
func _process(_delta): func _process(_delta):
if find_available_spawner(): if not multiplayer.multiplayer_peer: return
if not multiplayer.is_server(): return
# Safety check: don't try to spawn if the system isn't ready or is deleted
if not is_instance_valid(current_star_system): return
if not waiting_players.is_empty() and find_available_spawner():
_try_spawn_waiting_player() _try_spawn_waiting_player()
@ -150,3 +156,13 @@ func _get_orbital_body_ancestor(node: Node) -> OrbitalBody3D:
return current return current
current = current.get_parent() current = current.get_parent()
return null return null
func reset_game_state():
current_star_system = null
registered_spawners.clear()
waiting_players.clear()
player_pawns.clear()
player_controllers.clear()
# Reset any other state variables
print("GameManager state cleared.")