feat: Introduce LobbyManager to handle room management, player states, and game setting synchronization.

This commit is contained in:
Yogi Wiguna
2026-02-10 16:58:43 +08:00
parent a27ff8634d
commit 0c2a53c0cc
3 changed files with 49 additions and 46 deletions
+15 -27
View File
@@ -70,7 +70,7 @@ var can_finish: bool:
get: return race_manager.can_finish if race_manager else false
set(value): if race_manager: race_manager.can_finish = value
@export var cell_size: Vector3 = Vector3(2, 2, 2)
@export var cell_size: Vector3 = Vector3(1, 0.05, 1)
@export var cell_offset: Vector3 = Vector3(0, 0, 0)
@export var goals: Array[int]:
@@ -268,9 +268,9 @@ func _ready():
# Ensure proper initial positioning
if not LobbyManager.get_randomize_spawn() and not spawn_point_selected:
global_position = Vector3(
current_position.x * cell_size.x + cell_size.x * 0.5,
current_position.x * 1 + 1 * 0.5,
1.0,
current_position.y * cell_size.z + cell_size.z * 0.5
current_position.y * 1 + 1 * 0.5
)
target_visual_position = global_position
if is_multiplayer_authority():
@@ -1011,31 +1011,17 @@ func find_valid_starting_position() -> Vector2i:
if is_bot:
return _find_random_spawn_position()
else:
highlight_available_spawn_points()
# Return temporary position, will be updated when player selects spawn point
return Vector2i(-1, -1)
func highlight_available_spawn_points():
if not is_multiplayer_authority() or is_bot or spawn_point_selected:
return
# Auto-assign the first available spawn point for fixed spawning
for spawn_pos in spawn_locations:
if not is_position_occupied(spawn_pos):
return spawn_pos
# Clear any existing highlights
clear_highlights()
highlighted_spawn_points.clear()
# Get all currently occupied positions
var occupied_positions = get_occupied_positions()
# Check each spawn location
for spawn_pos in spawn_locations:
if not is_position_occupied(spawn_pos):
highlighted_spawn_points.append(spawn_pos)
if enhanced_gridmap:
# Highlight the cell at y=0 (ground level)
enhanced_gridmap.set_cell_item(
Vector3i(spawn_pos.x, 0, spawn_pos.y),
enhanced_gridmap.hover_item
)
# Fallback (should typically not be reached if spawn_locations > max_players)
return Vector2i(0, 0)
# highlight_available_spawn_points is no longer needed for manual selection in this mode
func highlight_available_spawn_points():
pass
# Add function to get all occupied positions
func get_occupied_positions() -> Array:
@@ -1808,6 +1794,8 @@ func set_spawn_position(pos: Vector2i):
current_position.y * cell_size.z + cell_size.z * 0.5
) + cell_offset
print("[Player %s] set_spawn_position: Grid %s -> World %s (CellSize: %s)" % [name, pos, new_pos, cell_size])
global_position = new_pos
target_visual_position = new_pos