feat: implement initial lobby scene with main menu, server browser, and networking options.

This commit is contained in:
Yogi Wiguna
2026-03-16 16:19:30 +08:00
parent 64dc1de15a
commit eb018903aa
6 changed files with 317 additions and 35 deletions
+21 -5
View File
@@ -51,7 +51,9 @@ func _ready():
# NetworkPanel is visible during gameplay
# Auto-start game if coming from lobby (already connected to match)
if NakamaManager.is_connected_to_nakama() and multiplayer.get_unique_id() != 0:
# Works for both Nakama mode and LAN direct mode (ENet).
var is_lan_connected = LobbyManager.is_lan_mode and multiplayer.has_multiplayer_peer() and multiplayer.multiplayer_peer.get_connection_status() == MultiplayerPeer.CONNECTION_CONNECTED
if (NakamaManager.is_connected_to_nakama() or is_lan_connected) and multiplayer.get_unique_id() != 0:
print("Coming from lobby - auto-starting game...")
await get_tree().process_frame
_auto_start_from_lobby()
@@ -685,9 +687,11 @@ func _start_game():
wait_time += 0.2
# Allow socket/peer to stabilize before blasting RPCs
await get_tree().create_timer(2.0).timeout
# Snappier delay for LAN mode
var delay = 0.5 if LobbyManager.is_lan_mode else 2.0
await get_tree().create_timer(delay).timeout
# NOW assign random spawn positions for EVERYONE (Host, Client, Bots)
# NOW assign spawn positions for EVERYONE (Host, Client, Bots)
# This safely sends RPCs over the completed socket connection
_assign_random_spawn_positions()
@@ -972,7 +976,8 @@ func spawn_tekton_npc():
# Generate a consistent ID/Name for sync (add index to ensure uniqueness)
var tekton_id = Time.get_ticks_msec() + spawned_count
_create_tekton(valid_pos, tekton_id)
if can_rpc():
# Only broadcast to clients if there are remote peers connected
if can_rpc() and multiplayer.get_peers().size() > 0:
rpc("sync_spawn_tekton", valid_pos, tekton_id)
spawned_count += 1
@@ -980,6 +985,8 @@ func spawn_tekton_npc():
@rpc("call_remote", "reliable")
func sync_spawn_tekton(pos: Vector2i, tekton_id: int):
# Safety: only create if scene is fully ready
if not is_inside_tree(): return
_create_tekton(pos, tekton_id)
func _create_tekton(pos: Vector2i, tekton_id: int, is_static: bool = false):
@@ -1566,6 +1573,12 @@ func request_randomize_item(grid_position: Vector2i):
func sync_grid_item(x: int, y: int, z: int, item: int):
var enhanced_gridmap = $EnhancedGridMap
if enhanced_gridmap:
# FLOOR ENFORCEMENT: Visual tiles (IDs 7-20) must ALWAYS be on layer Y=1.
# If somehow sent to Y=0, redirect them to Y=1.
if item >= 7 and item <= 20 and y == 0:
push_warning("[Main] Tile %d was sent to floor Y=0 at (%d,0,%d). Redirecting to Y=1." % [item, x, z])
y = 1
# PROTECTED FLOOR CHECK: Block tiles (7-20) from being placed on walls (4) or void (-1)
# Note: We allow spawning on Safe Zones, Start, and Finish as it's on Layer 1.
if y == 1 and item >= 7 and item <= 20:
@@ -1602,7 +1615,10 @@ func sync_grid_items_batch(data: Array):
var y = entry.get("y", 0)
var z = entry.get("z", 0)
var item = entry.get("item", -1)
# FLOOR ENFORCEMENT: Visual tiles (IDs 7-20) must ALWAYS be on layer Y=1.
if item >= 7 and item <= 20 and y == 0:
y = 1
# PROTECTED FLOOR CHECK
if y == 1 and item >= 7 and item <= 20:
var f0 = enhanced_gridmap.get_cell_item(Vector3i(x, 0, z))