test implement webrtc
This commit is contained in:
@@ -5,6 +5,8 @@ extends CanvasLayer
|
||||
@onready var main_menu = $Control/MainMenu
|
||||
@onready var host_button = $Control/MainMenu/VBoxContainer/HostButton
|
||||
@onready var join_button = $Control/MainMenu/VBoxContainer/JoinButton
|
||||
@onready var network_mode_option = $Control/MainMenu/VBoxContainer/NetworkModeContainer/NetworkModeOption
|
||||
@onready var network_mode_container = $Control/MainMenu/VBoxContainer/NetworkModeContainer
|
||||
@onready var local_players_spinbox = $Control/MainMenu/VBoxContainer/LocalPlayersContainer/SpinBox
|
||||
@onready var address_input = $Control/MainMenu/VBoxContainer/AddressContainer/AddressInput
|
||||
|
||||
@@ -32,6 +34,27 @@ func _ready():
|
||||
host_button.pressed.connect(_on_host_pressed)
|
||||
join_button.pressed.connect(_on_join_pressed)
|
||||
|
||||
# Setup network mode dropdown
|
||||
if network_mode_option:
|
||||
network_mode_option.item_selected.connect(_on_network_mode_changed)
|
||||
|
||||
# On web builds, filter out ENet option (only WebRTC and WebSocket available)
|
||||
if OS.get_name() == "Web":
|
||||
print("GameUI: Web platform detected, filtering network mode options")
|
||||
# Remove ENet option (index 0) for web builds
|
||||
network_mode_option.remove_item(0)
|
||||
# Adjust selected index (was 0 for ENet, now 0 is WebRTC)
|
||||
network_mode_option.selected = 0
|
||||
# Update network manager to use WebRTC by default
|
||||
network_manager.set_network_mode(1)
|
||||
else:
|
||||
# On native builds, default to ENet (index 0)
|
||||
network_mode_option.selected = 0
|
||||
network_manager.set_network_mode(0)
|
||||
|
||||
# Update address input placeholder based on initial mode
|
||||
_on_network_mode_changed(network_mode_option.selected)
|
||||
|
||||
# Connect network signals
|
||||
if network_manager:
|
||||
network_manager.connection_succeeded.connect(_on_connection_succeeded)
|
||||
@@ -50,7 +73,8 @@ func _check_command_line_args():
|
||||
var should_host = false
|
||||
var should_join = false
|
||||
var should_debug = false
|
||||
var join_address = "127.0.0.1"
|
||||
var force_webrtc = false
|
||||
var join_address = "ruinborn.thefirstboss.com"
|
||||
var local_count = 1
|
||||
|
||||
for arg in args:
|
||||
@@ -60,6 +84,9 @@ func _check_command_line_args():
|
||||
elif arg == "--join":
|
||||
should_join = true
|
||||
print("GameUI: Found --join argument")
|
||||
elif arg == "--websocket" or arg == "--webrtc":
|
||||
force_webrtc = true
|
||||
print("GameUI: Found --websocket/--webrtc argument (forcing WebSocket mode)")
|
||||
elif arg == "--room-debug":
|
||||
should_debug = true
|
||||
print("GameUI: Found --room-debug argument")
|
||||
@@ -68,7 +95,18 @@ func _check_command_line_args():
|
||||
elif arg.begins_with("--players="):
|
||||
local_count = int(arg.split("=")[1])
|
||||
|
||||
print("GameUI: Parsed flags - should_host: ", should_host, ", should_join: ", should_join, ", should_debug: ", should_debug)
|
||||
print("GameUI: Parsed flags - should_host: ", should_host, ", should_join: ", should_join, ", force_webrtc: ", force_webrtc, ", should_debug: ", should_debug)
|
||||
|
||||
# Force WebRTC mode if --webrtc flag is present
|
||||
if force_webrtc:
|
||||
network_manager.set_network_mode(1) # WebRTC
|
||||
if network_mode_option:
|
||||
if OS.get_name() == "Web":
|
||||
network_mode_option.selected = 0 # WebRTC is first option on web
|
||||
else:
|
||||
network_mode_option.selected = 1 # WebRTC is second option on native
|
||||
_on_network_mode_changed(network_mode_option.selected)
|
||||
print("GameUI: WebRTC mode forced via --webrtc flag")
|
||||
|
||||
# Set debug flag only if --room-debug is used with --host or --join
|
||||
if should_debug and (should_host or should_join):
|
||||
@@ -91,24 +129,68 @@ func _check_command_line_args():
|
||||
# Connection callback will handle starting the game
|
||||
pass
|
||||
|
||||
func _on_network_mode_changed(index: int):
|
||||
# On web builds, index 0 = WebRTC, index 1 = WebSocket
|
||||
# On native builds, index 0 = ENet, index 1 = WebRTC, index 2 = WebSocket
|
||||
var actual_mode: int
|
||||
if OS.get_name() == "Web":
|
||||
# Web builds: 0 = WebRTC, 1 = WebSocket
|
||||
actual_mode = index + 1 # Map 0->1 (WebRTC), 1->2 (WebSocket)
|
||||
else:
|
||||
# Native builds: 0 = ENet, 1 = WebRTC, 2 = WebSocket
|
||||
actual_mode = index
|
||||
|
||||
network_manager.set_network_mode(actual_mode)
|
||||
|
||||
# Update address input placeholder based on mode
|
||||
if address_input:
|
||||
match actual_mode:
|
||||
0: # ENet
|
||||
address_input.placeholder_text = "Server IP or domain"
|
||||
1: # WebRTC
|
||||
address_input.placeholder_text = "Enter Room Code (e.g., ABC123)"
|
||||
2: # WebSocket
|
||||
address_input.placeholder_text = "Enter Room Code (e.g., ABC123)"
|
||||
|
||||
var mode_names = ["ENet", "WebRTC", "WebSocket"]
|
||||
print("GameUI: Network mode changed to: ", mode_names[actual_mode])
|
||||
|
||||
func _on_host_pressed():
|
||||
var local_count = int(local_players_spinbox.value)
|
||||
network_manager.set_local_player_count(local_count)
|
||||
|
||||
if network_manager.host_game():
|
||||
print("Hosting game with ", local_count, " local players")
|
||||
var mode = network_manager.network_mode
|
||||
if mode == 1 or mode == 2: # WebRTC or WebSocket
|
||||
var room_id = network_manager.get_room_id()
|
||||
var mode_name = "WebRTC" if mode == 1 else "WebSocket"
|
||||
print("Hosting ", mode_name, " game - Room Code: ", room_id)
|
||||
print("Share this code with players!")
|
||||
else:
|
||||
print("Hosting ENet game with ", local_count, " local players")
|
||||
_start_game()
|
||||
|
||||
func _on_join_pressed():
|
||||
var address = address_input.text
|
||||
if address.is_empty():
|
||||
address = "127.0.0.1"
|
||||
var mode = network_manager.network_mode
|
||||
if mode == 1 or mode == 2: # WebRTC or WebSocket
|
||||
print("Error: Please enter a room code")
|
||||
return
|
||||
else: # ENet
|
||||
address = "127.0.0.1"
|
||||
|
||||
var local_count = int(local_players_spinbox.value)
|
||||
network_manager.set_local_player_count(local_count)
|
||||
|
||||
if network_manager.join_game(address):
|
||||
print("Joining game at ", address, " with ", local_count, " local players")
|
||||
var mode = network_manager.network_mode
|
||||
if mode == 1: # WebRTC
|
||||
print("Joining WebRTC game with room code: ", address)
|
||||
elif mode == 2: # WebSocket
|
||||
print("Joining WebSocket game with room code: ", address)
|
||||
else: # ENet
|
||||
print("Joining ENet game at ", address, " with ", local_count, " local players")
|
||||
|
||||
func _on_connection_succeeded():
|
||||
print("Connection succeeded, starting game")
|
||||
|
||||
Reference in New Issue
Block a user