fix: 修复聊天系统编译错误

- 修复 WebSocketManager/SocketIOClient 函数缩进错误
- 重命名 is_connected() 避免与 Object 基类冲突
- 修复 tscn 文件多余前导空格
- 修复测试文件 GUT 断言函数调用
- 添加 GUT 测试框架
This commit is contained in:
WhaleTown Developer
2026-01-08 00:11:12 +08:00
parent 16f24ab26f
commit c8e73bec59
255 changed files with 21876 additions and 91 deletions

View File

@@ -14,6 +14,7 @@ extends Control
# 场景节点引用
@onready var auth_scene: Control = $AuthScene
@onready var main_game_ui: Control = $MainGameUI
@onready var chat_ui: Control = %ChatUI
@onready var user_label: Label = $MainGameUI/TopBar/HBoxContainer/UserLabel
@onready var logout_button: Button = $MainGameUI/TopBar/HBoxContainer/LogoutButton
@@ -87,11 +88,21 @@ func _on_login_success(username: String):
# 登录成功后的处理
current_user = username
print("用户 ", username, " 登录成功!")
# 连接到聊天服务器(在进入游戏界面之前)
print("🔌 开始连接聊天服务器...")
ChatManager.connect_to_chat_server()
show_main_game()
func _on_logout_pressed():
# 登出处理
current_user = ""
# 断开聊天服务器连接
print("🔌 断开聊天服务器...")
ChatManager.disconnect_from_chat_server()
show_auth_scene()
# 游戏功能按钮处理

View File

@@ -2,6 +2,7 @@
[ext_resource type="Script" path="res://scenes/MainScene.gd" id="1_script"]
[ext_resource type="PackedScene" uid="uid://by7m8snb4xllf" path="res://scenes/ui/AuthScene.tscn" id="2_main"]
[ext_resource type="PackedScene" uid="uid://bv7k2nan4xj8q" path="res://scenes/ui/ChatUI.tscn" id="3_chat_ui"]
[node name="Main" type="Control"]
layout_mode = 3

View File

@@ -328,7 +328,7 @@ func _on_login_enter(_text: String):
# ============ 控制器信号处理 ============
# 登录成功处理
func _on_controller_login_success(username: String):
func _on_controller_login_success(username: String) -> void:
# 清空表单
login_username.text = ""
login_password.text = ""
@@ -336,7 +336,13 @@ func _on_controller_login_success(username: String):
_hide_field_error(login_username_error)
_hide_field_error(login_password_error)
_hide_field_error(login_verification_error)
# 设置 token 给 ChatManager用于 WebSocket 聊天认证)
var token: String = auth_manager.get_access_token()
if not token.is_empty():
ChatManager.set_game_token(token)
print("✅ 已设置 ChatManager token: ", token.substr(0, 20) + "...")
# 发送登录成功信号给上层
login_success.emit(username)

View File

@@ -297,16 +297,17 @@ func _on_chat_error(data: Dictionary) -> void:
# 3秒后恢复状态
var timer := get_tree().create_timer(3.0)
timer.timeout.connect(func():
_update_connection_status(ChatManager.is_connected())
)
var timeout_callback := func():
_update_connection_status(ChatManager.is_chat_connected())
timer.timeout.connect(timeout_callback)
# 处理连接状态变化
func _on_connection_state_changed(data: Dictionary) -> void:
var state: WebSocketManager.ConnectionState = data.get("state", WebSocketManager.ConnectionState.DISCONNECTED)
var state_names := ["DISCONNECTED", "CONNECTING", "CONNECTED", "RECONNECTING", "ERROR"]
var state: int = data.get("state", 0)
match state:
WebSocketManager.ConnectionState.CONNECTED:
2: # CONNECTED
_update_connection_status(true)
_:
_update_connection_status(false)

View File

@@ -1,8 +1,10 @@
[gd_scene load_steps=2 format=3 uid="uid://bv7k2m9n4xj8q"]
[gd_scene load_steps=3 format=3 uid="uid://bv7k2nan4xj8q"]
[ext_resource type="Script" path="res://scenes/ui/ChatUI.gd" id="1"]
[ext_resource type="Script" uid="uid://pibdlvhb12q8" path="res://scenes/ui/ChatUI.gd" id="1"]
[ext_resource type="Texture2D" uid="uid://flepo0gpb55h" path="res://assets/ui/chat/缩略框背景.png" id="2_7dhmv"]
[node name="ChatUI" type="Control"]
custom_minimum_size = Vector2(10, 20)
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
@@ -10,19 +12,28 @@ anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
mouse_filter = 2
unique_name_in_owner = true
script = ExtResource("1")
[node name="TextureRect" type="TextureRect" parent="."]
layout_mode = 0
offset_left = 10.0
offset_top = 358.0
offset_right = 460.0
offset_bottom = 758.0
texture = ExtResource("2_7dhmv")
expand_mode = 1
[node name="ChatPanel" type="Panel" parent="."]
unique_name_in_owner = true
layout_mode = 1
anchors_preset = 3
anchor_left = 1.0
anchors_preset = 2
anchor_top = 1.0
anchor_right = 1.0
anchor_bottom = 1.0
offset_left = -450.0
offset_top = -400.0
grow_horizontal = 0
offset_left = 10.0
offset_top = -410.0
offset_right = 460.0
offset_bottom = -10.0
grow_vertical = 0
[node name="VBoxContainer" type="VBoxContainer" parent="ChatPanel"]
@@ -30,13 +41,13 @@ layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
theme_override_constants/separation = 8
offset_left = 10.0
offset_top = 10.0
offset_right = -10.0
offset_bottom = -10.0
grow_horizontal = 2
grow_vertical = 2
theme_override_constants/separation = 8
[node name="HeaderContainer" type="HBoxContainer" parent="ChatPanel/VBoxContainer"]
layout_mode = 2