feat: Implement core lobby system including UI, player management, and game mode settings.
This commit is contained in:
+25
-9
@@ -1286,7 +1286,8 @@ func create_bot_with_state(bot_id: int, pos: Vector2i, p_score: int, p_goals: Ar
|
||||
|
||||
func _on_host_disconnected():
|
||||
"""Called when the host leaves. Returns clients to the main menu."""
|
||||
print("[Main] Host disconnected. Match terminated. Returning to lobby...")
|
||||
print("[Main] Host disconnected. Match terminated. Cleaning up and returning to lobby...")
|
||||
LobbyManager.leave_room()
|
||||
get_tree().change_scene_to_file("res://scenes/lobby.tscn")
|
||||
|
||||
func _on_rematch_starting():
|
||||
@@ -1575,6 +1576,14 @@ func sync_grid_item(x: int, y: int, z: int, item: int):
|
||||
# OR Layer 1 is already a wall (4)
|
||||
if f0 in [4, -1] or f1 == 4:
|
||||
return
|
||||
|
||||
# TEKTON DOORS: Prevent placing items on portal doors
|
||||
if LobbyManager.is_game_mode(GameMode.Mode.TEKTON_DOORS):
|
||||
var doors = get_tree().get_nodes_in_group("PortalDoors")
|
||||
for door in doors:
|
||||
var door_grid = enhanced_gridmap.local_to_map(enhanced_gridmap.to_local(door.global_position))
|
||||
if door_grid.x == x and door_grid.z == z:
|
||||
return
|
||||
|
||||
enhanced_gridmap.set_cell_item(Vector3i(x, y, z), item)
|
||||
# Force visual update
|
||||
@@ -1601,6 +1610,17 @@ func sync_grid_items_batch(data: Array):
|
||||
if f0 in [4, -1] or f1 == 4:
|
||||
continue
|
||||
|
||||
# TEKTON DOORS: Prevent placing items on portal doors
|
||||
if LobbyManager.is_game_mode(GameMode.Mode.TEKTON_DOORS) and y == 1:
|
||||
var doors = get_tree().get_nodes_in_group("PortalDoors")
|
||||
var on_door = false
|
||||
for door in doors:
|
||||
var door_grid = enhanced_gridmap.local_to_map(enhanced_gridmap.to_local(door.global_position))
|
||||
if door_grid.x == x and door_grid.z == z:
|
||||
on_door = true
|
||||
break
|
||||
if on_door: continue
|
||||
|
||||
enhanced_gridmap.set_cell_item(Vector3i(x, y, z), item)
|
||||
|
||||
# Force visual update ONCE after batch
|
||||
@@ -2084,12 +2104,8 @@ func _on_back_to_menu_pressed():
|
||||
"""Return to lobby/main menu and clean up game state."""
|
||||
print("[Main] Returning to lobby...")
|
||||
|
||||
# Proper ordered cleanup to avoid ghost players
|
||||
GameStateManager.end_game()
|
||||
LobbyManager.reset()
|
||||
|
||||
# Properly disconnect from Nakama match
|
||||
_cleanup_multiplayer()
|
||||
# Proper ordered cleanup to avoid ghost players and desync
|
||||
LobbyManager.leave_room()
|
||||
|
||||
# Small delay to let cleanup settle
|
||||
await get_tree().create_timer(0.2).timeout
|
||||
@@ -2357,8 +2373,8 @@ func _on_settings_pressed():
|
||||
|
||||
func _on_quit_match_pressed():
|
||||
get_tree().paused = false # Ensure unpaused when returning to menu
|
||||
# Properly disconnect from Nakama match
|
||||
_cleanup_multiplayer()
|
||||
# Properly disconnect from Nakama and clear lobby state to prevent desync
|
||||
LobbyManager.leave_room()
|
||||
# Return to lobby or main menu
|
||||
get_tree().change_scene_to_file("res://scenes/lobby.tscn")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user