forked from datawhale/whale-town-front
- 添加 SocketIOClient.gd 实现 Socket.IO 协议封装 - 添加 WebSocketManager.gd 管理连接生命周期和自动重连 - 添加 ChatManager.gd 实现聊天业务逻辑与会话管理 - 支持当前会话缓存(最多 100 条消息) - 支持历史消息按需加载(每次 100 条) - 每次登录/重连自动重置会话缓存 - 客户端频率限制(10 条/分钟) - Token 管理与认证 - 添加 ChatMessage.gd/tscn 消息气泡 UI 组件 - 添加 ChatUI.gd/tscn 聊天界面 - 在 EventNames.gd 添加 7 个聊天事件常量 - 在 AuthManager.gd 添加 game_token 管理方法 - 添加完整的单元测试(128 个测试用例) - test_socketio_client.gd (42 个测试) - test_websocket_manager.gd (38 个测试) - test_chat_manager.gd (48 个测试) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
71 lines
3.0 KiB
GDScript
71 lines
3.0 KiB
GDScript
# ============================================================================
|
|
# 事件名称定义 - EventNames.gd
|
|
#
|
|
# 定义项目中所有事件的名称常量,确保事件名称的一致性和可维护性
|
|
#
|
|
# 使用方式:
|
|
# EventSystem.emit_event(EventNames.PLAYER_MOVED, data)
|
|
# EventSystem.connect_event(EventNames.INTERACT_PRESSED, callback)
|
|
# ============================================================================
|
|
|
|
class_name EventNames
|
|
|
|
# ============================================================================
|
|
# 玩家相关事件
|
|
# ============================================================================
|
|
const PLAYER_MOVED = "player_moved"
|
|
const PLAYER_SPAWNED = "player_spawned"
|
|
const PLAYER_HEALTH_CHANGED = "player_health_changed"
|
|
const PLAYER_DIED = "player_died"
|
|
const PLAYER_RESPAWNED = "player_respawned"
|
|
const PLAYER_ATTACK = "player_attack"
|
|
|
|
# ============================================================================
|
|
# 交互事件
|
|
# ============================================================================
|
|
const INTERACT_PRESSED = "interact_pressed"
|
|
const NPC_TALKED = "npc_talked"
|
|
const ITEM_COLLECTED = "item_collected"
|
|
const OBJECT_INTERACTED = "object_interacted"
|
|
|
|
# ============================================================================
|
|
# UI事件
|
|
# ============================================================================
|
|
const UI_BUTTON_CLICKED = "ui_button_clicked"
|
|
const DIALOG_OPENED = "dialog_opened"
|
|
const DIALOG_CLOSED = "dialog_closed"
|
|
const MENU_OPENED = "menu_opened"
|
|
const MENU_CLOSED = "menu_closed"
|
|
|
|
# ============================================================================
|
|
# 游戏状态事件
|
|
# ============================================================================
|
|
const GAME_PAUSED = "game_paused"
|
|
const GAME_RESUMED = "game_resumed"
|
|
const SCENE_CHANGED = "scene_changed"
|
|
const SCENE_DATA_TRANSFER = "scene_data_transfer"
|
|
|
|
# ============================================================================
|
|
# 系统事件
|
|
# ============================================================================
|
|
const TILEMAP_READY = "tilemap_ready"
|
|
const COMPONENT_MESSAGE = "component_message"
|
|
const POSITION_UPDATE = "position_update"
|
|
const GRID_POSITION_CHANGED = "grid_position_changed"
|
|
const GRID_SNAP_REQUESTED = "grid_snap_requested"
|
|
|
|
# ============================================================================
|
|
# 测试事件
|
|
# ============================================================================
|
|
const TEST_EVENT = "test_event"
|
|
|
|
# ============================================================================
|
|
# 聊天事件
|
|
# ============================================================================
|
|
const CHAT_MESSAGE_SENT = "chat_message_sent"
|
|
const CHAT_MESSAGE_RECEIVED = "chat_message_received"
|
|
const CHAT_ERROR_OCCURRED = "chat_error_occurred"
|
|
const CHAT_CONNECTION_STATE_CHANGED = "chat_connection_state_changed"
|
|
const CHAT_POSITION_UPDATED = "chat_position_updated"
|
|
const CHAT_LOGIN_SUCCESS = "chat_login_success"
|
|
const CHAT_LOGIN_FAILED = "chat_login_failed" |