feat: Add initial lobby and main scenes with Nakama and lobby management scripts.

This commit is contained in:
2025-12-06 02:27:08 +08:00
parent 5000f3e269
commit 438c0c0d6e
9 changed files with 1061 additions and 39 deletions
+40
View File
@@ -112,6 +112,46 @@ func _on_bridge_match_join_error(error) -> void:
func is_connected_to_nakama() -> bool:
return socket != null and socket.is_connected_to_host()
# --- Match Listing ---
func list_matches_async() -> Array:
"""Query available matches from Nakama server."""
if not client:
push_error("Cannot list matches: Client not initialized")
return []
if not session or session.is_expired():
push_error("Cannot list matches: No valid session")
return []
print("Querying matches from Nakama server...")
# Query matches - min 0, max 8 players, limit 20, authoritative=false for relayed matches
var result = await client.list_matches_async(session, 0, 8, 20, false, "", "")
if result.is_exception():
printerr("Failed to list matches: ", result.get_exception().message)
return []
var rooms: Array = []
if result.matches:
print("Found %d matches" % result.matches.size())
for match_data in result.matches:
print(" Match: ", match_data.match_id, " - Size: ", match_data.size)
# Use first 8 chars of match ID as room identifier since Nakama doesn't store custom names
var short_id = match_data.match_id.substr(0, 8) if match_data.match_id.length() > 8 else match_data.match_id
rooms.append({
"match_id": match_data.match_id,
"room_name": short_id,
"host_name": "Host",
"player_count": match_data.size if match_data.size else 1,
"max_players": 4
})
else:
print("No matches found")
return rooms
func _exit_tree():
if socket:
socket.close()