test implement webrtc

This commit is contained in:
2026-01-14 18:25:07 +01:00
parent 0c0998cd05
commit f71b510cfc
9 changed files with 1091 additions and 56 deletions

View File

@@ -12,8 +12,12 @@ var label_time: Label = null
var label_time_value: Label = null
var label_boss: Label = null
var texture_progress_bar_boss_hp: TextureProgressBar = null
var label_host: Label = null
var label_player_count: Label = null
var label_room_code: Label = null
var game_world: Node = null
var network_manager: Node = null
var local_player: Node = null
var level_start_time: float = 0.0
var player_search_attempts: int = 0
@@ -34,6 +38,16 @@ func _ready():
label_time_value = get_node_or_null("UpperLeft/HBoxContainer/VBoxContainerTime/LabelTimeValue")
label_boss = get_node_or_null("UpperRight/HBoxContainer/VBoxContainerBoss/LabelBoss")
texture_progress_bar_boss_hp = get_node_or_null("UpperRight/HBoxContainer/VBoxContainerBoss/TextureProgressBarBossHP")
label_host = get_node_or_null("UpperRight/HBoxContainer/VBoxContainerHost/LabelHost")
label_player_count = get_node_or_null("UpperRight/HBoxContainer/VBoxContainerHost/LabelPlayerCount")
label_room_code = get_node_or_null("UpperRight/HBoxContainer/VBoxContainerHost/LabelRoomCode")
# Find network manager
network_manager = get_node_or_null("/root/NetworkManager")
if network_manager:
# Connect to player connection signals to update player count
network_manager.player_connected.connect(_on_player_connected)
network_manager.player_disconnected.connect(_on_player_disconnected)
# Debug: Check if nodes were found
if not label_time_value:
@@ -56,6 +70,9 @@ func _ready():
if label_boss:
label_boss.visible = false
# Update host info display
_update_host_info()
# Start level timer
level_start_time = Time.get_ticks_msec() / 1000.0
@@ -63,6 +80,41 @@ func _ready():
player_search_attempts = 0
_find_local_player()
func _on_player_connected(_peer_id: int, _player_info: Dictionary):
_update_host_info()
func _on_player_disconnected(_peer_id: int, _player_info: Dictionary):
_update_host_info()
func _update_host_info():
if not network_manager:
return
# Update HOST label visibility
if label_host:
label_host.visible = network_manager.is_hosting
# Update player count
if label_player_count and network_manager.players_info:
var total_players = 0
for peer_id in network_manager.players_info.keys():
var info = network_manager.players_info[peer_id]
total_players += info.get("local_player_count", 1)
label_player_count.text = "Players: " + str(total_players)
# Update room code (only show if WebRTC/WebSocket and hosting)
if label_room_code:
var mode = network_manager.network_mode
if (mode == 1 or mode == 2) and network_manager.is_hosting: # WebRTC or WebSocket
var room_id = network_manager.get_room_id()
if not room_id.is_empty():
label_room_code.text = "Room: " + room_id
label_room_code.visible = true
else:
label_room_code.visible = false
else:
label_room_code.visible = false
func _find_local_player():
# Prevent infinite recursion
player_search_attempts += 1