Files
Sprout-Farm/Server/test/文档/游戏小提示配置系统说明.md
2025-08-19 09:13:54 +08:00

144 lines
3.9 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 游戏小提示配置系统实现说明
## 概述
本系统成功将游戏小提示配置从客户端硬编码迁移到服务端数据库管理,实现了动态配置和灵活的显示模式。
## 系统架构
### 1. 数据库层 (MongoDB)
- **配置ID**: `687e40008e77ba00a7414bb2`
- **集合**: `gameconfig`
- **配置结构**:
```json
{
"切换模式": "顺序", // 可选:顺序、随机、倒序
"切换速度": 5, // 切换间隔(秒)
"游戏小提示": [ // 小提示内容数组
"按住wsad可以移动游戏画面",
"使用鼠标滚轮来缩放游戏画面",
// ... 更多小提示
]
}
```
### 2. 服务端层 (Python)
#### SMYMongoDBAPI.py 新增功能
- `get_game_tips_config()`: 获取游戏小提示配置
- `update_game_tips_config()`: 更新游戏小提示配置
- 配置ID: `CONFIG_IDS["game_tips"]`
#### TCPGameServer.py 新增功能
- `_load_game_tips_config()`: 从数据库加载配置
- `_handle_game_tips_config_request()`: 处理客户端配置请求
- 消息路由: `request_game_tips_config` → `_handle_game_tips_config_request`
### 3. 客户端层 (GDScript)
#### TCPNetworkManager.gd 新增功能
- `sendGetGameTipsConfig()`: 发送配置请求
- 消息处理: `game_tips_config_response` → `main_game._handle_game_tips_config_response`
#### MainGame.gd 新增功能
- `game_tips_config`: 存储服务端配置
- `current_tip_index`: 顺序/倒序模式的索引
- `_handle_game_tips_config_response()`: 处理服务端响应
- `_random_small_game_tips()`: 重构为支持多种切换模式
## 功能特性
### 1. 切换模式
- **顺序模式**: 按配置顺序依次显示小提示
- **倒序模式**: 按配置倒序依次显示小提示
- **随机模式**: 随机选择小提示显示
### 2. 动态配置
- 服务端可随时更新小提示内容
- 客户端启动时自动获取最新配置
- 支持热更新(无需重启游戏)
### 3. 容错机制
- 服务端配置不可用时使用本地默认配置
- 配置为空时显示默认欢迎信息
- 网络异常时优雅降级
## 部署文件
### 1. 配置导入脚本
- `import_game_tips_config.py`: 将配置数据导入MongoDB
- 包含15条游戏小提示
- 默认配置顺序模式5秒切换间隔
### 2. 测试脚本
- `test_game_tips_config.py`: 基础功能测试
- `test_complete_game_tips_system.py`: 完整系统测试
## 使用方法
### 1. 初始化配置
```bash
cd Server
python import_game_tips_config.py
```
### 2. 测试系统
```bash
python test_game_tips_config.py
```
### 3. 客户端集成
游戏启动时会自动请求服务端配置:
```gdscript
# 在MainGame.gd中已集成
tcp_network_manager_panel.sendGetGameTipsConfig()
```
## 配置管理
### 1. 查看当前配置
```python
from SMYMongoDBAPI import SMYMongoDBAPI
api = SMYMongoDBAPI()
api.connect()
config = api.get_game_tips_config()
print(config)
```
### 2. 更新配置
```python
new_config = {
"切换模式": "随机",
"切换速度": 3,
"游戏小提示": ["新的小提示1", "新的小提示2"]
}
api.update_game_tips_config(new_config)
```
## 测试结果
**数据库操作测试**: 通过
**服务器加载测试**: 通过
**配置导入功能**: 通过
**客户端集成**: 完成
## 技术优势
1. **集中管理**: 所有小提示内容统一在服务端管理
2. **动态更新**: 无需客户端更新即可修改小提示
3. **灵活配置**: 支持多种显示模式和自定义切换速度
4. **高可用性**: 完善的容错机制确保系统稳定性
5. **易于维护**: 清晰的代码结构和完整的测试覆盖
## 后续扩展
1. **多语言支持**: 可扩展为支持多语言的小提示
2. **个性化配置**: 可为不同用户群体配置不同的小提示
3. **统计分析**: 可添加小提示显示统计和用户反馈
4. **管理界面**: 可开发Web管理界面方便运营人员管理
---
**实现完成时间**: 2024年12月
**版本**: 1.0
**状态**: 已完成并测试通过