优化项目架构
This commit is contained in:
90
SproutFarm-Backend/test/文档/ConsoleCommandsAPI_README.md
Normal file
90
SproutFarm-Backend/test/文档/ConsoleCommandsAPI_README.md
Normal file
@@ -0,0 +1,90 @@
|
||||
# 控制台命令API模块 (ConsoleCommandsAPI)
|
||||
|
||||
## 功能特性
|
||||
|
||||
### 基础游戏管理命令
|
||||
- `/addmoney <QQ号> <数量>` - 为玩家添加金币
|
||||
- `/addxp <QQ号> <数量>` - 为玩家添加经验值
|
||||
- `/addlevel <QQ号> <数量>` - 为玩家添加等级
|
||||
- `/addseed <QQ号> <作物名称> <数量>` - 为玩家添加种子
|
||||
- `/lsplayer` - 列出所有在线玩家
|
||||
- `/playerinfo <QQ号>` - 查看玩家详细信息
|
||||
- `/resetland <QQ号>` - 重置玩家土地
|
||||
- `/weather <天气类型>` - 设置天气
|
||||
|
||||
### 系统管理命令
|
||||
- `/help` - 显示帮助信息
|
||||
- `/save` - 保存所有玩家数据
|
||||
- `/reload` - 重新加载配置文件
|
||||
- `/stop` - 停止服务器
|
||||
|
||||
### MongoDB数据库管理命令
|
||||
- `/dbtest` - 测试数据库连接
|
||||
- `/dbconfig <操作> [参数]` - 数据库配置管理
|
||||
- `list` - 列出所有配置类型
|
||||
- `get <配置类型>` - 获取指定配置
|
||||
- `reload <配置类型>` - 重新加载指定配置到服务器
|
||||
- `/dbchat <操作> [参数]` - 聊天消息管理
|
||||
- `latest` - 获取最新聊天消息
|
||||
- `history [天数] [数量]` - 获取聊天历史
|
||||
- `clean [保留天数]` - 清理旧聊天消息
|
||||
- `/dbclean <类型>` - 数据库清理
|
||||
- `codes` - 清理过期验证码
|
||||
- `chat [保留天数]` - 清理旧聊天消息
|
||||
- `all` - 清理所有过期数据
|
||||
- `/dbbackup [类型]` - 数据库备份
|
||||
- `config` - 备份游戏配置
|
||||
- `chat` - 备份聊天消息
|
||||
|
||||
## 使用方法
|
||||
|
||||
### 1. 导入模块
|
||||
```python
|
||||
from ConsoleCommandsAPI import ConsoleCommandsAPI
|
||||
```
|
||||
|
||||
### 2. 初始化
|
||||
```python
|
||||
# 在服务器初始化时创建控制台命令实例
|
||||
console = ConsoleCommandsAPI(server)
|
||||
```
|
||||
|
||||
### 3. 处理命令
|
||||
```python
|
||||
# 在控制台输入处理函数中
|
||||
command_line = input("服务器控制台> ")
|
||||
console.process_command(command_line)
|
||||
```
|
||||
|
||||
## 扩展功能
|
||||
|
||||
### 添加自定义命令
|
||||
```python
|
||||
# 添加新命令
|
||||
console.add_custom_command("mycommand", my_command_function, "我的自定义命令")
|
||||
|
||||
# 移除命令
|
||||
console.remove_command("mycommand")
|
||||
|
||||
# 获取命令信息
|
||||
info = console.get_command_info("addmoney")
|
||||
|
||||
# 批量执行命令
|
||||
commands = ["addmoney 123456 1000", "addxp 123456 500"]
|
||||
console.execute_batch_commands(commands)
|
||||
```
|
||||
|
||||
## 依赖项
|
||||
|
||||
- `SMYMongoDBAPI` - MongoDB数据库操作模块
|
||||
- `json` - JSON数据处理
|
||||
- `os` - 操作系统接口
|
||||
- `datetime` - 日期时间处理
|
||||
- `typing` - 类型提示
|
||||
|
||||
## 注意事项
|
||||
|
||||
1. **MongoDB集成**: 数据库相关命令需要服务器启用MongoDB支持
|
||||
2. **权限管理**: 所有命令都具有管理员权限,请谨慎使用
|
||||
3. **数据备份**: 建议定期使用 `/dbbackup` 命令备份重要数据
|
||||
4. **错误处理**: 所有命令都包含完善的错误处理和用户友好的提示信息
|
||||
559
SproutFarm-Backend/test/文档/DisplayServer_总结_Markdown.md
Normal file
559
SproutFarm-Backend/test/文档/DisplayServer_总结_Markdown.md
Normal file
@@ -0,0 +1,559 @@
|
||||
# DisplayServer API 参考文档
|
||||
|
||||
## 类简介
|
||||
|
||||
**继承**:Object
|
||||
|
||||
DisplayServer 是用于低阶窗口管理的服务器接口。所有与窗口管理相关的内容都由 DisplayServer(显示服务器)处理。
|
||||
|
||||
> **无头模式**:如果使用 `--headless` 命令行参数启动引擎,就会禁用所有渲染和窗口管理功能,此时 DisplayServer 的大多数函数都会返回虚设值。
|
||||
|
||||
---
|
||||
|
||||
## 方法列表
|
||||
|
||||
### 🔔 系统交互
|
||||
|
||||
#### `void beep()`
|
||||
发出系统提示音。
|
||||
|
||||
#### `void enable_for_stealing_focus(process_id: int)`
|
||||
允许指定进程获取焦点。
|
||||
|
||||
#### `void force_process_and_drop_events()`
|
||||
强制处理并丢弃所有事件。
|
||||
|
||||
---
|
||||
|
||||
### 📋 剪贴板操作
|
||||
|
||||
#### `String clipboard_get()`
|
||||
获取剪贴板文本内容。
|
||||
|
||||
#### `Image clipboard_get_image()`
|
||||
获取剪贴板图像内容。
|
||||
|
||||
#### `String clipboard_get_primary()`
|
||||
获取主剪贴板文本内容(仅限 Linux)。
|
||||
|
||||
#### `bool clipboard_has()`
|
||||
检查剪贴板是否有内容。
|
||||
|
||||
#### `bool clipboard_has_image()`
|
||||
检查剪贴板是否有图像。
|
||||
|
||||
#### `void clipboard_set(clipboard: String)`
|
||||
设置剪贴板文本内容。
|
||||
|
||||
#### `void clipboard_set_primary(clipboard_primary: String)`
|
||||
设置主剪贴板文本内容(仅限 Linux)。
|
||||
|
||||
---
|
||||
|
||||
### 🖱️ 鼠标和光标
|
||||
|
||||
#### `CursorShape cursor_get_shape()`
|
||||
获取当前光标形状。
|
||||
|
||||
#### `void cursor_set_custom_image(cursor: Resource, shape: CursorShape = 0, hotspot: Vector2 = Vector2(0, 0))`
|
||||
设置自定义光标图像。
|
||||
|
||||
#### `void cursor_set_shape(shape: CursorShape)`
|
||||
设置光标形状。
|
||||
|
||||
#### `BitField[MouseButtonMask] mouse_get_button_state()`
|
||||
获取鼠标按键状态。
|
||||
|
||||
#### `MouseMode mouse_get_mode()`
|
||||
获取鼠标模式。
|
||||
|
||||
#### `Vector2i mouse_get_position()`
|
||||
获取鼠标位置。
|
||||
|
||||
#### `void mouse_set_mode(mouse_mode: MouseMode)`
|
||||
设置鼠标模式。
|
||||
|
||||
#### `void warp_mouse(position: Vector2i)`
|
||||
将鼠标光标移动到指定位置。
|
||||
|
||||
---
|
||||
|
||||
### 💬 对话框
|
||||
|
||||
#### `Error dialog_input_text(title: String, description: String, existing_text: String, callback: Callable)`
|
||||
显示文本输入对话框。
|
||||
|
||||
#### `Error dialog_show(title: String, description: String, buttons: PackedStringArray, callback: Callable)`
|
||||
显示系统对话框。
|
||||
|
||||
#### `Error file_dialog_show(title: String, current_directory: String, filename: String, show_hidden: bool, mode: FileDialogMode, filters: PackedStringArray, callback: Callable)`
|
||||
显示文件选择对话框。
|
||||
|
||||
#### `Error file_dialog_with_options_show(title: String, current_directory: String, root: String, filename: String, show_hidden: bool, mode: FileDialogMode, filters: PackedStringArray, options: Array[Dictionary], callback: Callable)`
|
||||
显示带扩展选项的文件选择对话框。
|
||||
|
||||
---
|
||||
|
||||
### 🎨 主题和颜色
|
||||
|
||||
#### `Color get_accent_color()`
|
||||
获取系统强调色。
|
||||
|
||||
#### `Color get_base_color()`
|
||||
获取系统基础色。
|
||||
|
||||
#### `bool is_dark_mode()`
|
||||
检查系统是否为深色模式。
|
||||
|
||||
#### `bool is_dark_mode_supported()`
|
||||
检查系统是否支持深色模式。
|
||||
|
||||
#### `void set_system_theme_change_callback(callable: Callable)`
|
||||
设置系统主题变化时的回调。
|
||||
|
||||
---
|
||||
|
||||
### 📱 显示和屏幕
|
||||
|
||||
#### `Array[Rect2] get_display_cutouts()`
|
||||
获取显示器刘海信息。
|
||||
|
||||
#### `Rect2i get_display_safe_area()`
|
||||
获取显示器安全区域。
|
||||
|
||||
#### `int get_keyboard_focus_screen()`
|
||||
获取键盘焦点所在屏幕。
|
||||
|
||||
#### `String get_name()`
|
||||
获取显示服务器名称。
|
||||
|
||||
#### `int get_primary_screen()`
|
||||
获取主屏幕索引。
|
||||
|
||||
#### `int get_screen_count()`
|
||||
获取屏幕数量。
|
||||
|
||||
#### `int get_screen_from_rect(rect: Rect2)`
|
||||
根据矩形位置获取屏幕索引。
|
||||
|
||||
#### `bool get_swap_cancel_ok()`
|
||||
获取是否交换确定取消按钮。
|
||||
|
||||
#### `int get_window_at_screen_position(position: Vector2i)`
|
||||
获取指定屏幕位置的窗口ID。
|
||||
|
||||
#### `PackedInt32Array get_window_list()`
|
||||
获取所有窗口ID列表。
|
||||
|
||||
---
|
||||
|
||||
### 🖥️ 屏幕操作
|
||||
|
||||
#### `int screen_get_dpi(screen: int = -1)`
|
||||
获取屏幕DPI。
|
||||
|
||||
#### `Image screen_get_image(screen: int = -1)`
|
||||
获取屏幕截图。
|
||||
|
||||
#### `Image screen_get_image_rect(rect: Rect2i)`
|
||||
获取屏幕指定区域截图。
|
||||
|
||||
#### `float screen_get_max_scale()`
|
||||
获取所有屏幕的最大缩放系数。
|
||||
|
||||
#### `ScreenOrientation screen_get_orientation(screen: int = -1)`
|
||||
获取屏幕朝向。
|
||||
|
||||
#### `Color screen_get_pixel(position: Vector2i)`
|
||||
获取指定位置的像素颜色。
|
||||
|
||||
#### `Vector2i screen_get_position(screen: int = -1)`
|
||||
获取屏幕位置。
|
||||
|
||||
#### `float screen_get_refresh_rate(screen: int = -1)`
|
||||
获取屏幕刷新率。
|
||||
|
||||
#### `float screen_get_scale(screen: int = -1)`
|
||||
获取屏幕缩放系数。
|
||||
|
||||
#### `Vector2i screen_get_size(screen: int = -1)`
|
||||
获取屏幕大小。
|
||||
|
||||
#### `Rect2i screen_get_usable_rect(screen: int = -1)`
|
||||
获取屏幕可用区域。
|
||||
|
||||
#### `bool screen_is_kept_on()`
|
||||
检查屏幕是否保持开启。
|
||||
|
||||
#### `void screen_set_keep_on(enable: bool)`
|
||||
设置屏幕保持开启。
|
||||
|
||||
#### `void screen_set_orientation(orientation: ScreenOrientation, screen: int = -1)`
|
||||
设置屏幕朝向。
|
||||
|
||||
---
|
||||
|
||||
### 🖼️ 图标设置
|
||||
|
||||
#### `void set_icon(image: Image)`
|
||||
设置窗口图标。
|
||||
|
||||
#### `void set_native_icon(filename: String)`
|
||||
使用原生格式设置窗口图标。
|
||||
|
||||
---
|
||||
|
||||
### 💾 输出管理
|
||||
|
||||
#### `bool has_additional_outputs()`
|
||||
检查是否有额外输出设备。
|
||||
|
||||
#### `void register_additional_output(object: Object)`
|
||||
注册额外输出设备。
|
||||
|
||||
#### `void unregister_additional_output(object: Object)`
|
||||
取消注册额外输出设备。
|
||||
|
||||
---
|
||||
|
||||
### ⚡ 功能检测
|
||||
|
||||
#### `bool has_feature(feature: Feature)`
|
||||
检查是否支持指定功能。
|
||||
|
||||
#### `bool has_hardware_keyboard()`
|
||||
检查是否有硬件键盘。
|
||||
|
||||
#### `bool is_touchscreen_available()`
|
||||
检查是否支持触屏。
|
||||
|
||||
#### `bool is_window_transparency_available()`
|
||||
检查是否支持窗口透明。
|
||||
|
||||
---
|
||||
|
||||
### ⌨️ 键盘
|
||||
|
||||
#### `int keyboard_get_current_layout()`
|
||||
获取当前键盘布局。
|
||||
|
||||
#### `Key keyboard_get_keycode_from_physical(keycode: Key)`
|
||||
从物理按键获取键码。
|
||||
|
||||
#### `Key keyboard_get_label_from_physical(keycode: Key)`
|
||||
从物理按键获取标签。
|
||||
|
||||
#### `int keyboard_get_layout_count()`
|
||||
获取键盘布局数量。
|
||||
|
||||
#### `String keyboard_get_layout_language(index: int)`
|
||||
获取键盘布局语言。
|
||||
|
||||
#### `String keyboard_get_layout_name(index: int)`
|
||||
获取键盘布局名称。
|
||||
|
||||
#### `void keyboard_set_current_layout(index: int)`
|
||||
设置当前键盘布局。
|
||||
|
||||
---
|
||||
|
||||
### 📝 输入法
|
||||
|
||||
#### `Vector2i ime_get_selection()`
|
||||
获取输入法选中范围。
|
||||
|
||||
#### `String ime_get_text()`
|
||||
获取输入法文本。
|
||||
|
||||
---
|
||||
|
||||
### 🎯 状态指示器
|
||||
|
||||
#### `int create_status_indicator(icon: Texture2D, tooltip: String, callback: Callable)`
|
||||
创建状态指示器。
|
||||
|
||||
#### `void delete_status_indicator(id: int)`
|
||||
删除状态指示器。
|
||||
|
||||
#### `Rect2 status_indicator_get_rect(id: int)`
|
||||
获取状态指示器位置。
|
||||
|
||||
#### `void status_indicator_set_callback(id: int, callback: Callable)`
|
||||
设置状态指示器回调。
|
||||
|
||||
#### `void status_indicator_set_icon(id: int, icon: Texture2D)`
|
||||
设置状态指示器图标。
|
||||
|
||||
#### `void status_indicator_set_menu(id: int, menu_rid: RID)`
|
||||
设置状态指示器菜单。
|
||||
|
||||
#### `void status_indicator_set_tooltip(id: int, tooltip: String)`
|
||||
设置状态指示器提示文本。
|
||||
|
||||
---
|
||||
|
||||
### 📱 数位板
|
||||
|
||||
#### `String tablet_get_current_driver()`
|
||||
获取当前数位板驱动。
|
||||
|
||||
#### `int tablet_get_driver_count()`
|
||||
获取数位板驱动数量。
|
||||
|
||||
#### `String tablet_get_driver_name(idx: int)`
|
||||
获取数位板驱动名称。
|
||||
|
||||
#### `void tablet_set_current_driver(name: String)`
|
||||
设置数位板驱动。
|
||||
|
||||
---
|
||||
|
||||
### 🗣️ 文本转语音
|
||||
|
||||
#### `Array[Dictionary] tts_get_voices()`
|
||||
获取语音列表。
|
||||
|
||||
#### `PackedStringArray tts_get_voices_for_language(language: String)`
|
||||
获取指定语言的语音列表。
|
||||
|
||||
#### `bool tts_is_paused()`
|
||||
检查是否暂停。
|
||||
|
||||
#### `bool tts_is_speaking()`
|
||||
检查是否正在朗读。
|
||||
|
||||
#### `void tts_pause()`
|
||||
暂停朗读。
|
||||
|
||||
#### `void tts_resume()`
|
||||
恢复朗读。
|
||||
|
||||
#### `void tts_set_utterance_callback(event: TTSUtteranceEvent, callable: Callable)`
|
||||
设置朗读事件回调。
|
||||
|
||||
#### `void tts_speak(text: String, voice: String, volume: int = 50, pitch: float = 1.0, rate: float = 1.0, utterance_id: int = 0, interrupt: bool = false)`
|
||||
开始朗读文本。
|
||||
|
||||
#### `void tts_stop()`
|
||||
停止朗读。
|
||||
|
||||
---
|
||||
|
||||
### ⌨️ 虚拟键盘
|
||||
|
||||
#### `int virtual_keyboard_get_height()`
|
||||
获取虚拟键盘高度。
|
||||
|
||||
#### `void virtual_keyboard_hide()`
|
||||
隐藏虚拟键盘。
|
||||
|
||||
#### `void virtual_keyboard_show(existing_text: String, position: Rect2 = Rect2(0, 0, 0, 0), type: VirtualKeyboardType = 0, max_length: int = -1, cursor_start: int = -1, cursor_end: int = -1)`
|
||||
显示虚拟键盘。
|
||||
|
||||
---
|
||||
|
||||
### 🪟 窗口管理
|
||||
|
||||
#### `bool window_can_draw(window_id: int = 0)`
|
||||
检查窗口是否可绘制。
|
||||
|
||||
#### `int window_get_active_popup()`
|
||||
获取活动弹出窗口ID。
|
||||
|
||||
#### `int window_get_attached_instance_id(window_id: int = 0)`
|
||||
获取窗口附加的实例ID。
|
||||
|
||||
#### `int window_get_current_screen(window_id: int = 0)`
|
||||
获取窗口所在屏幕。
|
||||
|
||||
#### `bool window_get_flag(flag: WindowFlags, window_id: int = 0)`
|
||||
获取窗口标志。
|
||||
|
||||
#### `Vector2i window_get_max_size(window_id: int = 0)`
|
||||
获取窗口最大尺寸。
|
||||
|
||||
#### `Vector2i window_get_min_size(window_id: int = 0)`
|
||||
获取窗口最小尺寸。
|
||||
|
||||
#### `WindowMode window_get_mode(window_id: int = 0)`
|
||||
获取窗口模式。
|
||||
|
||||
#### `int window_get_native_handle(handle_type: HandleType, window_id: int = 0)`
|
||||
获取窗口原生句柄。
|
||||
|
||||
#### `Rect2i window_get_popup_safe_rect(window: int)`
|
||||
获取弹出窗口安全区域。
|
||||
|
||||
#### `Vector2i window_get_position(window_id: int = 0)`
|
||||
获取窗口位置。
|
||||
|
||||
#### `Vector2i window_get_position_with_decorations(window_id: int = 0)`
|
||||
获取窗口位置(含边框)。
|
||||
|
||||
#### `Vector3i window_get_safe_title_margins(window_id: int = 0)`
|
||||
获取标题栏安全边距。
|
||||
|
||||
#### `Vector2i window_get_size(window_id: int = 0)`
|
||||
获取窗口大小。
|
||||
|
||||
#### `Vector2i window_get_size_with_decorations(window_id: int = 0)`
|
||||
获取窗口大小(含边框)。
|
||||
|
||||
#### `Vector2i window_get_title_size(title: String, window_id: int = 0)`
|
||||
获取标题栏大小。
|
||||
|
||||
#### `VSyncMode window_get_vsync_mode(window_id: int = 0)`
|
||||
获取垂直同步模式。
|
||||
|
||||
#### `bool window_is_focused(window_id: int = 0)`
|
||||
检查窗口是否有焦点。
|
||||
|
||||
#### `bool window_is_maximize_allowed(window_id: int = 0)`
|
||||
检查窗口是否可最大化。
|
||||
|
||||
#### `bool window_maximize_on_title_dbl_click()`
|
||||
检查双击标题栏是否最大化。
|
||||
|
||||
#### `bool window_minimize_on_title_dbl_click()`
|
||||
检查双击标题栏是否最小化。
|
||||
|
||||
#### `void window_move_to_foreground(window_id: int = 0)`
|
||||
将窗口移到前台。
|
||||
|
||||
#### `void window_request_attention(window_id: int = 0)`
|
||||
请求窗口注意。
|
||||
|
||||
#### `void window_set_current_screen(screen: int, window_id: int = 0)`
|
||||
设置窗口所在屏幕。
|
||||
|
||||
#### `void window_set_drop_files_callback(callback: Callable, window_id: int = 0)`
|
||||
设置文件拖放回调。
|
||||
|
||||
#### `void window_set_exclusive(window_id: int, exclusive: bool)`
|
||||
设置窗口独占模式。
|
||||
|
||||
#### `void window_set_flag(flag: WindowFlags, enabled: bool, window_id: int = 0)`
|
||||
设置窗口标志。
|
||||
|
||||
#### `void window_set_ime_active(active: bool, window_id: int = 0)`
|
||||
设置输入法是否激活。
|
||||
|
||||
#### `void window_set_ime_position(position: Vector2i, window_id: int = 0)`
|
||||
设置输入法位置。
|
||||
|
||||
#### `void window_set_input_event_callback(callback: Callable, window_id: int = 0)`
|
||||
设置输入事件回调。
|
||||
|
||||
#### `void window_set_input_text_callback(callback: Callable, window_id: int = 0)`
|
||||
设置文本输入回调。
|
||||
|
||||
#### `void window_set_max_size(max_size: Vector2i, window_id: int = 0)`
|
||||
设置窗口最大尺寸。
|
||||
|
||||
#### `void window_set_min_size(min_size: Vector2i, window_id: int = 0)`
|
||||
设置窗口最小尺寸。
|
||||
|
||||
#### `void window_set_mode(mode: WindowMode, window_id: int = 0)`
|
||||
设置窗口模式。
|
||||
|
||||
#### `void window_set_mouse_passthrough(region: PackedVector2Array, window_id: int = 0)`
|
||||
设置鼠标穿透区域。
|
||||
|
||||
#### `void window_set_popup_safe_rect(window: int, rect: Rect2i)`
|
||||
设置弹出窗口安全区域。
|
||||
|
||||
#### `void window_set_position(position: Vector2i, window_id: int = 0)`
|
||||
设置窗口位置。
|
||||
|
||||
#### `void window_set_rect_changed_callback(callback: Callable, window_id: int = 0)`
|
||||
设置窗口位置大小变化回调。
|
||||
|
||||
#### `void window_set_size(size: Vector2i, window_id: int = 0)`
|
||||
设置窗口大小。
|
||||
|
||||
#### `void window_set_title(title: String, window_id: int = 0)`
|
||||
设置窗口标题。
|
||||
|
||||
#### `void window_set_transient(window_id: int, parent_window_id: int)`
|
||||
设置窗口为瞬态。
|
||||
|
||||
#### `void window_set_vsync_mode(vsync_mode: VSyncMode, window_id: int = 0)`
|
||||
设置垂直同步模式。
|
||||
|
||||
#### `void window_set_window_buttons_offset(offset: Vector2i, window_id: int = 0)`
|
||||
设置窗口按钮偏移。
|
||||
|
||||
#### `void window_set_window_event_callback(callback: Callable, window_id: int = 0)`
|
||||
设置窗口事件回调。
|
||||
|
||||
#### `void window_start_drag(window_id: int = 0)`
|
||||
开始拖拽窗口。
|
||||
|
||||
#### `void window_start_resize(edge: WindowResizeEdge, window_id: int = 0)`
|
||||
开始调整窗口大小。
|
||||
|
||||
---
|
||||
|
||||
### 📞 帮助系统
|
||||
|
||||
#### `void help_set_search_callbacks(search_callback: Callable, action_callback: Callable)`
|
||||
设置帮助系统搜索回调。
|
||||
|
||||
#### `void show_emoji_and_symbol_picker()`
|
||||
显示表情符号选择器。
|
||||
|
||||
---
|
||||
|
||||
### ⚙️ 事件处理
|
||||
|
||||
#### `void process_events()`
|
||||
处理事件。
|
||||
|
||||
---
|
||||
|
||||
## 常量
|
||||
|
||||
- `SCREEN_WITH_MOUSE_FOCUS = -4`:鼠标焦点所在屏幕
|
||||
- `SCREEN_WITH_KEYBOARD_FOCUS = -3`:键盘焦点所在屏幕
|
||||
- `SCREEN_PRIMARY = -2`:主屏幕
|
||||
- `SCREEN_OF_MAIN_WINDOW = -1`:主窗口所在屏幕
|
||||
- `MAIN_WINDOW_ID = 0`:主窗口ID
|
||||
- `INVALID_WINDOW_ID = -1`:无效窗口ID
|
||||
|
||||
---
|
||||
|
||||
## 枚举
|
||||
|
||||
### Feature
|
||||
系统功能支持检测枚举,包含多种功能如子窗口、触屏、鼠标、剪贴板、虚拟键盘等支持检测。
|
||||
|
||||
### MouseMode
|
||||
鼠标模式枚举:可见、隐藏、捕获、限制等模式。
|
||||
|
||||
### ScreenOrientation
|
||||
屏幕朝向枚举:横屏、竖屏及其反向,以及传感器自动模式。
|
||||
|
||||
### VirtualKeyboardType
|
||||
虚拟键盘类型:默认、多行、数字、小数、电话、邮箱、密码、URL等。
|
||||
|
||||
### CursorShape
|
||||
光标形状枚举:箭头、工字形、指向手形等多种光标样式。
|
||||
|
||||
### WindowFlags
|
||||
窗口标志枚举:控制窗口的各种行为和外观属性。
|
||||
|
||||
### WindowMode
|
||||
窗口模式枚举:窗口、最小化、最大化、全屏等模式。
|
||||
|
||||
### HandleType
|
||||
句柄类型枚举:用于获取不同类型的原生窗口句柄。
|
||||
|
||||
### VSyncMode
|
||||
垂直同步模式枚举:控制画面撕裂和帧率同步。
|
||||
|
||||
### TTSUtteranceEvent
|
||||
语音朗读事件枚举:开始、结束、取消、边界等事件。
|
||||
|
||||
---
|
||||
|
||||
> **注意**:此文档已排除所有已弃用的方法。某些功能可能仅在特定平台上可用,请参考原始文档中的平台支持说明。
|
||||
2120
SproutFarm-Backend/test/文档/display总结.txt
Normal file
2120
SproutFarm-Backend/test/文档/display总结.txt
Normal file
File diff suppressed because one or more lines are too long
144
SproutFarm-Backend/test/文档/游戏小提示配置系统说明.md
Normal file
144
SproutFarm-Backend/test/文档/游戏小提示配置系统说明.md
Normal file
@@ -0,0 +1,144 @@
|
||||
# 游戏小提示配置系统实现说明
|
||||
|
||||
## 概述
|
||||
|
||||
本系统成功将游戏小提示配置从客户端硬编码迁移到服务端数据库管理,实现了动态配置和灵活的显示模式。
|
||||
|
||||
## 系统架构
|
||||
|
||||
### 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
|
||||
**状态**: 已完成并测试通过
|
||||
218
SproutFarm-Backend/test/文档/特殊农场管理系统说明.md
Normal file
218
SproutFarm-Backend/test/文档/特殊农场管理系统说明.md
Normal file
@@ -0,0 +1,218 @@
|
||||
# 特殊农场管理系统
|
||||
|
||||
## 概述
|
||||
|
||||
特殊农场管理系统是一个自动化的农场维护工具,用于管理游戏中的特殊农场,为玩家提供特殊的不可购买作物。系统支持定时任务和手动维护两种模式。
|
||||
|
||||
## 功能特性
|
||||
|
||||
### 1. 自动定时维护
|
||||
- **执行时间**: 每天凌晨0点自动执行
|
||||
- **维护内容**: 为特殊农场种植指定的作物
|
||||
- **日志记录**: 详细记录维护过程和结果
|
||||
|
||||
### 2. 手动维护模式
|
||||
- 支持即时手动维护指定农场
|
||||
- 可用于测试和紧急维护
|
||||
|
||||
### 3. 多环境支持
|
||||
- **测试环境**: 用于开发和测试
|
||||
- **生产环境**: 用于正式运行
|
||||
|
||||
## 当前支持的特殊农场
|
||||
|
||||
### 杂交农场
|
||||
- **农场ID**: `689b4b9286cf953f2f4e56ee`
|
||||
- **种植作物**: 0号杂交树、1号杂交树
|
||||
- **种植方式**: 随机全屏种植
|
||||
- **土地要求**: 仅在已开垦的土地上种植
|
||||
- **作物状态**: 自动设置为已浇水、已施肥、立即成熟
|
||||
|
||||
## 使用方法
|
||||
|
||||
### 方法一:使用启动脚本(推荐)
|
||||
```bash
|
||||
# Windows
|
||||
start_special_farm.bat
|
||||
|
||||
# 然后选择运行模式:
|
||||
# 1. 测试环境
|
||||
# 2. 生产环境
|
||||
# 3. 手动维护模式
|
||||
```
|
||||
|
||||
### 方法二:直接命令行
|
||||
|
||||
#### 自动模式(定时任务)
|
||||
```bash
|
||||
# 测试环境
|
||||
python SpecialFarm.py test
|
||||
|
||||
# 生产环境
|
||||
python SpecialFarm.py production
|
||||
```
|
||||
|
||||
#### 手动维护模式
|
||||
```bash
|
||||
# 手动维护杂交农场(测试环境)
|
||||
python SpecialFarm.py test manual 杂交农场
|
||||
|
||||
# 手动维护杂交农场(生产环境)
|
||||
python SpecialFarm.py production manual 杂交农场
|
||||
```
|
||||
|
||||
### 方法三:运行测试
|
||||
```bash
|
||||
# 运行完整测试
|
||||
python test_special_farm.py
|
||||
```
|
||||
|
||||
## 系统架构
|
||||
|
||||
### 核心组件
|
||||
|
||||
1. **SpecialFarmManager**: 主管理类
|
||||
- 负责农场配置管理
|
||||
- 处理定时任务调度
|
||||
- 执行种植逻辑
|
||||
|
||||
2. **MongoDB集成**:
|
||||
- 使用 `SMYMongoDBAPI` 进行数据库操作
|
||||
- 支持玩家数据和作物配置的读写
|
||||
|
||||
3. **定时任务**:
|
||||
- 使用 `schedule` 库实现定时功能
|
||||
- 支持每日凌晨0点自动执行
|
||||
|
||||
### 数据结构
|
||||
|
||||
#### 农场配置
|
||||
```python
|
||||
special_farms = {
|
||||
"杂交农场": {
|
||||
"object_id": "689b4b9286cf953f2f4e56ee",
|
||||
"crop_types": ["杂交树1", "杂交树2"]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
#### 作物种植逻辑
|
||||
- 随机选择配置的作物类型
|
||||
- 仅在已开垦(`is_diged=True`)的土地上种植
|
||||
- 自动设置作物状态:
|
||||
- `is_planted=True`
|
||||
- `is_watered=True`
|
||||
- `is_fertilized=True`
|
||||
- `growth_time=0`(立即成熟)
|
||||
|
||||
## 日志系统
|
||||
|
||||
### 日志文件
|
||||
- **文件名**: `special_farm.log`
|
||||
- **位置**: 与脚本同目录
|
||||
- **格式**: `时间 - 级别 - 模块 - 消息`
|
||||
|
||||
### 日志级别
|
||||
- **INFO**: 正常操作信息
|
||||
- **WARNING**: 警告信息
|
||||
- **ERROR**: 错误信息
|
||||
|
||||
### 示例日志
|
||||
```
|
||||
2024-01-15 00:00:01,123 - INFO - __main__ - 开始执行每日特殊农场维护任务...
|
||||
2024-01-15 00:00:02,456 - INFO - __main__ - 成功为 杂交农场 种植了 40 块土地的作物
|
||||
2024-01-15 00:00:02,789 - INFO - __main__ - 每日维护任务完成: 1/1 个农场维护成功
|
||||
```
|
||||
|
||||
## 依赖要求
|
||||
|
||||
### Python包
|
||||
```
|
||||
schedule>=1.2.0
|
||||
pymongo>=4.0.0
|
||||
```
|
||||
|
||||
### 系统要求
|
||||
- Python 3.7+
|
||||
- MongoDB数据库连接
|
||||
- 有效的游戏数据库配置
|
||||
|
||||
## 扩展指南
|
||||
|
||||
### 添加新的特殊农场
|
||||
|
||||
1. **在数据库中创建农场数据**
|
||||
- 在 `playerdata` 集合中添加新的农场文档
|
||||
- 记录文档的 `ObjectId`
|
||||
|
||||
2. **更新农场配置**
|
||||
```python
|
||||
# 在 SpecialFarm.py 中的 special_farms 字典添加
|
||||
"新农场名称": {
|
||||
"object_id": "新农场的ObjectId",
|
||||
"crop_types": ["作物类型1", "作物类型2"]
|
||||
}
|
||||
```
|
||||
|
||||
3. **测试新农场**
|
||||
```bash
|
||||
python SpecialFarm.py test manual 新农场名称
|
||||
```
|
||||
|
||||
### 自定义种植逻辑
|
||||
|
||||
可以在 `plant_crops_in_farm` 方法中修改种植逻辑:
|
||||
- 改变作物选择算法
|
||||
- 调整作物生长参数
|
||||
- 添加特殊种植条件
|
||||
|
||||
## 故障排除
|
||||
|
||||
### 常见问题
|
||||
|
||||
1. **数据库连接失败**
|
||||
- 检查MongoDB服务是否运行
|
||||
- 验证数据库连接配置
|
||||
|
||||
2. **农场数据不存在**
|
||||
- 确认农场ObjectId是否正确
|
||||
- 检查数据库中是否存在对应文档
|
||||
|
||||
3. **作物配置错误**
|
||||
- 验证作物类型名称是否正确
|
||||
- 检查作物配置数据是否完整
|
||||
|
||||
### 调试模式
|
||||
|
||||
运行测试脚本获取详细信息:
|
||||
```bash
|
||||
python test_special_farm.py
|
||||
```
|
||||
|
||||
## 安全注意事项
|
||||
|
||||
1. **生产环境使用**
|
||||
- 确保在生产环境中使用正确的数据库配置
|
||||
- 定期备份重要数据
|
||||
|
||||
2. **权限管理**
|
||||
- 确保脚本有足够的数据库读写权限
|
||||
- 限制对生产数据库的访问
|
||||
|
||||
3. **监控和告警**
|
||||
- 定期检查日志文件
|
||||
- 设置维护任务失败的告警机制
|
||||
|
||||
## 版本历史
|
||||
|
||||
- **v1.0.0**: 初始版本,支持杂交农场的自动维护
|
||||
- 实现定时任务功能
|
||||
- 支持手动维护模式
|
||||
- 完整的日志系统
|
||||
- 测试和生产环境分离
|
||||
|
||||
---
|
||||
|
||||
**作者**: AI Assistant
|
||||
**创建时间**: 2024年
|
||||
**最后更新**: 2024年
|
||||
199
SproutFarm-Backend/test/文档/特殊农场系统优化说明.md
Normal file
199
SproutFarm-Backend/test/文档/特殊农场系统优化说明.md
Normal file
@@ -0,0 +1,199 @@
|
||||
# 特殊农场系统优化说明
|
||||
|
||||
## 概述
|
||||
|
||||
特殊农场系统已经过全面优化,解决了服务器重启时间重置和性能问题。现在系统更加稳定、高效,不会影响游戏服务器的正常运行。
|
||||
|
||||
## 主要优化内容
|
||||
|
||||
### 1. 解决服务器重启时间重置问题
|
||||
|
||||
**问题**: 之前每次服务器重启都会立即执行维护任务,导致重复种植。
|
||||
|
||||
**解决方案**:
|
||||
- 添加维护时间记录功能
|
||||
- 服务器启动时检查当日是否已执行维护
|
||||
- 只有当天未维护过才会执行维护任务
|
||||
- 确保每天只执行一次维护,无论服务器重启多少次
|
||||
|
||||
### 2. 性能优化
|
||||
|
||||
**CPU使用优化**:
|
||||
- 调度器检查间隔从1分钟优化到5分钟
|
||||
- 减少不必要的CPU占用
|
||||
- 后台线程使用守护模式,不阻塞主进程
|
||||
|
||||
**内存管理优化**:
|
||||
- 改进资源清理机制
|
||||
- 服务器停止时正确释放特殊农场系统资源
|
||||
- 避免内存泄漏
|
||||
|
||||
### 3. 稳定性改进
|
||||
|
||||
**错误处理**:
|
||||
- 增强异常处理机制
|
||||
- 添加详细的日志记录
|
||||
- 系统出错时自动恢复
|
||||
|
||||
**资源管理**:
|
||||
- 正确的启动和停止流程
|
||||
- 线程安全的操作
|
||||
- 避免资源竞争
|
||||
|
||||
## 系统工作原理
|
||||
|
||||
### 定时任务调度
|
||||
|
||||
```
|
||||
启动服务器 → 初始化特殊农场管理器 → 检查当日维护状态
|
||||
↓
|
||||
如果未维护 → 执行维护任务 → 记录维护时间
|
||||
↓
|
||||
如果已维护 → 跳过维护任务
|
||||
↓
|
||||
启动后台调度器 → 每天凌晨0点自动维护
|
||||
```
|
||||
|
||||
### 维护任务内容
|
||||
|
||||
1. **土地开垦**: 确保所有土地都处于已开垦状态
|
||||
2. **作物种植**: 随机种植杂交树1或杂交树2
|
||||
3. **状态设置**: 设置作物为立即成熟状态
|
||||
4. **记录更新**: 更新维护时间记录
|
||||
|
||||
## 使用方法
|
||||
|
||||
### 正常启动
|
||||
|
||||
特殊农场系统已集成到游戏服务器中,无需单独启动:
|
||||
|
||||
```bash
|
||||
cd Server
|
||||
python TCPGameServer.py
|
||||
```
|
||||
|
||||
### 手动维护
|
||||
|
||||
如果需要手动执行维护任务:
|
||||
|
||||
```bash
|
||||
# 维护所有特殊农场
|
||||
python SpecialFarm.py test manual
|
||||
|
||||
# 维护指定农场
|
||||
python SpecialFarm.py test manual 杂交农场
|
||||
```
|
||||
|
||||
### 性能监控
|
||||
|
||||
使用性能监控工具检查系统资源使用:
|
||||
|
||||
```bash
|
||||
python monitor_special_farm.py
|
||||
```
|
||||
|
||||
### 测试优化效果
|
||||
|
||||
运行测试脚本验证优化效果:
|
||||
|
||||
```bash
|
||||
python test_special_farm_optimization.py
|
||||
```
|
||||
|
||||
## 配置说明
|
||||
|
||||
### 特殊农场配置
|
||||
|
||||
在 `SpecialFarm.py` 中的 `special_farms` 字典:
|
||||
|
||||
```python
|
||||
self.special_farms = {
|
||||
"杂交农场": {
|
||||
"object_id": "689b4b9286cf953f2f4e56ee",
|
||||
"crops": ["杂交树1", "杂交树2"],
|
||||
"description": "专门种植杂交树的特殊农场"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 调度器配置
|
||||
|
||||
- **维护时间**: 每天凌晨0点
|
||||
- **检查间隔**: 5分钟
|
||||
- **运行模式**: 后台守护线程
|
||||
|
||||
## 性能指标
|
||||
|
||||
### 优化前 vs 优化后
|
||||
|
||||
| 指标 | 优化前 | 优化后 | 改进 |
|
||||
|------|--------|--------|------|
|
||||
| CPU检查间隔 | 1分钟 | 5分钟 | 减少80%检查频率 |
|
||||
| 重启重复执行 | 是 | 否 | 避免重复维护 |
|
||||
| 资源清理 | 不完整 | 完整 | 防止内存泄漏 |
|
||||
| 错误恢复 | 基础 | 增强 | 提高稳定性 |
|
||||
|
||||
### 预期性能表现
|
||||
|
||||
- **CPU使用率**: < 1%(正常运行时)
|
||||
- **内存使用**: < 50MB(额外占用)
|
||||
- **线程数**: +1(后台调度线程)
|
||||
- **启动时间**: < 1秒
|
||||
|
||||
## 故障排除
|
||||
|
||||
### 常见问题
|
||||
|
||||
1. **特殊农场未自动维护**
|
||||
- 检查MongoDB连接是否正常
|
||||
- 查看日志文件 `special_farm.log`
|
||||
- 确认特殊农场配置正确
|
||||
|
||||
2. **服务器启动缓慢**
|
||||
- 检查MongoDB连接速度
|
||||
- 查看是否有网络问题
|
||||
- 考虑使用本地MongoDB
|
||||
|
||||
3. **内存使用过高**
|
||||
- 运行性能监控工具
|
||||
- 检查是否有内存泄漏
|
||||
- 重启服务器释放资源
|
||||
|
||||
### 日志文件
|
||||
|
||||
- **特殊农场日志**: `special_farm.log`
|
||||
- **服务器日志**: 控制台输出
|
||||
- **MongoDB日志**: MongoDB服务器日志
|
||||
|
||||
## 维护建议
|
||||
|
||||
### 定期检查
|
||||
|
||||
1. **每周检查**:
|
||||
- 查看 `special_farm.log` 日志
|
||||
- 确认维护任务正常执行
|
||||
- 检查特殊农场作物状态
|
||||
|
||||
2. **每月检查**:
|
||||
- 运行性能监控工具
|
||||
- 清理过期日志文件
|
||||
- 检查MongoDB数据库状态
|
||||
|
||||
### 备份建议
|
||||
|
||||
- 定期备份MongoDB数据库
|
||||
- 保存特殊农场配置文件
|
||||
- 记录重要的配置变更
|
||||
|
||||
## 技术支持
|
||||
|
||||
如果遇到问题,请提供以下信息:
|
||||
|
||||
1. 错误日志内容
|
||||
2. 服务器运行环境
|
||||
3. MongoDB版本和配置
|
||||
4. 问题复现步骤
|
||||
|
||||
---
|
||||
|
||||
**注意**: 此优化版本向后兼容,不会影响现有的游戏数据和功能。
|
||||
Reference in New Issue
Block a user