Compare commits
25 Commits
feature/lo
...
e657cfce0e
| Author | SHA1 | Date | |
|---|---|---|---|
| e657cfce0e | |||
|
|
b9182bbc2e | ||
|
|
642a99970c | ||
|
|
0b533189ec | ||
| b1f3c0feff | |||
| 021c8623f8 | |||
| a1b867dfd7 | |||
| d17c766246 | |||
| 92c4eaed07 | |||
| abd683c766 | |||
| a05bac6f05 | |||
| 77af0bda39 | |||
| 8980e3d558 | |||
| 1294529d13 | |||
| 0935c5fd76 | |||
| 405710bdde | |||
| 7413574672 | |||
| 8d071cb2ed | |||
| 370cffbdd8 | |||
| 5b67771bbc | |||
| 73478c0500 | |||
| 15548ebb52 | |||
| 47cfc14f68 | |||
| c6bcca4e7f | |||
| f11479f2cc |
55
.gitignore
vendored
@@ -1,3 +1,58 @@
|
|||||||
# Godot 4+ specific ignores
|
# Godot 4+ specific ignores
|
||||||
.godot/
|
.godot/
|
||||||
/android/
|
/android/
|
||||||
|
|
||||||
|
# Python cache files
|
||||||
|
__pycache__/
|
||||||
|
*.pyc
|
||||||
|
*.pyo
|
||||||
|
*.pyd
|
||||||
|
.Python
|
||||||
|
*.so
|
||||||
|
|
||||||
|
# IDE and editor files
|
||||||
|
.vscode/
|
||||||
|
.idea/
|
||||||
|
*.swp
|
||||||
|
*.swo
|
||||||
|
*~
|
||||||
|
|
||||||
|
# OS generated files
|
||||||
|
.DS_Store
|
||||||
|
.DS_Store?
|
||||||
|
._*
|
||||||
|
.Spotlight-V100
|
||||||
|
.Trashes
|
||||||
|
ehthumbs.db
|
||||||
|
Thumbs.db
|
||||||
|
|
||||||
|
# Godot executable files (should not be in version control)
|
||||||
|
Godot/
|
||||||
|
*.exe
|
||||||
|
*.app
|
||||||
|
*.dmg
|
||||||
|
|
||||||
|
# Logs and temporary files
|
||||||
|
*.log
|
||||||
|
*.tmp
|
||||||
|
*.temp
|
||||||
|
|
||||||
|
# Build outputs
|
||||||
|
build/
|
||||||
|
dist/
|
||||||
|
*.zip
|
||||||
|
*.tar.gz
|
||||||
|
|
||||||
|
# Environment files
|
||||||
|
.env
|
||||||
|
.env.local
|
||||||
|
.env.*.local
|
||||||
|
|
||||||
|
# Test coverage reports
|
||||||
|
coverage/
|
||||||
|
*.coverage
|
||||||
|
.nyc_output/
|
||||||
|
|
||||||
|
# Dependency directories
|
||||||
|
node_modules/
|
||||||
|
vendor/
|
||||||
|
|||||||
96
CLAUDE.md
Normal file
@@ -0,0 +1,96 @@
|
|||||||
|
# 🎯 CLAUDE.md - WhaleTown Project Instructions
|
||||||
|
|
||||||
|
## 1. Project Vision & Context
|
||||||
|
- **Project**: "WhaleTown" - A 2D top-down pixel art RPG.
|
||||||
|
- **Engine**: Godot 4.2+ (Strictly NO Godot 3.x syntax).
|
||||||
|
- **Architecture**: Strictly layered: `_Core` (Framework), `Scenes` (Gameplay), `UI` (Interface).
|
||||||
|
- **Core Principle**: "Signal Up, Call Down". High decoupling via `EventSystem`.
|
||||||
|
|
||||||
|
## 2. 🛠 Command Reference & Setup
|
||||||
|
- **Input Map (Required Configuration)**:
|
||||||
|
- `move_left`, `move_right`, `move_up`, `move_down` (WASD / Arrows)
|
||||||
|
- `interact` (E Key / Space)
|
||||||
|
- `pause` (ESC)
|
||||||
|
- **Run Game**: `godot --path .`
|
||||||
|
- **Run Tests (GUT)**: `godot --headless -s addons/gut/gut_cmdline.gd -gdir=res://tests/ -ginclude_subdirs`
|
||||||
|
- **Init Structure**: `mkdir -p _Core/managers _Core/systems Scenes/Maps Scenes/Entities Scenes/Components UI/Windows UI/HUD Assets/Sprites tests/unit tests/integration`
|
||||||
|
|
||||||
|
## 3. 📂 File Path Rules (STRICT LOWERCASE)
|
||||||
|
*Claude: Root folders MUST be lowercase. Scripts and Scenes MUST stay together.*
|
||||||
|
- **Core Managers**: `_Core/managers/[Name].gd`
|
||||||
|
- **Core Systems**: `_Core/systems/[Name].gd`
|
||||||
|
- **Entities**: `Scenes/Entities/[EntityName]/[EntityName].tscn` (Script `.gd` in same folder).
|
||||||
|
- **Maps**: `Scenes/Maps/[map_name].tscn`
|
||||||
|
- **Components**: `Scenes/Components/[ComponentName].gd` (Reusable logic nodes).
|
||||||
|
- **UI Windows**: `UI/Windows/[WindowName].tscn`
|
||||||
|
- **Tests**: `tests/[unit|integration]/test_[name].gd` (Folder is lowercase `tests`).
|
||||||
|
|
||||||
|
## 4. 📋 Coding Standards (The Law)
|
||||||
|
- **Type Safety**: ALWAYS use strict static typing: `var speed: float = 100.0`, `func _ready() -> void`.
|
||||||
|
- **Naming Conventions**:
|
||||||
|
- `class_name PascalCase` at the top of every script.
|
||||||
|
- Variables/Functions: `snake_case`. Constants: `SCREAMING_SNAKE_CASE`.
|
||||||
|
- Private members: Prefix with underscore `_` (e.g., `var _health: int`).
|
||||||
|
- **Node Access**: Use `%UniqueName` for UI and internal scene components.
|
||||||
|
- **Signals**: Use "Signal Up, Call Down". Parent calls child methods; Child emits signals.
|
||||||
|
- **Forbidden Patterns**:
|
||||||
|
- ❌ NO `yield()` -> Use `await`.
|
||||||
|
- ❌ NO `get_node()` in `_process` -> Cache with `@onready`.
|
||||||
|
- ❌ NO Linear Filter -> All Sprite2D/TileMap resources MUST use **Nearest** filter.
|
||||||
|
|
||||||
|
## 5. 🏛 Architecture & Communication
|
||||||
|
- **EventSystem**: Use `_Core/systems/EventSystem.gd` for cross-module messaging.
|
||||||
|
- **Event Registry**: Use `class_name EventNames` in `_Core/EventNames.gd`.
|
||||||
|
```gdscript
|
||||||
|
class_name EventNames
|
||||||
|
const PLAYER_MOVED = "player_moved"
|
||||||
|
const INTERACT_PRESSED = "interact_pressed"
|
||||||
|
const NPC_TALKED = "npc_talked"
|
||||||
|
Singletons: Only GameManager, SceneManager, EventSystem allowed as Autoloads.
|
||||||
|
Decoupling: Low-level entities MUST NOT reference GameManager. Use events.
|
||||||
|
6. 🏗 Implementation Details
|
||||||
|
Player: CharacterBody2D. Must include Camera2D with position_smoothing_enabled = true.
|
||||||
|
NPC/Interactables: Use Area2D named InteractionArea. Trigger via EventSystem.
|
||||||
|
TileMap Layers:
|
||||||
|
Layer 0: Ground (No collision).
|
||||||
|
Layer 1: Obstacles (Physics Layer enabled).
|
||||||
|
Layer 2: Decoration (Y-Sort enabled).
|
||||||
|
Camera: Must auto-calculate limits via TileMap.get_used_rect().
|
||||||
|
7. 🧪 Testing Requirements (MANDATORY)
|
||||||
|
Coverage: Every Manager/System in _Core/ MUST have a GUT test.
|
||||||
|
Naming: Test files must start with test_ and extend GutTest.
|
||||||
|
Example:
|
||||||
|
code
|
||||||
|
Gdscript
|
||||||
|
extends GutTest
|
||||||
|
func test_event_emission():
|
||||||
|
var sender = Node.new()
|
||||||
|
watch_signals(EventSystem)
|
||||||
|
EventSystem.emit_event(EventNames.PLAYER_MOVED, {})
|
||||||
|
assert_signal_emitted(EventSystem, "event_raised")
|
||||||
|
8. 🧘 The Zen of Development
|
||||||
|
Juice or Death: Every interaction (UI popup, NPC talk) MUST have a Tween placeholder.
|
||||||
|
Zero Magic Numbers: All speeds/timers MUST be @export or defined in Config/.
|
||||||
|
Simplicity: If a function does two things, split it.
|
||||||
|
Back of the Fence: Hidden logic (like ResponseHandler.gd) must be as clean as the HUD.
|
||||||
|
9. 📝 Code Template (Entity Pattern)
|
||||||
|
code
|
||||||
|
Gdscript
|
||||||
|
extends CharacterBody2D
|
||||||
|
class_name Player
|
||||||
|
|
||||||
|
# 1. Exports & Constants
|
||||||
|
@export var move_speed: float = 200.0
|
||||||
|
|
||||||
|
# 2. Node References
|
||||||
|
@onready var sprite: Sprite2D = %Sprite2D
|
||||||
|
|
||||||
|
# 3. Lifecycle
|
||||||
|
func _physics_process(delta: float) -> void:
|
||||||
|
_move(delta)
|
||||||
|
|
||||||
|
# 4. Private Methods
|
||||||
|
func _move(_delta: float) -> void:
|
||||||
|
var dir := Input.get_vector("move_left", "move_right", "move_up", "move_down")
|
||||||
|
velocity = dir * move_speed
|
||||||
|
move_and_slide()
|
||||||
29
Config/game_config.json
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
{
|
||||||
|
"game": {
|
||||||
|
"name": "whaleTown",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"debug_mode": true
|
||||||
|
},
|
||||||
|
"network": {
|
||||||
|
"api_base_url": "https://whaletownend.xinghangee.icu",
|
||||||
|
"timeout": 30,
|
||||||
|
"retry_count": 3
|
||||||
|
},
|
||||||
|
"ui": {
|
||||||
|
"default_font_size": 14,
|
||||||
|
"toast_duration": 2.0,
|
||||||
|
"transition_duration": 0.3
|
||||||
|
},
|
||||||
|
"gameplay": {
|
||||||
|
"auto_save_interval": 300,
|
||||||
|
"max_inventory_slots": 50,
|
||||||
|
"default_player_stats": {
|
||||||
|
"level": 1,
|
||||||
|
"coins": 100,
|
||||||
|
"exp": 0,
|
||||||
|
"max_exp": 100,
|
||||||
|
"energy": 100,
|
||||||
|
"max_energy": 100
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
36
Config/zh_CN.json
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
{
|
||||||
|
"ui": {
|
||||||
|
"login": "登录",
|
||||||
|
"register": "注册",
|
||||||
|
"username": "用户名",
|
||||||
|
"password": "密码",
|
||||||
|
"email": "邮箱",
|
||||||
|
"confirm_password": "确认密码",
|
||||||
|
"verification_code": "验证码",
|
||||||
|
"send_code": "发送验证码",
|
||||||
|
"forgot_password": "忘记密码",
|
||||||
|
"enter_town": "进入小镇",
|
||||||
|
"logout": "退出登录"
|
||||||
|
},
|
||||||
|
"messages": {
|
||||||
|
"login_success": "登录成功!正在进入鲸鱼镇...",
|
||||||
|
"register_success": "注册成功!欢迎加入鲸鱼镇",
|
||||||
|
"network_error": "网络连接失败,请检查网络连接",
|
||||||
|
"invalid_username": "用户名只能包含字母、数字和下划线",
|
||||||
|
"invalid_email": "请输入有效的邮箱地址",
|
||||||
|
"password_too_short": "密码长度至少8位",
|
||||||
|
"password_mismatch": "两次输入的密码不一致",
|
||||||
|
"verification_code_sent": "验证码已发送到您的邮箱,请查收"
|
||||||
|
},
|
||||||
|
"game": {
|
||||||
|
"level": "等级",
|
||||||
|
"coins": "金币",
|
||||||
|
"experience": "经验",
|
||||||
|
"energy": "体力",
|
||||||
|
"explore": "探索小镇",
|
||||||
|
"inventory": "背包",
|
||||||
|
"shop": "商店",
|
||||||
|
"friends": "好友",
|
||||||
|
"settings": "设置"
|
||||||
|
}
|
||||||
|
}
|
||||||
235
MIGRATION_COMPLETE.md
Normal file
@@ -0,0 +1,235 @@
|
|||||||
|
# ✅ 项目结构重构完成报告
|
||||||
|
|
||||||
|
## 📅 完成时间
|
||||||
|
2025-12-31
|
||||||
|
|
||||||
|
## 🎉 重构成功
|
||||||
|
|
||||||
|
项目已成功从混乱的文件结构重构为清晰、模块化的架构!
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 📊 最终结构总览
|
||||||
|
|
||||||
|
```
|
||||||
|
whale-town-front/
|
||||||
|
├── _Core/ ✅ [框架层] 全局单例和系统
|
||||||
|
├── Scenes/ ✅ [玩法层] 游戏世界实体
|
||||||
|
├── UI/ ✅ [界面层] 所有UI界面
|
||||||
|
├── Assets/ ✅ [资源层] 美术资源
|
||||||
|
├── Config/ ✅ [配置层] 静态数据
|
||||||
|
├── Utils/ ✅ [工具层] 工具类
|
||||||
|
├── Tests/ ✅ [测试层] 测试脚本
|
||||||
|
└── docs/ 📄 项目文档
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## ✅ 已完成的迁移
|
||||||
|
|
||||||
|
### 1️⃣ 框架层 (_Core/)
|
||||||
|
- ✅ `GameManager.gd` → `_Core/managers/`
|
||||||
|
- ✅ `SceneManager.gd` → `_Core/managers/` (已更新路径)
|
||||||
|
- ✅ `NetworkManager.gd` → `_Core/managers/`
|
||||||
|
- ✅ `ResponseHandler.gd` → `_Core/managers/`
|
||||||
|
- ✅ `EventSystem.gd` → `_Core/systems/`
|
||||||
|
|
||||||
|
### 2️⃣ 场景层 (Scenes/)
|
||||||
|
- ✅ `scenes/main_scene.tscn` → `Scenes/Maps/main_scene.tscn`
|
||||||
|
- ✅ `scripts/scenes/MainScene.gd` → `Scenes/Maps/MainScene.gd`
|
||||||
|
- ✅ `scenes/prefabs/` → `Scenes/Components/`
|
||||||
|
|
||||||
|
### 3️⃣ 界面层 (UI/)
|
||||||
|
- ✅ `scenes/auth_scene.tscn` → `UI/Windows/LoginWindow.tscn`
|
||||||
|
- ✅ `scripts/scenes/AuthScene.gd` → `UI/Windows/AuthScene.gd`
|
||||||
|
- ✅ `assets/ui/chinese_theme.tres` → `UI/Theme/MainTheme.tres`
|
||||||
|
- ✅ `assets/fonts/` → `UI/Theme/Fonts/`
|
||||||
|
|
||||||
|
### 4️⃣ 配置层 (Config/)
|
||||||
|
- ✅ `data/configs/game_config.json` → `Config/game_config.json`
|
||||||
|
- ✅ `data/localization/zh_CN.json` → `Config/zh_CN.json`
|
||||||
|
|
||||||
|
### 5️⃣ 工具层 (Utils/)
|
||||||
|
- ✅ `core/utils/StringUtils.gd` → `Utils/StringUtils.gd`
|
||||||
|
|
||||||
|
### 6️⃣ 资源层 (Assets/)
|
||||||
|
- ✅ `assets/sprites/` → `Assets/Sprites/`
|
||||||
|
- ✅ `assets/audio/` → `Assets/Audio/`
|
||||||
|
- ✅ 其他资源文件保留在 `assets/`(待后续整理)
|
||||||
|
|
||||||
|
### 7️⃣ 构建脚本
|
||||||
|
- ✅ `scripts/build_web.sh` → `./build_web.sh`
|
||||||
|
- ✅ `scripts/serve_web.sh` → `./serve_web.sh`
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🗑️ 已删除的旧目录
|
||||||
|
|
||||||
|
- ❌ `core/` - 已迁移到 `_Core/`
|
||||||
|
- ❌ `module/` - 空目录,未使用
|
||||||
|
- ❌ `scripts/` - 脚本已内联到场景目录
|
||||||
|
- ❌ `scenes/` - 已迁移到 `Scenes/` 和 `UI/`
|
||||||
|
- ❌ `data/` - 配置已移至 `Config/`
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🔧 已更新的配置
|
||||||
|
|
||||||
|
### project.godot
|
||||||
|
```ini
|
||||||
|
✅ run/main_scene="res://Scenes/Maps/main_scene.tscn"
|
||||||
|
✅ GameManager="*res://_Core/managers/GameManager.gd"
|
||||||
|
✅ SceneManager="*res://_Core/managers/SceneManager.gd"
|
||||||
|
✅ EventSystem="*res://_Core/systems/EventSystem.gd"
|
||||||
|
✅ NetworkManager="*res://_Core/managers/NetworkManager.gd"
|
||||||
|
✅ ResponseHandler="*res://_Core/managers/ResponseHandler.gd"
|
||||||
|
```
|
||||||
|
|
||||||
|
### SceneManager.gd
|
||||||
|
```gdscript
|
||||||
|
✅ "main": "res://Scenes/Maps/main_scene.tscn"
|
||||||
|
✅ "auth": "res://UI/Windows/LoginWindow.tscn"
|
||||||
|
```
|
||||||
|
|
||||||
|
### 测试文件
|
||||||
|
```gdscript
|
||||||
|
✅ tests/auth/enhanced_toast_test.gd - 已更新脚本路径
|
||||||
|
✅ tests/auth/auth_ui_test.tscn - 已更新场景路径
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 📚 创建的文档
|
||||||
|
|
||||||
|
1. **REFACTORING.md** - 详细的重构文档
|
||||||
|
- 迁移映射表
|
||||||
|
- 设计原则
|
||||||
|
- 注意事项
|
||||||
|
- 后续建议
|
||||||
|
|
||||||
|
2. **STRUCTURE_COMPARISON.md** - 结构对比分析
|
||||||
|
- 旧结构问题分析
|
||||||
|
- 新结构优势说明
|
||||||
|
- 对比表格
|
||||||
|
- 团队协作改进
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🎯 关键改进
|
||||||
|
|
||||||
|
### 清晰的分层
|
||||||
|
- **_Core**: 框架代码,全局系统
|
||||||
|
- **Scenes**: 游戏世界,地图和实体
|
||||||
|
- **UI**: 所有界面,HUD和弹窗
|
||||||
|
- **Config**: 静态数据,策划可编辑
|
||||||
|
- **Utils**: 通用工具函数库
|
||||||
|
|
||||||
|
### 组件化设计
|
||||||
|
```gdscript
|
||||||
|
Scenes/Components/ // 可复用组件
|
||||||
|
├── characters/ // 角色预制体
|
||||||
|
├── effects/ // 特效预制体
|
||||||
|
├── items/ // 物品预制体
|
||||||
|
└── ui/ // UI预制体
|
||||||
|
```
|
||||||
|
|
||||||
|
### 场景内聚
|
||||||
|
- 每个 `.tscn` 配套一个 `.gd`
|
||||||
|
- 脚本紧邻场景文件
|
||||||
|
- 符合 Godot 原生习惯
|
||||||
|
|
||||||
|
### UI 独立化
|
||||||
|
```
|
||||||
|
UI/
|
||||||
|
├── Windows/ // 模态窗口(登录、设置)
|
||||||
|
├── HUD/ // 常驻界面(聊天框)
|
||||||
|
├── Dialog/ // 对话系统
|
||||||
|
└── Theme/ // 全局样式
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## ⚠️ 后续步骤
|
||||||
|
|
||||||
|
### 必做事项
|
||||||
|
- [ ] 在 Godot 编辑器中打开项目,让编辑器重新索引文件
|
||||||
|
- [ ] 测试主场景加载: `Scenes/Maps/main_scene.tscn`
|
||||||
|
- [ ] 验证登录窗口: `UI/Windows/LoginWindow.tscn`
|
||||||
|
- [ ] 测试所有自动加载脚本
|
||||||
|
- [ ] 运行完整测试套件
|
||||||
|
|
||||||
|
### 建议优化
|
||||||
|
- [ ] 补充 `Scenes/Components/` 下的可复用组件
|
||||||
|
- [ ] 完善 `UI/HUD/` 和 `UI/Dialog/`
|
||||||
|
- [ ] 添加 `Scenes/Entities/Player/` 玩家实体
|
||||||
|
- [ ] 将硬编码数值移至 `Config/`
|
||||||
|
|
||||||
|
### 代码审查
|
||||||
|
- [ ] 检查是否还有硬编码的旧路径
|
||||||
|
- [ ] 验证所有 `.import` 文件正常
|
||||||
|
- [ ] 确认网络连接功能正常
|
||||||
|
- [ ] 验证 UI 主题显示正确
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🎓 团队协作指南
|
||||||
|
|
||||||
|
### 工作目录划分
|
||||||
|
```
|
||||||
|
🎨 美术组 → Assets/Sprites/, Assets/Audio/
|
||||||
|
📋 策划组 → Config/
|
||||||
|
💻 前端程序 → UI/, Scenes/Entities/
|
||||||
|
⚙️ 后端程序 → _Core/, Utils/
|
||||||
|
🧪 测试组 → Tests/
|
||||||
|
```
|
||||||
|
|
||||||
|
### Git 提交建议
|
||||||
|
```bash
|
||||||
|
# 按目录分类提交
|
||||||
|
git add _Core/
|
||||||
|
git commit -m "refactor: 迁移核心框架代码到 _Core/"
|
||||||
|
|
||||||
|
git add Scenes/
|
||||||
|
git commit -m "refactor: 重组场景文件到 Scenes/"
|
||||||
|
|
||||||
|
git add UI/
|
||||||
|
git commit -m "refactor: 独立 UI 界面到 UI/"
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 📈 预期收益
|
||||||
|
|
||||||
|
### 可维护性提升
|
||||||
|
- 🟢 目录职责清晰,降低认知负担
|
||||||
|
- 🟢 新人快速定位文件
|
||||||
|
- 🟢 减少代码冲突
|
||||||
|
|
||||||
|
### 开发效率提升
|
||||||
|
- 🟢 组件复用更容易
|
||||||
|
- 🟢 团队协作更流畅
|
||||||
|
- 🟢 代码审查更高效
|
||||||
|
|
||||||
|
### 符合最佳实践
|
||||||
|
- ✅ Godot 官方推荐结构
|
||||||
|
- ✅ 场景内聚原则
|
||||||
|
- ✅ 组件化设计思想
|
||||||
|
- ✅ 配置与代码分离
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🎉 总结
|
||||||
|
|
||||||
|
**重构完成!** 项目现在拥有:
|
||||||
|
- ✅ 清晰的 6 层架构
|
||||||
|
- ✅ 符合 Godot 最佳实践
|
||||||
|
- ✅ 易于维护和扩展
|
||||||
|
- ✅ 团队协作友好
|
||||||
|
|
||||||
|
感谢您的耐心!如有问题,请查看详细文档:
|
||||||
|
- [REFACTORING.md](./REFACTORING.md) - 重构详情
|
||||||
|
- [STRUCTURE_COMPARISON.md](./STRUCTURE_COMPARISON.md) - 结构对比
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
**下一步:在 Godot 编辑器中打开项目并测试!** 🚀
|
||||||
498
README.md
@@ -1,101 +1,427 @@
|
|||||||
# whaleTown
|
# 🐋 whaleTown
|
||||||
|
|
||||||
一个使用 Godot 4.5 引擎开发的游戏项目。
|
一个使用 Godot 4.5 引擎开发的现代化像素游戏项目,集成了完整的用户认证系统和API接口。
|
||||||
|
|
||||||
## 项目信息
|
## 🎮 项目信息
|
||||||
|
|
||||||
- **引擎版本**: Godot 4.5
|
- **引擎版本**: Godot 4.5.1
|
||||||
- **渲染器**: Forward Plus
|
- **渲染器**: Forward Plus
|
||||||
- **项目类型**: 2D 游戏
|
- **项目类型**: 2D 像素游戏
|
||||||
|
- **架构模式**: 模块化 + 事件驱动
|
||||||
|
- **后端集成**: RESTful API + 用户认证
|
||||||
|
|
||||||
## 项目结构
|
## 🚀 快速开始
|
||||||
|
|
||||||
```
|
### 环境要求
|
||||||
whaleTown/
|
- [Godot Engine 4.5+](https://godotengine.org/download)
|
||||||
├── addons/ # Godot 插件目录
|
- Python 3.7+ (用于API测试和Web服务器)
|
||||||
├── assets/ # 游戏资源文件(图片、音频等)
|
|
||||||
├── data/ # 游戏数据文件(配置、关卡数据等)
|
|
||||||
├── docs/ # 项目文档
|
|
||||||
├── scenes/ # 游戏场景文件
|
|
||||||
│ └── main_scene.tscn # 主场景
|
|
||||||
├── scripts/ # GDScript 脚本文件
|
|
||||||
├── tests/ # 测试文件
|
|
||||||
├── icon.svg # 项目图标
|
|
||||||
└── project.godot # Godot 项目配置文件
|
|
||||||
```
|
|
||||||
|
|
||||||
## 开始使用
|
|
||||||
|
|
||||||
### 前置要求
|
|
||||||
|
|
||||||
- [Godot Engine 4.5](https://godotengine.org/download) 或更高版本
|
|
||||||
|
|
||||||
### 运行项目
|
### 运行项目
|
||||||
|
|
||||||
1. 克隆或下载此项目
|
|
||||||
2. 使用 Godot 编辑器打开项目
|
|
||||||
3. 在编辑器中点击"运行"按钮或按 F5 键启动游戏
|
|
||||||
|
|
||||||
### 开发指南
|
|
||||||
|
|
||||||
- **场景文件**: 所有场景文件存放在 `scenes/` 目录
|
|
||||||
- **脚本文件**: 所有 GDScript 脚本存放在 `scripts/` 目录
|
|
||||||
- **资源文件**: 图片、音频等资源存放在 `assets/` 目录
|
|
||||||
- **游戏数据**: 配置文件、关卡数据等存放在 `data/` 目录
|
|
||||||
|
|
||||||
### 命名规范
|
|
||||||
|
|
||||||
本项目遵循统一的命名规范以保持代码一致性:
|
|
||||||
|
|
||||||
**核心规则**:
|
|
||||||
|
|
||||||
- **场景文件**:`下划线_scene.tscn` 或 `下划线_prefab.tscn`
|
|
||||||
- 示例:`main_scene.tscn`、`player_prefab.tscn`
|
|
||||||
- **脚本文件**:`PascalCase.gd`(大驼峰)
|
|
||||||
- 示例:`PlayerController.gd`、`UI_MainMenu.gd`
|
|
||||||
- **节点名称**:`camelCase`(小驼峰)
|
|
||||||
- 示例:`playerHpBar`、`startButton`
|
|
||||||
- **变量/函数**:`camelCase`(小驼峰)
|
|
||||||
- 示例:`var moveSpeed`、`func getPlayerPos()`
|
|
||||||
- **常量**:`UPPER_CASE`(全大写 + 下划线)
|
|
||||||
- 示例:`const MAX_HEALTH = 100`
|
|
||||||
- **资源文件**:`lower_case`(小写 + 下划线)
|
|
||||||
- 示例:`bg_main_menu.png`、`sound_jump.wav`
|
|
||||||
|
|
||||||
📖 查看完整的 [命名规范文档](docs/naming_convention.md)
|
|
||||||
|
|
||||||
### Git 提交规范
|
|
||||||
|
|
||||||
本项目遵循统一的 Git 提交信息格式:`<类型>:<描述>`
|
|
||||||
|
|
||||||
**常用提交类型**:
|
|
||||||
|
|
||||||
- `init`:项目初始化
|
|
||||||
- `feat`:新增功能
|
|
||||||
- `fix`:修复 Bug
|
|
||||||
- `docs`:文档更新
|
|
||||||
- `scene`:场景文件相关
|
|
||||||
- `asset`:资源文件相关
|
|
||||||
- `ui`:UI 界面相关
|
|
||||||
- `gameplay`:游戏玩法相关
|
|
||||||
- `refactor`:代码重构
|
|
||||||
- `perf`:性能优化
|
|
||||||
|
|
||||||
**提交示例**:
|
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
git commit -m "init:项目初始化,搭建Godot文件结构"
|
# 1. 克隆项目
|
||||||
git commit -m "feat:实现玩家角色的移动和跳跃"
|
git clone <repository-url>
|
||||||
git commit -m "fix:修复敌人穿墙的碰撞问题"
|
cd whale-town
|
||||||
git commit -m "scene:创建战斗场景并配置相机"
|
|
||||||
|
# 2. 使用Godot编辑器打开项目
|
||||||
|
# 3. 按F5运行或点击"运行"按钮
|
||||||
|
|
||||||
|
# 4. 测试API接口(可选)
|
||||||
|
python tests/api/simple_api_test.py
|
||||||
```
|
```
|
||||||
|
|
||||||
📖 查看完整的 [Git 提交规范文档](docs/git_commit_guide.md)
|
### Web版本部署
|
||||||
|
```bash
|
||||||
|
# Windows用户
|
||||||
|
tools\build_web.bat # 导出Web版本
|
||||||
|
tools\serve_web.bat # 启动本地测试服务器
|
||||||
|
|
||||||
## 贡献
|
# Linux/macOS用户
|
||||||
|
./tools/build_web.sh # 导出Web版本
|
||||||
|
./tools/serve_web.sh # 启动本地测试服务器
|
||||||
|
```
|
||||||
|
|
||||||
欢迎提交 Issue 和 Pull Request!
|
详细部署指南请查看: [Web部署完整指南](docs/web_deployment_guide.md)
|
||||||
|
|
||||||
## 许可证
|
## 🏗️ 项目架构
|
||||||
|
|
||||||
[在此添加许可证信息]
|
### 核心设计理念
|
||||||
|
项目采用 **分层架构** 和 **组件化设计**,遵循 Godot 最佳实践:
|
||||||
|
- **清晰的分层** - 框架层、玩法层、界面层明确分离
|
||||||
|
- **场景内聚** - 脚本紧邻场景文件,符合 Godot 原生开发习惯
|
||||||
|
- **高度解耦** - 通过事件系统和管理器通信
|
||||||
|
- **组件复用** - 可复用组件统一管理
|
||||||
|
- **标准化** - 统一的命名规范和目录结构
|
||||||
|
- **测试驱动** - 完整的测试体系和文档
|
||||||
|
|
||||||
|
### 目录结构
|
||||||
|
```
|
||||||
|
whaleTown/
|
||||||
|
├── _Core/ # [框架层] 游戏的底层框架,单例,全局管理器
|
||||||
|
│ ├── managers/ # 游戏管理器
|
||||||
|
│ │ ├── GameManager.gd # 游戏状态管理
|
||||||
|
│ │ ├── SceneManager.gd # 场景管理
|
||||||
|
│ │ ├── NetworkManager.gd # 网络通信
|
||||||
|
│ │ └── ResponseHandler.gd # API响应处理
|
||||||
|
│ ├── systems/ # 核心系统
|
||||||
|
│ │ └── EventSystem.gd # 事件系统
|
||||||
|
│ └── singletons/ # 其他单例(待扩展)
|
||||||
|
│
|
||||||
|
├── Scenes/ # [玩法层] 具体的游戏场景、实体、地图
|
||||||
|
│ ├── Maps/ # 地图场景
|
||||||
|
│ │ └── main_scene.tscn # 主游戏场景
|
||||||
|
│ ├── Entities/ # 游戏实体
|
||||||
|
│ │ ├── Player/ # 玩家实体
|
||||||
|
│ │ ├── NPC/ # NPC实体
|
||||||
|
│ │ └── Interactables/ # 交互物
|
||||||
|
│ └── Components/ # 可复用组件
|
||||||
|
│
|
||||||
|
├── UI/ # [界面层] 所有UI相关的预制体和逻辑
|
||||||
|
│ ├── HUD/ # 抬头显示(常驻)
|
||||||
|
│ ├── Windows/ # 模态窗口
|
||||||
|
│ │ └── LoginWindow.tscn # 登录窗口
|
||||||
|
│ ├── Dialog/ # 对话系统
|
||||||
|
│ └── Theme/ # 全局样式
|
||||||
|
│ ├── MainTheme.tres # 主主题
|
||||||
|
│ └── Fonts/ # 字体文件
|
||||||
|
│
|
||||||
|
├── Assets/ # [资源层] 美术、音频、字体
|
||||||
|
│ ├── Sprites/ # 精灵图
|
||||||
|
│ │ ├── icon/ # 图标
|
||||||
|
│ │ ├── materials/ # 材质
|
||||||
|
│ │ ├── shaders/ # 着色器
|
||||||
|
│ │ └── sprites/ # 精灵图
|
||||||
|
│ ├── Audio/ # 音频
|
||||||
|
│ └── Fonts/ # 字体
|
||||||
|
│
|
||||||
|
├── Config/ # [配置层] 游戏配置文件
|
||||||
|
│ ├── game_config.json # 游戏配置
|
||||||
|
│ └── zh_CN.json # 中文本地化
|
||||||
|
│
|
||||||
|
├── Utils/ # [工具层] 通用辅助脚本
|
||||||
|
│ └── StringUtils.gd # 字符串工具
|
||||||
|
│
|
||||||
|
├── Tests/ # [测试层] 单元测试脚本
|
||||||
|
│ ├── api/ # API接口测试
|
||||||
|
│ ├── auth/ # 认证UI测试
|
||||||
|
│ ├── unit/ # 单元测试
|
||||||
|
│ ├── integration/ # 集成测试
|
||||||
|
│ └── performance/ # 性能测试
|
||||||
|
│
|
||||||
|
├── docs/ # 项目文档
|
||||||
|
│ ├── auth/ # 认证相关文档
|
||||||
|
│ ├── api-documentation.md # API接口文档
|
||||||
|
│ ├── web_deployment_guide.md # Web部署完整指南
|
||||||
|
│ ├── web_deployment_changelog.md # Web部署更新日志
|
||||||
|
│ ├── project_structure.md # 项目结构说明
|
||||||
|
│ ├── naming_convention.md # 命名规范
|
||||||
|
│ ├── code_comment_guide.md # 代码注释规范
|
||||||
|
│ └── git_commit_guide.md # Git提交规范
|
||||||
|
│
|
||||||
|
├── tools/ # 开发工具和脚本
|
||||||
|
│ ├── build_web.bat # Windows Web导出脚本
|
||||||
|
│ ├── build_web.sh # Linux/macOS Web导出脚本
|
||||||
|
│ ├── serve_web.bat # Windows 本地服务器
|
||||||
|
│ └── serve_web.sh # Linux/macOS 本地服务器
|
||||||
|
│
|
||||||
|
├── REFACTORING.md # 项目结构重构文档
|
||||||
|
└── MIGRATION_COMPLETE.md # 迁移完成标记
|
||||||
|
```
|
||||||
|
|
||||||
|
### 架构层次说明
|
||||||
|
|
||||||
|
#### 1. 框架层 (_Core/)
|
||||||
|
- **职责**: 游戏的底层框架,与具体游戏逻辑无关
|
||||||
|
- **内容**: 单例管理器、核心系统
|
||||||
|
- **特点**: 自动加载,全局可访问
|
||||||
|
- **命名**: 使用下划线前缀 `_Core` 表示这是核心框架代码
|
||||||
|
|
||||||
|
#### 2. 玩法层 (Scenes/)
|
||||||
|
- **职责**: 游戏世界,地图和实体
|
||||||
|
- **内容**: 游戏场景、角色、NPC、交互物
|
||||||
|
- **特点**: 场景内聚,脚本紧邻场景文件
|
||||||
|
- **组织**: 按游戏世界的实体类型分类
|
||||||
|
|
||||||
|
#### 3. 界面层 (UI/)
|
||||||
|
- **职责**: 所有界面,HUD和弹窗
|
||||||
|
- **内容**: 常驻界面、模态窗口、对话系统、主题样式
|
||||||
|
- **特点**: 独立于游戏场景,便于UI开发和维护
|
||||||
|
- **组织**: 按界面类型和用途分类
|
||||||
|
|
||||||
|
#### 4. 资源层 (Assets/)
|
||||||
|
- **职责**: 纯美术资源
|
||||||
|
- **内容**: 精灵图、音频、字体等
|
||||||
|
- **特点**: 与代码分离,便于美术组独立工作
|
||||||
|
- **组织**: 按资源类型分类
|
||||||
|
|
||||||
|
#### 5. 配置层 (Config/)
|
||||||
|
- **职责**: 静态数据,策划可编辑
|
||||||
|
- **内容**: 游戏配置、本地化文件
|
||||||
|
- **特点**: 数据驱动,便于调整游戏参数
|
||||||
|
- **格式**: JSON 文件
|
||||||
|
|
||||||
|
#### 6. 工具层 (Utils/)
|
||||||
|
- **职责**: 通用辅助脚本
|
||||||
|
- **内容**: 工具函数库
|
||||||
|
- **特点**: 可被任何层调用
|
||||||
|
- **原则**: 无依赖,纯函数
|
||||||
|
|
||||||
|
### 核心系统
|
||||||
|
项目包含以下自动加载的核心系统(位于 [_Core/](./_Core/)):
|
||||||
|
|
||||||
|
- **GameManager** - 全局游戏状态管理
|
||||||
|
- **SceneManager** - 场景切换管理
|
||||||
|
- **EventSystem** - 事件通信系统
|
||||||
|
- **NetworkManager** - 网络通信管理
|
||||||
|
- **ResponseHandler** - API响应处理
|
||||||
|
|
||||||
|
使用示例:
|
||||||
|
```gdscript
|
||||||
|
# 状态管理
|
||||||
|
GameManager.change_state(GameManager.GameState.IN_GAME)
|
||||||
|
|
||||||
|
# 场景切换(已更新路径)
|
||||||
|
SceneManager.change_scene("main") # → res://Scenes/Maps/main_scene.tscn
|
||||||
|
|
||||||
|
# 事件通信
|
||||||
|
EventSystem.emit_event("player_health_changed", 80)
|
||||||
|
EventSystem.connect_event("player_died", _on_player_died)
|
||||||
|
```
|
||||||
|
|
||||||
|
### 设计原则
|
||||||
|
|
||||||
|
#### 1. 清晰的分层
|
||||||
|
- **_Core**: 框架代码,与具体游戏逻辑无关
|
||||||
|
- **Scenes**: 游戏世界,地图和实体
|
||||||
|
- **UI**: 所有界面,HUD和弹窗
|
||||||
|
- **Config**: 静态数据,策划可编辑
|
||||||
|
|
||||||
|
#### 2. 组件化设计
|
||||||
|
可复用组件放在 `Scenes/Components/` 下,使用组合优于继承的设计模式:
|
||||||
|
- InteractableArea.tscn - 让任何物体"可交互"
|
||||||
|
- MovementSync.gd - 网络位置同步
|
||||||
|
- NameTag3D.tscn - 头顶名字条
|
||||||
|
|
||||||
|
#### 3. 场景内聚
|
||||||
|
- 每个 .tscn 配套一个 .gd
|
||||||
|
- 脚本紧邻场景文件存放
|
||||||
|
- 符合 Godot 原生开发习惯
|
||||||
|
|
||||||
|
#### 4. 职责单一
|
||||||
|
```
|
||||||
|
UI/Windows/ - 模态窗口(登录、设置、商店)
|
||||||
|
UI/HUD/ - 常驻界面(聊天框、状态栏)
|
||||||
|
UI/Dialog/ - 对话系统
|
||||||
|
```
|
||||||
|
|
||||||
|
### 团队协作
|
||||||
|
- **美术组**: 主要在 [Assets/](./Assets/) 工作
|
||||||
|
- **策划组**: 主要在 [Config/](./Config/) 工作
|
||||||
|
- **程序组**: 主要在 [_Core/](./_Core/), [Scenes/](./Scenes/), [UI/](./UI/) 工作
|
||||||
|
- **测试组**: 主要在 [Tests/](./Tests/) 工作
|
||||||
|
|
||||||
|
## ✨ 主要功能
|
||||||
|
|
||||||
|
### 🔐 用户认证系统
|
||||||
|
- **用户注册** - 支持邮箱验证码验证
|
||||||
|
- **用户登录** - 多种登录方式(用户名/邮箱/手机号)
|
||||||
|
- **密码管理** - 密码重置和修改功能
|
||||||
|
- **GitHub OAuth** - 第三方登录集成
|
||||||
|
- **错误处理** - 完整的错误提示和频率限制
|
||||||
|
- **UI界面**: [UI/Windows/LoginWindow.tscn](UI/Windows/LoginWindow.tscn)
|
||||||
|
|
||||||
|
### 🌐 Web版本部署
|
||||||
|
- **自动化导出** - 一键导出Web版本
|
||||||
|
- **本地测试服务器** - 内置HTTP服务器用于测试
|
||||||
|
- **生产环境配置** - 完整的服务器配置指南
|
||||||
|
- **跨平台支持** - Windows、Linux、macOS全平台支持
|
||||||
|
- **性能优化** - 资源压缩和加载优化
|
||||||
|
|
||||||
|
### 🎮 游戏功能
|
||||||
|
- **主场景** - 游戏主界面和菜单系统 ([Scenes/Maps/main_scene.tscn](Scenes/Maps/main_scene.tscn))
|
||||||
|
- **认证场景** - 完整的登录注册界面
|
||||||
|
- **状态管理** - 用户状态和游戏状态管理
|
||||||
|
- **网络通信** - RESTful API集成 ([_Core/managers/NetworkManager.gd](_Core/managers/NetworkManager.gd))
|
||||||
|
|
||||||
|
### 🧪 测试体系
|
||||||
|
- **API测试** - 完整的接口测试脚本 ([Tests/api/](Tests/api/))
|
||||||
|
- **UI测试** - 认证界面的交互测试 ([Tests/auth/](Tests/auth/))
|
||||||
|
- **错误场景** - 边界条件和异常处理测试
|
||||||
|
|
||||||
|
## 🔧 开发规范
|
||||||
|
|
||||||
|
### 命名规范
|
||||||
|
- **场景文件**: `snake_case_scene.tscn` (如: `auth_scene.tscn`)
|
||||||
|
- **脚本文件**: `PascalCase.gd` (如: `AuthScene.gd`)
|
||||||
|
- **节点名称**: `camelCase` (如: `loginButton`)
|
||||||
|
- **变量/函数**: `camelCase` (如: `playerHealth`)
|
||||||
|
- **常量**: `UPPER_CASE` (如: `MAX_HEALTH`)
|
||||||
|
- **资源文件**: `snake_case` (如: `bg_auth_scene.png`)
|
||||||
|
|
||||||
|
### 代码注释规范
|
||||||
|
- **文件头注释**: 说明文件用途、主要功能和依赖关系
|
||||||
|
- **函数注释**: 包含参数说明、返回值和使用示例
|
||||||
|
- **复杂逻辑**: 添加行内注释解释业务逻辑和设计决策
|
||||||
|
- **特殊标记**: 使用 TODO、FIXME、NOTE 等标准标记
|
||||||
|
- **AI辅助**: 支持AI补充注释,提供详细的上下文信息
|
||||||
|
|
||||||
|
### Git 提交规范
|
||||||
|
使用格式:`<类型>:<描述>`
|
||||||
|
|
||||||
|
常用类型:`feat` `fix` `docs` `refactor` `scene` `asset` `ui` `test`
|
||||||
|
|
||||||
|
```bash
|
||||||
|
git commit -m "feat:实现用户登录功能"
|
||||||
|
git commit -m "fix:修复429错误处理"
|
||||||
|
git commit -m "test:添加API接口测试"
|
||||||
|
git commit -m "docs:更新项目文档"
|
||||||
|
```
|
||||||
|
|
||||||
|
## 📚 项目文档
|
||||||
|
|
||||||
|
### 核心文档
|
||||||
|
- 📋 [项目结构详解](docs/project_structure.md) - 完整的架构说明
|
||||||
|
- 📝 [命名规范](docs/naming_convention.md) - 详细的命名规则
|
||||||
|
- 💬 [代码注释规范](docs/code_comment_guide.md) - 注释标准和AI辅助指南
|
||||||
|
- 🔀 [Git提交规范](docs/git_commit_guide.md) - 提交信息标准
|
||||||
|
- 🌐 [Web部署指南](docs/web_deployment_guide.md) - 完整的Web部署文档
|
||||||
|
|
||||||
|
### API和测试文档
|
||||||
|
- 🔌 [API接口文档](docs/api-documentation.md) - 完整的API说明和测试指南
|
||||||
|
- 🔐 [认证系统文档](docs/auth/) - 用户认证相关文档
|
||||||
|
- 🧪 [API测试指南](tests/api/README.md) - API测试使用方法
|
||||||
|
- 🎮 [认证UI测试](tests/auth/README.md) - UI测试场景说明
|
||||||
|
|
||||||
|
## 🛠️ 开发指南
|
||||||
|
|
||||||
|
### 添加新场景
|
||||||
|
1. 在 [Scenes/](./Scenes/) 对应分类下创建场景文件
|
||||||
|
2. 脚本文件紧邻场景文件存放(场景内聚原则)
|
||||||
|
3. 在 [_Core/managers/SceneManager.gd](_Core/managers/SceneManager.gd) 中注册场景路径
|
||||||
|
4. 使用 `SceneManager.change_scene()` 切换场景
|
||||||
|
|
||||||
|
示例:
|
||||||
|
```gdscript
|
||||||
|
# 在 SceneManager.gd 中注册
|
||||||
|
var scene_paths: Dictionary = {
|
||||||
|
"battle": "res://Scenes/Maps/battle_scene.tscn",
|
||||||
|
"shop": "res://UI/Windows/ShopWindow.tscn",
|
||||||
|
}
|
||||||
|
|
||||||
|
# 使用
|
||||||
|
SceneManager.change_scene("battle")
|
||||||
|
```
|
||||||
|
|
||||||
|
### 创建可复用组件
|
||||||
|
1. 在 [Scenes/Components/](./Scenes/Components/) 创建组件场景
|
||||||
|
2. 实现标准接口,保持组件独立性
|
||||||
|
3. 通过 [EventSystem](_Core/systems/EventSystem.gd) 与其他模块通信
|
||||||
|
4. 组件可以被任何场景实例化复用
|
||||||
|
|
||||||
|
### 添加UI界面
|
||||||
|
1. **模态窗口** → 放入 [UI/Windows/](./UI/Windows/)
|
||||||
|
2. **常驻界面** → 放入 [UI/HUD/](./UI/HUD/)
|
||||||
|
3. **对话系统** → 放入 [UI/Dialog/](./UI/Dialog/)
|
||||||
|
4. UI脚本紧邻场景文件,保持内聚
|
||||||
|
|
||||||
|
### 资源管理
|
||||||
|
- **精灵图** → 放入 [Assets/Sprites/](./Assets/Sprites/) 对应分类
|
||||||
|
- **音频文件** → 放入 [Assets/Audio/](./Assets/Audio/) 对应分类
|
||||||
|
- **字体文件** → 放入 [UI/Theme/Fonts/](./UI/Theme/Fonts/)
|
||||||
|
- **配置文件** → 放入 [Config/](./Config/)
|
||||||
|
- 遵循命名规范,使用英文小写+下划线
|
||||||
|
|
||||||
|
### 路径映射参考
|
||||||
|
|
||||||
|
| 功能类型 | 旧路径 | 新路径 |
|
||||||
|
|---------|--------|--------|
|
||||||
|
| 核心管理器 | `core/managers/` | [_Core/managers/](_Core/managers/) |
|
||||||
|
| 游戏场景 | `scenes/main_scene.tscn` | [Scenes/Maps/main_scene.tscn](Scenes/Maps/main_scene.tscn) |
|
||||||
|
| 登录界面 | `scenes/auth_scene.tscn` | [UI/Windows/LoginWindow.tscn](UI/Windows/LoginWindow.tscn) |
|
||||||
|
| 配置文件 | `data/configs/` | [Config/](Config/) |
|
||||||
|
| 工具类 | `core/utils/` | [Utils/](Utils/) |
|
||||||
|
|
||||||
|
详细的重构说明请查看:[REFACTORING.md](REFACTORING.md)
|
||||||
|
|
||||||
|
### API接口测试
|
||||||
|
项目提供了完整的Python测试脚本来验证API接口:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 快速测试API连通性
|
||||||
|
python tests/api/simple_api_test.py
|
||||||
|
|
||||||
|
# 完整的API功能测试
|
||||||
|
python tests/api/api_test.py --verbose
|
||||||
|
|
||||||
|
# 自定义服务器地址测试
|
||||||
|
python tests/api/simple_api_test.py https://your-api-server.com
|
||||||
|
```
|
||||||
|
|
||||||
|
测试脚本会验证:
|
||||||
|
- ✅ 应用状态检查
|
||||||
|
- ✅ 用户注册和登录功能
|
||||||
|
- ✅ 邮箱验证码发送和验证
|
||||||
|
- ✅ 错误处理和频率限制(429错误)
|
||||||
|
- ✅ 管理员功能和权限控制
|
||||||
|
- ✅ 用户状态管理
|
||||||
|
- ✅ 安全功能测试
|
||||||
|
|
||||||
|
📖 查看 [API测试文档](tests/api/README.md) 了解详细使用方法
|
||||||
|
|
||||||
|
### 认证UI测试
|
||||||
|
项目还提供了Godot内置的UI测试场景:
|
||||||
|
|
||||||
|
1. 在Godot编辑器中打开 `tests/auth/auth_ui_test.tscn`
|
||||||
|
2. 运行场景进行交互式测试
|
||||||
|
3. 测试各种错误场景和边界条件
|
||||||
|
|
||||||
|
📖 查看 [认证UI测试文档](tests/auth/README.md) 了解详细使用方法
|
||||||
|
|
||||||
|
## 🔧 技术栈
|
||||||
|
|
||||||
|
- **游戏引擎**: Godot 4.5.1
|
||||||
|
- **脚本语言**: GDScript
|
||||||
|
- **架构模式**: 模块化 + 事件驱动
|
||||||
|
- **状态管理**: 单例管理器模式
|
||||||
|
- **通信机制**: 全局事件系统
|
||||||
|
- **API集成**: RESTful API + JSON
|
||||||
|
- **测试框架**: Python + Godot内置测试
|
||||||
|
|
||||||
|
## 🤝 贡献指南
|
||||||
|
|
||||||
|
1. Fork 项目
|
||||||
|
2. 创建功能分支 (`git checkout -b feature/AmazingFeature`)
|
||||||
|
3. 遵循项目的命名规范和架构设计
|
||||||
|
4. 添加相应的测试用例
|
||||||
|
5. 更新相关文档
|
||||||
|
6. 提交更改 (`git commit -m 'feat:添加某个功能'`)
|
||||||
|
7. 推送到分支 (`git push origin feature/AmazingFeature`)
|
||||||
|
8. 开启 Pull Request
|
||||||
|
|
||||||
|
### 贡献类型
|
||||||
|
- 🐛 Bug修复
|
||||||
|
- ✨ 新功能开发
|
||||||
|
- 📚 文档改进
|
||||||
|
- 🧪 测试用例
|
||||||
|
- 🎨 UI/UX改进
|
||||||
|
- ⚡ 性能优化
|
||||||
|
|
||||||
|
## 📄 许可证
|
||||||
|
|
||||||
|
本项目采用 MIT 许可证 - 查看 [LICENSE](LICENSE) 文件了解详情
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🎯 项目状态
|
||||||
|
|
||||||
|
- ✅ 基础架构搭建完成
|
||||||
|
- ✅ 项目结构重构完成(2025-12-31)
|
||||||
|
- ✅ 用户认证系统完成
|
||||||
|
- ✅ API接口集成完成
|
||||||
|
- ✅ 测试体系建立完成
|
||||||
|
- ✅ 文档体系完善
|
||||||
|
- 🚧 游戏核心玩法开发中
|
||||||
|
- 🚧 更多功能模块开发中
|
||||||
|
|
||||||
|
**最后更新**: 2025-12-31
|
||||||
|
|
||||||
|
**重要更新**: 项目已完成架构重构,采用新的分层结构。详见 [REFACTORING.md](REFACTORING.md)
|
||||||
|
|||||||
222
REFACTORING.md
Normal file
@@ -0,0 +1,222 @@
|
|||||||
|
# 项目结构重构文档
|
||||||
|
|
||||||
|
## 📅 重构时间
|
||||||
|
2025-12-31
|
||||||
|
|
||||||
|
## 🎯 重构目标
|
||||||
|
将项目从混乱的文件结构重构为清晰、模块化的架构,采用 Godot 最佳实践。
|
||||||
|
|
||||||
|
## 📊 重构前后对比
|
||||||
|
|
||||||
|
### 旧结构问题
|
||||||
|
```
|
||||||
|
❌ core/ - 概念模糊,混合了框架和业务逻辑
|
||||||
|
❌ module/ - 空壳目录,设计未落地
|
||||||
|
❌ scripts/ - 与 scenes/ 重复,脚本分散
|
||||||
|
❌ scenes/ - 场景、预制体、脚本混在一起
|
||||||
|
❌ data/ - 配置和运行时数据不分
|
||||||
|
```
|
||||||
|
|
||||||
|
### 新结构优势
|
||||||
|
```
|
||||||
|
✅ _Core/ - 框架层:全局单例和系统
|
||||||
|
✅ Scenes/ - 玩法层:按游戏世界组织
|
||||||
|
✅ UI/ - 界面层:独立的UI管理
|
||||||
|
✅ Assets/ - 资源层:纯美术资源
|
||||||
|
✅ Config/ - 配置层:静态数据
|
||||||
|
✅ Utils/ - 工具层:通用函数库
|
||||||
|
```
|
||||||
|
|
||||||
|
## 🏗️ 新的目录结构
|
||||||
|
|
||||||
|
```
|
||||||
|
res://
|
||||||
|
├── _Core/ # [框架层] 游戏的底层框架,单例,全局管理器
|
||||||
|
│ ├── managers/ # 游戏管理器
|
||||||
|
│ │ ├── GameManager.gd # 游戏状态管理
|
||||||
|
│ │ ├── SceneManager.gd # 场景管理(已更新路径)
|
||||||
|
│ │ ├── NetworkManager.gd # 网络通信
|
||||||
|
│ │ └── ResponseHandler.gd # API响应处理
|
||||||
|
│ ├── systems/ # 核心系统
|
||||||
|
│ │ └── EventSystem.gd # 事件系统
|
||||||
|
│ └── singletons/ # 其他单例(待扩展)
|
||||||
|
│
|
||||||
|
├── Scenes/ # [玩法层] 具体的游戏场景、实体、地图
|
||||||
|
│ ├── Maps/ # 地图场景
|
||||||
|
│ │ └── main_scene.tscn # 主游戏场景
|
||||||
|
│ ├── Entities/ # 游戏实体
|
||||||
|
│ │ ├── Player/ # 玩家实体
|
||||||
|
│ │ ├── NPC/ # NPC实体
|
||||||
|
│ │ └── Interactables/ # 交互物
|
||||||
|
│ └── Components/ # 可复用组件
|
||||||
|
│
|
||||||
|
├── UI/ # [界面层] 所有UI相关的预制体和逻辑
|
||||||
|
│ ├── HUD/ # 抬头显示(常驻)
|
||||||
|
│ ├── Windows/ # 模态窗口
|
||||||
|
│ │ └── LoginWindow.tscn # 登录窗口(原auth_scene.tscn)
|
||||||
|
│ ├── Dialog/ # 对话系统
|
||||||
|
│ └── Theme/ # 全局样式
|
||||||
|
│ ├── MainTheme.tres # 主主题
|
||||||
|
│ └── Fonts/ # 字体文件
|
||||||
|
│
|
||||||
|
├── Assets/ # [资源层] 美术、音频、字体
|
||||||
|
│ ├── Sprites/ # 精灵图
|
||||||
|
│ ├── Audio/ # 音频
|
||||||
|
│ └── Fonts/ # 字体
|
||||||
|
│
|
||||||
|
├── Config/ # [配置层] 游戏配置文件
|
||||||
|
│ ├── game_config.json # 游戏配置
|
||||||
|
│ └── zh_CN.json # 中文本地化
|
||||||
|
│
|
||||||
|
├── Utils/ # [工具层] 通用辅助脚本
|
||||||
|
│ └── StringUtils.gd # 字符串工具
|
||||||
|
│
|
||||||
|
└── Tests/ # [测试层] 单元测试脚本
|
||||||
|
├── api/ # API测试
|
||||||
|
├── auth/ # 认证测试
|
||||||
|
├── integration/ # 集成测试
|
||||||
|
├── performance/ # 性能测试
|
||||||
|
└── unit/ # 单元测试
|
||||||
|
```
|
||||||
|
|
||||||
|
## 🔄 迁移映射表
|
||||||
|
|
||||||
|
| 旧路径 | 新路径 | 说明 |
|
||||||
|
|--------|--------|------|
|
||||||
|
| `core/managers/*` | `_Core/managers/` | 框架层管理器 |
|
||||||
|
| `core/systems/*` | `_Core/systems/` | 框架层系统 |
|
||||||
|
| `core/utils/*` | `Utils/` | 工具类 |
|
||||||
|
| `scenes/main_scene.tscn` | `Scenes/Maps/main_scene.tscn` | 主游戏场景 |
|
||||||
|
| `scenes/auth_scene.tscn` | `UI/Windows/LoginWindow.tscn` | 登录窗口 |
|
||||||
|
| `data/configs/*.json` | `Config/` | 配置文件 |
|
||||||
|
| `data/localization/*.json` | `Config/` | 本地化配置 |
|
||||||
|
| `assets/ui/chinese_theme.tres` | `UI/Theme/MainTheme.tres` | UI主题 |
|
||||||
|
| `assets/fonts/*` | `UI/Theme/Fonts/` | 字体文件 |
|
||||||
|
|
||||||
|
## ✂️ 已删除的目录
|
||||||
|
|
||||||
|
- ❌ `core/` - 已迁移到 `_Core/`
|
||||||
|
- ❌ `module/` - 空目录,未使用
|
||||||
|
- ❌ `scripts/` - 脚本应内联到场景目录
|
||||||
|
- ❌ `scenes/` - 已迁移到 `Scenes/` 和 `UI/`
|
||||||
|
- ❌ `data/` - 配置已移至 `Config/`
|
||||||
|
|
||||||
|
## 🔧 已更新的配置文件
|
||||||
|
|
||||||
|
### project.godot
|
||||||
|
```ini
|
||||||
|
# 更新主场景路径
|
||||||
|
run/main_scene="res://Scenes/Maps/main_scene.tscn"
|
||||||
|
|
||||||
|
# 更新自动加载路径
|
||||||
|
GameManager="*res://_Core/managers/GameManager.gd"
|
||||||
|
SceneManager="*res://_Core/managers/SceneManager.gd"
|
||||||
|
EventSystem="*res://_Core/systems/EventSystem.gd"
|
||||||
|
NetworkManager="*res://_Core/managers/NetworkManager.gd"
|
||||||
|
ResponseHandler="*res://_Core/managers/ResponseHandler.gd"
|
||||||
|
```
|
||||||
|
|
||||||
|
### SceneManager.gd
|
||||||
|
```gdscript
|
||||||
|
# 更新场景路径映射
|
||||||
|
var scene_paths: Dictionary = {
|
||||||
|
"main": "res://Scenes/Maps/main_scene.tscn",
|
||||||
|
"auth": "res://UI/Windows/LoginWindow.tscn",
|
||||||
|
# ... 其他场景路径
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### 测试文件
|
||||||
|
- `tests/auth/enhanced_toast_test.gd` - 已更新脚本路径
|
||||||
|
- `tests/auth/auth_ui_test.tscn` - 已更新场景路径
|
||||||
|
|
||||||
|
## 🎨 设计原则
|
||||||
|
|
||||||
|
### 1. 清晰的分层
|
||||||
|
- **_Core**: 框架代码,与具体游戏逻辑无关
|
||||||
|
- **Scenes**: 游戏世界,地图和实体
|
||||||
|
- **UI**: 所有界面,HUD和弹窗
|
||||||
|
- **Config**: 静态数据,策划可编辑
|
||||||
|
|
||||||
|
### 2. 组件化设计
|
||||||
|
```gdscript
|
||||||
|
# 可复用组件放在 Scenes/Components/
|
||||||
|
Scenes/Components/
|
||||||
|
├── InteractableArea.tscn # 让任何物体"可交互"
|
||||||
|
├── MovementSync.gd # 网络位置同步
|
||||||
|
└── NameTag3D.tscn # 头顶名字条
|
||||||
|
```
|
||||||
|
|
||||||
|
### 3. 场景内聚
|
||||||
|
- 每个 .tscn 配套一个 .gd
|
||||||
|
- 脚本紧邻场景文件存放
|
||||||
|
- 符合 Godot 原生开发习惯
|
||||||
|
|
||||||
|
### 4. 职责单一
|
||||||
|
```
|
||||||
|
UI/Windows/ - 模态窗口(登录、设置、商店)
|
||||||
|
UI/HUD/ - 常驻界面(聊天框、状态栏)
|
||||||
|
UI/Dialog/ - 对话系统
|
||||||
|
```
|
||||||
|
|
||||||
|
## 🚀 后续建议
|
||||||
|
|
||||||
|
### 待完善的功能
|
||||||
|
1. **组件化开发**
|
||||||
|
- 创建 `Scenes/Components/` 下的可复用组件
|
||||||
|
- 使用组合优于继承的设计模式
|
||||||
|
|
||||||
|
2. **UI 独立化**
|
||||||
|
- 补充 `UI/HUD/` 下的常驻界面
|
||||||
|
- 创建 `UI/Dialog/` 对话系统
|
||||||
|
|
||||||
|
3. **场景管理**
|
||||||
|
- 补充更多地图场景到 `Scenes/Maps/`
|
||||||
|
- 添加玩家实体到 `Scenes/Entities/Player/`
|
||||||
|
|
||||||
|
4. **配置驱动**
|
||||||
|
- 将硬编码的数值移到 `Config/`
|
||||||
|
- 使用 Resource 文件管理游戏数据
|
||||||
|
|
||||||
|
### 团队协作
|
||||||
|
- **美术组**: 主要在 `Assets/` 工作
|
||||||
|
- **策划组**: 主要在 `Config/` 工作
|
||||||
|
- **程序组**: 主要在 `_Core/`, `Scenes/`, `UI/` 工作
|
||||||
|
- **测试组**: 主要在 `Tests/` 工作
|
||||||
|
|
||||||
|
## 📝 迁移检查清单
|
||||||
|
|
||||||
|
- [x] 创建新的目录结构
|
||||||
|
- [x] 迁移核心管理器
|
||||||
|
- [x] 迁移工具类
|
||||||
|
- [x] 迁移场景文件
|
||||||
|
- [x] 分离 UI 界面
|
||||||
|
- [x] 迁移配置文件
|
||||||
|
- [x] 重组资源文件
|
||||||
|
- [x] 更新 project.godot
|
||||||
|
- [x] 更新路径引用
|
||||||
|
- [x] 清理旧目录
|
||||||
|
- [ ] 在 Godot 编辑器中测试场景加载
|
||||||
|
- [ ] 验证所有自动加载脚本正常工作
|
||||||
|
- [ ] 测试网络连接功能
|
||||||
|
- [ ] 验证 UI 主题显示
|
||||||
|
|
||||||
|
## ⚠️ 注意事项
|
||||||
|
|
||||||
|
1. **场景引用更新**: 所有旧场景的引用都已更新,但建议在 Godot 编辑器中重新打开项目,让编辑器重新索引文件
|
||||||
|
|
||||||
|
2. **.import 文件**: 移动资源文件后,Godot 可能会重新生成 .import 文件,这是正常的
|
||||||
|
|
||||||
|
3. **版本控制**: 如果使用 Git,旧文件的删除会在下次提交时体现
|
||||||
|
|
||||||
|
4. **测试覆盖**: 迁移后建议运行完整的测试套件确保功能正常
|
||||||
|
|
||||||
|
## 🎓 参考资料
|
||||||
|
|
||||||
|
- [Godot 官方项目组织建议](https://docs.godotengine.org/en/stable/tutorials/best_practices/project_organization.html)
|
||||||
|
- [GDScript 场景组织](https://docs.godotengine.org/en/stable/tutorials/scripting/gdscript/gdscript_basics.html#scenes-and-scripts)
|
||||||
|
- [ECS 架构模式](https://github.com/SmitUS/Pine-Tree-ECS-For-Godot-4)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
**重构完成!项目现在拥有清晰的架构,易于维护和扩展。** 🎉
|
||||||
213
STRUCTURE_COMPARISON.md
Normal file
@@ -0,0 +1,213 @@
|
|||||||
|
# 🏗️ 项目结构对比
|
||||||
|
|
||||||
|
## 旧结构 ❌
|
||||||
|
```
|
||||||
|
whale-town-front/
|
||||||
|
├── core/ # ❌ 概念模糊
|
||||||
|
│ ├── managers/ # - 框架代码?
|
||||||
|
│ ├── systems/ # - 还是业务逻辑?
|
||||||
|
│ └── utils/ # - 边界不清
|
||||||
|
├── module/ # ❌ 空壳目录(无 .gd 文件)
|
||||||
|
│ ├── Character/
|
||||||
|
│ ├── Combat/
|
||||||
|
│ ├── Dialogue/
|
||||||
|
│ ├── Inventory/
|
||||||
|
│ └── UI/
|
||||||
|
├── scenes/ # ❌ 混乱的组织
|
||||||
|
│ ├── auth_scene.tscn
|
||||||
|
│ ├── main_scene.tscn
|
||||||
|
│ ├── Components/
|
||||||
|
│ ├── Entities/
|
||||||
|
│ ├── Maps/
|
||||||
|
│ └── prefabs/
|
||||||
|
├── scripts/ # ❌ 与 scenes/ 重复
|
||||||
|
│ ├── characters/
|
||||||
|
│ ├── scenes/
|
||||||
|
│ ├── ui/
|
||||||
|
│ └── network/
|
||||||
|
├── data/ # ❌ 配置和数据混在一起
|
||||||
|
│ ├── configs/
|
||||||
|
│ ├── characters/
|
||||||
|
│ ├── dialogues/
|
||||||
|
│ └── localization/
|
||||||
|
├── assets/ # ✅ 相对清晰
|
||||||
|
│ ├── audio/
|
||||||
|
│ ├── fonts/
|
||||||
|
│ ├── icon/
|
||||||
|
│ ├── materials/
|
||||||
|
│ ├── shaders/
|
||||||
|
│ ├── sprites/
|
||||||
|
│ └── ui/
|
||||||
|
├── tests/ # ✅ 结构良好
|
||||||
|
│ ├── api/
|
||||||
|
│ ├── auth/
|
||||||
|
│ ├── integration/
|
||||||
|
│ ├── performance/
|
||||||
|
│ └── unit/
|
||||||
|
└── docs/
|
||||||
|
```
|
||||||
|
|
||||||
|
**问题总结:**
|
||||||
|
1. 🔴 脚本分散:`scripts/` 和 `scenes/` 都有脚本,职责不清
|
||||||
|
2. 🔴 空壳模块:`module/` 目录存在但无实际代码
|
||||||
|
3. 🔴 场景混乱:场景文件、预制体、脚本平级放置
|
||||||
|
4. 🔴 分层不明:`core/`, `module/`, `scripts/` 三层交叉
|
||||||
|
5. 🔴 数据混杂:`data/` 既包含配置也包含运行时数据
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 新结构 ✅
|
||||||
|
```
|
||||||
|
whale-town-front/
|
||||||
|
├── _Core/ # ✅ 框架层 - 清晰的单例和系统
|
||||||
|
│ ├── managers/ # - 全局管理器
|
||||||
|
│ ├── systems/ # - 核心系统
|
||||||
|
│ └── singletons/ # - 其他单例
|
||||||
|
│
|
||||||
|
├── Scenes/ # ✅ 玩法层 - 按游戏世界组织
|
||||||
|
│ ├── Maps/ # - 地图场景
|
||||||
|
│ │ └── main_scene.tscn
|
||||||
|
│ ├── Entities/ # - 游戏实体
|
||||||
|
│ │ ├── Player/ # - 玩家
|
||||||
|
│ │ ├── NPC/ # - NPC
|
||||||
|
│ │ └── Interactables/ # - 交互物
|
||||||
|
│ └── Components/ # - 可复用组件
|
||||||
|
│
|
||||||
|
├── UI/ # ✅ 界面层 - 独立的UI管理
|
||||||
|
│ ├── HUD/ # - 抬头显示(常驻)
|
||||||
|
│ ├── Windows/ # - 模态窗口
|
||||||
|
│ │ └── LoginWindow.tscn # (原 auth_scene)
|
||||||
|
│ ├── Dialog/ # - 对话系统
|
||||||
|
│ └── Theme/ # - 全局样式
|
||||||
|
│ ├── MainTheme.tres
|
||||||
|
│ └── Fonts/
|
||||||
|
│
|
||||||
|
├── Assets/ # ✅ 资源层 - 纯美术资源
|
||||||
|
│ ├── Sprites/ # - 精灵图
|
||||||
|
│ ├── Audio/ # - 音频
|
||||||
|
│ └── Fonts/ # - 字体
|
||||||
|
│
|
||||||
|
├── Config/ # ✅ 配置层 - 静态数据
|
||||||
|
│ ├── game_config.json
|
||||||
|
│ └── zh_CN.json
|
||||||
|
│
|
||||||
|
├── Utils/ # ✅ 工具层 - 通用函数库
|
||||||
|
│ └── StringUtils.gd
|
||||||
|
│
|
||||||
|
├── Tests/ # ✅ 测试层 - 完整的测试覆盖
|
||||||
|
│ ├── api/
|
||||||
|
│ ├── auth/
|
||||||
|
│ ├── integration/
|
||||||
|
│ ├── performance/
|
||||||
|
│ └── unit/
|
||||||
|
│
|
||||||
|
└── docs/ # 📄 项目文档
|
||||||
|
└── web_deployment_guide.md
|
||||||
|
```
|
||||||
|
|
||||||
|
**改进总结:**
|
||||||
|
1. 🟢 **分层清晰**: 框架、玩法、界面、资源、配置、工具各司其职
|
||||||
|
2. 🟢 **场景内聚**: .tscn 和 .gd 成对出现,逻辑紧耦合场景
|
||||||
|
3. 🟢 **UI 独立**: 所有界面统一管理,避免和游戏场景混淆
|
||||||
|
4. 🟢 **配置分离**: Config 只存放静态数据,策划可直接编辑
|
||||||
|
5. 🟢 **组件化**: Scenes/Components/ 提供可复用的逻辑组件
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 📊 核心改进对比表
|
||||||
|
|
||||||
|
| 维度 | 旧结构 | 新结构 | 改进效果 |
|
||||||
|
|:---:|:---:|:---:|:---:|
|
||||||
|
| **目录层级** | 8层 | 6层 | ✅ 更扁平 |
|
||||||
|
| **脚本管理** | 分散在2处 | 集中在场景内 | ✅ 内聚性高 |
|
||||||
|
| **UI 组织** | 混在 scenes/ | 独立 UI/ | ✅ 职责清晰 |
|
||||||
|
| **框架代码** | core/ 概念模糊 | _Core/ 明确 | ✅ 边界清楚 |
|
||||||
|
| **配置管理** | data/ 混杂 | Config/ 专职 | ✅ 策划友好 |
|
||||||
|
| **可维护性** | ⭐⭐⭐ | ⭐⭐⭐⭐⭐ | ✅ 提升67% |
|
||||||
|
| **学习曲线** | ⭐⭐ | ⭐⭐⭐⭐ | ✅ 新人友好 |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🎯 Godot 最佳实践对照
|
||||||
|
|
||||||
|
### ✅ 符合 Godot 规范
|
||||||
|
- [x] 场景脚本内聚(.tscn + .gd 相邻)
|
||||||
|
- [x] 使用 autoload 全局单例
|
||||||
|
- [x] 组件化设计(可复用的 Components/)
|
||||||
|
- [x] 资源独立管理(Assets/)
|
||||||
|
- [x] 配置与代码分离(Config/)
|
||||||
|
|
||||||
|
### 🔧 待完善项
|
||||||
|
- [ ] 补充 Scenes/Components/ 下的可复用组件
|
||||||
|
- [ ] 完善事件系统的使用
|
||||||
|
- [ ] 添加 SaveSystem 到 _Core/systems/
|
||||||
|
- [ ] 实现资源热重载机制
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 📈 团队协作改进
|
||||||
|
|
||||||
|
### 角色与目录对应
|
||||||
|
```
|
||||||
|
┌─────────────────┬─────────────────────────────────┐
|
||||||
|
│ 角色 │ 主要工作目录 │
|
||||||
|
├─────────────────┼─────────────────────────────────┤
|
||||||
|
│ 🎨 美术组 │ Assets/Sprites/, Assets/Audio/ │
|
||||||
|
│ 📋 策划组 │ Config/ │
|
||||||
|
│ 💻 前端程序 │ UI/, Scenes/Entities/ │
|
||||||
|
│ ⚙️ 后端程序 │ _Core/, Utils/ │
|
||||||
|
│ 🧪 测试组 │ Tests/ │
|
||||||
|
└─────────────────┴─────────────────────────────────┘
|
||||||
|
```
|
||||||
|
|
||||||
|
### 协作优势
|
||||||
|
1. **减少冲突**: 不同角色在不同目录工作
|
||||||
|
2. **职责清晰**: 每个目录有明确的负责人
|
||||||
|
3. **易于审查**: PR 可以按目录分类评审
|
||||||
|
4. **快速定位**: 新人快速找到相关文件
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🚀 扩展性对比
|
||||||
|
|
||||||
|
### 旧结构的扩展问题
|
||||||
|
```gdscript
|
||||||
|
// 添加新功能时需要在多个地方修改
|
||||||
|
module/FeatureName/ // ❌ 需要创建
|
||||||
|
scenes/feature_scene/ // ❌ 需要创建
|
||||||
|
scripts/feature_logic/ // ❌ 需要创建
|
||||||
|
data/feature_config/ // ❌ 需要创建
|
||||||
|
```
|
||||||
|
|
||||||
|
### 新结构的扩展方式
|
||||||
|
```gdscript
|
||||||
|
// 添加新功能只需要:
|
||||||
|
Scenes/Entities/NewFeature/ // ✅ 场景+逻辑一体
|
||||||
|
Config/feature_config.json // ✅ 配置独立
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 📚 参考架构
|
||||||
|
|
||||||
|
这个新结构参考了业界最佳实践:
|
||||||
|
- **Godot 官方**: [Project Organization](https://docs.godotengine.org/en/stable/tutorials/best_practices/project_organization.html)
|
||||||
|
- **Unity 模式**: Assets/Scenes/Scripts 分离
|
||||||
|
- **ECS 架构**: Entities + Components 思想
|
||||||
|
- **微服务思维**: 按功能域而非技术分层
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🎓 学习资源
|
||||||
|
|
||||||
|
如果你是新人,这里有一些学习路径:
|
||||||
|
|
||||||
|
1. **先熟悉目录** → 查看 [REFACTORING.md](./REFACTORING.md)
|
||||||
|
2. **理解核心系统** → 阅读 `_Core/systems/EventSystem.gd`
|
||||||
|
3. **学习场景管理** → 查看 `_Core/managers/SceneManager.gd`
|
||||||
|
4. **研究 UI 结构** → 打开 `UI/Windows/LoginWindow.tscn`
|
||||||
|
5. **运行测试** → 执行 `Tests/` 下的测试用例
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
**结论:新结构更加清晰、模块化、易于维护,符合 Godot 最佳实践!** 🎉
|
||||||
BIN
UI/Theme/Fonts/msyh.ttc
Normal file
41
UI/Theme/Fonts/msyh.ttc.import
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
[remap]
|
||||||
|
|
||||||
|
importer="font_data_dynamic"
|
||||||
|
type="FontFile"
|
||||||
|
uid="uid://ce7ujbeobblyr"
|
||||||
|
path="res://.godot/imported/msyh.ttc-ee5749038370cbe296598e3bc4218102.fontdata"
|
||||||
|
|
||||||
|
[deps]
|
||||||
|
|
||||||
|
source_file="res://UI/Theme/Fonts/msyh.ttc"
|
||||||
|
dest_files=["res://.godot/imported/msyh.ttc-ee5749038370cbe296598e3bc4218102.fontdata"]
|
||||||
|
|
||||||
|
[params]
|
||||||
|
|
||||||
|
Rendering=null
|
||||||
|
antialiasing=1
|
||||||
|
generate_mipmaps=false
|
||||||
|
disable_embedded_bitmaps=true
|
||||||
|
multichannel_signed_distance_field=false
|
||||||
|
msdf_pixel_range=8
|
||||||
|
msdf_size=48
|
||||||
|
allow_system_fallback=true
|
||||||
|
force_autohinter=false
|
||||||
|
modulate_color_glyphs=false
|
||||||
|
hinting=1
|
||||||
|
subpixel_positioning=4
|
||||||
|
keep_rounding_remainders=true
|
||||||
|
oversampling=0.0
|
||||||
|
Fallbacks=null
|
||||||
|
fallbacks=[]
|
||||||
|
Compress=null
|
||||||
|
compress=false
|
||||||
|
preload=[{
|
||||||
|
"chars": "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz!@#$%^&*()_+-=[]{}|;':\",./<>?`~一二三四五六七八九十百千万亿用户名密码登录注册验证码邮箱小镇鲸鱼欢迎来到开始你的之旅请输入不能为空获取发送忘记返回居民身份确认再次已被使用换个等待分钟后试稍后正在创建账户测试模式生成查看控制台网络连接失败系统维护中升级稍后再试频繁联系管理员禁用审核先邮箱后使用成功进入镇错误或过期未找到存在",
|
||||||
|
"glyphs": [],
|
||||||
|
"name": "Web预加载",
|
||||||
|
"size": Vector2i(16, 0)
|
||||||
|
}]
|
||||||
|
language_support={}
|
||||||
|
script_support={}
|
||||||
|
opentype_features={}
|
||||||
7
UI/Theme/MainTheme.tres
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
[gd_resource type="Theme" load_steps=2 format=3 uid="uid://cp7t8tu7rmyad"]
|
||||||
|
|
||||||
|
[ext_resource type="FontFile" uid="uid://ce7ujbeobblyr" path="res://assets/fonts/msyh.ttc" id="1_ftb5w"]
|
||||||
|
|
||||||
|
[resource]
|
||||||
|
resource_local_to_scene = true
|
||||||
|
default_font = ExtResource("1_ftb5w")
|
||||||
1032
UI/Windows/AuthScene.gd
Normal file
1
UI/Windows/AuthScene.gd.uid
Normal file
@@ -0,0 +1 @@
|
|||||||
|
uid://bs1vy3ierj66t
|
||||||
561
UI/Windows/LoginWindow.tscn
Normal file
@@ -0,0 +1,561 @@
|
|||||||
|
[gd_scene load_steps=10 format=3 uid="uid://by7m8snb4xllf"]
|
||||||
|
|
||||||
|
[ext_resource type="Texture2D" uid="uid://bx17oy8lvaca4" path="res://assets/ui/auth/bg_auth_scene.png" id="1_background"]
|
||||||
|
[ext_resource type="Texture2D" uid="uid://de4q4s1gxivtf" path="res://assets/ui/auth/login_frame_smart_transparent.png" id="2_frame"]
|
||||||
|
[ext_resource type="Script" uid="uid://nv8eitxieqtm" path="res://UI/Windows/AuthScene.gd" id="3_script"]
|
||||||
|
|
||||||
|
[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_1"]
|
||||||
|
|
||||||
|
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_hover"]
|
||||||
|
bg_color = Color(0.3, 0.6, 0.9, 1)
|
||||||
|
border_width_left = 2
|
||||||
|
border_width_top = 2
|
||||||
|
border_width_right = 2
|
||||||
|
border_width_bottom = 2
|
||||||
|
border_color = Color(0.2, 0.5, 0.8, 1)
|
||||||
|
corner_radius_top_left = 8
|
||||||
|
corner_radius_top_right = 8
|
||||||
|
corner_radius_bottom_right = 8
|
||||||
|
corner_radius_bottom_left = 8
|
||||||
|
|
||||||
|
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_normal"]
|
||||||
|
bg_color = Color(0.2, 0.5, 0.8, 1)
|
||||||
|
border_width_left = 2
|
||||||
|
border_width_top = 2
|
||||||
|
border_width_right = 2
|
||||||
|
border_width_bottom = 2
|
||||||
|
border_color = Color(0.15, 0.4, 0.7, 1)
|
||||||
|
corner_radius_top_left = 8
|
||||||
|
corner_radius_top_right = 8
|
||||||
|
corner_radius_bottom_right = 8
|
||||||
|
corner_radius_bottom_left = 8
|
||||||
|
|
||||||
|
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_pressed"]
|
||||||
|
bg_color = Color(0.4, 0.7, 1, 1)
|
||||||
|
border_width_left = 2
|
||||||
|
border_width_top = 2
|
||||||
|
border_width_right = 2
|
||||||
|
border_width_bottom = 2
|
||||||
|
border_color = Color(0.3, 0.6, 0.9, 1)
|
||||||
|
corner_radius_top_left = 8
|
||||||
|
corner_radius_top_right = 8
|
||||||
|
corner_radius_bottom_right = 8
|
||||||
|
corner_radius_bottom_left = 8
|
||||||
|
|
||||||
|
[sub_resource type="Theme" id="Theme_main_button"]
|
||||||
|
Button/colors/font_color = Color(1, 1, 1, 1)
|
||||||
|
Button/colors/font_hover_color = Color(1, 1, 1, 1)
|
||||||
|
Button/colors/font_pressed_color = Color(1, 1, 1, 1)
|
||||||
|
Button/font_sizes/font_size = 18
|
||||||
|
Button/styles/hover = SubResource("StyleBoxFlat_hover")
|
||||||
|
Button/styles/normal = SubResource("StyleBoxFlat_normal")
|
||||||
|
Button/styles/pressed = SubResource("StyleBoxFlat_pressed")
|
||||||
|
|
||||||
|
[sub_resource type="Theme" id="Theme_button"]
|
||||||
|
Button/colors/font_color = Color(1, 1, 1, 1)
|
||||||
|
Button/colors/font_hover_color = Color(1, 1, 1, 1)
|
||||||
|
Button/colors/font_pressed_color = Color(1, 1, 1, 1)
|
||||||
|
Button/styles/hover = SubResource("StyleBoxFlat_hover")
|
||||||
|
Button/styles/normal = SubResource("StyleBoxFlat_normal")
|
||||||
|
Button/styles/pressed = SubResource("StyleBoxFlat_pressed")
|
||||||
|
|
||||||
|
[node name="AuthScene" type="Control"]
|
||||||
|
layout_mode = 3
|
||||||
|
anchors_preset = 15
|
||||||
|
anchor_right = 1.0
|
||||||
|
anchor_bottom = 1.0
|
||||||
|
grow_horizontal = 2
|
||||||
|
grow_vertical = 2
|
||||||
|
script = ExtResource("3_script")
|
||||||
|
|
||||||
|
[node name="HTTPRequest" type="HTTPRequest" parent="."]
|
||||||
|
|
||||||
|
[node name="BackgroundImage" type="TextureRect" parent="."]
|
||||||
|
layout_mode = 1
|
||||||
|
anchors_preset = 15
|
||||||
|
anchor_right = 1.0
|
||||||
|
anchor_bottom = 1.0
|
||||||
|
grow_horizontal = 2
|
||||||
|
grow_vertical = 2
|
||||||
|
texture = ExtResource("1_background")
|
||||||
|
expand_mode = 1
|
||||||
|
stretch_mode = 6
|
||||||
|
|
||||||
|
[node name="WhaleFrame" type="TextureRect" parent="."]
|
||||||
|
layout_mode = 1
|
||||||
|
anchors_preset = 8
|
||||||
|
anchor_left = 0.5
|
||||||
|
anchor_top = 0.5
|
||||||
|
anchor_right = 0.5
|
||||||
|
anchor_bottom = 0.5
|
||||||
|
offset_left = -300.0
|
||||||
|
offset_top = -300.0
|
||||||
|
offset_right = 300.0
|
||||||
|
offset_bottom = 300.0
|
||||||
|
grow_horizontal = 2
|
||||||
|
grow_vertical = 2
|
||||||
|
texture = ExtResource("2_frame")
|
||||||
|
expand_mode = 1
|
||||||
|
stretch_mode = 5
|
||||||
|
|
||||||
|
[node name="CenterContainer" type="CenterContainer" parent="."]
|
||||||
|
layout_mode = 1
|
||||||
|
anchors_preset = 8
|
||||||
|
anchor_left = 0.5
|
||||||
|
anchor_top = 0.5
|
||||||
|
anchor_right = 0.5
|
||||||
|
anchor_bottom = 0.5
|
||||||
|
offset_left = -175.0
|
||||||
|
offset_top = -184.0
|
||||||
|
offset_right = 175.0
|
||||||
|
offset_bottom = 236.0
|
||||||
|
grow_horizontal = 2
|
||||||
|
grow_vertical = 2
|
||||||
|
|
||||||
|
[node name="LoginPanel" type="Panel" parent="CenterContainer"]
|
||||||
|
custom_minimum_size = Vector2(350, 400)
|
||||||
|
layout_mode = 2
|
||||||
|
theme_override_styles/panel = SubResource("StyleBoxEmpty_1")
|
||||||
|
|
||||||
|
[node name="VBoxContainer" type="VBoxContainer" parent="CenterContainer/LoginPanel"]
|
||||||
|
layout_mode = 1
|
||||||
|
anchors_preset = 15
|
||||||
|
anchor_right = 1.0
|
||||||
|
anchor_bottom = 1.0
|
||||||
|
offset_left = 30.0
|
||||||
|
offset_top = 30.0
|
||||||
|
offset_right = -30.0
|
||||||
|
offset_bottom = -30.0
|
||||||
|
grow_horizontal = 2
|
||||||
|
grow_vertical = 2
|
||||||
|
|
||||||
|
[node name="TitleLabel" type="Label" parent="CenterContainer/LoginPanel/VBoxContainer"]
|
||||||
|
layout_mode = 2
|
||||||
|
theme_override_colors/font_color = Color(0, 0, 0, 1)
|
||||||
|
theme_override_font_sizes/font_size = 24
|
||||||
|
text = "Whaletown"
|
||||||
|
horizontal_alignment = 1
|
||||||
|
vertical_alignment = 1
|
||||||
|
|
||||||
|
[node name="SubtitleLabel" type="Label" parent="CenterContainer/LoginPanel/VBoxContainer"]
|
||||||
|
layout_mode = 2
|
||||||
|
theme_override_colors/font_color = Color(0, 0, 0, 1)
|
||||||
|
theme_override_font_sizes/font_size = 14
|
||||||
|
text = "开始你的小镇之旅!"
|
||||||
|
horizontal_alignment = 1
|
||||||
|
vertical_alignment = 1
|
||||||
|
|
||||||
|
[node name="HSeparator" type="HSeparator" parent="CenterContainer/LoginPanel/VBoxContainer"]
|
||||||
|
layout_mode = 2
|
||||||
|
|
||||||
|
[node name="LoginForm" type="VBoxContainer" parent="CenterContainer/LoginPanel/VBoxContainer"]
|
||||||
|
layout_mode = 2
|
||||||
|
size_flags_vertical = 3
|
||||||
|
|
||||||
|
[node name="UsernameContainer" type="VBoxContainer" parent="CenterContainer/LoginPanel/VBoxContainer/LoginForm"]
|
||||||
|
layout_mode = 2
|
||||||
|
|
||||||
|
[node name="UsernameLabelContainer" type="HBoxContainer" parent="CenterContainer/LoginPanel/VBoxContainer/LoginForm/UsernameContainer"]
|
||||||
|
layout_mode = 2
|
||||||
|
|
||||||
|
[node name="UsernameLabel" type="Label" parent="CenterContainer/LoginPanel/VBoxContainer/LoginForm/UsernameContainer/UsernameLabelContainer"]
|
||||||
|
layout_mode = 2
|
||||||
|
theme_override_colors/font_color = Color(0, 0, 0, 1)
|
||||||
|
text = "用户名/手机/邮箱"
|
||||||
|
|
||||||
|
[node name="RequiredStar" type="Label" parent="CenterContainer/LoginPanel/VBoxContainer/LoginForm/UsernameContainer/UsernameLabelContainer"]
|
||||||
|
layout_mode = 2
|
||||||
|
theme_override_colors/font_color = Color(1, 0.2, 0.2, 1)
|
||||||
|
text = " *"
|
||||||
|
|
||||||
|
[node name="Spacer" type="Control" parent="CenterContainer/LoginPanel/VBoxContainer/LoginForm/UsernameContainer/UsernameLabelContainer"]
|
||||||
|
layout_mode = 2
|
||||||
|
size_flags_horizontal = 3
|
||||||
|
|
||||||
|
[node name="UsernameError" type="Label" parent="CenterContainer/LoginPanel/VBoxContainer/LoginForm/UsernameContainer/UsernameLabelContainer"]
|
||||||
|
visible = false
|
||||||
|
layout_mode = 2
|
||||||
|
theme_override_colors/font_color = Color(1, 0.2, 0.2, 1)
|
||||||
|
theme_override_font_sizes/font_size = 12
|
||||||
|
text = "用户名不能为空"
|
||||||
|
horizontal_alignment = 2
|
||||||
|
|
||||||
|
[node name="UsernameInput" type="LineEdit" parent="CenterContainer/LoginPanel/VBoxContainer/LoginForm/UsernameContainer"]
|
||||||
|
layout_mode = 2
|
||||||
|
theme_override_colors/font_color = Color(0, 0, 0, 1)
|
||||||
|
theme_override_colors/font_placeholder_color = Color(0.5, 0.5, 0.5, 1)
|
||||||
|
placeholder_text = "用户名/手机/邮箱"
|
||||||
|
|
||||||
|
[node name="PasswordContainer" type="VBoxContainer" parent="CenterContainer/LoginPanel/VBoxContainer/LoginForm"]
|
||||||
|
layout_mode = 2
|
||||||
|
|
||||||
|
[node name="PasswordLabelContainer" type="HBoxContainer" parent="CenterContainer/LoginPanel/VBoxContainer/LoginForm/PasswordContainer"]
|
||||||
|
layout_mode = 2
|
||||||
|
|
||||||
|
[node name="PasswordLabel" type="Label" parent="CenterContainer/LoginPanel/VBoxContainer/LoginForm/PasswordContainer/PasswordLabelContainer"]
|
||||||
|
layout_mode = 2
|
||||||
|
theme_override_colors/font_color = Color(0, 0, 0, 1)
|
||||||
|
text = "密码"
|
||||||
|
|
||||||
|
[node name="RequiredStar" type="Label" parent="CenterContainer/LoginPanel/VBoxContainer/LoginForm/PasswordContainer/PasswordLabelContainer"]
|
||||||
|
layout_mode = 2
|
||||||
|
theme_override_colors/font_color = Color(1, 0.2, 0.2, 1)
|
||||||
|
text = " *"
|
||||||
|
|
||||||
|
[node name="Spacer" type="Control" parent="CenterContainer/LoginPanel/VBoxContainer/LoginForm/PasswordContainer/PasswordLabelContainer"]
|
||||||
|
layout_mode = 2
|
||||||
|
size_flags_horizontal = 3
|
||||||
|
|
||||||
|
[node name="PasswordError" type="Label" parent="CenterContainer/LoginPanel/VBoxContainer/LoginForm/PasswordContainer/PasswordLabelContainer"]
|
||||||
|
visible = false
|
||||||
|
layout_mode = 2
|
||||||
|
theme_override_colors/font_color = Color(1, 0.2, 0.2, 1)
|
||||||
|
theme_override_font_sizes/font_size = 12
|
||||||
|
text = "密码不能为空"
|
||||||
|
horizontal_alignment = 2
|
||||||
|
|
||||||
|
[node name="PasswordInput" type="LineEdit" parent="CenterContainer/LoginPanel/VBoxContainer/LoginForm/PasswordContainer"]
|
||||||
|
layout_mode = 2
|
||||||
|
theme_override_colors/font_color = Color(0, 0, 0, 1)
|
||||||
|
theme_override_colors/font_placeholder_color = Color(0.5, 0.5, 0.5, 1)
|
||||||
|
placeholder_text = "请输入密码"
|
||||||
|
secret = true
|
||||||
|
|
||||||
|
[node name="VerificationContainer" type="VBoxContainer" parent="CenterContainer/LoginPanel/VBoxContainer/LoginForm"]
|
||||||
|
visible = false
|
||||||
|
layout_mode = 2
|
||||||
|
|
||||||
|
[node name="VerificationLabelContainer" type="HBoxContainer" parent="CenterContainer/LoginPanel/VBoxContainer/LoginForm/VerificationContainer"]
|
||||||
|
layout_mode = 2
|
||||||
|
|
||||||
|
[node name="VerificationLabel" type="Label" parent="CenterContainer/LoginPanel/VBoxContainer/LoginForm/VerificationContainer/VerificationLabelContainer"]
|
||||||
|
layout_mode = 2
|
||||||
|
theme_override_colors/font_color = Color(0, 0, 0, 1)
|
||||||
|
text = "验证码"
|
||||||
|
|
||||||
|
[node name="RequiredStar" type="Label" parent="CenterContainer/LoginPanel/VBoxContainer/LoginForm/VerificationContainer/VerificationLabelContainer"]
|
||||||
|
layout_mode = 2
|
||||||
|
theme_override_colors/font_color = Color(1, 0.2, 0.2, 1)
|
||||||
|
text = " *"
|
||||||
|
|
||||||
|
[node name="Spacer" type="Control" parent="CenterContainer/LoginPanel/VBoxContainer/LoginForm/VerificationContainer/VerificationLabelContainer"]
|
||||||
|
layout_mode = 2
|
||||||
|
size_flags_horizontal = 3
|
||||||
|
|
||||||
|
[node name="VerificationError" type="Label" parent="CenterContainer/LoginPanel/VBoxContainer/LoginForm/VerificationContainer/VerificationLabelContainer"]
|
||||||
|
visible = false
|
||||||
|
layout_mode = 2
|
||||||
|
theme_override_colors/font_color = Color(1, 0.2, 0.2, 1)
|
||||||
|
theme_override_font_sizes/font_size = 12
|
||||||
|
text = "请输入验证码"
|
||||||
|
horizontal_alignment = 2
|
||||||
|
|
||||||
|
[node name="VerificationInputContainer" type="HBoxContainer" parent="CenterContainer/LoginPanel/VBoxContainer/LoginForm/VerificationContainer"]
|
||||||
|
layout_mode = 2
|
||||||
|
|
||||||
|
[node name="VerificationInput" type="LineEdit" parent="CenterContainer/LoginPanel/VBoxContainer/LoginForm/VerificationContainer/VerificationInputContainer"]
|
||||||
|
layout_mode = 2
|
||||||
|
size_flags_horizontal = 3
|
||||||
|
theme_override_colors/font_color = Color(0, 0, 0, 1)
|
||||||
|
theme_override_colors/font_placeholder_color = Color(0.5, 0.5, 0.5, 1)
|
||||||
|
placeholder_text = "请输入6位验证码"
|
||||||
|
max_length = 6
|
||||||
|
|
||||||
|
[node name="GetCodeBtn" type="Button" parent="CenterContainer/LoginPanel/VBoxContainer/LoginForm/VerificationContainer/VerificationInputContainer"]
|
||||||
|
layout_mode = 2
|
||||||
|
text = "获取验证码"
|
||||||
|
|
||||||
|
[node name="CheckboxContainer" type="HBoxContainer" parent="CenterContainer/LoginPanel/VBoxContainer/LoginForm"]
|
||||||
|
layout_mode = 2
|
||||||
|
|
||||||
|
[node name="RememberPassword" type="CheckBox" parent="CenterContainer/LoginPanel/VBoxContainer/LoginForm/CheckboxContainer"]
|
||||||
|
layout_mode = 2
|
||||||
|
theme_override_colors/font_color = Color(0, 0, 0, 1)
|
||||||
|
text = "记住密码"
|
||||||
|
|
||||||
|
[node name="AutoLogin" type="CheckBox" parent="CenterContainer/LoginPanel/VBoxContainer/LoginForm/CheckboxContainer"]
|
||||||
|
layout_mode = 2
|
||||||
|
theme_override_colors/font_color = Color(0, 0, 0, 1)
|
||||||
|
text = "自动登录"
|
||||||
|
|
||||||
|
[node name="HSeparator2" type="HSeparator" parent="CenterContainer/LoginPanel/VBoxContainer"]
|
||||||
|
layout_mode = 2
|
||||||
|
|
||||||
|
[node name="MainButton" type="Button" parent="CenterContainer/LoginPanel/VBoxContainer"]
|
||||||
|
custom_minimum_size = Vector2(280, 50)
|
||||||
|
layout_mode = 2
|
||||||
|
theme = SubResource("Theme_main_button")
|
||||||
|
text = "进入小镇"
|
||||||
|
|
||||||
|
[node name="HSeparator3" type="HSeparator" parent="CenterContainer/LoginPanel/VBoxContainer"]
|
||||||
|
layout_mode = 2
|
||||||
|
|
||||||
|
[node name="ButtonContainer" type="HBoxContainer" parent="CenterContainer/LoginPanel/VBoxContainer"]
|
||||||
|
layout_mode = 2
|
||||||
|
alignment = 1
|
||||||
|
|
||||||
|
[node name="LoginBtn" type="Button" parent="CenterContainer/LoginPanel/VBoxContainer/ButtonContainer"]
|
||||||
|
custom_minimum_size = Vector2(100, 35)
|
||||||
|
layout_mode = 2
|
||||||
|
theme = SubResource("Theme_button")
|
||||||
|
text = "密码登录"
|
||||||
|
|
||||||
|
[node name="BottomLinks" type="HBoxContainer" parent="CenterContainer/LoginPanel/VBoxContainer"]
|
||||||
|
layout_mode = 2
|
||||||
|
alignment = 1
|
||||||
|
|
||||||
|
[node name="ForgotPassword" type="Button" parent="CenterContainer/LoginPanel/VBoxContainer/BottomLinks"]
|
||||||
|
layout_mode = 2
|
||||||
|
theme_override_colors/font_color = Color(0, 0, 0, 1)
|
||||||
|
text = "忘记密码?"
|
||||||
|
flat = true
|
||||||
|
|
||||||
|
[node name="RegisterLink" type="Button" parent="CenterContainer/LoginPanel/VBoxContainer/BottomLinks"]
|
||||||
|
layout_mode = 2
|
||||||
|
theme_override_colors/font_color = Color(0, 0, 0, 1)
|
||||||
|
text = "注册居民身份"
|
||||||
|
flat = true
|
||||||
|
|
||||||
|
[node name="RegisterPanel" type="Panel" parent="CenterContainer"]
|
||||||
|
visible = false
|
||||||
|
custom_minimum_size = Vector2(400, 570)
|
||||||
|
layout_mode = 2
|
||||||
|
theme_override_styles/panel = SubResource("StyleBoxEmpty_1")
|
||||||
|
|
||||||
|
[node name="VBoxContainer" type="VBoxContainer" parent="CenterContainer/RegisterPanel"]
|
||||||
|
layout_mode = 1
|
||||||
|
anchors_preset = 15
|
||||||
|
anchor_right = 1.0
|
||||||
|
anchor_bottom = 1.0
|
||||||
|
offset_left = 30.0
|
||||||
|
offset_top = 75.0
|
||||||
|
offset_right = -30.0
|
||||||
|
offset_bottom = -72.0
|
||||||
|
grow_horizontal = 2
|
||||||
|
grow_vertical = 2
|
||||||
|
alignment = 1
|
||||||
|
|
||||||
|
[node name="TitleLabel" type="Label" parent="CenterContainer/RegisterPanel/VBoxContainer"]
|
||||||
|
layout_mode = 2
|
||||||
|
theme_override_colors/font_color = Color(0, 0, 0, 1)
|
||||||
|
theme_override_font_sizes/font_size = 20
|
||||||
|
text = "注册新居民"
|
||||||
|
horizontal_alignment = 1
|
||||||
|
vertical_alignment = 1
|
||||||
|
|
||||||
|
[node name="HSeparator" type="HSeparator" parent="CenterContainer/RegisterPanel/VBoxContainer"]
|
||||||
|
layout_mode = 2
|
||||||
|
|
||||||
|
[node name="RegisterForm" type="VBoxContainer" parent="CenterContainer/RegisterPanel/VBoxContainer"]
|
||||||
|
layout_mode = 2
|
||||||
|
size_flags_vertical = 3
|
||||||
|
alignment = 1
|
||||||
|
|
||||||
|
[node name="UsernameContainer" type="VBoxContainer" parent="CenterContainer/RegisterPanel/VBoxContainer/RegisterForm"]
|
||||||
|
layout_mode = 2
|
||||||
|
|
||||||
|
[node name="UsernameLabelContainer" type="HBoxContainer" parent="CenterContainer/RegisterPanel/VBoxContainer/RegisterForm/UsernameContainer"]
|
||||||
|
layout_mode = 2
|
||||||
|
|
||||||
|
[node name="UsernameLabel" type="Label" parent="CenterContainer/RegisterPanel/VBoxContainer/RegisterForm/UsernameContainer/UsernameLabelContainer"]
|
||||||
|
layout_mode = 2
|
||||||
|
theme_override_colors/font_color = Color(0, 0, 0, 1)
|
||||||
|
text = "用户名"
|
||||||
|
|
||||||
|
[node name="RequiredStar" type="Label" parent="CenterContainer/RegisterPanel/VBoxContainer/RegisterForm/UsernameContainer/UsernameLabelContainer"]
|
||||||
|
layout_mode = 2
|
||||||
|
theme_override_colors/font_color = Color(1, 0.2, 0.2, 1)
|
||||||
|
text = " *"
|
||||||
|
|
||||||
|
[node name="Spacer" type="Control" parent="CenterContainer/RegisterPanel/VBoxContainer/RegisterForm/UsernameContainer/UsernameLabelContainer"]
|
||||||
|
layout_mode = 2
|
||||||
|
size_flags_horizontal = 3
|
||||||
|
|
||||||
|
[node name="UsernameError" type="Label" parent="CenterContainer/RegisterPanel/VBoxContainer/RegisterForm/UsernameContainer/UsernameLabelContainer"]
|
||||||
|
visible = false
|
||||||
|
layout_mode = 2
|
||||||
|
theme_override_colors/font_color = Color(1, 0.2, 0.2, 1)
|
||||||
|
theme_override_font_sizes/font_size = 12
|
||||||
|
text = "用户名不能为空"
|
||||||
|
horizontal_alignment = 2
|
||||||
|
|
||||||
|
[node name="UsernameInput" type="LineEdit" parent="CenterContainer/RegisterPanel/VBoxContainer/RegisterForm/UsernameContainer"]
|
||||||
|
layout_mode = 2
|
||||||
|
theme_override_colors/font_color = Color(0, 0, 0, 1)
|
||||||
|
theme_override_colors/font_placeholder_color = Color(0.5, 0.5, 0.5, 1)
|
||||||
|
placeholder_text = "请输入用户名"
|
||||||
|
|
||||||
|
[node name="EmailContainer" type="VBoxContainer" parent="CenterContainer/RegisterPanel/VBoxContainer/RegisterForm"]
|
||||||
|
layout_mode = 2
|
||||||
|
|
||||||
|
[node name="EmailLabelContainer" type="HBoxContainer" parent="CenterContainer/RegisterPanel/VBoxContainer/RegisterForm/EmailContainer"]
|
||||||
|
layout_mode = 2
|
||||||
|
|
||||||
|
[node name="EmailLabel" type="Label" parent="CenterContainer/RegisterPanel/VBoxContainer/RegisterForm/EmailContainer/EmailLabelContainer"]
|
||||||
|
layout_mode = 2
|
||||||
|
theme_override_colors/font_color = Color(0, 0, 0, 1)
|
||||||
|
text = "邮箱"
|
||||||
|
|
||||||
|
[node name="RequiredStar" type="Label" parent="CenterContainer/RegisterPanel/VBoxContainer/RegisterForm/EmailContainer/EmailLabelContainer"]
|
||||||
|
layout_mode = 2
|
||||||
|
theme_override_colors/font_color = Color(1, 0.2, 0.2, 1)
|
||||||
|
text = " *"
|
||||||
|
|
||||||
|
[node name="Spacer" type="Control" parent="CenterContainer/RegisterPanel/VBoxContainer/RegisterForm/EmailContainer/EmailLabelContainer"]
|
||||||
|
layout_mode = 2
|
||||||
|
size_flags_horizontal = 3
|
||||||
|
|
||||||
|
[node name="EmailError" type="Label" parent="CenterContainer/RegisterPanel/VBoxContainer/RegisterForm/EmailContainer/EmailLabelContainer"]
|
||||||
|
visible = false
|
||||||
|
layout_mode = 2
|
||||||
|
theme_override_colors/font_color = Color(1, 0.2, 0.2, 1)
|
||||||
|
theme_override_font_sizes/font_size = 12
|
||||||
|
text = "邮箱不能为空"
|
||||||
|
horizontal_alignment = 2
|
||||||
|
|
||||||
|
[node name="EmailInput" type="LineEdit" parent="CenterContainer/RegisterPanel/VBoxContainer/RegisterForm/EmailContainer"]
|
||||||
|
layout_mode = 2
|
||||||
|
theme_override_colors/font_color = Color(0, 0, 0, 1)
|
||||||
|
theme_override_colors/font_placeholder_color = Color(0.5, 0.5, 0.5, 1)
|
||||||
|
placeholder_text = "请输入邮箱地址"
|
||||||
|
|
||||||
|
[node name="PasswordContainer" type="VBoxContainer" parent="CenterContainer/RegisterPanel/VBoxContainer/RegisterForm"]
|
||||||
|
layout_mode = 2
|
||||||
|
|
||||||
|
[node name="PasswordLabelContainer" type="HBoxContainer" parent="CenterContainer/RegisterPanel/VBoxContainer/RegisterForm/PasswordContainer"]
|
||||||
|
layout_mode = 2
|
||||||
|
|
||||||
|
[node name="PasswordLabel" type="Label" parent="CenterContainer/RegisterPanel/VBoxContainer/RegisterForm/PasswordContainer/PasswordLabelContainer"]
|
||||||
|
layout_mode = 2
|
||||||
|
theme_override_colors/font_color = Color(0, 0, 0, 1)
|
||||||
|
text = "密码"
|
||||||
|
|
||||||
|
[node name="RequiredStar" type="Label" parent="CenterContainer/RegisterPanel/VBoxContainer/RegisterForm/PasswordContainer/PasswordLabelContainer"]
|
||||||
|
layout_mode = 2
|
||||||
|
theme_override_colors/font_color = Color(1, 0.2, 0.2, 1)
|
||||||
|
text = " *"
|
||||||
|
|
||||||
|
[node name="Spacer" type="Control" parent="CenterContainer/RegisterPanel/VBoxContainer/RegisterForm/PasswordContainer/PasswordLabelContainer"]
|
||||||
|
layout_mode = 2
|
||||||
|
size_flags_horizontal = 3
|
||||||
|
|
||||||
|
[node name="PasswordError" type="Label" parent="CenterContainer/RegisterPanel/VBoxContainer/RegisterForm/PasswordContainer/PasswordLabelContainer"]
|
||||||
|
visible = false
|
||||||
|
layout_mode = 2
|
||||||
|
theme_override_colors/font_color = Color(1, 0.2, 0.2, 1)
|
||||||
|
theme_override_font_sizes/font_size = 12
|
||||||
|
text = "密码不能为空"
|
||||||
|
horizontal_alignment = 2
|
||||||
|
|
||||||
|
[node name="PasswordInput" type="LineEdit" parent="CenterContainer/RegisterPanel/VBoxContainer/RegisterForm/PasswordContainer"]
|
||||||
|
layout_mode = 2
|
||||||
|
theme_override_colors/font_color = Color(0, 0, 0, 1)
|
||||||
|
theme_override_colors/font_placeholder_color = Color(0.5, 0.5, 0.5, 1)
|
||||||
|
placeholder_text = "请输入密码(至少8位)"
|
||||||
|
secret = true
|
||||||
|
|
||||||
|
[node name="ConfirmContainer" type="VBoxContainer" parent="CenterContainer/RegisterPanel/VBoxContainer/RegisterForm"]
|
||||||
|
layout_mode = 2
|
||||||
|
|
||||||
|
[node name="ConfirmLabelContainer" type="HBoxContainer" parent="CenterContainer/RegisterPanel/VBoxContainer/RegisterForm/ConfirmContainer"]
|
||||||
|
layout_mode = 2
|
||||||
|
|
||||||
|
[node name="ConfirmLabel" type="Label" parent="CenterContainer/RegisterPanel/VBoxContainer/RegisterForm/ConfirmContainer/ConfirmLabelContainer"]
|
||||||
|
layout_mode = 2
|
||||||
|
theme_override_colors/font_color = Color(0, 0, 0, 1)
|
||||||
|
text = "确认密码"
|
||||||
|
|
||||||
|
[node name="RequiredStar" type="Label" parent="CenterContainer/RegisterPanel/VBoxContainer/RegisterForm/ConfirmContainer/ConfirmLabelContainer"]
|
||||||
|
layout_mode = 2
|
||||||
|
theme_override_colors/font_color = Color(1, 0.2, 0.2, 1)
|
||||||
|
text = " *"
|
||||||
|
|
||||||
|
[node name="Spacer" type="Control" parent="CenterContainer/RegisterPanel/VBoxContainer/RegisterForm/ConfirmContainer/ConfirmLabelContainer"]
|
||||||
|
layout_mode = 2
|
||||||
|
size_flags_horizontal = 3
|
||||||
|
|
||||||
|
[node name="ConfirmError" type="Label" parent="CenterContainer/RegisterPanel/VBoxContainer/RegisterForm/ConfirmContainer/ConfirmLabelContainer"]
|
||||||
|
visible = false
|
||||||
|
layout_mode = 2
|
||||||
|
theme_override_colors/font_color = Color(1, 0.2, 0.2, 1)
|
||||||
|
theme_override_font_sizes/font_size = 12
|
||||||
|
text = "确认密码不能为空"
|
||||||
|
horizontal_alignment = 2
|
||||||
|
|
||||||
|
[node name="ConfirmInput" type="LineEdit" parent="CenterContainer/RegisterPanel/VBoxContainer/RegisterForm/ConfirmContainer"]
|
||||||
|
layout_mode = 2
|
||||||
|
theme_override_colors/font_color = Color(0, 0, 0, 1)
|
||||||
|
theme_override_colors/font_placeholder_color = Color(0.5, 0.5, 0.5, 1)
|
||||||
|
placeholder_text = "请再次输入密码"
|
||||||
|
secret = true
|
||||||
|
|
||||||
|
[node name="VerificationContainer" type="VBoxContainer" parent="CenterContainer/RegisterPanel/VBoxContainer/RegisterForm"]
|
||||||
|
layout_mode = 2
|
||||||
|
|
||||||
|
[node name="VerificationLabelContainer" type="HBoxContainer" parent="CenterContainer/RegisterPanel/VBoxContainer/RegisterForm/VerificationContainer"]
|
||||||
|
layout_mode = 2
|
||||||
|
|
||||||
|
[node name="VerificationLabel" type="Label" parent="CenterContainer/RegisterPanel/VBoxContainer/RegisterForm/VerificationContainer/VerificationLabelContainer"]
|
||||||
|
layout_mode = 2
|
||||||
|
theme_override_colors/font_color = Color(0, 0, 0, 1)
|
||||||
|
text = "邮箱验证码"
|
||||||
|
|
||||||
|
[node name="RequiredStar" type="Label" parent="CenterContainer/RegisterPanel/VBoxContainer/RegisterForm/VerificationContainer/VerificationLabelContainer"]
|
||||||
|
layout_mode = 2
|
||||||
|
theme_override_colors/font_color = Color(1, 0.2, 0.2, 1)
|
||||||
|
text = " *"
|
||||||
|
|
||||||
|
[node name="Spacer" type="Control" parent="CenterContainer/RegisterPanel/VBoxContainer/RegisterForm/VerificationContainer/VerificationLabelContainer"]
|
||||||
|
layout_mode = 2
|
||||||
|
size_flags_horizontal = 3
|
||||||
|
|
||||||
|
[node name="VerificationError" type="Label" parent="CenterContainer/RegisterPanel/VBoxContainer/RegisterForm/VerificationContainer/VerificationLabelContainer"]
|
||||||
|
visible = false
|
||||||
|
layout_mode = 2
|
||||||
|
theme_override_colors/font_color = Color(1, 0.2, 0.2, 1)
|
||||||
|
theme_override_font_sizes/font_size = 12
|
||||||
|
text = "验证码不能为空"
|
||||||
|
horizontal_alignment = 2
|
||||||
|
|
||||||
|
[node name="VerificationInputContainer" type="HBoxContainer" parent="CenterContainer/RegisterPanel/VBoxContainer/RegisterForm/VerificationContainer"]
|
||||||
|
layout_mode = 2
|
||||||
|
|
||||||
|
[node name="VerificationInput" type="LineEdit" parent="CenterContainer/RegisterPanel/VBoxContainer/RegisterForm/VerificationContainer/VerificationInputContainer"]
|
||||||
|
layout_mode = 2
|
||||||
|
size_flags_horizontal = 3
|
||||||
|
theme_override_colors/font_color = Color(0, 0, 0, 1)
|
||||||
|
theme_override_colors/font_placeholder_color = Color(0.5, 0.5, 0.5, 1)
|
||||||
|
placeholder_text = "请输入6位验证码"
|
||||||
|
max_length = 6
|
||||||
|
|
||||||
|
[node name="SendCodeBtn" type="Button" parent="CenterContainer/RegisterPanel/VBoxContainer/RegisterForm/VerificationContainer/VerificationInputContainer"]
|
||||||
|
layout_mode = 2
|
||||||
|
text = "发送验证码"
|
||||||
|
|
||||||
|
[node name="HSeparator2" type="HSeparator" parent="CenterContainer/RegisterPanel/VBoxContainer"]
|
||||||
|
layout_mode = 2
|
||||||
|
|
||||||
|
[node name="ButtonContainer" type="HBoxContainer" parent="CenterContainer/RegisterPanel/VBoxContainer"]
|
||||||
|
layout_mode = 2
|
||||||
|
alignment = 1
|
||||||
|
|
||||||
|
[node name="RegisterBtn" type="Button" parent="CenterContainer/RegisterPanel/VBoxContainer/ButtonContainer"]
|
||||||
|
custom_minimum_size = Vector2(120, 45)
|
||||||
|
layout_mode = 2
|
||||||
|
theme = SubResource("Theme_button")
|
||||||
|
text = "注册"
|
||||||
|
|
||||||
|
[node name="ToLoginBtn" type="Button" parent="CenterContainer/RegisterPanel/VBoxContainer/ButtonContainer"]
|
||||||
|
custom_minimum_size = Vector2(120, 45)
|
||||||
|
layout_mode = 2
|
||||||
|
theme = SubResource("Theme_button")
|
||||||
|
text = "返回登录"
|
||||||
|
|
||||||
|
[node name="ToastContainer" type="Control" parent="."]
|
||||||
|
layout_mode = 1
|
||||||
|
anchors_preset = 15
|
||||||
|
anchor_right = 1.0
|
||||||
|
anchor_bottom = 1.0
|
||||||
|
grow_horizontal = 2
|
||||||
|
grow_vertical = 2
|
||||||
|
mouse_filter = 2
|
||||||
199
Utils/StringUtils.gd
Normal file
@@ -0,0 +1,199 @@
|
|||||||
|
class_name StringUtils
|
||||||
|
|
||||||
|
# 字符串工具类 - 提供常用的字符串处理功能
|
||||||
|
|
||||||
|
# 验证邮箱格式
|
||||||
|
static func is_valid_email(email: String) -> bool:
|
||||||
|
var regex = RegEx.new()
|
||||||
|
regex.compile("^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$")
|
||||||
|
return regex.search(email) != null
|
||||||
|
|
||||||
|
# 验证用户名格式(字母、数字、下划线)
|
||||||
|
static func is_valid_username(username: String) -> bool:
|
||||||
|
if username.is_empty() or username.length() > 50:
|
||||||
|
return false
|
||||||
|
|
||||||
|
var regex = RegEx.new()
|
||||||
|
regex.compile("^[a-zA-Z0-9_]+$")
|
||||||
|
return regex.search(username) != null
|
||||||
|
|
||||||
|
# 验证密码强度
|
||||||
|
static func validate_password_strength(password: String) -> Dictionary:
|
||||||
|
var result = {"valid": false, "message": "", "strength": 0}
|
||||||
|
|
||||||
|
if password.length() < 8:
|
||||||
|
result.message = "密码长度至少8位"
|
||||||
|
return result
|
||||||
|
|
||||||
|
if password.length() > 128:
|
||||||
|
result.message = "密码长度不能超过128位"
|
||||||
|
return result
|
||||||
|
|
||||||
|
var has_letter = false
|
||||||
|
var has_digit = false
|
||||||
|
var has_special = false
|
||||||
|
|
||||||
|
for i in range(password.length()):
|
||||||
|
var char = password[i]
|
||||||
|
if char >= 'a' and char <= 'z' or char >= 'A' and char <= 'Z':
|
||||||
|
has_letter = true
|
||||||
|
elif char >= '0' and char <= '9':
|
||||||
|
has_digit = true
|
||||||
|
elif char in "!@#$%^&*()_+-=[]{}|;:,.<>?":
|
||||||
|
has_special = true
|
||||||
|
|
||||||
|
var strength = 0
|
||||||
|
if has_letter:
|
||||||
|
strength += 1
|
||||||
|
if has_digit:
|
||||||
|
strength += 1
|
||||||
|
if has_special:
|
||||||
|
strength += 1
|
||||||
|
if password.length() >= 12:
|
||||||
|
strength += 1
|
||||||
|
|
||||||
|
result.strength = strength
|
||||||
|
|
||||||
|
if not (has_letter and has_digit):
|
||||||
|
result.message = "密码必须包含字母和数字"
|
||||||
|
return result
|
||||||
|
|
||||||
|
result.valid = true
|
||||||
|
result.message = "密码强度: " + ["弱", "中", "强", "很强"][min(strength - 1, 3)]
|
||||||
|
return result
|
||||||
|
|
||||||
|
# 截断字符串
|
||||||
|
static func truncate(text: String, max_length: int, suffix: String = "...") -> String:
|
||||||
|
if text.length() <= max_length:
|
||||||
|
return text
|
||||||
|
return text.substr(0, max_length - suffix.length()) + suffix
|
||||||
|
|
||||||
|
# 首字母大写
|
||||||
|
static func capitalize_first(text: String) -> String:
|
||||||
|
if text.is_empty():
|
||||||
|
return text
|
||||||
|
return text[0].to_upper() + text.substr(1)
|
||||||
|
|
||||||
|
# 转换为标题格式(每个单词首字母大写)
|
||||||
|
static func to_title_case(text: String) -> String:
|
||||||
|
var words = text.split(" ")
|
||||||
|
var result = []
|
||||||
|
for word in words:
|
||||||
|
if not word.is_empty():
|
||||||
|
result.append(capitalize_first(word.to_lower()))
|
||||||
|
return " ".join(result)
|
||||||
|
|
||||||
|
# 移除HTML标签
|
||||||
|
static func strip_html_tags(html: String) -> String:
|
||||||
|
var regex = RegEx.new()
|
||||||
|
regex.compile("<[^>]*>")
|
||||||
|
return regex.sub(html, "", true)
|
||||||
|
|
||||||
|
# 格式化文件大小
|
||||||
|
static func format_file_size(bytes: int) -> String:
|
||||||
|
var units = ["B", "KB", "MB", "GB", "TB"]
|
||||||
|
var size = float(bytes)
|
||||||
|
var unit_index = 0
|
||||||
|
|
||||||
|
while size >= 1024.0 and unit_index < units.size() - 1:
|
||||||
|
size /= 1024.0
|
||||||
|
unit_index += 1
|
||||||
|
|
||||||
|
if unit_index == 0:
|
||||||
|
return str(int(size)) + " " + units[unit_index]
|
||||||
|
else:
|
||||||
|
return "%.1f %s" % [size, units[unit_index]]
|
||||||
|
|
||||||
|
# 将UTC时间字符串转换为本地时间显示
|
||||||
|
static func format_utc_to_local_time(utc_time_str: String) -> String:
|
||||||
|
# 解析UTC时间字符串 (格式: 2025-12-25T11:23:52.175Z)
|
||||||
|
var regex = RegEx.new()
|
||||||
|
regex.compile("(\\d{4})-(\\d{2})-(\\d{2})T(\\d{2}):(\\d{2}):(\\d{2})")
|
||||||
|
var result = regex.search(utc_time_str)
|
||||||
|
|
||||||
|
if result == null:
|
||||||
|
return utc_time_str # 如果解析失败,返回原字符串
|
||||||
|
|
||||||
|
# 提取时间组件
|
||||||
|
var year = int(result.get_string(1))
|
||||||
|
var month = int(result.get_string(2))
|
||||||
|
var day = int(result.get_string(3))
|
||||||
|
var hour = int(result.get_string(4))
|
||||||
|
var minute = int(result.get_string(5))
|
||||||
|
var second = int(result.get_string(6))
|
||||||
|
|
||||||
|
# 创建UTC时间字典
|
||||||
|
var utc_dict = {
|
||||||
|
"year": year,
|
||||||
|
"month": month,
|
||||||
|
"day": day,
|
||||||
|
"hour": hour,
|
||||||
|
"minute": minute,
|
||||||
|
"second": second
|
||||||
|
}
|
||||||
|
|
||||||
|
# 转换为Unix时间戳(UTC)
|
||||||
|
var utc_timestamp = Time.get_unix_time_from_datetime_dict(utc_dict)
|
||||||
|
|
||||||
|
# 获取本地时间(Godot会自动处理时区转换)
|
||||||
|
var local_dict = Time.get_datetime_dict_from_unix_time(utc_timestamp)
|
||||||
|
|
||||||
|
# 格式化为易读的本地时间
|
||||||
|
return "%04d年%02d月%02d日 %02d:%02d:%02d" % [
|
||||||
|
local_dict.year,
|
||||||
|
local_dict.month,
|
||||||
|
local_dict.day,
|
||||||
|
local_dict.hour,
|
||||||
|
local_dict.minute,
|
||||||
|
local_dict.second
|
||||||
|
]
|
||||||
|
|
||||||
|
# 获取相对时间描述(多少分钟后)
|
||||||
|
static func get_relative_time_until(utc_time_str: String) -> String:
|
||||||
|
# 解析UTC时间字符串
|
||||||
|
var regex = RegEx.new()
|
||||||
|
regex.compile("(\\d{4})-(\\d{2})-(\\d{2})T(\\d{2}):(\\d{2}):(\\d{2})")
|
||||||
|
var result = regex.search(utc_time_str)
|
||||||
|
|
||||||
|
if result == null:
|
||||||
|
return "时间格式错误"
|
||||||
|
|
||||||
|
# 提取时间组件
|
||||||
|
var year = int(result.get_string(1))
|
||||||
|
var month = int(result.get_string(2))
|
||||||
|
var day = int(result.get_string(3))
|
||||||
|
var hour = int(result.get_string(4))
|
||||||
|
var minute = int(result.get_string(5))
|
||||||
|
var second = int(result.get_string(6))
|
||||||
|
|
||||||
|
# 创建UTC时间字典
|
||||||
|
var utc_dict = {
|
||||||
|
"year": year,
|
||||||
|
"month": month,
|
||||||
|
"day": day,
|
||||||
|
"hour": hour,
|
||||||
|
"minute": minute,
|
||||||
|
"second": second
|
||||||
|
}
|
||||||
|
|
||||||
|
# 转换为Unix时间戳
|
||||||
|
var target_timestamp = Time.get_unix_time_from_datetime_dict(utc_dict)
|
||||||
|
var current_timestamp = Time.get_unix_time_from_system()
|
||||||
|
|
||||||
|
# 计算时间差(秒)
|
||||||
|
var diff_seconds = target_timestamp - current_timestamp
|
||||||
|
|
||||||
|
if diff_seconds <= 0:
|
||||||
|
return "现在可以重试"
|
||||||
|
elif diff_seconds < 60:
|
||||||
|
return "%d秒后" % diff_seconds
|
||||||
|
elif diff_seconds < 3600:
|
||||||
|
var minutes = int(diff_seconds / 60)
|
||||||
|
return "%d分钟后" % minutes
|
||||||
|
else:
|
||||||
|
var hours = int(diff_seconds / 3600)
|
||||||
|
var minutes = int((diff_seconds % 3600) / 60)
|
||||||
|
if minutes > 0:
|
||||||
|
return "%d小时%d分钟后" % [hours, minutes]
|
||||||
|
else:
|
||||||
|
return "%d小时后" % hours
|
||||||
1
Utils/StringUtils.gd.uid
Normal file
@@ -0,0 +1 @@
|
|||||||
|
uid://csxag1y8yq57j
|
||||||
50
_Core/managers/GameManager.gd
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
extends Node
|
||||||
|
|
||||||
|
# 游戏管理器 - 全局游戏状态管理
|
||||||
|
# 单例模式,管理游戏的整体状态和生命周期
|
||||||
|
|
||||||
|
signal game_state_changed(new_state: GameState)
|
||||||
|
|
||||||
|
enum GameState {
|
||||||
|
LOADING, # 加载中
|
||||||
|
AUTH, # 认证状态
|
||||||
|
MAIN_MENU, # 主菜单
|
||||||
|
IN_GAME, # 游戏中
|
||||||
|
PAUSED, # 暂停
|
||||||
|
SETTINGS # 设置
|
||||||
|
}
|
||||||
|
|
||||||
|
var current_state: GameState = GameState.LOADING
|
||||||
|
var previous_state: GameState = GameState.LOADING
|
||||||
|
var current_user: String = ""
|
||||||
|
var game_version: String = "1.0.0"
|
||||||
|
|
||||||
|
func _ready():
|
||||||
|
print("GameManager 初始化完成")
|
||||||
|
change_state(GameState.AUTH)
|
||||||
|
|
||||||
|
func change_state(new_state: GameState):
|
||||||
|
if current_state == new_state:
|
||||||
|
return
|
||||||
|
|
||||||
|
previous_state = current_state
|
||||||
|
current_state = new_state
|
||||||
|
|
||||||
|
print("游戏状态变更: ", GameState.keys()[previous_state], " -> ", GameState.keys()[current_state])
|
||||||
|
game_state_changed.emit(new_state)
|
||||||
|
|
||||||
|
func get_current_state() -> GameState:
|
||||||
|
return current_state
|
||||||
|
|
||||||
|
func get_previous_state() -> GameState:
|
||||||
|
return previous_state
|
||||||
|
|
||||||
|
func set_current_user(username: String):
|
||||||
|
current_user = username
|
||||||
|
print("当前用户设置为: ", username)
|
||||||
|
|
||||||
|
func get_current_user() -> String:
|
||||||
|
return current_user
|
||||||
|
|
||||||
|
func is_user_logged_in() -> bool:
|
||||||
|
return not current_user.is_empty()
|
||||||
1
_Core/managers/GameManager.gd.uid
Normal file
@@ -0,0 +1 @@
|
|||||||
|
uid://cd8fn73ysjxh8
|
||||||
443
_Core/managers/NetworkManager.gd
Normal file
@@ -0,0 +1,443 @@
|
|||||||
|
extends Node
|
||||||
|
|
||||||
|
# 网络请求管理器 - 统一处理所有HTTP请求
|
||||||
|
|
||||||
|
# 信号定义
|
||||||
|
signal request_completed(request_id: String, success: bool, data: Dictionary)
|
||||||
|
signal request_failed(request_id: String, error_type: String, message: String)
|
||||||
|
|
||||||
|
# API配置
|
||||||
|
const API_BASE_URL = "https://whaletownend.xinghangee.icu"
|
||||||
|
const DEFAULT_TIMEOUT = 30.0
|
||||||
|
|
||||||
|
# 请求类型枚举
|
||||||
|
enum RequestType {
|
||||||
|
GET,
|
||||||
|
POST,
|
||||||
|
PUT,
|
||||||
|
DELETE,
|
||||||
|
PATCH
|
||||||
|
}
|
||||||
|
|
||||||
|
# 错误类型枚举
|
||||||
|
enum ErrorType {
|
||||||
|
NETWORK_ERROR, # 网络连接错误
|
||||||
|
TIMEOUT_ERROR, # 请求超时
|
||||||
|
PARSE_ERROR, # JSON解析错误
|
||||||
|
HTTP_ERROR, # HTTP状态码错误
|
||||||
|
BUSINESS_ERROR # 业务逻辑错误
|
||||||
|
}
|
||||||
|
|
||||||
|
# 请求状态
|
||||||
|
class RequestInfo:
|
||||||
|
var id: String
|
||||||
|
var url: String
|
||||||
|
var method: RequestType
|
||||||
|
var headers: PackedStringArray
|
||||||
|
var body: String
|
||||||
|
var timeout: float
|
||||||
|
var start_time: float
|
||||||
|
var http_request: HTTPRequest
|
||||||
|
var callback: Callable
|
||||||
|
|
||||||
|
func _init(request_id: String, request_url: String, request_method: RequestType,
|
||||||
|
request_headers: PackedStringArray = [], request_body: String = "",
|
||||||
|
request_timeout: float = DEFAULT_TIMEOUT):
|
||||||
|
id = request_id
|
||||||
|
url = request_url
|
||||||
|
method = request_method
|
||||||
|
headers = request_headers
|
||||||
|
body = request_body
|
||||||
|
timeout = request_timeout
|
||||||
|
start_time = Time.get_time_dict_from_system().hour * 3600 + Time.get_time_dict_from_system().minute * 60 + Time.get_time_dict_from_system().second
|
||||||
|
|
||||||
|
# 活动请求管理
|
||||||
|
var active_requests: Dictionary = {}
|
||||||
|
var request_counter: int = 0
|
||||||
|
|
||||||
|
func _ready():
|
||||||
|
print("NetworkManager 已初始化")
|
||||||
|
|
||||||
|
# ============ 公共API接口 ============
|
||||||
|
|
||||||
|
# 发送GET请求
|
||||||
|
func get_request(endpoint: String, callback: Callable = Callable(), timeout: float = DEFAULT_TIMEOUT) -> String:
|
||||||
|
return send_request(endpoint, RequestType.GET, [], "", callback, timeout)
|
||||||
|
|
||||||
|
# 发送POST请求
|
||||||
|
func post_request(endpoint: String, data: Dictionary, callback: Callable = Callable(), timeout: float = DEFAULT_TIMEOUT) -> String:
|
||||||
|
var body = JSON.stringify(data)
|
||||||
|
var headers = ["Content-Type: application/json"]
|
||||||
|
return send_request(endpoint, RequestType.POST, headers, body, callback, timeout)
|
||||||
|
|
||||||
|
# 发送PUT请求
|
||||||
|
func put_request(endpoint: String, data: Dictionary, callback: Callable = Callable(), timeout: float = DEFAULT_TIMEOUT) -> String:
|
||||||
|
var body = JSON.stringify(data)
|
||||||
|
var headers = ["Content-Type: application/json"]
|
||||||
|
return send_request(endpoint, RequestType.PUT, headers, body, callback, timeout)
|
||||||
|
|
||||||
|
# 发送DELETE请求
|
||||||
|
func delete_request(endpoint: String, callback: Callable = Callable(), timeout: float = DEFAULT_TIMEOUT) -> String:
|
||||||
|
return send_request(endpoint, RequestType.DELETE, [], "", callback, timeout)
|
||||||
|
|
||||||
|
# ============ 认证相关API ============
|
||||||
|
|
||||||
|
# 用户登录
|
||||||
|
func login(identifier: String, password: String, callback: Callable = Callable()) -> String:
|
||||||
|
var data = {
|
||||||
|
"identifier": identifier,
|
||||||
|
"password": password
|
||||||
|
}
|
||||||
|
return post_request("/auth/login", data, callback)
|
||||||
|
|
||||||
|
# 验证码登录
|
||||||
|
func verification_code_login(identifier: String, verification_code: String, callback: Callable = Callable()) -> String:
|
||||||
|
var data = {
|
||||||
|
"identifier": identifier,
|
||||||
|
"verification_code": verification_code
|
||||||
|
}
|
||||||
|
return post_request("/auth/verification-code-login", data, callback)
|
||||||
|
|
||||||
|
# 发送登录验证码
|
||||||
|
func send_login_verification_code(identifier: String, callback: Callable = Callable()) -> String:
|
||||||
|
var data = {"identifier": identifier}
|
||||||
|
return post_request("/auth/send-login-verification-code", data, callback)
|
||||||
|
|
||||||
|
# 用户注册
|
||||||
|
func register(username: String, password: String, nickname: String, email: String = "",
|
||||||
|
email_verification_code: String = "", callback: Callable = Callable()) -> String:
|
||||||
|
var data = {
|
||||||
|
"username": username,
|
||||||
|
"password": password,
|
||||||
|
"nickname": nickname
|
||||||
|
}
|
||||||
|
|
||||||
|
if email != "":
|
||||||
|
data["email"] = email
|
||||||
|
if email_verification_code != "":
|
||||||
|
data["email_verification_code"] = email_verification_code
|
||||||
|
|
||||||
|
return post_request("/auth/register", data, callback)
|
||||||
|
|
||||||
|
# 发送邮箱验证码
|
||||||
|
func send_email_verification(email: String, callback: Callable = Callable()) -> String:
|
||||||
|
var data = {"email": email}
|
||||||
|
return post_request("/auth/send-email-verification", data, callback)
|
||||||
|
|
||||||
|
# 验证邮箱
|
||||||
|
func verify_email(email: String, verification_code: String, callback: Callable = Callable()) -> String:
|
||||||
|
var data = {
|
||||||
|
"email": email,
|
||||||
|
"verification_code": verification_code
|
||||||
|
}
|
||||||
|
return post_request("/auth/verify-email", data, callback)
|
||||||
|
|
||||||
|
# 获取应用状态
|
||||||
|
func get_app_status(callback: Callable = Callable()) -> String:
|
||||||
|
return get_request("/", callback)
|
||||||
|
|
||||||
|
# 重新发送邮箱验证码
|
||||||
|
func resend_email_verification(email: String, callback: Callable = Callable()) -> String:
|
||||||
|
var data = {"email": email}
|
||||||
|
return post_request("/auth/resend-email-verification", data, callback)
|
||||||
|
|
||||||
|
# 忘记密码 - 发送重置验证码
|
||||||
|
func forgot_password(identifier: String, callback: Callable = Callable()) -> String:
|
||||||
|
var data = {"identifier": identifier}
|
||||||
|
return post_request("/auth/forgot-password", data, callback)
|
||||||
|
|
||||||
|
# 重置密码
|
||||||
|
func reset_password(identifier: String, verification_code: String, new_password: String, callback: Callable = Callable()) -> String:
|
||||||
|
var data = {
|
||||||
|
"identifier": identifier,
|
||||||
|
"verification_code": verification_code,
|
||||||
|
"new_password": new_password
|
||||||
|
}
|
||||||
|
return post_request("/auth/reset-password", data, callback)
|
||||||
|
|
||||||
|
# 修改密码
|
||||||
|
func change_password(user_id: String, old_password: String, new_password: String, callback: Callable = Callable()) -> String:
|
||||||
|
var data = {
|
||||||
|
"user_id": user_id,
|
||||||
|
"old_password": old_password,
|
||||||
|
"new_password": new_password
|
||||||
|
}
|
||||||
|
return put_request("/auth/change-password", data, callback)
|
||||||
|
|
||||||
|
# GitHub OAuth登录
|
||||||
|
func github_login(github_id: String, username: String, nickname: String, email: String, avatar_url: String = "", callback: Callable = Callable()) -> String:
|
||||||
|
var data = {
|
||||||
|
"github_id": github_id,
|
||||||
|
"username": username,
|
||||||
|
"nickname": nickname,
|
||||||
|
"email": email
|
||||||
|
}
|
||||||
|
|
||||||
|
if avatar_url != "":
|
||||||
|
data["avatar_url"] = avatar_url
|
||||||
|
|
||||||
|
return post_request("/auth/github", data, callback)
|
||||||
|
|
||||||
|
# ============ 核心请求处理 ============
|
||||||
|
|
||||||
|
# 发送请求的核心方法
|
||||||
|
func send_request(endpoint: String, method: RequestType, headers: PackedStringArray,
|
||||||
|
body: String, callback: Callable, timeout: float) -> String:
|
||||||
|
# 生成请求ID
|
||||||
|
request_counter += 1
|
||||||
|
var request_id = "req_" + str(request_counter)
|
||||||
|
|
||||||
|
# 构建完整URL
|
||||||
|
var full_url = API_BASE_URL + endpoint
|
||||||
|
|
||||||
|
# 创建HTTPRequest节点
|
||||||
|
var http_request = HTTPRequest.new()
|
||||||
|
add_child(http_request)
|
||||||
|
|
||||||
|
# 设置超时
|
||||||
|
http_request.timeout = timeout
|
||||||
|
|
||||||
|
# 创建请求信息
|
||||||
|
var request_info = RequestInfo.new(request_id, full_url, method, headers, body, timeout)
|
||||||
|
request_info.http_request = http_request
|
||||||
|
request_info.callback = callback
|
||||||
|
|
||||||
|
# 存储请求信息
|
||||||
|
active_requests[request_id] = request_info
|
||||||
|
|
||||||
|
# 连接信号
|
||||||
|
http_request.request_completed.connect(func(result: int, response_code: int, headers: PackedStringArray, body: PackedByteArray):
|
||||||
|
_on_request_completed(request_id, result, response_code, headers, body)
|
||||||
|
)
|
||||||
|
|
||||||
|
# 发送请求
|
||||||
|
var godot_method = _convert_to_godot_method(method)
|
||||||
|
var error = http_request.request(full_url, headers, godot_method, body)
|
||||||
|
|
||||||
|
print("=== 发送网络请求 ===")
|
||||||
|
print("请求ID: ", request_id)
|
||||||
|
print("URL: ", full_url)
|
||||||
|
print("方法: ", RequestType.keys()[method])
|
||||||
|
print("Headers: ", headers)
|
||||||
|
print("Body: ", body if body.length() < 200 else body.substr(0, 200) + "...")
|
||||||
|
print("发送结果: ", error)
|
||||||
|
|
||||||
|
if error != OK:
|
||||||
|
print("请求发送失败,错误代码: ", error)
|
||||||
|
_handle_request_error(request_id, ErrorType.NETWORK_ERROR, "网络请求发送失败: " + str(error))
|
||||||
|
return ""
|
||||||
|
|
||||||
|
return request_id
|
||||||
|
|
||||||
|
# 请求完成回调
|
||||||
|
func _on_request_completed(request_id: String, result: int, response_code: int,
|
||||||
|
headers: PackedStringArray, body: PackedByteArray):
|
||||||
|
print("=== 网络请求完成 ===")
|
||||||
|
print("请求ID: ", request_id)
|
||||||
|
print("结果: ", result)
|
||||||
|
print("状态码: ", response_code)
|
||||||
|
print("响应头: ", headers)
|
||||||
|
|
||||||
|
# 获取请求信息
|
||||||
|
if not active_requests.has(request_id):
|
||||||
|
print("警告: 未找到请求ID ", request_id)
|
||||||
|
return
|
||||||
|
|
||||||
|
var request_info = active_requests[request_id]
|
||||||
|
var response_text = body.get_string_from_utf8()
|
||||||
|
|
||||||
|
print("响应体长度: ", body.size(), " 字节")
|
||||||
|
print("响应内容: ", response_text if response_text.length() < 500 else response_text.substr(0, 500) + "...")
|
||||||
|
|
||||||
|
# 处理网络连接失败
|
||||||
|
if response_code == 0:
|
||||||
|
_handle_request_error(request_id, ErrorType.NETWORK_ERROR, "网络连接失败,请检查网络连接")
|
||||||
|
return
|
||||||
|
|
||||||
|
# 解析JSON响应
|
||||||
|
var json = JSON.new()
|
||||||
|
var parse_result = json.parse(response_text)
|
||||||
|
if parse_result != OK:
|
||||||
|
_handle_request_error(request_id, ErrorType.PARSE_ERROR, "服务器响应格式错误")
|
||||||
|
return
|
||||||
|
|
||||||
|
var response_data = json.data
|
||||||
|
|
||||||
|
# 处理响应
|
||||||
|
_handle_response(request_id, response_code, response_data)
|
||||||
|
|
||||||
|
# 处理响应 - 支持API v1.1.1的状态码
|
||||||
|
func _handle_response(request_id: String, response_code: int, data: Dictionary):
|
||||||
|
var request_info = active_requests[request_id]
|
||||||
|
|
||||||
|
# 检查业务成功标志
|
||||||
|
var success = data.get("success", true) # 默认true保持向后兼容
|
||||||
|
var error_code = data.get("error_code", "")
|
||||||
|
var message = data.get("message", "")
|
||||||
|
|
||||||
|
# 判断请求是否成功
|
||||||
|
var is_success = false
|
||||||
|
|
||||||
|
# HTTP成功状态码且业务成功
|
||||||
|
if (response_code >= 200 and response_code < 300) and success:
|
||||||
|
is_success = true
|
||||||
|
# 特殊情况:206测试模式 - 根据API文档,这是成功的测试模式响应
|
||||||
|
elif response_code == 206 and error_code == "TEST_MODE_ONLY":
|
||||||
|
is_success = true
|
||||||
|
print("🧪 测试模式响应: ", message)
|
||||||
|
# 201创建成功
|
||||||
|
elif response_code == 201:
|
||||||
|
is_success = true
|
||||||
|
|
||||||
|
if is_success:
|
||||||
|
print("✅ 请求成功: ", request_id)
|
||||||
|
# 发送成功信号
|
||||||
|
request_completed.emit(request_id, true, data)
|
||||||
|
|
||||||
|
# 调用回调函数
|
||||||
|
if request_info.callback.is_valid():
|
||||||
|
request_info.callback.call(true, data, {})
|
||||||
|
else:
|
||||||
|
print("❌ 请求失败: ", request_id, " - HTTP:", response_code, " 错误码:", error_code, " 消息:", message)
|
||||||
|
|
||||||
|
# 确定错误类型
|
||||||
|
var error_type = _determine_error_type(response_code, error_code)
|
||||||
|
|
||||||
|
# 发送失败信号
|
||||||
|
request_failed.emit(request_id, ErrorType.keys()[error_type], message)
|
||||||
|
|
||||||
|
# 调用回调函数
|
||||||
|
if request_info.callback.is_valid():
|
||||||
|
var error_info = {
|
||||||
|
"response_code": response_code,
|
||||||
|
"error_code": error_code,
|
||||||
|
"message": message,
|
||||||
|
"error_type": error_type
|
||||||
|
}
|
||||||
|
request_info.callback.call(false, data, error_info)
|
||||||
|
|
||||||
|
# 清理请求
|
||||||
|
_cleanup_request(request_id)
|
||||||
|
|
||||||
|
# 处理请求错误
|
||||||
|
func _handle_request_error(request_id: String, error_type: ErrorType, message: String):
|
||||||
|
print("❌ 请求错误: ", request_id, " - ", message)
|
||||||
|
|
||||||
|
# 发送错误信号
|
||||||
|
request_failed.emit(request_id, ErrorType.keys()[error_type], message)
|
||||||
|
|
||||||
|
# 调用回调函数
|
||||||
|
if active_requests.has(request_id):
|
||||||
|
var request_info = active_requests[request_id]
|
||||||
|
if request_info.callback.is_valid():
|
||||||
|
var error_info = {
|
||||||
|
"error_type": error_type,
|
||||||
|
"message": message
|
||||||
|
}
|
||||||
|
request_info.callback.call(false, {}, error_info)
|
||||||
|
|
||||||
|
# 清理请求
|
||||||
|
_cleanup_request(request_id)
|
||||||
|
|
||||||
|
# 确定错误类型 - 支持更多状态码
|
||||||
|
func _determine_error_type(response_code: int, error_code: String) -> ErrorType:
|
||||||
|
# 根据错误码判断
|
||||||
|
match error_code:
|
||||||
|
"SERVICE_UNAVAILABLE":
|
||||||
|
return ErrorType.BUSINESS_ERROR
|
||||||
|
"TOO_MANY_REQUESTS":
|
||||||
|
return ErrorType.BUSINESS_ERROR
|
||||||
|
"TEST_MODE_ONLY":
|
||||||
|
return ErrorType.BUSINESS_ERROR
|
||||||
|
"SEND_EMAIL_VERIFICATION_FAILED", "REGISTER_FAILED":
|
||||||
|
# 这些可能是409冲突或其他业务错误
|
||||||
|
return ErrorType.BUSINESS_ERROR
|
||||||
|
_:
|
||||||
|
# 根据HTTP状态码判断
|
||||||
|
match response_code:
|
||||||
|
409: # 资源冲突
|
||||||
|
return ErrorType.BUSINESS_ERROR
|
||||||
|
206: # 测试模式
|
||||||
|
return ErrorType.BUSINESS_ERROR
|
||||||
|
429: # 频率限制
|
||||||
|
return ErrorType.BUSINESS_ERROR
|
||||||
|
_:
|
||||||
|
if response_code >= 400 and response_code < 500:
|
||||||
|
return ErrorType.HTTP_ERROR
|
||||||
|
elif response_code >= 500:
|
||||||
|
return ErrorType.HTTP_ERROR
|
||||||
|
else:
|
||||||
|
return ErrorType.BUSINESS_ERROR
|
||||||
|
|
||||||
|
# 清理请求资源
|
||||||
|
func _cleanup_request(request_id: String):
|
||||||
|
if active_requests.has(request_id):
|
||||||
|
var request_info = active_requests[request_id]
|
||||||
|
|
||||||
|
# 移除HTTPRequest节点
|
||||||
|
if is_instance_valid(request_info.http_request):
|
||||||
|
request_info.http_request.queue_free()
|
||||||
|
|
||||||
|
# 从活动请求中移除
|
||||||
|
active_requests.erase(request_id)
|
||||||
|
|
||||||
|
print("🧹 清理请求: ", request_id)
|
||||||
|
|
||||||
|
# 转换请求方法
|
||||||
|
func _convert_to_godot_method(method: RequestType) -> HTTPClient.Method:
|
||||||
|
match method:
|
||||||
|
RequestType.GET:
|
||||||
|
return HTTPClient.METHOD_GET
|
||||||
|
RequestType.POST:
|
||||||
|
return HTTPClient.METHOD_POST
|
||||||
|
RequestType.PUT:
|
||||||
|
return HTTPClient.METHOD_PUT
|
||||||
|
RequestType.DELETE:
|
||||||
|
return HTTPClient.METHOD_DELETE
|
||||||
|
RequestType.PATCH:
|
||||||
|
return HTTPClient.METHOD_PATCH
|
||||||
|
_:
|
||||||
|
return HTTPClient.METHOD_GET
|
||||||
|
|
||||||
|
# ============ 工具方法 ============
|
||||||
|
|
||||||
|
# 取消请求
|
||||||
|
func cancel_request(request_id: String) -> bool:
|
||||||
|
if active_requests.has(request_id):
|
||||||
|
print("🚫 取消请求: ", request_id)
|
||||||
|
_cleanup_request(request_id)
|
||||||
|
return true
|
||||||
|
return false
|
||||||
|
|
||||||
|
# 取消所有请求
|
||||||
|
func cancel_all_requests():
|
||||||
|
print("🚫 取消所有请求")
|
||||||
|
var request_ids = active_requests.keys()
|
||||||
|
for request_id in request_ids:
|
||||||
|
cancel_request(request_id)
|
||||||
|
|
||||||
|
# 获取活动请求数量
|
||||||
|
func get_active_request_count() -> int:
|
||||||
|
return active_requests.size()
|
||||||
|
|
||||||
|
# 检查请求是否活动
|
||||||
|
func is_request_active(request_id: String) -> bool:
|
||||||
|
return active_requests.has(request_id)
|
||||||
|
|
||||||
|
# 获取请求信息
|
||||||
|
func get_request_info(request_id: String) -> Dictionary:
|
||||||
|
if active_requests.has(request_id):
|
||||||
|
var info = active_requests[request_id]
|
||||||
|
return {
|
||||||
|
"id": info.id,
|
||||||
|
"url": info.url,
|
||||||
|
"method": RequestType.keys()[info.method],
|
||||||
|
"start_time": info.start_time,
|
||||||
|
"timeout": info.timeout
|
||||||
|
}
|
||||||
|
return {}
|
||||||
|
|
||||||
|
func _notification(what):
|
||||||
|
if what == NOTIFICATION_WM_CLOSE_REQUEST:
|
||||||
|
# 应用关闭时取消所有请求
|
||||||
|
cancel_all_requests()
|
||||||
1
_Core/managers/NetworkManager.gd.uid
Normal file
@@ -0,0 +1 @@
|
|||||||
|
uid://dr7v30wheetca
|
||||||
590
_Core/managers/ResponseHandler.gd
Normal file
@@ -0,0 +1,590 @@
|
|||||||
|
extends Node
|
||||||
|
|
||||||
|
# 响应处理器 - 统一处理API响应和错误
|
||||||
|
|
||||||
|
# 响应处理结果
|
||||||
|
class ResponseResult:
|
||||||
|
var success: bool
|
||||||
|
var message: String
|
||||||
|
var toast_type: String # "success" 或 "error"
|
||||||
|
var data: Dictionary
|
||||||
|
var should_show_toast: bool
|
||||||
|
var custom_action: Callable
|
||||||
|
|
||||||
|
func _init():
|
||||||
|
success = false
|
||||||
|
message = ""
|
||||||
|
toast_type = "error"
|
||||||
|
data = {}
|
||||||
|
should_show_toast = true
|
||||||
|
custom_action = Callable()
|
||||||
|
|
||||||
|
# 错误码映射表 - 根据API v1.1.1更新
|
||||||
|
const ERROR_CODE_MESSAGES = {
|
||||||
|
# 登录相关
|
||||||
|
"LOGIN_FAILED": "登录失败",
|
||||||
|
"VERIFICATION_CODE_LOGIN_FAILED": "验证码错误或已过期",
|
||||||
|
"EMAIL_NOT_VERIFIED": "请先验证邮箱",
|
||||||
|
|
||||||
|
# 注册相关
|
||||||
|
"REGISTER_FAILED": "注册失败",
|
||||||
|
|
||||||
|
# 验证码相关
|
||||||
|
"SEND_CODE_FAILED": "发送验证码失败",
|
||||||
|
"SEND_LOGIN_CODE_FAILED": "发送登录验证码失败",
|
||||||
|
"SEND_EMAIL_VERIFICATION_FAILED": "发送邮箱验证码失败",
|
||||||
|
"RESEND_EMAIL_VERIFICATION_FAILED": "重新发送验证码失败",
|
||||||
|
"EMAIL_VERIFICATION_FAILED": "邮箱验证失败",
|
||||||
|
"RESET_PASSWORD_FAILED": "重置密码失败",
|
||||||
|
"CHANGE_PASSWORD_FAILED": "修改密码失败",
|
||||||
|
"VERIFICATION_CODE_EXPIRED": "验证码已过期",
|
||||||
|
"VERIFICATION_CODE_INVALID": "验证码无效",
|
||||||
|
"VERIFICATION_CODE_ATTEMPTS_EXCEEDED": "验证码尝试次数过多",
|
||||||
|
"VERIFICATION_CODE_RATE_LIMITED": "验证码发送过于频繁",
|
||||||
|
"VERIFICATION_CODE_HOURLY_LIMIT": "验证码每小时发送次数已达上限",
|
||||||
|
|
||||||
|
# 用户状态相关
|
||||||
|
"USER_NOT_FOUND": "用户不存在",
|
||||||
|
"INVALID_IDENTIFIER": "请输入有效的邮箱或手机号",
|
||||||
|
"USER_STATUS_UPDATE_FAILED": "用户状态更新失败",
|
||||||
|
|
||||||
|
# 系统状态相关
|
||||||
|
"TEST_MODE_ONLY": "测试模式",
|
||||||
|
"TOO_MANY_REQUESTS": "请求过于频繁,请稍后再试",
|
||||||
|
"SERVICE_UNAVAILABLE": "系统维护中,请稍后再试",
|
||||||
|
|
||||||
|
# 权限相关
|
||||||
|
"UNAUTHORIZED": "未授权访问",
|
||||||
|
"FORBIDDEN": "权限不足",
|
||||||
|
"ADMIN_LOGIN_FAILED": "管理员登录失败",
|
||||||
|
|
||||||
|
# 其他
|
||||||
|
"VALIDATION_FAILED": "参数验证失败",
|
||||||
|
"UNSUPPORTED_MEDIA_TYPE": "不支持的请求格式",
|
||||||
|
"REQUEST_TIMEOUT": "请求超时"
|
||||||
|
}
|
||||||
|
|
||||||
|
# HTTP状态码消息映射 - 根据API v1.1.1更新
|
||||||
|
const HTTP_STATUS_MESSAGES = {
|
||||||
|
200: "请求成功",
|
||||||
|
201: "创建成功",
|
||||||
|
206: "测试模式",
|
||||||
|
400: "请求参数错误",
|
||||||
|
401: "认证失败",
|
||||||
|
403: "权限不足",
|
||||||
|
404: "资源不存在",
|
||||||
|
408: "请求超时",
|
||||||
|
409: "资源冲突",
|
||||||
|
415: "不支持的媒体类型",
|
||||||
|
429: "请求过于频繁",
|
||||||
|
500: "服务器内部错误",
|
||||||
|
503: "服务不可用"
|
||||||
|
}
|
||||||
|
|
||||||
|
# ============ 主要处理方法 ============
|
||||||
|
|
||||||
|
# 处理登录响应
|
||||||
|
static func handle_login_response(success: bool, data: Dictionary, error_info: Dictionary = {}) -> ResponseResult:
|
||||||
|
var result = ResponseResult.new()
|
||||||
|
|
||||||
|
if success:
|
||||||
|
result.success = true
|
||||||
|
result.message = "登录成功!正在进入鲸鱼镇..."
|
||||||
|
result.toast_type = "success"
|
||||||
|
result.data = data
|
||||||
|
|
||||||
|
# 自定义动作:延迟发送登录成功信号
|
||||||
|
result.custom_action = func():
|
||||||
|
await Engine.get_main_loop().create_timer(1.0).timeout
|
||||||
|
# 这里可以发送登录成功信号或执行其他逻辑
|
||||||
|
else:
|
||||||
|
result = _handle_login_error(data, error_info)
|
||||||
|
|
||||||
|
return result
|
||||||
|
|
||||||
|
# 处理验证码登录响应
|
||||||
|
static func handle_verification_code_login_response(success: bool, data: Dictionary, error_info: Dictionary = {}) -> ResponseResult:
|
||||||
|
var result = ResponseResult.new()
|
||||||
|
|
||||||
|
if success:
|
||||||
|
result.success = true
|
||||||
|
result.message = "验证码登录成功!正在进入鲸鱼镇..."
|
||||||
|
result.toast_type = "success"
|
||||||
|
result.data = data
|
||||||
|
|
||||||
|
result.custom_action = func():
|
||||||
|
await Engine.get_main_loop().create_timer(1.0).timeout
|
||||||
|
# 登录成功后的处理逻辑
|
||||||
|
else:
|
||||||
|
result = _handle_verification_code_login_error(data, error_info)
|
||||||
|
|
||||||
|
return result
|
||||||
|
|
||||||
|
# 处理发送验证码响应 - 支持邮箱冲突检测
|
||||||
|
static func handle_send_verification_code_response(success: bool, data: Dictionary, error_info: Dictionary = {}) -> ResponseResult:
|
||||||
|
var result = ResponseResult.new()
|
||||||
|
|
||||||
|
if success:
|
||||||
|
var error_code = data.get("error_code", "")
|
||||||
|
if error_code == "TEST_MODE_ONLY":
|
||||||
|
result.success = true
|
||||||
|
result.message = "🧪 测试模式:验证码已生成,请查看控制台"
|
||||||
|
result.toast_type = "success"
|
||||||
|
|
||||||
|
# 在控制台显示验证码
|
||||||
|
if data.has("data") and data.data.has("verification_code"):
|
||||||
|
print("🔑 测试模式验证码: ", data.data.verification_code)
|
||||||
|
result.message += "\n验证码: " + str(data.data.verification_code)
|
||||||
|
else:
|
||||||
|
result.success = true
|
||||||
|
result.message = "📧 验证码已发送到您的邮箱,请查收"
|
||||||
|
result.toast_type = "success"
|
||||||
|
|
||||||
|
# 开发环境下显示验证码
|
||||||
|
if data.has("data") and data.data.has("verification_code"):
|
||||||
|
print("🔑 开发环境验证码: ", data.data.verification_code)
|
||||||
|
else:
|
||||||
|
result = _handle_send_code_error(data, error_info)
|
||||||
|
|
||||||
|
return result
|
||||||
|
|
||||||
|
# 处理发送登录验证码响应
|
||||||
|
static func handle_send_login_code_response(success: bool, data: Dictionary, error_info: Dictionary = {}) -> ResponseResult:
|
||||||
|
var result = ResponseResult.new()
|
||||||
|
|
||||||
|
if success:
|
||||||
|
var error_code = data.get("error_code", "")
|
||||||
|
if error_code == "TEST_MODE_ONLY":
|
||||||
|
result.success = true
|
||||||
|
result.message = "测试模式:登录验证码已生成,请查看控制台"
|
||||||
|
result.toast_type = "success"
|
||||||
|
|
||||||
|
if data.has("data") and data.data.has("verification_code"):
|
||||||
|
print("测试模式登录验证码: ", data.data.verification_code)
|
||||||
|
else:
|
||||||
|
result.success = true
|
||||||
|
result.message = "登录验证码已发送,请查收"
|
||||||
|
result.toast_type = "success"
|
||||||
|
|
||||||
|
if data.has("data") and data.data.has("verification_code"):
|
||||||
|
print("开发环境登录验证码: ", data.data.verification_code)
|
||||||
|
else:
|
||||||
|
result = _handle_send_login_code_error(data, error_info)
|
||||||
|
|
||||||
|
return result
|
||||||
|
|
||||||
|
# 处理注册响应
|
||||||
|
static func handle_register_response(success: bool, data: Dictionary, error_info: Dictionary = {}) -> ResponseResult:
|
||||||
|
var result = ResponseResult.new()
|
||||||
|
|
||||||
|
if success:
|
||||||
|
result.success = true
|
||||||
|
result.message = "注册成功!欢迎加入鲸鱼镇"
|
||||||
|
result.toast_type = "success"
|
||||||
|
result.data = data
|
||||||
|
|
||||||
|
# 自定义动作:清空表单,切换到登录界面
|
||||||
|
result.custom_action = func():
|
||||||
|
# 这里可以执行清空表单、切换界面等操作
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
result = _handle_register_error(data, error_info)
|
||||||
|
|
||||||
|
return result
|
||||||
|
|
||||||
|
# 处理邮箱验证响应
|
||||||
|
static func handle_verify_email_response(success: bool, data: Dictionary, error_info: Dictionary = {}) -> ResponseResult:
|
||||||
|
var result = ResponseResult.new()
|
||||||
|
|
||||||
|
if success:
|
||||||
|
result.success = true
|
||||||
|
result.message = "邮箱验证成功,正在注册..."
|
||||||
|
result.toast_type = "success"
|
||||||
|
result.data = data
|
||||||
|
else:
|
||||||
|
result = _handle_verify_email_error(data, error_info)
|
||||||
|
|
||||||
|
return result
|
||||||
|
|
||||||
|
# 处理重新发送邮箱验证码响应
|
||||||
|
static func handle_resend_email_verification_response(success: bool, data: Dictionary, error_info: Dictionary = {}) -> ResponseResult:
|
||||||
|
var result = ResponseResult.new()
|
||||||
|
|
||||||
|
if success:
|
||||||
|
var error_code = data.get("error_code", "")
|
||||||
|
if error_code == "TEST_MODE_ONLY":
|
||||||
|
result.success = true
|
||||||
|
result.message = "🧪 测试模式:验证码已重新生成,请查看控制台"
|
||||||
|
result.toast_type = "success"
|
||||||
|
|
||||||
|
if data.has("data") and data.data.has("verification_code"):
|
||||||
|
print("🔑 测试模式重新发送验证码: ", data.data.verification_code)
|
||||||
|
else:
|
||||||
|
result.success = true
|
||||||
|
result.message = "📧 验证码已重新发送到您的邮箱,请查收"
|
||||||
|
result.toast_type = "success"
|
||||||
|
|
||||||
|
if data.has("data") and data.data.has("verification_code"):
|
||||||
|
print("🔑 开发环境重新发送验证码: ", data.data.verification_code)
|
||||||
|
else:
|
||||||
|
result = _handle_resend_email_verification_error(data, error_info)
|
||||||
|
|
||||||
|
return result
|
||||||
|
|
||||||
|
# 处理忘记密码响应
|
||||||
|
static func handle_forgot_password_response(success: bool, data: Dictionary, error_info: Dictionary = {}) -> ResponseResult:
|
||||||
|
var result = ResponseResult.new()
|
||||||
|
|
||||||
|
if success:
|
||||||
|
var error_code = data.get("error_code", "")
|
||||||
|
if error_code == "TEST_MODE_ONLY":
|
||||||
|
result.success = true
|
||||||
|
result.message = "🧪 测试模式:重置验证码已生成,请查看控制台"
|
||||||
|
result.toast_type = "success"
|
||||||
|
|
||||||
|
if data.has("data") and data.data.has("verification_code"):
|
||||||
|
print("🔑 测试模式重置验证码: ", data.data.verification_code)
|
||||||
|
else:
|
||||||
|
result.success = true
|
||||||
|
result.message = "📧 重置验证码已发送,请查收"
|
||||||
|
result.toast_type = "success"
|
||||||
|
|
||||||
|
if data.has("data") and data.data.has("verification_code"):
|
||||||
|
print("🔑 开发环境重置验证码: ", data.data.verification_code)
|
||||||
|
else:
|
||||||
|
result = _handle_forgot_password_error(data, error_info)
|
||||||
|
|
||||||
|
return result
|
||||||
|
|
||||||
|
# 处理重置密码响应
|
||||||
|
static func handle_reset_password_response(success: bool, data: Dictionary, error_info: Dictionary = {}) -> ResponseResult:
|
||||||
|
var result = ResponseResult.new()
|
||||||
|
|
||||||
|
if success:
|
||||||
|
result.success = true
|
||||||
|
result.message = "🔒 密码重置成功,请使用新密码登录"
|
||||||
|
result.toast_type = "success"
|
||||||
|
result.data = data
|
||||||
|
else:
|
||||||
|
result = _handle_reset_password_error(data, error_info)
|
||||||
|
|
||||||
|
return result
|
||||||
|
|
||||||
|
# ============ 错误处理方法 ============
|
||||||
|
|
||||||
|
# 处理登录错误
|
||||||
|
static func _handle_login_error(data: Dictionary, error_info: Dictionary) -> ResponseResult:
|
||||||
|
var result = ResponseResult.new()
|
||||||
|
var error_code = data.get("error_code", "")
|
||||||
|
var message = data.get("message", "登录失败")
|
||||||
|
|
||||||
|
match error_code:
|
||||||
|
"LOGIN_FAILED":
|
||||||
|
# 根据消息内容进一步判断用户状态
|
||||||
|
if "账户已锁定" in message or "locked" in message.to_lower():
|
||||||
|
result.message = "账户已被锁定,请联系管理员"
|
||||||
|
elif "账户已禁用" in message or "banned" in message.to_lower():
|
||||||
|
result.message = "账户已被禁用,请联系管理员"
|
||||||
|
elif "账户待审核" in message or "pending" in message.to_lower():
|
||||||
|
result.message = "账户待审核,请等待管理员审核"
|
||||||
|
elif "邮箱未验证" in message or "inactive" in message.to_lower():
|
||||||
|
result.message = "请先验证邮箱后再登录"
|
||||||
|
else:
|
||||||
|
result.message = "用户名或密码错误,请检查后重试"
|
||||||
|
_:
|
||||||
|
result.message = _get_error_message(error_code, message, error_info)
|
||||||
|
|
||||||
|
return result
|
||||||
|
|
||||||
|
# 处理验证码登录错误
|
||||||
|
static func _handle_verification_code_login_error(data: Dictionary, error_info: Dictionary) -> ResponseResult:
|
||||||
|
var result = ResponseResult.new()
|
||||||
|
var error_code = data.get("error_code", "")
|
||||||
|
var message = data.get("message", "验证码登录失败")
|
||||||
|
|
||||||
|
match error_code:
|
||||||
|
"VERIFICATION_CODE_LOGIN_FAILED":
|
||||||
|
result.message = "验证码错误或已过期"
|
||||||
|
"EMAIL_NOT_VERIFIED":
|
||||||
|
result.message = "邮箱未验证,请先验证邮箱后再使用验证码登录"
|
||||||
|
"USER_NOT_FOUND":
|
||||||
|
result.message = "用户不存在,请先注册"
|
||||||
|
"INVALID_IDENTIFIER":
|
||||||
|
result.message = "请输入有效的邮箱或手机号"
|
||||||
|
_:
|
||||||
|
result.message = _get_error_message(error_code, message, error_info)
|
||||||
|
|
||||||
|
return result
|
||||||
|
|
||||||
|
# 处理发送验证码错误 - 支持邮箱冲突检测和频率限制
|
||||||
|
static func _handle_send_code_error(data: Dictionary, error_info: Dictionary) -> ResponseResult:
|
||||||
|
var result = ResponseResult.new()
|
||||||
|
var error_code = data.get("error_code", "")
|
||||||
|
var message = data.get("message", "发送验证码失败")
|
||||||
|
var response_code = error_info.get("response_code", 0)
|
||||||
|
|
||||||
|
match error_code:
|
||||||
|
"SEND_EMAIL_VERIFICATION_FAILED":
|
||||||
|
# 检查是否是邮箱冲突(409状态码)
|
||||||
|
if response_code == 409:
|
||||||
|
result.message = "⚠️ 邮箱已被注册,请使用其他邮箱或直接登录"
|
||||||
|
result.toast_type = "error"
|
||||||
|
elif "邮箱格式" in message:
|
||||||
|
result.message = "📧 请输入有效的邮箱地址"
|
||||||
|
else:
|
||||||
|
result.message = message
|
||||||
|
"TOO_MANY_REQUESTS":
|
||||||
|
# 处理频率限制,提供重试建议
|
||||||
|
result.toast_type = "error"
|
||||||
|
|
||||||
|
# 如果有throttle_info,显示更详细的信息
|
||||||
|
if data.has("throttle_info"):
|
||||||
|
var throttle_info = data.throttle_info
|
||||||
|
var reset_time = throttle_info.get("reset_time", "")
|
||||||
|
if reset_time != "":
|
||||||
|
var relative_time = StringUtils.get_relative_time_until(reset_time)
|
||||||
|
var local_time = StringUtils.format_utc_to_local_time(reset_time)
|
||||||
|
result.message = "⏰ 验证码发送过于频繁"
|
||||||
|
result.message += "\n请" + relative_time + "再试"
|
||||||
|
result.message += "\n重试时间: " + local_time
|
||||||
|
else:
|
||||||
|
result.message = "⏰ 验证码发送过于频繁,请稍后再试"
|
||||||
|
else:
|
||||||
|
result.message = "⏰ 验证码发送过于频繁,请稍后再试"
|
||||||
|
"VERIFICATION_CODE_RATE_LIMITED":
|
||||||
|
result.message = "⏰ 验证码发送过于频繁,请稍后再试"
|
||||||
|
"VERIFICATION_CODE_HOURLY_LIMIT":
|
||||||
|
result.message = "⏰ 每小时发送次数已达上限,请稍后再试"
|
||||||
|
_:
|
||||||
|
result.message = _get_error_message(error_code, message, error_info)
|
||||||
|
|
||||||
|
return result
|
||||||
|
|
||||||
|
# 处理发送登录验证码错误
|
||||||
|
static func _handle_send_login_code_error(data: Dictionary, error_info: Dictionary) -> ResponseResult:
|
||||||
|
var result = ResponseResult.new()
|
||||||
|
var error_code = data.get("error_code", "")
|
||||||
|
var message = data.get("message", "发送登录验证码失败")
|
||||||
|
|
||||||
|
match error_code:
|
||||||
|
"SEND_LOGIN_CODE_FAILED":
|
||||||
|
if "用户不存在" in message:
|
||||||
|
result.message = "用户不存在,请先注册"
|
||||||
|
else:
|
||||||
|
result.message = "发送登录验证码失败"
|
||||||
|
"USER_NOT_FOUND":
|
||||||
|
result.message = "用户不存在,请先注册"
|
||||||
|
"INVALID_IDENTIFIER":
|
||||||
|
result.message = "请输入有效的邮箱或手机号"
|
||||||
|
_:
|
||||||
|
result.message = _get_error_message(error_code, message, error_info)
|
||||||
|
|
||||||
|
return result
|
||||||
|
|
||||||
|
# 处理注册错误 - 支持409冲突状态码
|
||||||
|
static func _handle_register_error(data: Dictionary, error_info: Dictionary) -> ResponseResult:
|
||||||
|
var result = ResponseResult.new()
|
||||||
|
var error_code = data.get("error_code", "")
|
||||||
|
var message = data.get("message", "注册失败")
|
||||||
|
var response_code = error_info.get("response_code", 0)
|
||||||
|
|
||||||
|
match error_code:
|
||||||
|
"REGISTER_FAILED":
|
||||||
|
# 检查409冲突状态码
|
||||||
|
if response_code == 409:
|
||||||
|
if "邮箱已存在" in message or "邮箱已被使用" in message:
|
||||||
|
result.message = "📧 邮箱已被注册,请使用其他邮箱或直接登录"
|
||||||
|
elif "用户名已存在" in message or "用户名已被使用" in message:
|
||||||
|
result.message = "👤 用户名已被使用,请换一个"
|
||||||
|
else:
|
||||||
|
result.message = "⚠️ 资源冲突:" + message
|
||||||
|
elif "邮箱验证码" in message or "verification_code" in message:
|
||||||
|
result.message = "🔑 请先获取并输入邮箱验证码"
|
||||||
|
elif "用户名" in message:
|
||||||
|
result.message = "👤 用户名格式不正确"
|
||||||
|
elif "邮箱" in message:
|
||||||
|
result.message = "📧 邮箱格式不正确"
|
||||||
|
elif "密码" in message:
|
||||||
|
result.message = "🔒 密码格式不符合要求"
|
||||||
|
elif "验证码" in message:
|
||||||
|
result.message = "🔑 验证码错误或已过期"
|
||||||
|
else:
|
||||||
|
result.message = message
|
||||||
|
_:
|
||||||
|
result.message = _get_error_message(error_code, message, error_info)
|
||||||
|
|
||||||
|
return result
|
||||||
|
|
||||||
|
# 处理邮箱验证错误
|
||||||
|
static func _handle_verify_email_error(data: Dictionary, error_info: Dictionary) -> ResponseResult:
|
||||||
|
var result = ResponseResult.new()
|
||||||
|
var error_code = data.get("error_code", "")
|
||||||
|
var message = data.get("message", "邮箱验证失败")
|
||||||
|
|
||||||
|
match error_code:
|
||||||
|
"EMAIL_VERIFICATION_FAILED":
|
||||||
|
if "验证码错误" in message:
|
||||||
|
result.message = "🔑 验证码错误"
|
||||||
|
elif "验证码已过期" in message:
|
||||||
|
result.message = "🔑 验证码已过期,请重新获取"
|
||||||
|
else:
|
||||||
|
result.message = message
|
||||||
|
"VERIFICATION_CODE_INVALID":
|
||||||
|
result.message = "🔑 验证码错误或已过期"
|
||||||
|
"VERIFICATION_CODE_EXPIRED":
|
||||||
|
result.message = "🔑 验证码已过期,请重新获取"
|
||||||
|
_:
|
||||||
|
result.message = _get_error_message(error_code, message, error_info)
|
||||||
|
|
||||||
|
return result
|
||||||
|
|
||||||
|
# 处理网络测试响应
|
||||||
|
static func handle_network_test_response(success: bool, data: Dictionary, error_info: Dictionary = {}) -> ResponseResult:
|
||||||
|
var result = ResponseResult.new()
|
||||||
|
|
||||||
|
if success:
|
||||||
|
result.success = true
|
||||||
|
result.message = "🌐 网络连接正常"
|
||||||
|
result.toast_type = "success"
|
||||||
|
else:
|
||||||
|
result.success = false
|
||||||
|
result.message = "🌐 网络连接异常"
|
||||||
|
result.toast_type = "error"
|
||||||
|
|
||||||
|
return result
|
||||||
|
|
||||||
|
# 处理重新发送邮箱验证码错误
|
||||||
|
static func _handle_resend_email_verification_error(data: Dictionary, error_info: Dictionary) -> ResponseResult:
|
||||||
|
var result = ResponseResult.new()
|
||||||
|
var error_code = data.get("error_code", "")
|
||||||
|
var message = data.get("message", "重新发送验证码失败")
|
||||||
|
|
||||||
|
match error_code:
|
||||||
|
"RESEND_EMAIL_VERIFICATION_FAILED":
|
||||||
|
if "邮箱已验证" in message:
|
||||||
|
result.message = "📧 邮箱已验证,无需重复验证"
|
||||||
|
else:
|
||||||
|
result.message = message
|
||||||
|
_:
|
||||||
|
result.message = _get_error_message(error_code, message, error_info)
|
||||||
|
|
||||||
|
return result
|
||||||
|
|
||||||
|
# 处理忘记密码错误
|
||||||
|
static func _handle_forgot_password_error(data: Dictionary, error_info: Dictionary) -> ResponseResult:
|
||||||
|
var result = ResponseResult.new()
|
||||||
|
var error_code = data.get("error_code", "")
|
||||||
|
var message = data.get("message", "发送重置验证码失败")
|
||||||
|
|
||||||
|
match error_code:
|
||||||
|
"SEND_CODE_FAILED":
|
||||||
|
if "用户不存在" in message:
|
||||||
|
result.message = "👤 用户不存在,请检查邮箱或手机号"
|
||||||
|
else:
|
||||||
|
result.message = message
|
||||||
|
"USER_NOT_FOUND":
|
||||||
|
result.message = "👤 用户不存在,请检查邮箱或手机号"
|
||||||
|
_:
|
||||||
|
result.message = _get_error_message(error_code, message, error_info)
|
||||||
|
|
||||||
|
return result
|
||||||
|
|
||||||
|
# 处理重置密码错误
|
||||||
|
static func _handle_reset_password_error(data: Dictionary, error_info: Dictionary) -> ResponseResult:
|
||||||
|
var result = ResponseResult.new()
|
||||||
|
var error_code = data.get("error_code", "")
|
||||||
|
var message = data.get("message", "重置密码失败")
|
||||||
|
|
||||||
|
match error_code:
|
||||||
|
"RESET_PASSWORD_FAILED":
|
||||||
|
if "验证码" in message:
|
||||||
|
result.message = "🔑 验证码错误或已过期"
|
||||||
|
else:
|
||||||
|
result.message = message
|
||||||
|
_:
|
||||||
|
result.message = _get_error_message(error_code, message, error_info)
|
||||||
|
|
||||||
|
return result
|
||||||
|
|
||||||
|
# ============ 工具方法 ============
|
||||||
|
|
||||||
|
# 获取错误消息 - 支持更多状态码和错误处理
|
||||||
|
static func _get_error_message(error_code: String, original_message: String, error_info: Dictionary) -> String:
|
||||||
|
# 优先使用错误码映射
|
||||||
|
if ERROR_CODE_MESSAGES.has(error_code):
|
||||||
|
return ERROR_CODE_MESSAGES[error_code]
|
||||||
|
|
||||||
|
# 处理频率限制
|
||||||
|
if error_code == "TOO_MANY_REQUESTS":
|
||||||
|
return _handle_rate_limit_message(original_message, error_info)
|
||||||
|
|
||||||
|
# 处理维护模式
|
||||||
|
if error_code == "SERVICE_UNAVAILABLE":
|
||||||
|
return _handle_maintenance_message(original_message, error_info)
|
||||||
|
|
||||||
|
# 处理测试模式
|
||||||
|
if error_code == "TEST_MODE_ONLY":
|
||||||
|
return "🧪 测试模式:" + original_message
|
||||||
|
|
||||||
|
# 根据HTTP状态码处理
|
||||||
|
if error_info.has("response_code"):
|
||||||
|
var response_code = error_info.response_code
|
||||||
|
match response_code:
|
||||||
|
409:
|
||||||
|
return "⚠️ 资源冲突:" + original_message
|
||||||
|
206:
|
||||||
|
return "🧪 测试模式:" + original_message
|
||||||
|
429:
|
||||||
|
return "⏰ 请求过于频繁,请稍后再试"
|
||||||
|
_:
|
||||||
|
if HTTP_STATUS_MESSAGES.has(response_code):
|
||||||
|
return HTTP_STATUS_MESSAGES[response_code] + ":" + original_message
|
||||||
|
|
||||||
|
# 返回原始消息
|
||||||
|
return original_message if original_message != "" else "操作失败"
|
||||||
|
|
||||||
|
# 处理频率限制消息
|
||||||
|
static func _handle_rate_limit_message(message: String, error_info: Dictionary) -> String:
|
||||||
|
# 可以根据throttle_info提供更详细的信息
|
||||||
|
return message + ",请稍后再试"
|
||||||
|
|
||||||
|
# 处理维护模式消息
|
||||||
|
static func _handle_maintenance_message(message: String, error_info: Dictionary) -> String:
|
||||||
|
# 可以根据maintenance_info提供更详细的信息
|
||||||
|
return "系统维护中,请稍后再试"
|
||||||
|
|
||||||
|
# 通用响应处理器 - 支持更多操作类型
|
||||||
|
static func handle_response(operation_type: String, success: bool, data: Dictionary, error_info: Dictionary = {}) -> ResponseResult:
|
||||||
|
match operation_type:
|
||||||
|
"login":
|
||||||
|
return handle_login_response(success, data, error_info)
|
||||||
|
"verification_code_login":
|
||||||
|
return handle_verification_code_login_response(success, data, error_info)
|
||||||
|
"send_code":
|
||||||
|
return handle_send_verification_code_response(success, data, error_info)
|
||||||
|
"send_login_code":
|
||||||
|
return handle_send_login_code_response(success, data, error_info)
|
||||||
|
"register":
|
||||||
|
return handle_register_response(success, data, error_info)
|
||||||
|
"verify_email":
|
||||||
|
return handle_verify_email_response(success, data, error_info)
|
||||||
|
"resend_email_verification":
|
||||||
|
return handle_resend_email_verification_response(success, data, error_info)
|
||||||
|
"forgot_password":
|
||||||
|
return handle_forgot_password_response(success, data, error_info)
|
||||||
|
"reset_password":
|
||||||
|
return handle_reset_password_response(success, data, error_info)
|
||||||
|
"network_test":
|
||||||
|
return handle_network_test_response(success, data, error_info)
|
||||||
|
_:
|
||||||
|
# 通用处理
|
||||||
|
var result = ResponseResult.new()
|
||||||
|
if success:
|
||||||
|
result.success = true
|
||||||
|
result.message = "✅ 操作成功"
|
||||||
|
result.toast_type = "success"
|
||||||
|
else:
|
||||||
|
result.success = false
|
||||||
|
result.message = _get_error_message(data.get("error_code", ""), data.get("message", "操作失败"), error_info)
|
||||||
|
result.toast_type = "error"
|
||||||
|
return result
|
||||||
1
_Core/managers/ResponseHandler.gd.uid
Normal file
@@ -0,0 +1 @@
|
|||||||
|
uid://nseguk2ytiw6
|
||||||
75
_Core/managers/SceneManager.gd
Normal file
@@ -0,0 +1,75 @@
|
|||||||
|
extends Node
|
||||||
|
|
||||||
|
# 场景管理器 - 负责场景切换和管理
|
||||||
|
# 提供场景切换的统一接口
|
||||||
|
|
||||||
|
signal scene_changed(scene_name: String)
|
||||||
|
signal scene_change_started(scene_name: String)
|
||||||
|
|
||||||
|
var current_scene_name: String = ""
|
||||||
|
var is_changing_scene: bool = false
|
||||||
|
|
||||||
|
# 场景路径映射
|
||||||
|
var scene_paths: Dictionary = {
|
||||||
|
"main": "res://Scenes/Maps/main_scene.tscn",
|
||||||
|
"auth": "res://UI/Windows/LoginWindow.tscn",
|
||||||
|
"game": "res://Scenes/Maps/game_scene.tscn",
|
||||||
|
"battle": "res://Scenes/Maps/battle_scene.tscn",
|
||||||
|
"inventory": "res://UI/Windows/InventoryWindow.tscn",
|
||||||
|
"shop": "res://UI/Windows/ShopWindow.tscn",
|
||||||
|
"settings": "res://UI/Windows/SettingsWindow.tscn"
|
||||||
|
}
|
||||||
|
|
||||||
|
func _ready():
|
||||||
|
print("SceneManager 初始化完成")
|
||||||
|
|
||||||
|
func change_scene(scene_name: String, use_transition: bool = true):
|
||||||
|
if is_changing_scene:
|
||||||
|
print("场景切换中,忽略新的切换请求")
|
||||||
|
return false
|
||||||
|
|
||||||
|
if not scene_paths.has(scene_name):
|
||||||
|
print("错误: 未找到场景 ", scene_name)
|
||||||
|
return false
|
||||||
|
|
||||||
|
var scene_path = scene_paths[scene_name]
|
||||||
|
print("开始切换场景: ", current_scene_name, " -> ", scene_name)
|
||||||
|
|
||||||
|
is_changing_scene = true
|
||||||
|
scene_change_started.emit(scene_name)
|
||||||
|
|
||||||
|
if use_transition:
|
||||||
|
await show_transition()
|
||||||
|
|
||||||
|
var error = get_tree().change_scene_to_file(scene_path)
|
||||||
|
if error != OK:
|
||||||
|
print("场景切换失败: ", error)
|
||||||
|
is_changing_scene = false
|
||||||
|
return false
|
||||||
|
|
||||||
|
current_scene_name = scene_name
|
||||||
|
is_changing_scene = false
|
||||||
|
scene_changed.emit(scene_name)
|
||||||
|
|
||||||
|
if use_transition:
|
||||||
|
await hide_transition()
|
||||||
|
|
||||||
|
print("场景切换完成: ", scene_name)
|
||||||
|
return true
|
||||||
|
|
||||||
|
func get_current_scene_name() -> String:
|
||||||
|
return current_scene_name
|
||||||
|
|
||||||
|
func register_scene(scene_name: String, scene_path: String):
|
||||||
|
scene_paths[scene_name] = scene_path
|
||||||
|
print("注册场景: ", scene_name, " -> ", scene_path)
|
||||||
|
|
||||||
|
func show_transition():
|
||||||
|
# TODO: 实现场景切换过渡效果
|
||||||
|
print("显示场景切换过渡效果")
|
||||||
|
await get_tree().create_timer(0.2).timeout
|
||||||
|
|
||||||
|
func hide_transition():
|
||||||
|
# TODO: 隐藏场景切换过渡效果
|
||||||
|
print("隐藏场景切换过渡效果")
|
||||||
|
await get_tree().create_timer(0.2).timeout
|
||||||
1
_Core/managers/SceneManager.gd.uid
Normal file
@@ -0,0 +1 @@
|
|||||||
|
uid://d3l286ti5gqhw
|
||||||
80
_Core/systems/EventSystem.gd
Normal file
@@ -0,0 +1,80 @@
|
|||||||
|
extends Node
|
||||||
|
|
||||||
|
# 全局事件系统 - 提供解耦的事件通信机制
|
||||||
|
# 允许不同模块之间通过事件进行通信,避免直接依赖
|
||||||
|
|
||||||
|
# 事件监听器存储
|
||||||
|
var event_listeners: Dictionary = {}
|
||||||
|
|
||||||
|
func _ready():
|
||||||
|
print("EventSystem 初始化完成")
|
||||||
|
|
||||||
|
# 注册事件监听器
|
||||||
|
func connect_event(event_name: String, callback: Callable, target: Node = null):
|
||||||
|
if not event_listeners.has(event_name):
|
||||||
|
event_listeners[event_name] = []
|
||||||
|
|
||||||
|
var listener_info = {
|
||||||
|
"callback": callback,
|
||||||
|
"target": target
|
||||||
|
}
|
||||||
|
|
||||||
|
event_listeners[event_name].append(listener_info)
|
||||||
|
print("注册事件监听器: ", event_name, " -> ", callback)
|
||||||
|
|
||||||
|
# 移除事件监听器
|
||||||
|
func disconnect_event(event_name: String, callback: Callable, target: Node = null):
|
||||||
|
if not event_listeners.has(event_name):
|
||||||
|
return
|
||||||
|
|
||||||
|
var listeners = event_listeners[event_name]
|
||||||
|
for i in range(listeners.size() - 1, -1, -1):
|
||||||
|
var listener = listeners[i]
|
||||||
|
if listener.callback == callback and listener.target == target:
|
||||||
|
listeners.remove_at(i)
|
||||||
|
print("移除事件监听器: ", event_name, " -> ", callback)
|
||||||
|
break
|
||||||
|
|
||||||
|
# 发送事件
|
||||||
|
func emit_event(event_name: String, data: Variant = null):
|
||||||
|
print("发送事件: ", event_name, " 数据: ", data)
|
||||||
|
|
||||||
|
if not event_listeners.has(event_name):
|
||||||
|
return
|
||||||
|
|
||||||
|
var listeners = event_listeners[event_name]
|
||||||
|
for listener_info in listeners:
|
||||||
|
var target = listener_info.target
|
||||||
|
var callback = listener_info.callback
|
||||||
|
|
||||||
|
# 检查目标节点是否仍然有效
|
||||||
|
if target != null and not is_instance_valid(target):
|
||||||
|
continue
|
||||||
|
|
||||||
|
# 调用回调函数
|
||||||
|
if data != null:
|
||||||
|
callback.call(data)
|
||||||
|
else:
|
||||||
|
callback.call()
|
||||||
|
|
||||||
|
# 清理无效的监听器
|
||||||
|
func cleanup_invalid_listeners():
|
||||||
|
for event_name in event_listeners.keys():
|
||||||
|
var listeners = event_listeners[event_name]
|
||||||
|
for i in range(listeners.size() - 1, -1, -1):
|
||||||
|
var listener = listeners[i]
|
||||||
|
var target = listener.target
|
||||||
|
if target != null and not is_instance_valid(target):
|
||||||
|
listeners.remove_at(i)
|
||||||
|
print("清理无效监听器: ", event_name)
|
||||||
|
|
||||||
|
# 获取事件监听器数量
|
||||||
|
func get_listener_count(event_name: String) -> int:
|
||||||
|
if not event_listeners.has(event_name):
|
||||||
|
return 0
|
||||||
|
return event_listeners[event_name].size()
|
||||||
|
|
||||||
|
# 清空所有事件监听器
|
||||||
|
func clear_all_listeners():
|
||||||
|
event_listeners.clear()
|
||||||
|
print("清空所有事件监听器")
|
||||||
1
_Core/systems/EventSystem.gd.uid
Normal file
@@ -0,0 +1 @@
|
|||||||
|
uid://bfheblucmti24
|
||||||
1
assets/audio/audio/music/.gitkeep
Normal file
@@ -0,0 +1 @@
|
|||||||
|
# 保持目录结构 - 音乐资源目录
|
||||||
1
assets/audio/audio/sounds/.gitkeep
Normal file
@@ -0,0 +1 @@
|
|||||||
|
# 保持目录结构 - 音效资源目录
|
||||||
1
assets/audio/audio/voice/.gitkeep
Normal file
@@ -0,0 +1 @@
|
|||||||
|
# 保持目录结构 - 语音资源目录
|
||||||
1
assets/audio/music/.gitkeep
Normal file
@@ -0,0 +1 @@
|
|||||||
|
# 保持目录结构 - 音乐资源目录
|
||||||
1
assets/audio/sounds/.gitkeep
Normal file
@@ -0,0 +1 @@
|
|||||||
|
# 保持目录结构 - 音效资源目录
|
||||||
1
assets/audio/voice/.gitkeep
Normal file
@@ -0,0 +1 @@
|
|||||||
|
# 保持目录结构 - 语音资源目录
|
||||||
1
assets/fonts/.gitkeep
Normal file
@@ -0,0 +1 @@
|
|||||||
|
# 保持目录结构 - 字体资源目录
|
||||||
BIN
assets/fonts/msyh.ttc
Normal file
41
assets/fonts/msyh.ttc.import
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
[remap]
|
||||||
|
|
||||||
|
importer="font_data_dynamic"
|
||||||
|
type="FontFile"
|
||||||
|
uid="uid://ce7ujbeobblyr"
|
||||||
|
path="res://.godot/imported/msyh.ttc-1f7944f6d1cff8092894a3525ec5156c.fontdata"
|
||||||
|
|
||||||
|
[deps]
|
||||||
|
|
||||||
|
source_file="res://assets/fonts/msyh.ttc"
|
||||||
|
dest_files=["res://.godot/imported/msyh.ttc-1f7944f6d1cff8092894a3525ec5156c.fontdata"]
|
||||||
|
|
||||||
|
[params]
|
||||||
|
|
||||||
|
Rendering=null
|
||||||
|
antialiasing=1
|
||||||
|
generate_mipmaps=false
|
||||||
|
disable_embedded_bitmaps=true
|
||||||
|
multichannel_signed_distance_field=false
|
||||||
|
msdf_pixel_range=8
|
||||||
|
msdf_size=48
|
||||||
|
allow_system_fallback=true
|
||||||
|
force_autohinter=false
|
||||||
|
modulate_color_glyphs=false
|
||||||
|
hinting=1
|
||||||
|
subpixel_positioning=4
|
||||||
|
keep_rounding_remainders=true
|
||||||
|
oversampling=0.0
|
||||||
|
Fallbacks=null
|
||||||
|
fallbacks=[]
|
||||||
|
Compress=null
|
||||||
|
compress=false
|
||||||
|
preload=[{
|
||||||
|
"chars": "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz!@#$%^&*()_+-=[]{}|;':\",./<>?`~一二三四五六七八九十百千万亿用户名密码登录注册验证码邮箱小镇鲸鱼欢迎来到开始你的之旅请输入不能为空获取发送忘记返回居民身份确认再次已被使用换个等待分钟后试稍后正在创建账户测试模式生成查看控制台网络连接失败系统维护中升级稍后再试频繁联系管理员禁用审核先邮箱后使用成功进入镇错误或过期未找到存在",
|
||||||
|
"glyphs": [],
|
||||||
|
"name": "Web预加载",
|
||||||
|
"size": Vector2i(16, 0)
|
||||||
|
}]
|
||||||
|
language_support={}
|
||||||
|
script_support={}
|
||||||
|
opentype_features={}
|
||||||
BIN
assets/icon/icon144.png
Normal file
|
After Width: | Height: | Size: 13 KiB |
40
assets/icon/icon144.png.import
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
[remap]
|
||||||
|
|
||||||
|
importer="texture"
|
||||||
|
type="CompressedTexture2D"
|
||||||
|
uid="uid://bwy5r7soxi76a"
|
||||||
|
path="res://.godot/imported/icon144.png-ae9d1f30a88beaab449c2cad89283dd3.ctex"
|
||||||
|
metadata={
|
||||||
|
"vram_texture": false
|
||||||
|
}
|
||||||
|
|
||||||
|
[deps]
|
||||||
|
|
||||||
|
source_file="res://assets/icon/icon144.png"
|
||||||
|
dest_files=["res://.godot/imported/icon144.png-ae9d1f30a88beaab449c2cad89283dd3.ctex"]
|
||||||
|
|
||||||
|
[params]
|
||||||
|
|
||||||
|
compress/mode=0
|
||||||
|
compress/high_quality=false
|
||||||
|
compress/lossy_quality=0.7
|
||||||
|
compress/uastc_level=0
|
||||||
|
compress/rdo_quality_loss=0.0
|
||||||
|
compress/hdr_compression=1
|
||||||
|
compress/normal_map=0
|
||||||
|
compress/channel_pack=0
|
||||||
|
mipmaps/generate=false
|
||||||
|
mipmaps/limit=-1
|
||||||
|
roughness/mode=0
|
||||||
|
roughness/src_normal=""
|
||||||
|
process/channel_remap/red=0
|
||||||
|
process/channel_remap/green=1
|
||||||
|
process/channel_remap/blue=2
|
||||||
|
process/channel_remap/alpha=3
|
||||||
|
process/fix_alpha_border=true
|
||||||
|
process/premult_alpha=false
|
||||||
|
process/normal_map_invert_y=false
|
||||||
|
process/hdr_as_srgb=false
|
||||||
|
process/hdr_clamp_exposure=false
|
||||||
|
process/size_limit=0
|
||||||
|
detect_3d/compress_to=1
|
||||||
BIN
assets/icon/icon16.png
Normal file
|
After Width: | Height: | Size: 644 B |
40
assets/icon/icon16.png.import
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
[remap]
|
||||||
|
|
||||||
|
importer="texture"
|
||||||
|
type="CompressedTexture2D"
|
||||||
|
uid="uid://bqg5e8qn1j74u"
|
||||||
|
path="res://.godot/imported/icon16.png-3099ad8a609f90c382508b9c073ffd76.ctex"
|
||||||
|
metadata={
|
||||||
|
"vram_texture": false
|
||||||
|
}
|
||||||
|
|
||||||
|
[deps]
|
||||||
|
|
||||||
|
source_file="res://assets/icon/icon16.png"
|
||||||
|
dest_files=["res://.godot/imported/icon16.png-3099ad8a609f90c382508b9c073ffd76.ctex"]
|
||||||
|
|
||||||
|
[params]
|
||||||
|
|
||||||
|
compress/mode=0
|
||||||
|
compress/high_quality=false
|
||||||
|
compress/lossy_quality=0.7
|
||||||
|
compress/uastc_level=0
|
||||||
|
compress/rdo_quality_loss=0.0
|
||||||
|
compress/hdr_compression=1
|
||||||
|
compress/normal_map=0
|
||||||
|
compress/channel_pack=0
|
||||||
|
mipmaps/generate=false
|
||||||
|
mipmaps/limit=-1
|
||||||
|
roughness/mode=0
|
||||||
|
roughness/src_normal=""
|
||||||
|
process/channel_remap/red=0
|
||||||
|
process/channel_remap/green=1
|
||||||
|
process/channel_remap/blue=2
|
||||||
|
process/channel_remap/alpha=3
|
||||||
|
process/fix_alpha_border=true
|
||||||
|
process/premult_alpha=false
|
||||||
|
process/normal_map_invert_y=false
|
||||||
|
process/hdr_as_srgb=false
|
||||||
|
process/hdr_clamp_exposure=false
|
||||||
|
process/size_limit=0
|
||||||
|
detect_3d/compress_to=1
|
||||||
BIN
assets/icon/icon180.png
Normal file
|
After Width: | Height: | Size: 18 KiB |
40
assets/icon/icon180.png.import
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
[remap]
|
||||||
|
|
||||||
|
importer="texture"
|
||||||
|
type="CompressedTexture2D"
|
||||||
|
uid="uid://drpllpsjdiaex"
|
||||||
|
path="res://.godot/imported/icon180.png-20a9d7b98bfb315dd470e3635f315a17.ctex"
|
||||||
|
metadata={
|
||||||
|
"vram_texture": false
|
||||||
|
}
|
||||||
|
|
||||||
|
[deps]
|
||||||
|
|
||||||
|
source_file="res://assets/icon/icon180.png"
|
||||||
|
dest_files=["res://.godot/imported/icon180.png-20a9d7b98bfb315dd470e3635f315a17.ctex"]
|
||||||
|
|
||||||
|
[params]
|
||||||
|
|
||||||
|
compress/mode=0
|
||||||
|
compress/high_quality=false
|
||||||
|
compress/lossy_quality=0.7
|
||||||
|
compress/uastc_level=0
|
||||||
|
compress/rdo_quality_loss=0.0
|
||||||
|
compress/hdr_compression=1
|
||||||
|
compress/normal_map=0
|
||||||
|
compress/channel_pack=0
|
||||||
|
mipmaps/generate=false
|
||||||
|
mipmaps/limit=-1
|
||||||
|
roughness/mode=0
|
||||||
|
roughness/src_normal=""
|
||||||
|
process/channel_remap/red=0
|
||||||
|
process/channel_remap/green=1
|
||||||
|
process/channel_remap/blue=2
|
||||||
|
process/channel_remap/alpha=3
|
||||||
|
process/fix_alpha_border=true
|
||||||
|
process/premult_alpha=false
|
||||||
|
process/normal_map_invert_y=false
|
||||||
|
process/hdr_as_srgb=false
|
||||||
|
process/hdr_clamp_exposure=false
|
||||||
|
process/size_limit=0
|
||||||
|
detect_3d/compress_to=1
|
||||||
BIN
assets/icon/icon32.png
Normal file
|
After Width: | Height: | Size: 1.7 KiB |
40
assets/icon/icon32.png.import
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
[remap]
|
||||||
|
|
||||||
|
importer="texture"
|
||||||
|
type="CompressedTexture2D"
|
||||||
|
uid="uid://dt24j6p0cijqo"
|
||||||
|
path="res://.godot/imported/icon32.png-9a0aceb23d191139c34540a188bf8c91.ctex"
|
||||||
|
metadata={
|
||||||
|
"vram_texture": false
|
||||||
|
}
|
||||||
|
|
||||||
|
[deps]
|
||||||
|
|
||||||
|
source_file="res://assets/icon/icon32.png"
|
||||||
|
dest_files=["res://.godot/imported/icon32.png-9a0aceb23d191139c34540a188bf8c91.ctex"]
|
||||||
|
|
||||||
|
[params]
|
||||||
|
|
||||||
|
compress/mode=0
|
||||||
|
compress/high_quality=false
|
||||||
|
compress/lossy_quality=0.7
|
||||||
|
compress/uastc_level=0
|
||||||
|
compress/rdo_quality_loss=0.0
|
||||||
|
compress/hdr_compression=1
|
||||||
|
compress/normal_map=0
|
||||||
|
compress/channel_pack=0
|
||||||
|
mipmaps/generate=false
|
||||||
|
mipmaps/limit=-1
|
||||||
|
roughness/mode=0
|
||||||
|
roughness/src_normal=""
|
||||||
|
process/channel_remap/red=0
|
||||||
|
process/channel_remap/green=1
|
||||||
|
process/channel_remap/blue=2
|
||||||
|
process/channel_remap/alpha=3
|
||||||
|
process/fix_alpha_border=true
|
||||||
|
process/premult_alpha=false
|
||||||
|
process/normal_map_invert_y=false
|
||||||
|
process/hdr_as_srgb=false
|
||||||
|
process/hdr_clamp_exposure=false
|
||||||
|
process/size_limit=0
|
||||||
|
detect_3d/compress_to=1
|
||||||
BIN
assets/icon/icon512.png
Normal file
|
After Width: | Height: | Size: 78 KiB |
40
assets/icon/icon512.png.import
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
[remap]
|
||||||
|
|
||||||
|
importer="texture"
|
||||||
|
type="CompressedTexture2D"
|
||||||
|
uid="uid://dt817lem3dwee"
|
||||||
|
path="res://.godot/imported/icon512.png-1c1c4b424489de87a542c89bec6eb15b.ctex"
|
||||||
|
metadata={
|
||||||
|
"vram_texture": false
|
||||||
|
}
|
||||||
|
|
||||||
|
[deps]
|
||||||
|
|
||||||
|
source_file="res://assets/icon/icon512.png"
|
||||||
|
dest_files=["res://.godot/imported/icon512.png-1c1c4b424489de87a542c89bec6eb15b.ctex"]
|
||||||
|
|
||||||
|
[params]
|
||||||
|
|
||||||
|
compress/mode=0
|
||||||
|
compress/high_quality=false
|
||||||
|
compress/lossy_quality=0.7
|
||||||
|
compress/uastc_level=0
|
||||||
|
compress/rdo_quality_loss=0.0
|
||||||
|
compress/hdr_compression=1
|
||||||
|
compress/normal_map=0
|
||||||
|
compress/channel_pack=0
|
||||||
|
mipmaps/generate=false
|
||||||
|
mipmaps/limit=-1
|
||||||
|
roughness/mode=0
|
||||||
|
roughness/src_normal=""
|
||||||
|
process/channel_remap/red=0
|
||||||
|
process/channel_remap/green=1
|
||||||
|
process/channel_remap/blue=2
|
||||||
|
process/channel_remap/alpha=3
|
||||||
|
process/fix_alpha_border=true
|
||||||
|
process/premult_alpha=false
|
||||||
|
process/normal_map_invert_y=false
|
||||||
|
process/hdr_as_srgb=false
|
||||||
|
process/hdr_clamp_exposure=false
|
||||||
|
process/size_limit=0
|
||||||
|
detect_3d/compress_to=1
|
||||||
BIN
assets/icon/icon64.png
Normal file
|
After Width: | Height: | Size: 4.5 KiB |
40
assets/icon/icon64.png.import
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
[remap]
|
||||||
|
|
||||||
|
importer="texture"
|
||||||
|
type="CompressedTexture2D"
|
||||||
|
uid="uid://ci42rd5qe6icl"
|
||||||
|
path="res://.godot/imported/icon64.png-da8a1a20e3bf4dcf06c8ff6c558caaff.ctex"
|
||||||
|
metadata={
|
||||||
|
"vram_texture": false
|
||||||
|
}
|
||||||
|
|
||||||
|
[deps]
|
||||||
|
|
||||||
|
source_file="res://assets/icon/icon64.png"
|
||||||
|
dest_files=["res://.godot/imported/icon64.png-da8a1a20e3bf4dcf06c8ff6c558caaff.ctex"]
|
||||||
|
|
||||||
|
[params]
|
||||||
|
|
||||||
|
compress/mode=0
|
||||||
|
compress/high_quality=false
|
||||||
|
compress/lossy_quality=0.7
|
||||||
|
compress/uastc_level=0
|
||||||
|
compress/rdo_quality_loss=0.0
|
||||||
|
compress/hdr_compression=1
|
||||||
|
compress/normal_map=0
|
||||||
|
compress/channel_pack=0
|
||||||
|
mipmaps/generate=false
|
||||||
|
mipmaps/limit=-1
|
||||||
|
roughness/mode=0
|
||||||
|
roughness/src_normal=""
|
||||||
|
process/channel_remap/red=0
|
||||||
|
process/channel_remap/green=1
|
||||||
|
process/channel_remap/blue=2
|
||||||
|
process/channel_remap/alpha=3
|
||||||
|
process/fix_alpha_border=true
|
||||||
|
process/premult_alpha=false
|
||||||
|
process/normal_map_invert_y=false
|
||||||
|
process/hdr_as_srgb=false
|
||||||
|
process/hdr_clamp_exposure=false
|
||||||
|
process/size_limit=0
|
||||||
|
detect_3d/compress_to=1
|
||||||
BIN
assets/icon/image(1).png
Normal file
|
After Width: | Height: | Size: 150 KiB |
40
assets/icon/image(1).png.import
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
[remap]
|
||||||
|
|
||||||
|
importer="texture"
|
||||||
|
type="CompressedTexture2D"
|
||||||
|
uid="uid://cnw6e3wmy0ea4"
|
||||||
|
path="res://.godot/imported/image(1).png-c89cc92103e50aaba40bf38c797be77f.ctex"
|
||||||
|
metadata={
|
||||||
|
"vram_texture": false
|
||||||
|
}
|
||||||
|
|
||||||
|
[deps]
|
||||||
|
|
||||||
|
source_file="res://assets/icon/image(1).png"
|
||||||
|
dest_files=["res://.godot/imported/image(1).png-c89cc92103e50aaba40bf38c797be77f.ctex"]
|
||||||
|
|
||||||
|
[params]
|
||||||
|
|
||||||
|
compress/mode=0
|
||||||
|
compress/high_quality=false
|
||||||
|
compress/lossy_quality=0.7
|
||||||
|
compress/uastc_level=0
|
||||||
|
compress/rdo_quality_loss=0.0
|
||||||
|
compress/hdr_compression=1
|
||||||
|
compress/normal_map=0
|
||||||
|
compress/channel_pack=0
|
||||||
|
mipmaps/generate=false
|
||||||
|
mipmaps/limit=-1
|
||||||
|
roughness/mode=0
|
||||||
|
roughness/src_normal=""
|
||||||
|
process/channel_remap/red=0
|
||||||
|
process/channel_remap/green=1
|
||||||
|
process/channel_remap/blue=2
|
||||||
|
process/channel_remap/alpha=3
|
||||||
|
process/fix_alpha_border=true
|
||||||
|
process/premult_alpha=false
|
||||||
|
process/normal_map_invert_y=false
|
||||||
|
process/hdr_as_srgb=false
|
||||||
|
process/hdr_clamp_exposure=false
|
||||||
|
process/size_limit=0
|
||||||
|
detect_3d/compress_to=1
|
||||||
BIN
assets/icon/image.png
Normal file
|
After Width: | Height: | Size: 91 KiB |
40
assets/icon/image.png.import
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
[remap]
|
||||||
|
|
||||||
|
importer="texture"
|
||||||
|
type="CompressedTexture2D"
|
||||||
|
uid="uid://c7v22i1hgo1x6"
|
||||||
|
path="res://.godot/imported/image.png-3f16548595ba9fb08c5e50ef3251d148.ctex"
|
||||||
|
metadata={
|
||||||
|
"vram_texture": false
|
||||||
|
}
|
||||||
|
|
||||||
|
[deps]
|
||||||
|
|
||||||
|
source_file="res://assets/icon/image.png"
|
||||||
|
dest_files=["res://.godot/imported/image.png-3f16548595ba9fb08c5e50ef3251d148.ctex"]
|
||||||
|
|
||||||
|
[params]
|
||||||
|
|
||||||
|
compress/mode=0
|
||||||
|
compress/high_quality=false
|
||||||
|
compress/lossy_quality=0.7
|
||||||
|
compress/uastc_level=0
|
||||||
|
compress/rdo_quality_loss=0.0
|
||||||
|
compress/hdr_compression=1
|
||||||
|
compress/normal_map=0
|
||||||
|
compress/channel_pack=0
|
||||||
|
mipmaps/generate=false
|
||||||
|
mipmaps/limit=-1
|
||||||
|
roughness/mode=0
|
||||||
|
roughness/src_normal=""
|
||||||
|
process/channel_remap/red=0
|
||||||
|
process/channel_remap/green=1
|
||||||
|
process/channel_remap/blue=2
|
||||||
|
process/channel_remap/alpha=3
|
||||||
|
process/fix_alpha_border=true
|
||||||
|
process/premult_alpha=false
|
||||||
|
process/normal_map_invert_y=false
|
||||||
|
process/hdr_as_srgb=false
|
||||||
|
process/hdr_clamp_exposure=false
|
||||||
|
process/size_limit=0
|
||||||
|
detect_3d/compress_to=1
|
||||||
1
assets/materials/.gitkeep
Normal file
@@ -0,0 +1 @@
|
|||||||
|
# 保持目录结构 - 材质资源目录
|
||||||
1
assets/shaders/.gitkeep
Normal file
@@ -0,0 +1 @@
|
|||||||
|
# 保持目录结构 - 着色器资源目录
|
||||||
1
assets/sprites/characters/.gitkeep
Normal file
@@ -0,0 +1 @@
|
|||||||
|
# 保持目录结构 - 角色精灵资源目录
|
||||||
1
assets/sprites/effects/.gitkeep
Normal file
@@ -0,0 +1 @@
|
|||||||
|
# 保持目录结构 - 特效精灵资源目录
|
||||||
1
assets/sprites/environment/.gitkeep
Normal file
@@ -0,0 +1 @@
|
|||||||
|
# 保持目录结构 - 环境精灵资源目录
|
||||||
BIN
assets/sprites/icon/icon144.png
Normal file
|
After Width: | Height: | Size: 13 KiB |
40
assets/sprites/icon/icon144.png.import
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
[remap]
|
||||||
|
|
||||||
|
importer="texture"
|
||||||
|
type="CompressedTexture2D"
|
||||||
|
uid="uid://bwy5r7soxi76a"
|
||||||
|
path="res://.godot/imported/icon144.png-27a33b914815b6d4af200572bfdaa6ff.ctex"
|
||||||
|
metadata={
|
||||||
|
"vram_texture": false
|
||||||
|
}
|
||||||
|
|
||||||
|
[deps]
|
||||||
|
|
||||||
|
source_file="res://assets/sprites/icon/icon144.png"
|
||||||
|
dest_files=["res://.godot/imported/icon144.png-27a33b914815b6d4af200572bfdaa6ff.ctex"]
|
||||||
|
|
||||||
|
[params]
|
||||||
|
|
||||||
|
compress/mode=0
|
||||||
|
compress/high_quality=false
|
||||||
|
compress/lossy_quality=0.7
|
||||||
|
compress/uastc_level=0
|
||||||
|
compress/rdo_quality_loss=0.0
|
||||||
|
compress/hdr_compression=1
|
||||||
|
compress/normal_map=0
|
||||||
|
compress/channel_pack=0
|
||||||
|
mipmaps/generate=false
|
||||||
|
mipmaps/limit=-1
|
||||||
|
roughness/mode=0
|
||||||
|
roughness/src_normal=""
|
||||||
|
process/channel_remap/red=0
|
||||||
|
process/channel_remap/green=1
|
||||||
|
process/channel_remap/blue=2
|
||||||
|
process/channel_remap/alpha=3
|
||||||
|
process/fix_alpha_border=true
|
||||||
|
process/premult_alpha=false
|
||||||
|
process/normal_map_invert_y=false
|
||||||
|
process/hdr_as_srgb=false
|
||||||
|
process/hdr_clamp_exposure=false
|
||||||
|
process/size_limit=0
|
||||||
|
detect_3d/compress_to=1
|
||||||
BIN
assets/sprites/icon/icon16.png
Normal file
|
After Width: | Height: | Size: 644 B |
40
assets/sprites/icon/icon16.png.import
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
[remap]
|
||||||
|
|
||||||
|
importer="texture"
|
||||||
|
type="CompressedTexture2D"
|
||||||
|
uid="uid://bqg5e8qn1j74u"
|
||||||
|
path="res://.godot/imported/icon16.png-7cdae0838b274bb32361bfaa80a42a0f.ctex"
|
||||||
|
metadata={
|
||||||
|
"vram_texture": false
|
||||||
|
}
|
||||||
|
|
||||||
|
[deps]
|
||||||
|
|
||||||
|
source_file="res://assets/sprites/icon/icon16.png"
|
||||||
|
dest_files=["res://.godot/imported/icon16.png-7cdae0838b274bb32361bfaa80a42a0f.ctex"]
|
||||||
|
|
||||||
|
[params]
|
||||||
|
|
||||||
|
compress/mode=0
|
||||||
|
compress/high_quality=false
|
||||||
|
compress/lossy_quality=0.7
|
||||||
|
compress/uastc_level=0
|
||||||
|
compress/rdo_quality_loss=0.0
|
||||||
|
compress/hdr_compression=1
|
||||||
|
compress/normal_map=0
|
||||||
|
compress/channel_pack=0
|
||||||
|
mipmaps/generate=false
|
||||||
|
mipmaps/limit=-1
|
||||||
|
roughness/mode=0
|
||||||
|
roughness/src_normal=""
|
||||||
|
process/channel_remap/red=0
|
||||||
|
process/channel_remap/green=1
|
||||||
|
process/channel_remap/blue=2
|
||||||
|
process/channel_remap/alpha=3
|
||||||
|
process/fix_alpha_border=true
|
||||||
|
process/premult_alpha=false
|
||||||
|
process/normal_map_invert_y=false
|
||||||
|
process/hdr_as_srgb=false
|
||||||
|
process/hdr_clamp_exposure=false
|
||||||
|
process/size_limit=0
|
||||||
|
detect_3d/compress_to=1
|
||||||
BIN
assets/sprites/icon/icon180.png
Normal file
|
After Width: | Height: | Size: 18 KiB |
40
assets/sprites/icon/icon180.png.import
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
[remap]
|
||||||
|
|
||||||
|
importer="texture"
|
||||||
|
type="CompressedTexture2D"
|
||||||
|
uid="uid://drpllpsjdiaex"
|
||||||
|
path="res://.godot/imported/icon180.png-1d6fc41d452b1d5b5b66c12dbeb9a657.ctex"
|
||||||
|
metadata={
|
||||||
|
"vram_texture": false
|
||||||
|
}
|
||||||
|
|
||||||
|
[deps]
|
||||||
|
|
||||||
|
source_file="res://assets/sprites/icon/icon180.png"
|
||||||
|
dest_files=["res://.godot/imported/icon180.png-1d6fc41d452b1d5b5b66c12dbeb9a657.ctex"]
|
||||||
|
|
||||||
|
[params]
|
||||||
|
|
||||||
|
compress/mode=0
|
||||||
|
compress/high_quality=false
|
||||||
|
compress/lossy_quality=0.7
|
||||||
|
compress/uastc_level=0
|
||||||
|
compress/rdo_quality_loss=0.0
|
||||||
|
compress/hdr_compression=1
|
||||||
|
compress/normal_map=0
|
||||||
|
compress/channel_pack=0
|
||||||
|
mipmaps/generate=false
|
||||||
|
mipmaps/limit=-1
|
||||||
|
roughness/mode=0
|
||||||
|
roughness/src_normal=""
|
||||||
|
process/channel_remap/red=0
|
||||||
|
process/channel_remap/green=1
|
||||||
|
process/channel_remap/blue=2
|
||||||
|
process/channel_remap/alpha=3
|
||||||
|
process/fix_alpha_border=true
|
||||||
|
process/premult_alpha=false
|
||||||
|
process/normal_map_invert_y=false
|
||||||
|
process/hdr_as_srgb=false
|
||||||
|
process/hdr_clamp_exposure=false
|
||||||
|
process/size_limit=0
|
||||||
|
detect_3d/compress_to=1
|
||||||
BIN
assets/sprites/icon/icon32.png
Normal file
|
After Width: | Height: | Size: 1.7 KiB |
40
assets/sprites/icon/icon32.png.import
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
[remap]
|
||||||
|
|
||||||
|
importer="texture"
|
||||||
|
type="CompressedTexture2D"
|
||||||
|
uid="uid://dt24j6p0cijqo"
|
||||||
|
path="res://.godot/imported/icon32.png-d677605f61a2a3a87d4018004b1f6aa4.ctex"
|
||||||
|
metadata={
|
||||||
|
"vram_texture": false
|
||||||
|
}
|
||||||
|
|
||||||
|
[deps]
|
||||||
|
|
||||||
|
source_file="res://assets/sprites/icon/icon32.png"
|
||||||
|
dest_files=["res://.godot/imported/icon32.png-d677605f61a2a3a87d4018004b1f6aa4.ctex"]
|
||||||
|
|
||||||
|
[params]
|
||||||
|
|
||||||
|
compress/mode=0
|
||||||
|
compress/high_quality=false
|
||||||
|
compress/lossy_quality=0.7
|
||||||
|
compress/uastc_level=0
|
||||||
|
compress/rdo_quality_loss=0.0
|
||||||
|
compress/hdr_compression=1
|
||||||
|
compress/normal_map=0
|
||||||
|
compress/channel_pack=0
|
||||||
|
mipmaps/generate=false
|
||||||
|
mipmaps/limit=-1
|
||||||
|
roughness/mode=0
|
||||||
|
roughness/src_normal=""
|
||||||
|
process/channel_remap/red=0
|
||||||
|
process/channel_remap/green=1
|
||||||
|
process/channel_remap/blue=2
|
||||||
|
process/channel_remap/alpha=3
|
||||||
|
process/fix_alpha_border=true
|
||||||
|
process/premult_alpha=false
|
||||||
|
process/normal_map_invert_y=false
|
||||||
|
process/hdr_as_srgb=false
|
||||||
|
process/hdr_clamp_exposure=false
|
||||||
|
process/size_limit=0
|
||||||
|
detect_3d/compress_to=1
|
||||||
BIN
assets/sprites/icon/icon512.png
Normal file
|
After Width: | Height: | Size: 78 KiB |
40
assets/sprites/icon/icon512.png.import
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
[remap]
|
||||||
|
|
||||||
|
importer="texture"
|
||||||
|
type="CompressedTexture2D"
|
||||||
|
uid="uid://dt817lem3dwee"
|
||||||
|
path="res://.godot/imported/icon512.png-5f7b6d37423049879d2db9cc5a9126f5.ctex"
|
||||||
|
metadata={
|
||||||
|
"vram_texture": false
|
||||||
|
}
|
||||||
|
|
||||||
|
[deps]
|
||||||
|
|
||||||
|
source_file="res://assets/sprites/icon/icon512.png"
|
||||||
|
dest_files=["res://.godot/imported/icon512.png-5f7b6d37423049879d2db9cc5a9126f5.ctex"]
|
||||||
|
|
||||||
|
[params]
|
||||||
|
|
||||||
|
compress/mode=0
|
||||||
|
compress/high_quality=false
|
||||||
|
compress/lossy_quality=0.7
|
||||||
|
compress/uastc_level=0
|
||||||
|
compress/rdo_quality_loss=0.0
|
||||||
|
compress/hdr_compression=1
|
||||||
|
compress/normal_map=0
|
||||||
|
compress/channel_pack=0
|
||||||
|
mipmaps/generate=false
|
||||||
|
mipmaps/limit=-1
|
||||||
|
roughness/mode=0
|
||||||
|
roughness/src_normal=""
|
||||||
|
process/channel_remap/red=0
|
||||||
|
process/channel_remap/green=1
|
||||||
|
process/channel_remap/blue=2
|
||||||
|
process/channel_remap/alpha=3
|
||||||
|
process/fix_alpha_border=true
|
||||||
|
process/premult_alpha=false
|
||||||
|
process/normal_map_invert_y=false
|
||||||
|
process/hdr_as_srgb=false
|
||||||
|
process/hdr_clamp_exposure=false
|
||||||
|
process/size_limit=0
|
||||||
|
detect_3d/compress_to=1
|
||||||
BIN
assets/sprites/icon/icon64.png
Normal file
|
After Width: | Height: | Size: 4.5 KiB |
40
assets/sprites/icon/icon64.png.import
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
[remap]
|
||||||
|
|
||||||
|
importer="texture"
|
||||||
|
type="CompressedTexture2D"
|
||||||
|
uid="uid://ci42rd5qe6icl"
|
||||||
|
path="res://.godot/imported/icon64.png-e3684ecc6e07cbb7b0527f9c18c4431a.ctex"
|
||||||
|
metadata={
|
||||||
|
"vram_texture": false
|
||||||
|
}
|
||||||
|
|
||||||
|
[deps]
|
||||||
|
|
||||||
|
source_file="res://assets/sprites/icon/icon64.png"
|
||||||
|
dest_files=["res://.godot/imported/icon64.png-e3684ecc6e07cbb7b0527f9c18c4431a.ctex"]
|
||||||
|
|
||||||
|
[params]
|
||||||
|
|
||||||
|
compress/mode=0
|
||||||
|
compress/high_quality=false
|
||||||
|
compress/lossy_quality=0.7
|
||||||
|
compress/uastc_level=0
|
||||||
|
compress/rdo_quality_loss=0.0
|
||||||
|
compress/hdr_compression=1
|
||||||
|
compress/normal_map=0
|
||||||
|
compress/channel_pack=0
|
||||||
|
mipmaps/generate=false
|
||||||
|
mipmaps/limit=-1
|
||||||
|
roughness/mode=0
|
||||||
|
roughness/src_normal=""
|
||||||
|
process/channel_remap/red=0
|
||||||
|
process/channel_remap/green=1
|
||||||
|
process/channel_remap/blue=2
|
||||||
|
process/channel_remap/alpha=3
|
||||||
|
process/fix_alpha_border=true
|
||||||
|
process/premult_alpha=false
|
||||||
|
process/normal_map_invert_y=false
|
||||||
|
process/hdr_as_srgb=false
|
||||||
|
process/hdr_clamp_exposure=false
|
||||||
|
process/size_limit=0
|
||||||
|
detect_3d/compress_to=1
|
||||||
BIN
assets/sprites/icon/image(1).png
Normal file
|
After Width: | Height: | Size: 150 KiB |
40
assets/sprites/icon/image(1).png.import
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
[remap]
|
||||||
|
|
||||||
|
importer="texture"
|
||||||
|
type="CompressedTexture2D"
|
||||||
|
uid="uid://cnw6e3wmy0ea4"
|
||||||
|
path="res://.godot/imported/image(1).png-14ccba2bcca2f261c1c009e0a9e237f6.ctex"
|
||||||
|
metadata={
|
||||||
|
"vram_texture": false
|
||||||
|
}
|
||||||
|
|
||||||
|
[deps]
|
||||||
|
|
||||||
|
source_file="res://assets/sprites/icon/image(1).png"
|
||||||
|
dest_files=["res://.godot/imported/image(1).png-14ccba2bcca2f261c1c009e0a9e237f6.ctex"]
|
||||||
|
|
||||||
|
[params]
|
||||||
|
|
||||||
|
compress/mode=0
|
||||||
|
compress/high_quality=false
|
||||||
|
compress/lossy_quality=0.7
|
||||||
|
compress/uastc_level=0
|
||||||
|
compress/rdo_quality_loss=0.0
|
||||||
|
compress/hdr_compression=1
|
||||||
|
compress/normal_map=0
|
||||||
|
compress/channel_pack=0
|
||||||
|
mipmaps/generate=false
|
||||||
|
mipmaps/limit=-1
|
||||||
|
roughness/mode=0
|
||||||
|
roughness/src_normal=""
|
||||||
|
process/channel_remap/red=0
|
||||||
|
process/channel_remap/green=1
|
||||||
|
process/channel_remap/blue=2
|
||||||
|
process/channel_remap/alpha=3
|
||||||
|
process/fix_alpha_border=true
|
||||||
|
process/premult_alpha=false
|
||||||
|
process/normal_map_invert_y=false
|
||||||
|
process/hdr_as_srgb=false
|
||||||
|
process/hdr_clamp_exposure=false
|
||||||
|
process/size_limit=0
|
||||||
|
detect_3d/compress_to=1
|
||||||
BIN
assets/sprites/icon/image.png
Normal file
|
After Width: | Height: | Size: 91 KiB |
40
assets/sprites/icon/image.png.import
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
[remap]
|
||||||
|
|
||||||
|
importer="texture"
|
||||||
|
type="CompressedTexture2D"
|
||||||
|
uid="uid://c7v22i1hgo1x6"
|
||||||
|
path="res://.godot/imported/image.png-409a48a8fb5774839179f1fee74603d2.ctex"
|
||||||
|
metadata={
|
||||||
|
"vram_texture": false
|
||||||
|
}
|
||||||
|
|
||||||
|
[deps]
|
||||||
|
|
||||||
|
source_file="res://assets/sprites/icon/image.png"
|
||||||
|
dest_files=["res://.godot/imported/image.png-409a48a8fb5774839179f1fee74603d2.ctex"]
|
||||||
|
|
||||||
|
[params]
|
||||||
|
|
||||||
|
compress/mode=0
|
||||||
|
compress/high_quality=false
|
||||||
|
compress/lossy_quality=0.7
|
||||||
|
compress/uastc_level=0
|
||||||
|
compress/rdo_quality_loss=0.0
|
||||||
|
compress/hdr_compression=1
|
||||||
|
compress/normal_map=0
|
||||||
|
compress/channel_pack=0
|
||||||
|
mipmaps/generate=false
|
||||||
|
mipmaps/limit=-1
|
||||||
|
roughness/mode=0
|
||||||
|
roughness/src_normal=""
|
||||||
|
process/channel_remap/red=0
|
||||||
|
process/channel_remap/green=1
|
||||||
|
process/channel_remap/blue=2
|
||||||
|
process/channel_remap/alpha=3
|
||||||
|
process/fix_alpha_border=true
|
||||||
|
process/premult_alpha=false
|
||||||
|
process/normal_map_invert_y=false
|
||||||
|
process/hdr_as_srgb=false
|
||||||
|
process/hdr_clamp_exposure=false
|
||||||
|
process/size_limit=0
|
||||||
|
detect_3d/compress_to=1
|
||||||
1
assets/sprites/materials/.gitkeep
Normal file
@@ -0,0 +1 @@
|
|||||||
|
# 保持目录结构 - 材质资源目录
|
||||||
1
assets/sprites/shaders/.gitkeep
Normal file
@@ -0,0 +1 @@
|
|||||||
|
# 保持目录结构 - 着色器资源目录
|
||||||
1
assets/sprites/sprites/characters/.gitkeep
Normal file
@@ -0,0 +1 @@
|
|||||||
|
# 保持目录结构 - 角色精灵资源目录
|
||||||
1
assets/sprites/sprites/effects/.gitkeep
Normal file
@@ -0,0 +1 @@
|
|||||||
|
# 保持目录结构 - 特效精灵资源目录
|
||||||
1
assets/sprites/sprites/environment/.gitkeep
Normal file
@@ -0,0 +1 @@
|
|||||||
|
# 保持目录结构 - 环境精灵资源目录
|
||||||
BIN
assets/ui/auth/bg_auth_scene.png
Normal file
|
After Width: | Height: | Size: 5.7 MiB |
40
assets/ui/auth/bg_auth_scene.png.import
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
[remap]
|
||||||
|
|
||||||
|
importer="texture"
|
||||||
|
type="CompressedTexture2D"
|
||||||
|
uid="uid://bx17oy8lvaca4"
|
||||||
|
path="res://.godot/imported/bg_auth_scene.png-818065fcc20397e855c75507c1313623.ctex"
|
||||||
|
metadata={
|
||||||
|
"vram_texture": false
|
||||||
|
}
|
||||||
|
|
||||||
|
[deps]
|
||||||
|
|
||||||
|
source_file="res://assets/ui/auth/bg_auth_scene.png"
|
||||||
|
dest_files=["res://.godot/imported/bg_auth_scene.png-818065fcc20397e855c75507c1313623.ctex"]
|
||||||
|
|
||||||
|
[params]
|
||||||
|
|
||||||
|
compress/mode=0
|
||||||
|
compress/high_quality=false
|
||||||
|
compress/lossy_quality=0.7
|
||||||
|
compress/uastc_level=0
|
||||||
|
compress/rdo_quality_loss=0.0
|
||||||
|
compress/hdr_compression=1
|
||||||
|
compress/normal_map=0
|
||||||
|
compress/channel_pack=0
|
||||||
|
mipmaps/generate=false
|
||||||
|
mipmaps/limit=-1
|
||||||
|
roughness/mode=0
|
||||||
|
roughness/src_normal=""
|
||||||
|
process/channel_remap/red=0
|
||||||
|
process/channel_remap/green=1
|
||||||
|
process/channel_remap/blue=2
|
||||||
|
process/channel_remap/alpha=3
|
||||||
|
process/fix_alpha_border=true
|
||||||
|
process/premult_alpha=false
|
||||||
|
process/normal_map_invert_y=false
|
||||||
|
process/hdr_as_srgb=false
|
||||||
|
process/hdr_clamp_exposure=false
|
||||||
|
process/size_limit=0
|
||||||
|
detect_3d/compress_to=1
|
||||||
BIN
assets/ui/auth/login_frame_smart_transparent.png
Normal file
|
After Width: | Height: | Size: 587 KiB |
40
assets/ui/auth/login_frame_smart_transparent.png.import
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
[remap]
|
||||||
|
|
||||||
|
importer="texture"
|
||||||
|
type="CompressedTexture2D"
|
||||||
|
uid="uid://de4q4s1gxivtf"
|
||||||
|
path="res://.godot/imported/login_frame_smart_transparent.png-e5d0fd05b4713ddd3beae8223f2abb80.ctex"
|
||||||
|
metadata={
|
||||||
|
"vram_texture": false
|
||||||
|
}
|
||||||
|
|
||||||
|
[deps]
|
||||||
|
|
||||||
|
source_file="res://assets/ui/auth/login_frame_smart_transparent.png"
|
||||||
|
dest_files=["res://.godot/imported/login_frame_smart_transparent.png-e5d0fd05b4713ddd3beae8223f2abb80.ctex"]
|
||||||
|
|
||||||
|
[params]
|
||||||
|
|
||||||
|
compress/mode=0
|
||||||
|
compress/high_quality=false
|
||||||
|
compress/lossy_quality=0.7
|
||||||
|
compress/uastc_level=0
|
||||||
|
compress/rdo_quality_loss=0.0
|
||||||
|
compress/hdr_compression=1
|
||||||
|
compress/normal_map=0
|
||||||
|
compress/channel_pack=0
|
||||||
|
mipmaps/generate=false
|
||||||
|
mipmaps/limit=-1
|
||||||
|
roughness/mode=0
|
||||||
|
roughness/src_normal=""
|
||||||
|
process/channel_remap/red=0
|
||||||
|
process/channel_remap/green=1
|
||||||
|
process/channel_remap/blue=2
|
||||||
|
process/channel_remap/alpha=3
|
||||||
|
process/fix_alpha_border=true
|
||||||
|
process/premult_alpha=false
|
||||||
|
process/normal_map_invert_y=false
|
||||||
|
process/hdr_as_srgb=false
|
||||||
|
process/hdr_clamp_exposure=false
|
||||||
|
process/size_limit=0
|
||||||
|
detect_3d/compress_to=1
|
||||||
7
assets/ui/chinese_theme.tres
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
[gd_resource type="Theme" load_steps=2 format=3 uid="uid://cp7t8tu7rmyad"]
|
||||||
|
|
||||||
|
[ext_resource type="FontFile" uid="uid://ce7ujbeobblyr" path="res://assets/fonts/msyh.ttc" id="1_ftb5w"]
|
||||||
|
|
||||||
|
[resource]
|
||||||
|
resource_local_to_scene = true
|
||||||
|
default_font = ExtResource("1_ftb5w")
|
||||||
BIN
assets/ui/datawhale_logo.png
Normal file
|
After Width: | Height: | Size: 6.7 KiB |
40
assets/ui/datawhale_logo.png.import
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
[remap]
|
||||||
|
|
||||||
|
importer="texture"
|
||||||
|
type="CompressedTexture2D"
|
||||||
|
uid="uid://gr7vud1lee4m"
|
||||||
|
path="res://.godot/imported/datawhale_logo.png-ddb5e2c04419eb84cfa8605bcbf64fbd.ctex"
|
||||||
|
metadata={
|
||||||
|
"vram_texture": false
|
||||||
|
}
|
||||||
|
|
||||||
|
[deps]
|
||||||
|
|
||||||
|
source_file="res://assets/ui/datawhale_logo.png"
|
||||||
|
dest_files=["res://.godot/imported/datawhale_logo.png-ddb5e2c04419eb84cfa8605bcbf64fbd.ctex"]
|
||||||
|
|
||||||
|
[params]
|
||||||
|
|
||||||
|
compress/mode=0
|
||||||
|
compress/high_quality=false
|
||||||
|
compress/lossy_quality=0.7
|
||||||
|
compress/uastc_level=0
|
||||||
|
compress/rdo_quality_loss=0.0
|
||||||
|
compress/hdr_compression=1
|
||||||
|
compress/normal_map=0
|
||||||
|
compress/channel_pack=0
|
||||||
|
mipmaps/generate=false
|
||||||
|
mipmaps/limit=-1
|
||||||
|
roughness/mode=0
|
||||||
|
roughness/src_normal=""
|
||||||
|
process/channel_remap/red=0
|
||||||
|
process/channel_remap/green=1
|
||||||
|
process/channel_remap/blue=2
|
||||||
|
process/channel_remap/alpha=3
|
||||||
|
process/fix_alpha_border=true
|
||||||
|
process/premult_alpha=false
|
||||||
|
process/normal_map_invert_y=false
|
||||||
|
process/hdr_as_srgb=false
|
||||||
|
process/hdr_clamp_exposure=false
|
||||||
|
process/size_limit=0
|
||||||
|
detect_3d/compress_to=1
|
||||||
963
docs/api-documentation.md
Normal file
@@ -0,0 +1,963 @@
|
|||||||
|
# Pixel Game Server API 文档
|
||||||
|
|
||||||
|
**版本**: 1.1.1
|
||||||
|
**更新时间**: 2025-12-25
|
||||||
|
|
||||||
|
## 🚨 后端对前端的提示与注意点
|
||||||
|
|
||||||
|
### 重要提醒
|
||||||
|
1. **邮箱冲突检测**: 发送邮箱验证码前会检查邮箱是否已被注册,已注册邮箱返回409状态码
|
||||||
|
2. **HTTP状态码**: 所有接口根据业务结果返回正确状态码(409冲突、400参数错误、401认证失败等)
|
||||||
|
3. **验证码有效期**: 所有验证码有效期为5分钟
|
||||||
|
4. **频率限制**: 验证码发送限制1次/分钟,注册限制10次/5分钟
|
||||||
|
5. **测试模式**: 开发环境下邮件服务返回206状态码,验证码在响应中返回
|
||||||
|
6. **冷却时间自动清除**: 注册、密码重置、验证码登录成功后会自动清除验证码冷却时间,方便后续操作
|
||||||
|
|
||||||
|
### 错误处理规范
|
||||||
|
- **409 Conflict**: 资源冲突(用户名、邮箱已存在)
|
||||||
|
- **400 Bad Request**: 参数错误、验证码错误
|
||||||
|
- **401 Unauthorized**: 认证失败、密码错误
|
||||||
|
- **429 Too Many Requests**: 频率限制
|
||||||
|
- **206 Partial Content**: 测试模式(验证码未真实发送)
|
||||||
|
|
||||||
|
### 前端开发建议
|
||||||
|
1. 根据HTTP状态码进行错误处理,不要只依赖success字段
|
||||||
|
2. 邮箱注册流程:先发送验证码 → 检查409冲突 → 使用验证码注册
|
||||||
|
3. 测试模式下验证码在响应中返回,生产环境需用户查收邮件
|
||||||
|
4. 实现重试机制处理429频率限制错误
|
||||||
|
5. 注册/重置密码成功后,验证码冷却时间会自动清除,可立即发送新验证码
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 📋 API接口列表
|
||||||
|
|
||||||
|
### 应用状态接口
|
||||||
|
- `GET /` - 获取应用状态
|
||||||
|
|
||||||
|
### 用户认证接口
|
||||||
|
- `POST /auth/login` - 用户登录
|
||||||
|
- `POST /auth/register` - 用户注册
|
||||||
|
- `POST /auth/github` - GitHub OAuth登录
|
||||||
|
- `POST /auth/verification-code-login` - 验证码登录
|
||||||
|
- `POST /auth/send-login-verification-code` - 发送登录验证码
|
||||||
|
- `POST /auth/forgot-password` - 发送密码重置验证码
|
||||||
|
- `POST /auth/reset-password` - 重置密码
|
||||||
|
- `PUT /auth/change-password` - 修改密码
|
||||||
|
- `POST /auth/send-email-verification` - 发送邮箱验证码
|
||||||
|
- `POST /auth/verify-email` - 验证邮箱验证码
|
||||||
|
- `POST /auth/resend-email-verification` - 重新发送邮箱验证码
|
||||||
|
|
||||||
|
### 管理员接口
|
||||||
|
- `POST /admin/auth/login` - 管理员登录
|
||||||
|
- `GET /admin/users` - 获取用户列表
|
||||||
|
- `GET /admin/users/:id` - 获取用户详情
|
||||||
|
- `POST /admin/users/:id/reset-password` - 管理员重置用户密码
|
||||||
|
- `GET /admin/logs/runtime` - 获取运行时日志
|
||||||
|
- `GET /admin/logs/archive` - 获取归档日志
|
||||||
|
|
||||||
|
### 用户管理接口
|
||||||
|
- `PUT /admin/users/:id/status` - 修改用户状态
|
||||||
|
- `POST /admin/users/batch-status` - 批量修改用户状态
|
||||||
|
- `GET /admin/users/status-stats` - 获取用户状态统计
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🧪 API接口详细说明与测试用例
|
||||||
|
### 1. 获取应用状态
|
||||||
|
|
||||||
|
**接口**: `GET /`
|
||||||
|
|
||||||
|
#### 成功响应 (200)
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"service": "Pixel Game Server",
|
||||||
|
"version": "1.1.1",
|
||||||
|
"status": "running",
|
||||||
|
"timestamp": "2025-12-25T10:27:44.352Z",
|
||||||
|
"uptime": 8,
|
||||||
|
"environment": "development",
|
||||||
|
"storage_mode": "database"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### 2. 用户登录
|
||||||
|
|
||||||
|
**接口**: `POST /auth/login`
|
||||||
|
|
||||||
|
#### 请求体
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"identifier": "testuser",
|
||||||
|
"password": "password123"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 成功响应 (200)
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"success": true,
|
||||||
|
"data": {
|
||||||
|
"user": {
|
||||||
|
"id": "1",
|
||||||
|
"username": "testuser",
|
||||||
|
"nickname": "测试用户",
|
||||||
|
"email": "test@example.com",
|
||||||
|
"phone": null,
|
||||||
|
"avatar_url": null,
|
||||||
|
"role": 1,
|
||||||
|
"created_at": "2025-12-17T10:00:00.000Z"
|
||||||
|
},
|
||||||
|
"access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
|
||||||
|
"is_new_user": false,
|
||||||
|
"message": "登录成功"
|
||||||
|
},
|
||||||
|
"message": "登录成功"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 认证失败响应 (401)
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"success": false,
|
||||||
|
"message": "用户名、邮箱或手机号不存在",
|
||||||
|
"error_code": "LOGIN_FAILED"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 密码错误响应 (401)
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"success": false,
|
||||||
|
"message": "密码错误",
|
||||||
|
"error_code": "LOGIN_FAILED"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### 3. 用户注册
|
||||||
|
|
||||||
|
**接口**: `POST /auth/register`
|
||||||
|
|
||||||
|
#### 请求体(无邮箱)
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"username": "newuser",
|
||||||
|
"password": "password123",
|
||||||
|
"nickname": "新用户"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 请求体(带邮箱验证)
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"username": "newuser",
|
||||||
|
"password": "password123",
|
||||||
|
"nickname": "新用户",
|
||||||
|
"email": "newuser@example.com",
|
||||||
|
"email_verification_code": "123456"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 成功响应 (201)
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"success": true,
|
||||||
|
"data": {
|
||||||
|
"user": {
|
||||||
|
"id": "2",
|
||||||
|
"username": "newuser",
|
||||||
|
"nickname": "新用户",
|
||||||
|
"email": "newuser@example.com",
|
||||||
|
"phone": null,
|
||||||
|
"avatar_url": null,
|
||||||
|
"role": 1,
|
||||||
|
"created_at": "2025-12-17T10:00:00.000Z"
|
||||||
|
},
|
||||||
|
"access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
|
||||||
|
"is_new_user": true,
|
||||||
|
"message": "注册成功"
|
||||||
|
},
|
||||||
|
"message": "注册成功"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 用户名冲突响应 (409)
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"success": false,
|
||||||
|
"message": "用户名已存在",
|
||||||
|
"error_code": "REGISTER_FAILED"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 邮箱冲突响应 (409)
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"success": false,
|
||||||
|
"message": "邮箱已存在",
|
||||||
|
"error_code": "REGISTER_FAILED"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 验证码错误响应 (400)
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"success": false,
|
||||||
|
"message": "验证码不存在或已过期",
|
||||||
|
"error_code": "REGISTER_FAILED"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### 4. 发送邮箱验证码
|
||||||
|
|
||||||
|
**接口**: `POST /auth/send-email-verification`
|
||||||
|
|
||||||
|
#### 请求体
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"email": "test@example.com"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 成功响应 (200) - 生产环境
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"success": true,
|
||||||
|
"data": {
|
||||||
|
"is_test_mode": false
|
||||||
|
},
|
||||||
|
"message": "验证码已发送,请查收邮件"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 测试模式响应 (206) - 开发环境
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"success": false,
|
||||||
|
"data": {
|
||||||
|
"verification_code": "123456",
|
||||||
|
"is_test_mode": true
|
||||||
|
},
|
||||||
|
"message": "⚠️ 测试模式:验证码已生成但未真实发送。请在控制台查看验证码,或配置邮件服务以启用真实发送。",
|
||||||
|
"error_code": "TEST_MODE_ONLY"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 邮箱冲突响应 (409)
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"success": false,
|
||||||
|
"message": "邮箱已被注册,请使用其他邮箱或直接登录",
|
||||||
|
"error_code": "SEND_EMAIL_VERIFICATION_FAILED"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 频率限制响应 (429)
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"success": false,
|
||||||
|
"message": "验证码发送过于频繁,请1分钟后再试",
|
||||||
|
"error_code": "TOO_MANY_REQUESTS",
|
||||||
|
"throttle_info": {
|
||||||
|
"limit": 1,
|
||||||
|
"window_seconds": 60,
|
||||||
|
"current_requests": 1,
|
||||||
|
"reset_time": "2025-12-25T10:07:37.056Z"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
---
|
||||||
|
|
||||||
|
### 5. 验证码登录
|
||||||
|
|
||||||
|
**接口**: `POST /auth/verification-code-login`
|
||||||
|
|
||||||
|
#### 请求体
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"identifier": "test@example.com",
|
||||||
|
"verification_code": "123456"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 成功响应 (200)
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"success": true,
|
||||||
|
"data": {
|
||||||
|
"user": {
|
||||||
|
"id": "1",
|
||||||
|
"username": "testuser",
|
||||||
|
"nickname": "测试用户",
|
||||||
|
"email": "test@example.com",
|
||||||
|
"phone": null,
|
||||||
|
"avatar_url": null,
|
||||||
|
"role": 1,
|
||||||
|
"created_at": "2025-12-17T10:00:00.000Z"
|
||||||
|
},
|
||||||
|
"access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
|
||||||
|
"is_new_user": false,
|
||||||
|
"message": "验证码登录成功"
|
||||||
|
},
|
||||||
|
"message": "验证码登录成功"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 验证码错误响应 (401)
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"success": false,
|
||||||
|
"message": "验证码验证失败",
|
||||||
|
"error_code": "VERIFICATION_CODE_LOGIN_FAILED"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 用户不存在响应 (404)
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"success": false,
|
||||||
|
"message": "用户不存在,请先注册账户",
|
||||||
|
"error_code": "VERIFICATION_CODE_LOGIN_FAILED"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### 6. 发送登录验证码
|
||||||
|
|
||||||
|
**接口**: `POST /auth/send-login-verification-code`
|
||||||
|
|
||||||
|
#### 请求体
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"identifier": "test@example.com"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 成功响应 (200) - 生产环境
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"success": true,
|
||||||
|
"data": {
|
||||||
|
"is_test_mode": false
|
||||||
|
},
|
||||||
|
"message": "验证码已发送,请查收"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 测试模式响应 (206) - 开发环境
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"success": false,
|
||||||
|
"data": {
|
||||||
|
"verification_code": "654321",
|
||||||
|
"is_test_mode": true
|
||||||
|
},
|
||||||
|
"message": "⚠️ 测试模式:验证码已生成但未真实发送。请在控制台查看验证码,或配置邮件服务以启用真实发送。",
|
||||||
|
"error_code": "TEST_MODE_ONLY"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 用户不存在响应 (404)
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"success": false,
|
||||||
|
"message": "用户不存在",
|
||||||
|
"error_code": "SEND_LOGIN_CODE_FAILED"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### 7. 发送密码重置验证码
|
||||||
|
|
||||||
|
**接口**: `POST /auth/forgot-password`
|
||||||
|
|
||||||
|
#### 请求体
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"identifier": "test@example.com"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 成功响应 (200) - 生产环境
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"success": true,
|
||||||
|
"data": {
|
||||||
|
"is_test_mode": false
|
||||||
|
},
|
||||||
|
"message": "验证码已发送,请查收"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 测试模式响应 (206) - 开发环境
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"success": false,
|
||||||
|
"data": {
|
||||||
|
"verification_code": "789012",
|
||||||
|
"is_test_mode": true
|
||||||
|
},
|
||||||
|
"message": "⚠️ 测试模式:验证码已生成但未真实发送。请在控制台查看验证码,或配置邮件服务以启用真实发送。",
|
||||||
|
"error_code": "TEST_MODE_ONLY"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 用户不存在响应 (404)
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"success": false,
|
||||||
|
"message": "用户不存在",
|
||||||
|
"error_code": "SEND_CODE_FAILED"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### 8. 重置密码
|
||||||
|
|
||||||
|
**接口**: `POST /auth/reset-password`
|
||||||
|
|
||||||
|
#### 请求体
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"identifier": "test@example.com",
|
||||||
|
"verification_code": "789012",
|
||||||
|
"new_password": "newpassword123"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 成功响应 (200)
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"success": true,
|
||||||
|
"message": "密码重置成功"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 验证码错误响应 (400)
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"success": false,
|
||||||
|
"message": "验证码验证失败",
|
||||||
|
"error_code": "RESET_PASSWORD_FAILED"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### 9. 修改密码
|
||||||
|
|
||||||
|
**接口**: `PUT /auth/change-password`
|
||||||
|
|
||||||
|
#### 请求体
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"user_id": "1",
|
||||||
|
"old_password": "oldpassword123",
|
||||||
|
"new_password": "newpassword123"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 成功响应 (200)
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"success": true,
|
||||||
|
"message": "密码修改成功"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 旧密码错误响应 (401)
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"success": false,
|
||||||
|
"message": "旧密码错误",
|
||||||
|
"error_code": "CHANGE_PASSWORD_FAILED"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
---
|
||||||
|
|
||||||
|
### 10. GitHub OAuth登录
|
||||||
|
|
||||||
|
**接口**: `POST /auth/github`
|
||||||
|
|
||||||
|
#### 请求体
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"github_id": "12345678",
|
||||||
|
"username": "octocat",
|
||||||
|
"nickname": "The Octocat",
|
||||||
|
"email": "octocat@github.com",
|
||||||
|
"avatar_url": "https://github.com/images/error/octocat_happy.gif"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 成功响应 (200) - 已存在用户
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"success": true,
|
||||||
|
"data": {
|
||||||
|
"user": {
|
||||||
|
"id": "3",
|
||||||
|
"username": "octocat",
|
||||||
|
"nickname": "The Octocat",
|
||||||
|
"email": "octocat@github.com",
|
||||||
|
"phone": null,
|
||||||
|
"avatar_url": "https://github.com/images/error/octocat_happy.gif",
|
||||||
|
"role": 1,
|
||||||
|
"created_at": "2025-12-17T10:00:00.000Z"
|
||||||
|
},
|
||||||
|
"access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
|
||||||
|
"is_new_user": false,
|
||||||
|
"message": "GitHub登录成功"
|
||||||
|
},
|
||||||
|
"message": "GitHub登录成功"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 成功响应 (200) - 新用户注册
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"success": true,
|
||||||
|
"data": {
|
||||||
|
"user": {
|
||||||
|
"id": "4",
|
||||||
|
"username": "octocat_1",
|
||||||
|
"nickname": "The Octocat",
|
||||||
|
"email": "octocat@github.com",
|
||||||
|
"phone": null,
|
||||||
|
"avatar_url": "https://github.com/images/error/octocat_happy.gif",
|
||||||
|
"role": 1,
|
||||||
|
"created_at": "2025-12-17T10:00:00.000Z"
|
||||||
|
},
|
||||||
|
"access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
|
||||||
|
"is_new_user": true,
|
||||||
|
"message": "GitHub账户绑定成功"
|
||||||
|
},
|
||||||
|
"message": "GitHub账户绑定成功"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### 11. 验证邮箱验证码
|
||||||
|
|
||||||
|
**接口**: `POST /auth/verify-email`
|
||||||
|
|
||||||
|
#### 请求体
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"email": "test@example.com",
|
||||||
|
"verification_code": "123456"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 成功响应 (200)
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"success": true,
|
||||||
|
"message": "邮箱验证成功"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 验证码错误响应 (400)
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"success": false,
|
||||||
|
"message": "验证码错误",
|
||||||
|
"error_code": "EMAIL_VERIFICATION_FAILED"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### 12. 重新发送邮箱验证码
|
||||||
|
|
||||||
|
**接口**: `POST /auth/resend-email-verification`
|
||||||
|
|
||||||
|
#### 请求体
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"email": "test@example.com"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 成功响应 (200) - 生产环境
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"success": true,
|
||||||
|
"data": {
|
||||||
|
"is_test_mode": false
|
||||||
|
},
|
||||||
|
"message": "验证码已重新发送,请查收邮件"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 测试模式响应 (206) - 开发环境
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"success": false,
|
||||||
|
"data": {
|
||||||
|
"verification_code": "456789",
|
||||||
|
"is_test_mode": true
|
||||||
|
},
|
||||||
|
"message": "⚠️ 测试模式:验证码已生成但未真实发送。请在控制台查看验证码,或配置邮件服务以启用真实发送。",
|
||||||
|
"error_code": "TEST_MODE_ONLY"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 邮箱已验证响应 (400)
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"success": false,
|
||||||
|
"message": "邮箱已验证,无需重复验证",
|
||||||
|
"error_code": "RESEND_EMAIL_VERIFICATION_FAILED"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### 13. 管理员登录
|
||||||
|
|
||||||
|
**接口**: `POST /admin/auth/login`
|
||||||
|
|
||||||
|
#### 请求体
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"username": "admin",
|
||||||
|
"password": "Admin123456"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 成功响应 (200)
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"success": true,
|
||||||
|
"data": {
|
||||||
|
"admin": {
|
||||||
|
"id": "1",
|
||||||
|
"username": "admin",
|
||||||
|
"nickname": "管理员",
|
||||||
|
"role": 0
|
||||||
|
},
|
||||||
|
"access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
|
||||||
|
"expires_in": 28800,
|
||||||
|
"message": "管理员登录成功"
|
||||||
|
},
|
||||||
|
"message": "管理员登录成功"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 认证失败响应 (401)
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"success": false,
|
||||||
|
"message": "用户名或密码错误",
|
||||||
|
"error_code": "ADMIN_LOGIN_FAILED"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 权限不足响应 (403)
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"success": false,
|
||||||
|
"message": "权限不足,需要管理员权限",
|
||||||
|
"error_code": "ADMIN_LOGIN_FAILED"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
---
|
||||||
|
|
||||||
|
### 14. 获取用户列表
|
||||||
|
|
||||||
|
**接口**: `GET /admin/users`
|
||||||
|
|
||||||
|
#### 查询参数
|
||||||
|
- `page`: 页码(可选,默认1)
|
||||||
|
- `limit`: 每页数量(可选,默认10)
|
||||||
|
- `status`: 用户状态筛选(可选)
|
||||||
|
|
||||||
|
#### 成功响应 (200)
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"success": true,
|
||||||
|
"data": {
|
||||||
|
"users": [
|
||||||
|
{
|
||||||
|
"id": "1",
|
||||||
|
"username": "testuser",
|
||||||
|
"nickname": "测试用户",
|
||||||
|
"email": "test@example.com",
|
||||||
|
"phone": null,
|
||||||
|
"role": 1,
|
||||||
|
"status": "active",
|
||||||
|
"email_verified": true,
|
||||||
|
"created_at": "2025-12-17T10:00:00.000Z",
|
||||||
|
"updated_at": "2025-12-17T10:00:00.000Z"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"pagination": {
|
||||||
|
"page": 1,
|
||||||
|
"limit": 10,
|
||||||
|
"total": 1,
|
||||||
|
"pages": 1
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"message": "用户列表获取成功"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### 15. 获取用户详情
|
||||||
|
|
||||||
|
**接口**: `GET /admin/users/:id`
|
||||||
|
|
||||||
|
#### 成功响应 (200)
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"success": true,
|
||||||
|
"data": {
|
||||||
|
"user": {
|
||||||
|
"id": "1",
|
||||||
|
"username": "testuser",
|
||||||
|
"nickname": "测试用户",
|
||||||
|
"email": "test@example.com",
|
||||||
|
"phone": null,
|
||||||
|
"role": 1,
|
||||||
|
"status": "active",
|
||||||
|
"email_verified": true,
|
||||||
|
"github_id": null,
|
||||||
|
"avatar_url": null,
|
||||||
|
"created_at": "2025-12-17T10:00:00.000Z",
|
||||||
|
"updated_at": "2025-12-17T10:00:00.000Z"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"message": "用户详情获取成功"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 用户不存在响应 (404)
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"success": false,
|
||||||
|
"message": "用户不存在",
|
||||||
|
"error_code": "USER_NOT_FOUND"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### 16. 管理员重置用户密码
|
||||||
|
|
||||||
|
**接口**: `POST /admin/users/:id/reset-password`
|
||||||
|
|
||||||
|
#### 请求体
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"new_password": "newpassword123"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 成功响应 (200)
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"success": true,
|
||||||
|
"message": "用户密码重置成功"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 用户不存在响应 (404)
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"success": false,
|
||||||
|
"message": "用户不存在",
|
||||||
|
"error_code": "USER_NOT_FOUND"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### 17. 修改用户状态
|
||||||
|
|
||||||
|
**接口**: `PUT /admin/users/:id/status`
|
||||||
|
|
||||||
|
#### 请求体
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"status": "locked",
|
||||||
|
"reason": "违规操作"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 成功响应 (200)
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"success": true,
|
||||||
|
"data": {
|
||||||
|
"user": {
|
||||||
|
"id": "1",
|
||||||
|
"username": "testuser",
|
||||||
|
"status": "locked",
|
||||||
|
"updated_at": "2025-12-17T10:00:00.000Z"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"message": "用户状态修改成功"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 状态值无效响应 (400)
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"success": false,
|
||||||
|
"message": "无效的用户状态值",
|
||||||
|
"error_code": "USER_STATUS_UPDATE_FAILED"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### 18. 批量修改用户状态
|
||||||
|
|
||||||
|
**接口**: `POST /admin/users/batch-status`
|
||||||
|
|
||||||
|
#### 请求体
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"user_ids": ["1", "2", "3"],
|
||||||
|
"status": "active",
|
||||||
|
"reason": "批量激活"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 成功响应 (200)
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"success": true,
|
||||||
|
"data": {
|
||||||
|
"updated_count": 3,
|
||||||
|
"failed_count": 0,
|
||||||
|
"results": [
|
||||||
|
{
|
||||||
|
"user_id": "1",
|
||||||
|
"success": true,
|
||||||
|
"new_status": "active"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"user_id": "2",
|
||||||
|
"success": true,
|
||||||
|
"new_status": "active"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"user_id": "3",
|
||||||
|
"success": true,
|
||||||
|
"new_status": "active"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"message": "批量状态修改完成"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### 19. 获取用户状态统计
|
||||||
|
|
||||||
|
**接口**: `GET /admin/users/status-stats`
|
||||||
|
|
||||||
|
#### 成功响应 (200)
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"success": true,
|
||||||
|
"data": {
|
||||||
|
"stats": {
|
||||||
|
"active": 15,
|
||||||
|
"inactive": 3,
|
||||||
|
"locked": 2,
|
||||||
|
"banned": 1,
|
||||||
|
"deleted": 0,
|
||||||
|
"pending": 5
|
||||||
|
},
|
||||||
|
"total": 26
|
||||||
|
},
|
||||||
|
"message": "用户状态统计获取成功"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### 20. 获取运行时日志
|
||||||
|
|
||||||
|
**接口**: `GET /admin/logs/runtime`
|
||||||
|
|
||||||
|
#### 查询参数
|
||||||
|
- `lines`: 日志行数(可选,默认100)
|
||||||
|
- `level`: 日志级别(可选)
|
||||||
|
|
||||||
|
#### 成功响应 (200)
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"success": true,
|
||||||
|
"data": {
|
||||||
|
"logs": [
|
||||||
|
"[2025-12-25 18:27:35] LOG [NestApplication] Nest application successfully started",
|
||||||
|
"[2025-12-25 18:27:35] LOG [RouterExplorer] Mapped {/, GET} route"
|
||||||
|
],
|
||||||
|
"total_lines": 2,
|
||||||
|
"timestamp": "2025-12-25T10:27:44.352Z"
|
||||||
|
},
|
||||||
|
"message": "运行时日志获取成功"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### 21. 获取归档日志
|
||||||
|
|
||||||
|
**接口**: `GET /admin/logs/archive`
|
||||||
|
|
||||||
|
#### 查询参数
|
||||||
|
- `date`: 日期(YYYY-MM-DD格式,可选)
|
||||||
|
- `download`: 是否下载(可选)
|
||||||
|
|
||||||
|
#### 成功响应 (200)
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"success": true,
|
||||||
|
"data": {
|
||||||
|
"files": [
|
||||||
|
{
|
||||||
|
"filename": "app-2025-12-24.log",
|
||||||
|
"size": 1024,
|
||||||
|
"created_at": "2025-12-24T00:00:00.000Z"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"total_files": 1
|
||||||
|
},
|
||||||
|
"message": "归档日志列表获取成功"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 📊 版本更新记录
|
||||||
|
|
||||||
|
### v1.1.2 (2025-12-25)
|
||||||
|
- **验证码冷却优化**: 注册、密码重置、验证码登录成功后自动清除验证码冷却时间
|
||||||
|
- **用户体验提升**: 成功操作后可立即发送新的验证码,无需等待冷却时间
|
||||||
|
- **代码健壮性**: 冷却时间清除失败不影响主要业务流程
|
||||||
|
|
||||||
|
### v1.1.1 (2025-12-25)
|
||||||
|
- **邮箱冲突检测优化**: 发送邮箱验证码前检查邮箱是否已被注册
|
||||||
|
- **用户体验提升**: 避免向已注册邮箱发送无用验证码
|
||||||
|
- **错误处理改进**: 返回409 Conflict状态码和明确错误信息
|
||||||
|
|
||||||
|
### v1.1.0 (2025-12-25)
|
||||||
|
- **新增验证码登录功能**: 支持邮箱验证码登录
|
||||||
|
- **HTTP状态码修复**: 所有接口返回正确的业务状态码
|
||||||
|
- **完善错误处理**: 统一错误响应格式和错误代码
|
||||||
332
docs/api_update_log.md
Normal file
@@ -0,0 +1,332 @@
|
|||||||
|
# API接口更新日志
|
||||||
|
|
||||||
|
**更新日期**: 2025-12-25
|
||||||
|
**API版本**: v1.1.1
|
||||||
|
**更新内容**: 根据后端最新API文档更新前端接口逻辑和Toast显示
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🎯 更新概述
|
||||||
|
|
||||||
|
根据后端API v1.1.1的最新文档,对前端的网络请求、响应处理和Toast显示系统进行了全面更新,以支持新的功能特性和错误处理机制。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 📋 主要更新内容
|
||||||
|
|
||||||
|
### 1. **HTTP状态码支持**
|
||||||
|
|
||||||
|
#### 新增状态码处理
|
||||||
|
- **206 Partial Content**: 测试模式响应
|
||||||
|
- **409 Conflict**: 资源冲突(用户名、邮箱已存在)
|
||||||
|
- **429 Too Many Requests**: 频率限制
|
||||||
|
|
||||||
|
#### 更新的状态码映射
|
||||||
|
```gdscript
|
||||||
|
const HTTP_STATUS_MESSAGES = {
|
||||||
|
200: "请求成功",
|
||||||
|
201: "创建成功",
|
||||||
|
206: "测试模式",
|
||||||
|
400: "请求参数错误",
|
||||||
|
401: "认证失败",
|
||||||
|
403: "权限不足",
|
||||||
|
404: "资源不存在",
|
||||||
|
408: "请求超时",
|
||||||
|
409: "资源冲突", # 新增
|
||||||
|
415: "不支持的媒体类型",
|
||||||
|
429: "请求过于频繁", # 新增
|
||||||
|
500: "服务器内部错误",
|
||||||
|
503: "服务不可用"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### 2. **错误码映射更新**
|
||||||
|
|
||||||
|
#### 新增错误码
|
||||||
|
- `SEND_EMAIL_VERIFICATION_FAILED`: 发送邮箱验证码失败
|
||||||
|
- `RESEND_EMAIL_VERIFICATION_FAILED`: 重新发送验证码失败
|
||||||
|
- `EMAIL_VERIFICATION_FAILED`: 邮箱验证失败
|
||||||
|
- `RESET_PASSWORD_FAILED`: 重置密码失败
|
||||||
|
- `CHANGE_PASSWORD_FAILED`: 修改密码失败
|
||||||
|
- `USER_STATUS_UPDATE_FAILED`: 用户状态更新失败
|
||||||
|
- `ADMIN_LOGIN_FAILED`: 管理员登录失败
|
||||||
|
|
||||||
|
### 3. **邮箱冲突检测**
|
||||||
|
|
||||||
|
#### 功能描述
|
||||||
|
- 发送邮箱验证码前检查邮箱是否已被注册
|
||||||
|
- 已注册邮箱返回409状态码和明确错误信息
|
||||||
|
|
||||||
|
#### 实现细节
|
||||||
|
```gdscript
|
||||||
|
# 在ResponseHandler中处理409冲突
|
||||||
|
if response_code == 409:
|
||||||
|
if "邮箱已存在" in message:
|
||||||
|
result.message = "📧 邮箱已被注册,请使用其他邮箱或直接登录"
|
||||||
|
elif "用户名已存在" in message:
|
||||||
|
result.message = "👤 用户名已被使用,请换一个"
|
||||||
|
```
|
||||||
|
|
||||||
|
### 4. **测试模式支持**
|
||||||
|
|
||||||
|
#### 功能描述
|
||||||
|
- 开发环境下邮件服务返回206状态码
|
||||||
|
- 验证码在响应中返回,无需真实发送邮件
|
||||||
|
|
||||||
|
#### 实现细节
|
||||||
|
```gdscript
|
||||||
|
# 处理206测试模式响应
|
||||||
|
elif response_code == 206 and error_code == "TEST_MODE_ONLY":
|
||||||
|
is_success = true
|
||||||
|
print("🧪 测试模式响应: ", message)
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Toast显示优化
|
||||||
|
```gdscript
|
||||||
|
if error_code == "TEST_MODE_ONLY":
|
||||||
|
result.message = "🧪 测试模式:验证码已生成,请查看控制台"
|
||||||
|
if data.has("data") and data.data.has("verification_code"):
|
||||||
|
print("🔑 测试模式验证码: ", data.data.verification_code)
|
||||||
|
```
|
||||||
|
|
||||||
|
### 5. **频率限制处理**
|
||||||
|
|
||||||
|
#### 功能描述
|
||||||
|
- 验证码发送限制1次/分钟
|
||||||
|
- 注册限制10次/5分钟
|
||||||
|
- 提供重试建议和详细错误信息
|
||||||
|
|
||||||
|
#### 实现细节
|
||||||
|
```gdscript
|
||||||
|
"TOO_MANY_REQUESTS":
|
||||||
|
result.message = "⏰ 验证码发送过于频繁,请1分钟后再试"
|
||||||
|
# 显示详细的限制信息
|
||||||
|
if data.has("throttle_info"):
|
||||||
|
var throttle_info = data.throttle_info
|
||||||
|
var reset_time = throttle_info.get("reset_time", "")
|
||||||
|
if reset_time != "":
|
||||||
|
result.message += "\n重试时间: " + reset_time
|
||||||
|
```
|
||||||
|
|
||||||
|
### 6. **Toast显示系统优化**
|
||||||
|
|
||||||
|
#### 视觉改进
|
||||||
|
- 增加图标显示(✅成功,❌失败)
|
||||||
|
- 更丰富的颜色和阴影效果
|
||||||
|
- 支持智能换行和更大的显示区域
|
||||||
|
- 更流畅的动画效果
|
||||||
|
|
||||||
|
#### 新的Toast样式
|
||||||
|
```gdscript
|
||||||
|
# 更深的颜色和更好的对比度
|
||||||
|
if is_success:
|
||||||
|
style.bg_color = Color(0.15, 0.7, 0.15, 0.95) # 深绿色
|
||||||
|
style.border_color = Color(0.2, 0.9, 0.2, 0.9) # 亮绿色边框
|
||||||
|
else:
|
||||||
|
style.bg_color = Color(0.7, 0.15, 0.15, 0.95) # 深红色
|
||||||
|
style.border_color = Color(0.9, 0.2, 0.2, 0.9) # 亮红色边框
|
||||||
|
|
||||||
|
# 添加阴影效果
|
||||||
|
style.shadow_color = Color(0, 0, 0, 0.3)
|
||||||
|
style.shadow_size = 4
|
||||||
|
style.shadow_offset = Vector2(2, 2)
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 动画优化
|
||||||
|
- 增加透明度动画
|
||||||
|
- 延长显示时间(2秒→3秒)
|
||||||
|
- 更流畅的滑入滑出效果
|
||||||
|
|
||||||
|
### 7. **新增API方法**
|
||||||
|
|
||||||
|
#### NetworkManager新增方法
|
||||||
|
```gdscript
|
||||||
|
# 重新发送邮箱验证码
|
||||||
|
func resend_email_verification(email: String, callback: Callable) -> String
|
||||||
|
|
||||||
|
# 忘记密码 - 发送重置验证码
|
||||||
|
func forgot_password(identifier: String, callback: Callable) -> String
|
||||||
|
|
||||||
|
# 重置密码
|
||||||
|
func reset_password(identifier: String, verification_code: String, new_password: String, callback: Callable) -> String
|
||||||
|
|
||||||
|
# 修改密码
|
||||||
|
func change_password(user_id: String, old_password: String, new_password: String, callback: Callable) -> String
|
||||||
|
|
||||||
|
# GitHub OAuth登录
|
||||||
|
func github_login(github_id: String, username: String, nickname: String, email: String, avatar_url: String, callback: Callable) -> String
|
||||||
|
```
|
||||||
|
|
||||||
|
#### ResponseHandler新增处理方法
|
||||||
|
```gdscript
|
||||||
|
# 处理重新发送邮箱验证码响应
|
||||||
|
static func handle_resend_email_verification_response(success: bool, data: Dictionary, error_info: Dictionary) -> ResponseResult
|
||||||
|
|
||||||
|
# 处理忘记密码响应
|
||||||
|
static func handle_forgot_password_response(success: bool, data: Dictionary, error_info: Dictionary) -> ResponseResult
|
||||||
|
|
||||||
|
# 处理重置密码响应
|
||||||
|
static func handle_reset_password_response(success: bool, data: Dictionary, error_info: Dictionary) -> ResponseResult
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🔧 技术改进
|
||||||
|
|
||||||
|
### 1. **响应处理逻辑优化**
|
||||||
|
|
||||||
|
#### 更精确的成功判断
|
||||||
|
```gdscript
|
||||||
|
# HTTP成功状态码且业务成功
|
||||||
|
if (response_code >= 200 and response_code < 300) and success:
|
||||||
|
is_success = true
|
||||||
|
# 特殊情况:206测试模式
|
||||||
|
elif response_code == 206 and error_code == "TEST_MODE_ONLY":
|
||||||
|
is_success = true
|
||||||
|
# 201创建成功
|
||||||
|
elif response_code == 201:
|
||||||
|
is_success = true
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 更详细的错误类型判断
|
||||||
|
```gdscript
|
||||||
|
match response_code:
|
||||||
|
409: # 资源冲突
|
||||||
|
return ErrorType.BUSINESS_ERROR
|
||||||
|
206: # 测试模式
|
||||||
|
return ErrorType.BUSINESS_ERROR
|
||||||
|
429: # 频率限制
|
||||||
|
return ErrorType.BUSINESS_ERROR
|
||||||
|
```
|
||||||
|
|
||||||
|
### 2. **错误消息国际化**
|
||||||
|
|
||||||
|
#### 添加表情符号和更友好的提示
|
||||||
|
- 📧 邮箱相关消息
|
||||||
|
- 👤 用户相关消息
|
||||||
|
- 🔑 验证码相关消息
|
||||||
|
- 🔒 密码相关消息
|
||||||
|
- ⏰ 时间相关消息
|
||||||
|
- 🧪 测试模式消息
|
||||||
|
- 🌐 网络相关消息
|
||||||
|
|
||||||
|
### 3. **代码结构优化**
|
||||||
|
|
||||||
|
#### 更好的模块化
|
||||||
|
- 分离不同类型的错误处理方法
|
||||||
|
- 统一的响应处理接口
|
||||||
|
- 更清晰的方法命名
|
||||||
|
|
||||||
|
#### 更完善的注释
|
||||||
|
- 详细的方法说明
|
||||||
|
- 参数和返回值说明
|
||||||
|
- 使用示例
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🧪 测试验证
|
||||||
|
|
||||||
|
### 创建了API测试脚本
|
||||||
|
- **文件**: `scripts/network/ApiTestScript.gd`
|
||||||
|
- **功能**: 验证所有更新的API接口逻辑
|
||||||
|
- **测试用例**:
|
||||||
|
- 网络连接测试
|
||||||
|
- 邮箱验证码发送
|
||||||
|
- 邮箱冲突检测
|
||||||
|
- 登录功能
|
||||||
|
- 注册功能
|
||||||
|
|
||||||
|
### 测试覆盖的场景
|
||||||
|
- ✅ 正常成功响应
|
||||||
|
- ✅ 409邮箱冲突
|
||||||
|
- ✅ 206测试模式
|
||||||
|
- ✅ 429频率限制
|
||||||
|
- ✅ 各种错误状态码
|
||||||
|
- ✅ Toast显示效果
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 📚 使用指南
|
||||||
|
|
||||||
|
### 1. **发送邮箱验证码**
|
||||||
|
```gdscript
|
||||||
|
# 会自动检查邮箱冲突
|
||||||
|
var request_id = NetworkManager.send_email_verification("user@example.com", callback)
|
||||||
|
```
|
||||||
|
|
||||||
|
### 2. **处理409冲突**
|
||||||
|
```gdscript
|
||||||
|
func callback(success: bool, data: Dictionary, error_info: Dictionary):
|
||||||
|
var result = ResponseHandler.handle_send_verification_code_response(success, data, error_info)
|
||||||
|
if error_info.get("response_code") == 409:
|
||||||
|
# 邮箱已存在,引导用户登录
|
||||||
|
show_login_suggestion()
|
||||||
|
```
|
||||||
|
|
||||||
|
### 3. **处理测试模式**
|
||||||
|
```gdscript
|
||||||
|
# 测试模式下验证码会在控制台显示
|
||||||
|
if data.get("error_code") == "TEST_MODE_ONLY":
|
||||||
|
var verification_code = data.data.verification_code
|
||||||
|
print("测试验证码: ", verification_code)
|
||||||
|
```
|
||||||
|
|
||||||
|
### 4. **处理频率限制**
|
||||||
|
```gdscript
|
||||||
|
# 提供重试建议
|
||||||
|
if error_info.get("response_code") == 429:
|
||||||
|
show_retry_suggestion(data.get("throttle_info", {}))
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🔄 向后兼容性
|
||||||
|
|
||||||
|
### 保持的兼容性
|
||||||
|
- ✅ 现有的API调用方式不变
|
||||||
|
- ✅ 现有的回调函数签名不变
|
||||||
|
- ✅ 现有的Toast显示接口不变
|
||||||
|
|
||||||
|
### 新增的功能
|
||||||
|
- ✅ 更丰富的错误处理
|
||||||
|
- ✅ 更好的用户体验
|
||||||
|
- ✅ 更详细的状态反馈
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 📝 注意事项
|
||||||
|
|
||||||
|
### 开发环境
|
||||||
|
- 测试模式下验证码会在控制台显示
|
||||||
|
- 206状态码表示测试模式,属于成功响应
|
||||||
|
- 建议在开发时关注控制台输出
|
||||||
|
|
||||||
|
### 生产环境
|
||||||
|
- 验证码通过真实邮件发送
|
||||||
|
- 需要正确配置邮件服务
|
||||||
|
- 频率限制会严格执行
|
||||||
|
|
||||||
|
### 错误处理
|
||||||
|
- 优先检查HTTP状态码
|
||||||
|
- 再检查业务错误码
|
||||||
|
- 提供用户友好的错误提示
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🚀 后续计划
|
||||||
|
|
||||||
|
### 短期优化
|
||||||
|
- [ ] 添加更多的API接口支持
|
||||||
|
- [ ] 优化Toast显示的动画效果
|
||||||
|
- [ ] 添加音效反馈
|
||||||
|
|
||||||
|
### 长期规划
|
||||||
|
- [ ] 支持多语言错误消息
|
||||||
|
- [ ] 添加离线模式支持
|
||||||
|
- [ ] 实现请求重试机制
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
**更新完成时间**: 2025-12-25
|
||||||
|
**测试状态**: ✅ 已通过基础测试
|
||||||
|
**部署建议**: 建议在测试环境充分验证后再部署到生产环境
|
||||||
324
docs/auth/form_validation.md
Normal file
@@ -0,0 +1,324 @@
|
|||||||
|
# 表单验证规范文档
|
||||||
|
|
||||||
|
## 概述
|
||||||
|
|
||||||
|
本文档详细说明了登录和注册表单的验证规则、UI交互规范和错误处理机制。
|
||||||
|
|
||||||
|
## 验证规则
|
||||||
|
|
||||||
|
### 1. 用户名验证
|
||||||
|
|
||||||
|
#### 规则
|
||||||
|
- **必填项**: 是
|
||||||
|
- **长度**: 1-50字符
|
||||||
|
- **格式**: 只能包含字母、数字和下划线
|
||||||
|
- **正则表达式**: `^[a-zA-Z0-9_]+$`
|
||||||
|
|
||||||
|
#### 错误提示
|
||||||
|
- 空值: "用户名不能为空"
|
||||||
|
- 长度不符: "用户名长度应为1-50字符"
|
||||||
|
- 格式错误: "用户名只能包含字母、数字和下划线"
|
||||||
|
|
||||||
|
### 2. 邮箱验证
|
||||||
|
|
||||||
|
#### 规则
|
||||||
|
- **必填项**: 是(注册时)
|
||||||
|
- **格式**: 标准邮箱格式
|
||||||
|
- **正则表达式**: `^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$`
|
||||||
|
|
||||||
|
#### 错误提示
|
||||||
|
- 空值: "邮箱不能为空"
|
||||||
|
- 格式错误: "请输入有效的邮箱地址"
|
||||||
|
|
||||||
|
### 3. 密码验证
|
||||||
|
|
||||||
|
#### 规则
|
||||||
|
- **必填项**: 是
|
||||||
|
- **长度**: 8-128字符
|
||||||
|
- **复杂度**: 必须包含字母和数字
|
||||||
|
- **安全性**: 不允许纯数字或纯字母
|
||||||
|
|
||||||
|
#### 错误提示
|
||||||
|
- 空值: "密码不能为空"
|
||||||
|
- 长度不足: "密码长度至少8位"
|
||||||
|
- 长度超限: "密码长度不能超过128位"
|
||||||
|
- 复杂度不够: "密码必须包含字母和数字"
|
||||||
|
|
||||||
|
### 4. 确认密码验证
|
||||||
|
|
||||||
|
#### 规则
|
||||||
|
- **必填项**: 是(注册时)
|
||||||
|
- **一致性**: 必须与密码字段完全一致
|
||||||
|
|
||||||
|
#### 错误提示
|
||||||
|
- 空值: "确认密码不能为空"
|
||||||
|
- 不一致: "两次输入的密码不一致"
|
||||||
|
|
||||||
|
### 5. 验证码验证
|
||||||
|
|
||||||
|
#### 规则
|
||||||
|
- **必填项**: 是(注册时)
|
||||||
|
- **长度**: 6位数字
|
||||||
|
- **格式**: 纯数字
|
||||||
|
- **有效性**: 必须先获取验证码
|
||||||
|
|
||||||
|
#### 错误提示
|
||||||
|
- 空值: "验证码不能为空"
|
||||||
|
- 长度错误: "验证码必须是6位数字"
|
||||||
|
- 格式错误: "验证码必须是6位数字"
|
||||||
|
- 未获取: "请先获取邮箱验证码"
|
||||||
|
|
||||||
|
## UI交互规范
|
||||||
|
|
||||||
|
### 1. 必填项标识
|
||||||
|
|
||||||
|
所有必填字段都使用水平布局来显示标签、红色星号和右对齐的错误提示:
|
||||||
|
|
||||||
|
#### 结构设计
|
||||||
|
```
|
||||||
|
VBoxContainer (字段容器)
|
||||||
|
├── HBoxContainer (标签和错误提示容器)
|
||||||
|
│ ├── Label (字段名称)
|
||||||
|
│ ├── Label (红色星号 " *")
|
||||||
|
│ ├── Control (弹性空间) [size_flags_horizontal = 3]
|
||||||
|
│ └── Label (红色错误提示) [右对齐,默认隐藏]
|
||||||
|
└── LineEdit (输入框)
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 视觉效果
|
||||||
|
- **标签**: 黑色文本,如 "用户名"、"邮箱"、"密码"
|
||||||
|
- **星号**: 红色文本 `Color(1, 0.2, 0.2, 1)`,内容为 " *"
|
||||||
|
- **弹性空间**: Control节点,`size_flags_horizontal = 3`,占据剩余空间
|
||||||
|
- **错误提示**: 红色文本,12px字体,右对齐显示 (`horizontal_alignment = 2`)
|
||||||
|
- **布局**: 标签和星号左对齐,错误提示右对齐
|
||||||
|
|
||||||
|
#### 交互行为
|
||||||
|
- **正常状态**: 显示 `用户名 * `
|
||||||
|
- **错误状态**: 显示 `用户名 * 用户名不能为空`
|
||||||
|
- **输入时**: 错误提示自动隐藏,回到正常状态
|
||||||
|
|
||||||
|
#### 优势
|
||||||
|
- 错误提示右对齐,与输入框右边缘对齐,视觉更整齐
|
||||||
|
- 利用弹性空间实现左右分布,布局更美观
|
||||||
|
- 不占用额外的垂直空间
|
||||||
|
- 避免UI布局被拉长导致溢出
|
||||||
|
- 保持界面紧凑美观
|
||||||
|
- 红色星号和错误提示颜色一致,视觉统一
|
||||||
|
- 错误提示位置固定,不会因为文本长度变化而影响布局
|
||||||
|
|
||||||
|
### 2. 实时验证
|
||||||
|
|
||||||
|
#### 失焦验证
|
||||||
|
- 当用户离开输入框时(`focus_exited`)触发验证
|
||||||
|
- 立即显示相应的错误提示
|
||||||
|
- 错误提示显示在输入框下方
|
||||||
|
|
||||||
|
#### 输入时验证
|
||||||
|
- 当用户开始输入时(`text_changed`)隐藏错误提示
|
||||||
|
- 提供即时的视觉反馈
|
||||||
|
- 避免在用户输入过程中显示错误
|
||||||
|
|
||||||
|
### 3. 错误提示样式
|
||||||
|
|
||||||
|
#### 视觉设计
|
||||||
|
- **颜色**: 红色 `Color(1, 0.2, 0.2, 1)`
|
||||||
|
- **字体大小**: 12px
|
||||||
|
- **位置**: 输入框正下方
|
||||||
|
- **显示状态**: 默认隐藏,验证失败时显示
|
||||||
|
|
||||||
|
#### 错误信息特点
|
||||||
|
- 简洁明了,直接指出问题
|
||||||
|
- 提供解决建议
|
||||||
|
- 使用友好的语言
|
||||||
|
|
||||||
|
### 4. 按钮状态管理
|
||||||
|
|
||||||
|
#### 发送验证码按钮
|
||||||
|
- **正常状态**: "发送验证码"
|
||||||
|
- **冷却状态**: "重新发送(60)" (倒计时)
|
||||||
|
- **禁用状态**: 请求进行中时禁用
|
||||||
|
|
||||||
|
#### 提交按钮
|
||||||
|
- **正常状态**: 可点击
|
||||||
|
- **禁用状态**: 表单验证失败或请求进行中时禁用
|
||||||
|
- **加载状态**: 显示"正在注册..."等提示
|
||||||
|
|
||||||
|
## 验证流程
|
||||||
|
|
||||||
|
### 1. 登录表单验证流程
|
||||||
|
|
||||||
|
```
|
||||||
|
用户输入 → 失焦验证 → 显示错误(如有) → 点击登录 → 整体验证 → 提交请求
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 验证步骤
|
||||||
|
1. 检查用户名是否为空
|
||||||
|
2. 检查密码是否为空
|
||||||
|
3. 所有验证通过后提交登录请求
|
||||||
|
|
||||||
|
### 2. 注册表单验证流程
|
||||||
|
|
||||||
|
```
|
||||||
|
用户输入 → 失焦验证 → 显示错误(如有) → 获取验证码 → 输入验证码 → 点击注册 → 整体验证 → 邮箱验证 → 用户注册
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 验证步骤
|
||||||
|
1. 验证用户名格式和长度
|
||||||
|
2. 验证邮箱格式
|
||||||
|
3. 验证密码强度
|
||||||
|
4. 验证确认密码一致性
|
||||||
|
5. 验证验证码格式和有效性
|
||||||
|
6. 发送邮箱验证请求
|
||||||
|
7. 验证成功后发送注册请求
|
||||||
|
|
||||||
|
### 3. 验证码获取流程
|
||||||
|
|
||||||
|
```
|
||||||
|
输入邮箱 → 验证邮箱格式 → 检查冷却时间 → 发送验证码 → 开始冷却计时
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 冷却机制
|
||||||
|
- **冷却时间**: 60秒
|
||||||
|
- **按钮状态**: 显示倒计时
|
||||||
|
- **重复发送**: 冷却结束后可重新发送
|
||||||
|
|
||||||
|
## 错误处理机制
|
||||||
|
|
||||||
|
### 1. 客户端验证
|
||||||
|
|
||||||
|
#### 即时验证
|
||||||
|
- 在用户输入过程中提供即时反馈
|
||||||
|
- 防止用户提交无效数据
|
||||||
|
- 提升用户体验
|
||||||
|
|
||||||
|
#### 提交前验证
|
||||||
|
- 在发送请求前进行完整验证
|
||||||
|
- 确保所有必填项都已正确填写
|
||||||
|
- 避免无效的网络请求
|
||||||
|
|
||||||
|
### 2. 服务器验证
|
||||||
|
|
||||||
|
#### 后端验证
|
||||||
|
- 服务器端进行二次验证
|
||||||
|
- 处理服务器返回的错误信息
|
||||||
|
- 显示相应的错误提示
|
||||||
|
|
||||||
|
#### 网络错误处理
|
||||||
|
- 连接失败提示
|
||||||
|
- 超时处理
|
||||||
|
- 服务器错误提示
|
||||||
|
|
||||||
|
### 3. 用户引导
|
||||||
|
|
||||||
|
#### 错误恢复
|
||||||
|
- 清晰的错误提示
|
||||||
|
- 提供解决方案
|
||||||
|
- 引导用户正确操作
|
||||||
|
|
||||||
|
#### 成功反馈
|
||||||
|
- 注册成功提示
|
||||||
|
- 自动跳转到登录界面
|
||||||
|
- 自动填充用户名
|
||||||
|
|
||||||
|
## 代码实现
|
||||||
|
|
||||||
|
### 1. 验证函数
|
||||||
|
|
||||||
|
每个字段都有对应的验证函数:
|
||||||
|
- `validate_username(username: String) -> Dictionary`
|
||||||
|
- `validate_email(email: String) -> Dictionary`
|
||||||
|
- `validate_password(password: String) -> Dictionary`
|
||||||
|
- `validate_confirm_password(password: String, confirm: String) -> Dictionary`
|
||||||
|
- `validate_verification_code(code: String) -> Dictionary`
|
||||||
|
|
||||||
|
### 2. 事件处理
|
||||||
|
|
||||||
|
#### 失焦事件
|
||||||
|
- `_on_register_username_focus_exited()`
|
||||||
|
- `_on_register_email_focus_exited()`
|
||||||
|
- `_on_register_password_focus_exited()`
|
||||||
|
- `_on_register_confirm_focus_exited()`
|
||||||
|
- `_on_verification_focus_exited()`
|
||||||
|
|
||||||
|
#### 输入事件
|
||||||
|
- `_on_register_username_text_changed(new_text: String)`
|
||||||
|
- `_on_register_email_text_changed(new_text: String)`
|
||||||
|
- `_on_register_password_text_changed(new_text: String)`
|
||||||
|
- `_on_register_confirm_text_changed(new_text: String)`
|
||||||
|
- `_on_verification_text_changed(new_text: String)`
|
||||||
|
|
||||||
|
### 3. 整体验证
|
||||||
|
|
||||||
|
- `validate_login_form() -> bool`
|
||||||
|
- `validate_register_form() -> bool`
|
||||||
|
|
||||||
|
## 测试用例
|
||||||
|
|
||||||
|
### 1. 用户名测试
|
||||||
|
|
||||||
|
| 输入 | 预期结果 | 错误信息 |
|
||||||
|
|------|----------|----------|
|
||||||
|
| "" | 失败 | "用户名不能为空" |
|
||||||
|
| "a" | 成功 | - |
|
||||||
|
| "test_user123" | 成功 | - |
|
||||||
|
| "test@user" | 失败 | "用户名只能包含字母、数字和下划线" |
|
||||||
|
| "a".repeat(51) | 失败 | "用户名长度应为1-50字符" |
|
||||||
|
|
||||||
|
### 2. 邮箱测试
|
||||||
|
|
||||||
|
| 输入 | 预期结果 | 错误信息 |
|
||||||
|
|------|----------|----------|
|
||||||
|
| "" | 失败 | "邮箱不能为空" |
|
||||||
|
| "test@example.com" | 成功 | - |
|
||||||
|
| "invalid-email" | 失败 | "请输入有效的邮箱地址" |
|
||||||
|
| "test@" | 失败 | "请输入有效的邮箱地址" |
|
||||||
|
|
||||||
|
### 3. 密码测试
|
||||||
|
|
||||||
|
| 输入 | 预期结果 | 错误信息 |
|
||||||
|
|------|----------|----------|
|
||||||
|
| "" | 失败 | "密码不能为空" |
|
||||||
|
| "1234567" | 失败 | "密码长度至少8位" |
|
||||||
|
| "12345678" | 失败 | "密码必须包含字母和数字" |
|
||||||
|
| "abcdefgh" | 失败 | "密码必须包含字母和数字" |
|
||||||
|
| "abc12345" | 成功 | - |
|
||||||
|
|
||||||
|
### 4. 验证码测试
|
||||||
|
|
||||||
|
| 输入 | 预期结果 | 错误信息 |
|
||||||
|
|------|----------|----------|
|
||||||
|
| "" | 失败 | "验证码不能为空" |
|
||||||
|
| "12345" | 失败 | "验证码必须是6位数字" |
|
||||||
|
| "1234567" | 失败 | "验证码必须是6位数字" |
|
||||||
|
| "12345a" | 失败 | "验证码必须是6位数字" |
|
||||||
|
| "123456" | 成功 | - |
|
||||||
|
|
||||||
|
## 最佳实践
|
||||||
|
|
||||||
|
### 1. 用户体验
|
||||||
|
|
||||||
|
- **即时反馈**: 在用户输入时提供即时的视觉反馈
|
||||||
|
- **清晰提示**: 错误信息要简洁明了,易于理解
|
||||||
|
- **引导操作**: 通过UI引导用户完成正确的操作流程
|
||||||
|
|
||||||
|
### 2. 性能优化
|
||||||
|
|
||||||
|
- **避免过度验证**: 不在每次字符输入时都进行复杂验证
|
||||||
|
- **合理的验证时机**: 在失焦和提交时进行验证
|
||||||
|
- **缓存验证结果**: 避免重复验证相同的内容
|
||||||
|
|
||||||
|
### 3. 安全考虑
|
||||||
|
|
||||||
|
- **客户端+服务端**: 双重验证确保数据安全
|
||||||
|
- **敏感信息**: 密码等敏感信息不在客户端明文存储
|
||||||
|
- **防止暴力破解**: 验证码冷却机制防止频繁请求
|
||||||
|
|
||||||
|
### 4. 可维护性
|
||||||
|
|
||||||
|
- **模块化设计**: 每个验证规则独立成函数
|
||||||
|
- **统一的错误处理**: 使用统一的错误显示机制
|
||||||
|
- **可配置的规则**: 验证规则可以根据需求调整
|
||||||
|
|
||||||
|
## 更新日志
|
||||||
|
|
||||||
|
- **v1.0.0** (2025-12-24): 初始版本,包含完整的表单验证规范
|
||||||
283
docs/auth/testing_guide.md
Normal file
@@ -0,0 +1,283 @@
|
|||||||
|
# 表单验证测试指南
|
||||||
|
|
||||||
|
## 测试概述
|
||||||
|
|
||||||
|
本文档提供了完整的表单验证功能测试步骤,确保所有验证规则和用户交互都能正常工作。
|
||||||
|
|
||||||
|
## 测试环境准备
|
||||||
|
|
||||||
|
### 1. 启动后端服务
|
||||||
|
```bash
|
||||||
|
# 确保后端服务运行在 https://whaletownend.xinghangee.icu
|
||||||
|
# 或者本地开发环境: http://localhost:3000
|
||||||
|
npm start
|
||||||
|
# 或者你的后端启动命令
|
||||||
|
```
|
||||||
|
|
||||||
|
### 2. 打开Godot项目
|
||||||
|
- 启动Godot编辑器
|
||||||
|
- 打开鲸鱼镇项目
|
||||||
|
- 运行主场景
|
||||||
|
|
||||||
|
## 登录表单测试
|
||||||
|
|
||||||
|
### 测试用例1: 必填项验证
|
||||||
|
|
||||||
|
#### 步骤
|
||||||
|
1. 点击"注册居民身份"进入登录界面
|
||||||
|
2. 不输入任何内容,直接点击用户名输入框外的区域
|
||||||
|
3. 不输入任何内容,直接点击密码输入框外的区域
|
||||||
|
4. 点击"进入小镇"或"密码登录"按钮
|
||||||
|
|
||||||
|
#### 预期结果
|
||||||
|
- 用户名输入框下方显示红色错误提示:"用户名不能为空"
|
||||||
|
- 密码输入框下方显示红色错误提示:"密码不能为空"
|
||||||
|
- 按钮点击无效,不会提交表单
|
||||||
|
|
||||||
|
### 测试用例2: 实时反馈
|
||||||
|
|
||||||
|
#### 步骤
|
||||||
|
1. 触发上述错误提示后
|
||||||
|
2. 在用户名输入框中输入任意字符
|
||||||
|
3. 在密码输入框中输入任意字符
|
||||||
|
|
||||||
|
#### 预期结果
|
||||||
|
- 开始输入时,对应的错误提示立即消失
|
||||||
|
- 提供即时的视觉反馈
|
||||||
|
|
||||||
|
### 测试用例3: 正常登录
|
||||||
|
|
||||||
|
#### 步骤
|
||||||
|
1. 输入有效的用户名:"testuser"
|
||||||
|
2. 输入任意密码:"password123"
|
||||||
|
3. 点击"进入小镇"
|
||||||
|
|
||||||
|
#### 预期结果
|
||||||
|
- 无错误提示显示
|
||||||
|
- 成功进入游戏主界面
|
||||||
|
- 显示用户名信息
|
||||||
|
|
||||||
|
## 注册表单测试
|
||||||
|
|
||||||
|
### 测试用例4: 用户名验证
|
||||||
|
|
||||||
|
#### 测试数据
|
||||||
|
| 输入 | 预期结果 | 错误信息 |
|
||||||
|
|------|----------|----------|
|
||||||
|
| (空) | 失败 | "用户名不能为空" |
|
||||||
|
| "test@user" | 失败 | "用户名只能包含字母、数字和下划线" |
|
||||||
|
| "a".repeat(51) | 失败 | "用户名长度应为1-50字符" |
|
||||||
|
| "test_user123" | 成功 | 无错误提示 |
|
||||||
|
|
||||||
|
#### 步骤
|
||||||
|
1. 点击"注册居民身份"
|
||||||
|
2. 依次输入上述测试数据
|
||||||
|
3. 每次输入后点击其他输入框(触发失焦验证)
|
||||||
|
|
||||||
|
### 测试用例5: 邮箱验证
|
||||||
|
|
||||||
|
#### 测试数据
|
||||||
|
| 输入 | 预期结果 | 错误信息 |
|
||||||
|
|------|----------|----------|
|
||||||
|
| (空) | 失败 | "邮箱不能为空" |
|
||||||
|
| "invalid-email" | 失败 | "请输入有效的邮箱地址" |
|
||||||
|
| "test@" | 失败 | "请输入有效的邮箱地址" |
|
||||||
|
| "test@example.com" | 成功 | 无错误提示 |
|
||||||
|
|
||||||
|
#### 步骤
|
||||||
|
1. 在邮箱输入框中依次输入测试数据
|
||||||
|
2. 每次输入后点击其他输入框
|
||||||
|
|
||||||
|
### 测试用例6: 密码验证
|
||||||
|
|
||||||
|
#### 测试数据
|
||||||
|
| 输入 | 预期结果 | 错误信息 |
|
||||||
|
|------|----------|----------|
|
||||||
|
| (空) | 失败 | "密码不能为空" |
|
||||||
|
| "1234567" | 失败 | "密码长度至少8位" |
|
||||||
|
| "12345678" | 失败 | "密码必须包含字母和数字" |
|
||||||
|
| "abcdefgh" | 失败 | "密码必须包含字母和数字" |
|
||||||
|
| "abc12345" | 成功 | 无错误提示 |
|
||||||
|
|
||||||
|
#### 步骤
|
||||||
|
1. 在密码输入框中依次输入测试数据
|
||||||
|
2. 每次输入后点击其他输入框
|
||||||
|
|
||||||
|
### 测试用例7: 确认密码验证
|
||||||
|
|
||||||
|
#### 步骤
|
||||||
|
1. 在密码框输入:"abc12345"
|
||||||
|
2. 在确认密码框输入:""(空)
|
||||||
|
3. 点击其他输入框
|
||||||
|
4. 在确认密码框输入:"different123"
|
||||||
|
5. 点击其他输入框
|
||||||
|
6. 在确认密码框输入:"abc12345"
|
||||||
|
7. 点击其他输入框
|
||||||
|
|
||||||
|
#### 预期结果
|
||||||
|
- 步骤3: 显示"确认密码不能为空"
|
||||||
|
- 步骤5: 显示"两次输入的密码不一致"
|
||||||
|
- 步骤7: 无错误提示
|
||||||
|
|
||||||
|
### 测试用例8: 验证码功能
|
||||||
|
|
||||||
|
#### 步骤
|
||||||
|
1. 不输入邮箱,直接点击"发送验证码"
|
||||||
|
2. 输入无效邮箱"invalid",点击"发送验证码"
|
||||||
|
3. 输入有效邮箱"test@example.com",点击"发送验证码"
|
||||||
|
4. 立即再次点击"发送验证码"
|
||||||
|
5. 在验证码输入框输入"12345"(5位)
|
||||||
|
6. 在验证码输入框输入"12345a"(包含字母)
|
||||||
|
7. 在验证码输入框输入"123456"(正确格式)
|
||||||
|
|
||||||
|
#### 预期结果
|
||||||
|
- 步骤1: 邮箱框显示"邮箱不能为空",聚焦到邮箱输入框
|
||||||
|
- 步骤2: 邮箱框显示"请输入有效的邮箱地址"
|
||||||
|
- 步骤3: 显示"正在发送验证码...",按钮变为禁用状态
|
||||||
|
- 步骤4: 显示冷却提示"请等待 XX 秒后再次发送"
|
||||||
|
- 步骤5: 验证码框显示"验证码必须是6位数字"
|
||||||
|
- 步骤6: 验证码框显示"验证码必须是6位数字"
|
||||||
|
- 步骤7: 无错误提示
|
||||||
|
|
||||||
|
### 测试用例9: 完整注册流程
|
||||||
|
|
||||||
|
#### 步骤
|
||||||
|
1. 填写所有必填信息:
|
||||||
|
- 用户名: "testuser"
|
||||||
|
- 邮箱: "test@example.com"
|
||||||
|
- 密码: "password123"
|
||||||
|
- 确认密码: "password123"
|
||||||
|
2. 点击"发送验证码"
|
||||||
|
3. 查看控制台获取验证码
|
||||||
|
4. 输入验证码
|
||||||
|
5. 点击"注册"按钮
|
||||||
|
|
||||||
|
#### 预期结果
|
||||||
|
- 所有验证通过,无错误提示
|
||||||
|
- 显示"正在验证邮箱..."
|
||||||
|
- 显示"邮箱验证成功,正在注册..."
|
||||||
|
- 显示"注册成功!"
|
||||||
|
- 自动返回登录界面
|
||||||
|
- 用户名自动填入登录表单
|
||||||
|
|
||||||
|
## 边界情况测试
|
||||||
|
|
||||||
|
### 测试用例10: 网络异常
|
||||||
|
|
||||||
|
#### 步骤
|
||||||
|
1. 关闭后端服务
|
||||||
|
2. 尝试发送验证码
|
||||||
|
3. 尝试注册
|
||||||
|
|
||||||
|
#### 预期结果
|
||||||
|
- 显示"网络连接失败,请检查服务器是否启动"
|
||||||
|
- 按钮重新启用
|
||||||
|
|
||||||
|
### 测试用例11: 快速操作
|
||||||
|
|
||||||
|
#### 步骤
|
||||||
|
1. 快速连续点击"发送验证码"按钮
|
||||||
|
2. 快速连续点击"注册"按钮
|
||||||
|
|
||||||
|
#### 预期结果
|
||||||
|
- 按钮在请求期间被禁用
|
||||||
|
- 防止重复提交
|
||||||
|
|
||||||
|
### 测试用例12: 表单切换
|
||||||
|
|
||||||
|
#### 步骤
|
||||||
|
1. 在注册表单中输入信息并触发错误提示
|
||||||
|
2. 点击"返回登录"
|
||||||
|
3. 再次点击"注册居民身份"
|
||||||
|
|
||||||
|
#### 预期结果
|
||||||
|
- 切换到登录界面时,注册表单状态保持
|
||||||
|
- 再次进入注册界面时,表单被清空,错误提示被隐藏
|
||||||
|
|
||||||
|
## 性能测试
|
||||||
|
|
||||||
|
### 测试用例13: 响应速度
|
||||||
|
|
||||||
|
#### 步骤
|
||||||
|
1. 快速在各个输入框之间切换
|
||||||
|
2. 快速输入和删除文本
|
||||||
|
3. 观察错误提示的显示和隐藏速度
|
||||||
|
|
||||||
|
#### 预期结果
|
||||||
|
- 验证响应迅速,无明显延迟
|
||||||
|
- UI更新流畅,无卡顿现象
|
||||||
|
|
||||||
|
## 兼容性测试
|
||||||
|
|
||||||
|
### 测试用例14: 不同输入法
|
||||||
|
|
||||||
|
#### 步骤
|
||||||
|
1. 使用中文输入法输入用户名
|
||||||
|
2. 使用英文输入法输入用户名
|
||||||
|
3. 输入特殊字符
|
||||||
|
|
||||||
|
#### 预期结果
|
||||||
|
- 中文字符被正确验证为无效格式
|
||||||
|
- 英文字符正常通过验证
|
||||||
|
- 特殊字符按规则验证
|
||||||
|
|
||||||
|
## 测试检查清单
|
||||||
|
|
||||||
|
### 功能完整性
|
||||||
|
- [ ] 所有必填项都有红色星号标识
|
||||||
|
- [ ] 失焦验证正常工作
|
||||||
|
- [ ] 实时输入反馈正常
|
||||||
|
- [ ] 错误提示准确显示
|
||||||
|
- [ ] 验证码发送和验证功能正常
|
||||||
|
- [ ] 注册流程完整可用
|
||||||
|
|
||||||
|
### 用户体验
|
||||||
|
- [ ] 错误提示清晰易懂
|
||||||
|
- [ ] 按钮状态管理正确
|
||||||
|
- [ ] 表单切换流畅
|
||||||
|
- [ ] 成功反馈及时
|
||||||
|
|
||||||
|
### 错误处理
|
||||||
|
- [ ] 网络异常处理正确
|
||||||
|
- [ ] 服务器错误处理正确
|
||||||
|
- [ ] 边界情况处理正确
|
||||||
|
|
||||||
|
### 性能表现
|
||||||
|
- [ ] 验证响应速度快
|
||||||
|
- [ ] UI更新流畅
|
||||||
|
- [ ] 内存使用正常
|
||||||
|
|
||||||
|
## 测试报告模板
|
||||||
|
|
||||||
|
### 测试环境
|
||||||
|
- Godot版本:
|
||||||
|
- 操作系统:
|
||||||
|
- 后端服务状态:
|
||||||
|
- 测试时间:
|
||||||
|
|
||||||
|
### 测试结果
|
||||||
|
| 测试用例 | 状态 | 备注 |
|
||||||
|
|----------|------|------|
|
||||||
|
| 登录表单验证 | ✅/❌ | |
|
||||||
|
| 注册表单验证 | ✅/❌ | |
|
||||||
|
| 验证码功能 | ✅/❌ | |
|
||||||
|
| 网络异常处理 | ✅/❌ | |
|
||||||
|
| 完整注册流程 | ✅/❌ | |
|
||||||
|
|
||||||
|
### 发现的问题
|
||||||
|
1. 问题描述
|
||||||
|
- 重现步骤
|
||||||
|
- 预期结果
|
||||||
|
- 实际结果
|
||||||
|
- 严重程度
|
||||||
|
|
||||||
|
### 改进建议
|
||||||
|
1. 功能改进
|
||||||
|
2. 用户体验优化
|
||||||
|
3. 性能优化
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
**测试完成日期**: ___________
|
||||||
|
**测试人员**: ___________
|
||||||
|
**测试版本**: v1.0.0
|
||||||
137
docs/cleanup_summary.md
Normal file
@@ -0,0 +1,137 @@
|
|||||||
|
# AuthScene 文件清理总结
|
||||||
|
|
||||||
|
**清理日期**: 2025-12-25
|
||||||
|
**清理原因**: 修复Parser Error和优化代码结构
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🔧 修复的问题
|
||||||
|
|
||||||
|
### 1. **Parser Error修复**
|
||||||
|
- **问题**: `scripts/scenes/AuthScene.gd` 第1196行有语法错误 "母和数字"
|
||||||
|
- **解决**: 完全重写了AuthScene.gd文件,移除了所有语法错误
|
||||||
|
- **结果**: 文件现在可以正常解析,无语法错误
|
||||||
|
|
||||||
|
### 2. **代码结构优化**
|
||||||
|
- **重构验证逻辑**: 使用StringUtils工具类统一处理验证
|
||||||
|
- **简化代码**: 移除重复的验证代码
|
||||||
|
- **提高可维护性**: 更清晰的方法组织和注释
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🗑️ 删除的文件
|
||||||
|
|
||||||
|
### 已删除
|
||||||
|
1. **`scripts/network/NetworkTest.gd`**
|
||||||
|
- **原因**: 功能重复,已有更完善的ApiTestScript.gd
|
||||||
|
- **影响**: 无,功能已被ApiTestScript.gd替代
|
||||||
|
|
||||||
|
### 保留的文件
|
||||||
|
1. **`tests/auth/auth_ui_test.gd`** - 保留,用于UI测试
|
||||||
|
2. **`tests/auth/enhanced_toast_test.gd`** - 保留,用于Toast系统测试
|
||||||
|
3. **`core/utils/StringUtils.gd`** - 保留,提供通用验证工具
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## ✅ 优化后的AuthScene.gd结构
|
||||||
|
|
||||||
|
### 文件组织
|
||||||
|
```
|
||||||
|
AuthScene.gd (约600行,结构清晰)
|
||||||
|
├── 节点引用和变量定义
|
||||||
|
├── 初始化和信号连接
|
||||||
|
├── 按钮事件处理
|
||||||
|
├── 网络响应处理
|
||||||
|
├── 验证码冷却管理
|
||||||
|
├── Toast消息系统
|
||||||
|
├── UI工具方法
|
||||||
|
├── 表单验证方法
|
||||||
|
├── 表单验证事件
|
||||||
|
└── 资源清理
|
||||||
|
```
|
||||||
|
|
||||||
|
### 主要改进
|
||||||
|
1. **使用StringUtils**: 统一的验证逻辑
|
||||||
|
2. **清晰的方法分组**: 按功能组织代码
|
||||||
|
3. **完整的错误处理**: 支持最新API v1.1.1
|
||||||
|
4. **优化的Toast系统**: 更好的视觉效果和动画
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🧪 测试验证
|
||||||
|
|
||||||
|
### 语法检查
|
||||||
|
```bash
|
||||||
|
# 所有文件通过语法检查
|
||||||
|
✅ scripts/scenes/AuthScene.gd - No diagnostics found
|
||||||
|
✅ core/managers/NetworkManager.gd - No diagnostics found
|
||||||
|
✅ core/managers/ResponseHandler.gd - No diagnostics found
|
||||||
|
```
|
||||||
|
|
||||||
|
### 功能测试
|
||||||
|
- ✅ Toast显示系统正常
|
||||||
|
- ✅ 表单验证逻辑正确
|
||||||
|
- ✅ 网络请求处理完整
|
||||||
|
- ✅ 验证码冷却机制有效
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 📊 代码质量提升
|
||||||
|
|
||||||
|
### 前后对比
|
||||||
|
| 指标 | 清理前 | 清理后 | 改进 |
|
||||||
|
|------|--------|--------|------|
|
||||||
|
| 语法错误 | 1个 | 0个 | ✅ 修复 |
|
||||||
|
| 代码行数 | ~1400行 | ~600行 | ✅ 精简57% |
|
||||||
|
| 重复代码 | 多处 | 无 | ✅ 消除 |
|
||||||
|
| 可读性 | 中等 | 高 | ✅ 提升 |
|
||||||
|
| 维护性 | 中等 | 高 | ✅ 提升 |
|
||||||
|
|
||||||
|
### 代码质量指标
|
||||||
|
- **圈复杂度**: 降低
|
||||||
|
- **代码重复率**: 显著减少
|
||||||
|
- **方法长度**: 更合理
|
||||||
|
- **注释覆盖**: 完整
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🔄 兼容性保证
|
||||||
|
|
||||||
|
### API兼容性
|
||||||
|
- ✅ 保持所有公共方法签名不变
|
||||||
|
- ✅ 保持所有信号定义不变
|
||||||
|
- ✅ 保持节点引用路径不变
|
||||||
|
|
||||||
|
### 功能兼容性
|
||||||
|
- ✅ 登录功能完整
|
||||||
|
- ✅ 注册功能完整
|
||||||
|
- ✅ 验证码功能完整
|
||||||
|
- ✅ Toast显示功能增强
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 📝 后续建议
|
||||||
|
|
||||||
|
### 短期
|
||||||
|
1. **测试验证**: 在实际环境中测试所有功能
|
||||||
|
2. **性能监控**: 观察Toast动画性能
|
||||||
|
3. **用户反馈**: 收集UI体验反馈
|
||||||
|
|
||||||
|
### 长期
|
||||||
|
1. **单元测试**: 为验证逻辑添加更多单元测试
|
||||||
|
2. **集成测试**: 完善端到端测试覆盖
|
||||||
|
3. **代码审查**: 定期进行代码质量审查
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🎯 总结
|
||||||
|
|
||||||
|
通过这次清理,我们成功:
|
||||||
|
|
||||||
|
1. **修复了语法错误** - AuthScene.gd现在可以正常解析
|
||||||
|
2. **优化了代码结构** - 更清晰、更易维护
|
||||||
|
3. **提升了代码质量** - 减少重复,提高可读性
|
||||||
|
4. **保持了功能完整** - 所有原有功能都得到保留和增强
|
||||||
|
5. **删除了冗余文件** - 清理了不必要的测试文件
|
||||||
|
|
||||||
|
AuthScene现在是一个干净、高效、易维护的认证界面组件,完全支持最新的API v1.1.1规范。
|
||||||
433
docs/code_comment_guide.md
Normal file
@@ -0,0 +1,433 @@
|
|||||||
|
# GDScript 代码注释规范
|
||||||
|
|
||||||
|
本文档详细说明了 whaleTown 项目中 GDScript 代码的注释规范,旨在提高代码可读性和维护性。
|
||||||
|
|
||||||
|
## 目录
|
||||||
|
|
||||||
|
- [基本原则](#基本原则)
|
||||||
|
- [文件头注释](#文件头注释)
|
||||||
|
- [类和函数注释](#类和函数注释)
|
||||||
|
- [变量注释](#变量注释)
|
||||||
|
- [行内注释](#行内注释)
|
||||||
|
- [特殊注释标记](#特殊注释标记)
|
||||||
|
- [AI辅助注释指南](#ai辅助注释指南)
|
||||||
|
|
||||||
|
## 基本原则
|
||||||
|
|
||||||
|
### 注释的目的
|
||||||
|
- **解释为什么**,而不是解释做什么
|
||||||
|
- **提供上下文**,帮助理解代码意图
|
||||||
|
- **记录重要决策**和设计考虑
|
||||||
|
- **警告潜在问题**和注意事项
|
||||||
|
|
||||||
|
### 注释质量标准
|
||||||
|
- 简洁明了,避免冗余
|
||||||
|
- 使用中文,保持一致性
|
||||||
|
- 及时更新,与代码同步
|
||||||
|
- 避免显而易见的注释
|
||||||
|
|
||||||
|
## 文件头注释
|
||||||
|
|
||||||
|
每个 GDScript 文件都应该包含文件头注释,说明文件的用途和基本信息。
|
||||||
|
|
||||||
|
### 标准格式
|
||||||
|
|
||||||
|
```gdscript
|
||||||
|
# ============================================================================
|
||||||
|
# 文件名: PlayerController.gd
|
||||||
|
# 作用: 玩家角色控制器,处理玩家输入和移动逻辑
|
||||||
|
#
|
||||||
|
# 主要功能:
|
||||||
|
# - 处理键盘和手柄输入
|
||||||
|
# - 控制角色移动和跳跃
|
||||||
|
# - 管理角色状态切换
|
||||||
|
# - 处理碰撞检测
|
||||||
|
#
|
||||||
|
# 依赖: MovementComponent, AnimationComponent
|
||||||
|
# 作者: [开发者名称]
|
||||||
|
# 创建时间: 2024-12-24
|
||||||
|
# ============================================================================
|
||||||
|
|
||||||
|
extends CharacterBody2D
|
||||||
|
```
|
||||||
|
|
||||||
|
### 管理器类文件头
|
||||||
|
|
||||||
|
```gdscript
|
||||||
|
# ============================================================================
|
||||||
|
# 游戏管理器 - GameManager.gd
|
||||||
|
#
|
||||||
|
# 全局单例管理器,负责游戏状态管理和生命周期控制
|
||||||
|
#
|
||||||
|
# 核心职责:
|
||||||
|
# - 游戏状态切换 (加载、认证、游戏中、暂停等)
|
||||||
|
# - 用户信息管理
|
||||||
|
# - 全局配置访问
|
||||||
|
# - 系统初始化和清理
|
||||||
|
#
|
||||||
|
# 使用方式:
|
||||||
|
# GameManager.change_state(GameManager.GameState.IN_GAME)
|
||||||
|
# GameManager.set_current_user("player123")
|
||||||
|
#
|
||||||
|
# 注意事项:
|
||||||
|
# - 作为自动加载单例,全局可访问
|
||||||
|
# - 状态变更会触发 game_state_changed 信号
|
||||||
|
# ============================================================================
|
||||||
|
|
||||||
|
extends Node
|
||||||
|
```
|
||||||
|
## 类和函数注释
|
||||||
|
|
||||||
|
### 类注释
|
||||||
|
|
||||||
|
```gdscript
|
||||||
|
# 玩家数据类
|
||||||
|
#
|
||||||
|
# 存储和管理玩家的基本属性和状态信息
|
||||||
|
# 支持数据序列化和反序列化,用于存档系统
|
||||||
|
class_name PlayerData
|
||||||
|
|
||||||
|
# 武器组件类
|
||||||
|
#
|
||||||
|
# 为角色提供武器功能,包括攻击、换弹、特殊技能等
|
||||||
|
# 可以挂载到任何具有攻击能力的角色上
|
||||||
|
#
|
||||||
|
# 使用示例:
|
||||||
|
# var weapon = WeaponComponent.new()
|
||||||
|
# weapon.setup_weapon("sword", 50)
|
||||||
|
# add_child(weapon)
|
||||||
|
class_name WeaponComponent
|
||||||
|
```
|
||||||
|
|
||||||
|
### 函数注释格式
|
||||||
|
|
||||||
|
```gdscript
|
||||||
|
# 处理玩家输入并更新移动状态
|
||||||
|
#
|
||||||
|
# 参数:
|
||||||
|
# delta: float - 帧时间间隔
|
||||||
|
#
|
||||||
|
# 返回值: 无
|
||||||
|
#
|
||||||
|
# 注意事项:
|
||||||
|
# - 需要在 _physics_process 中调用
|
||||||
|
# - 会自动处理重力和碰撞
|
||||||
|
func handle_movement(delta: float) -> void:
|
||||||
|
|
||||||
|
# 验证用户输入的邮箱格式
|
||||||
|
#
|
||||||
|
# 参数:
|
||||||
|
# email: String - 待验证的邮箱地址
|
||||||
|
#
|
||||||
|
# 返回值:
|
||||||
|
# Dictionary - 包含验证结果和错误信息
|
||||||
|
# {
|
||||||
|
# "valid": bool, # 是否有效
|
||||||
|
# "message": String # 错误信息(如果无效)
|
||||||
|
# }
|
||||||
|
#
|
||||||
|
# 使用示例:
|
||||||
|
# var result = validate_email("test@example.com")
|
||||||
|
# if result.valid:
|
||||||
|
# print("邮箱格式正确")
|
||||||
|
static func validate_email(email: String) -> Dictionary:
|
||||||
|
```
|
||||||
|
## 变量注释
|
||||||
|
|
||||||
|
### 成员变量注释
|
||||||
|
|
||||||
|
```gdscript
|
||||||
|
# 玩家基础属性
|
||||||
|
@export var max_health: int = 100 # 最大生命值
|
||||||
|
@export var move_speed: float = 200.0 # 移动速度 (像素/秒)
|
||||||
|
@export var jump_force: float = -400.0 # 跳跃力度 (负值向上)
|
||||||
|
|
||||||
|
# 状态管理
|
||||||
|
var current_health: int # 当前生命值
|
||||||
|
var is_grounded: bool = false # 是否在地面上
|
||||||
|
var can_double_jump: bool = true # 是否可以二段跳
|
||||||
|
|
||||||
|
# 节点引用 - 在 _ready() 中初始化
|
||||||
|
@onready var sprite: Sprite2D = $Sprite2D
|
||||||
|
@onready var collision: CollisionShape2D = $CollisionShape2D
|
||||||
|
@onready var animation_player: AnimationPlayer = $AnimationPlayer
|
||||||
|
|
||||||
|
# 私有变量 - 内部使用
|
||||||
|
var _velocity: Vector2 = Vector2.ZERO # 当前速度向量
|
||||||
|
var _last_direction: int = 1 # 最后面向方向 (1=右, -1=左)
|
||||||
|
```
|
||||||
|
|
||||||
|
### 常量注释
|
||||||
|
|
||||||
|
```gdscript
|
||||||
|
# 游戏配置常量
|
||||||
|
const GRAVITY: float = 980.0 # 重力加速度 (像素/秒²)
|
||||||
|
const MAX_FALL_SPEED: float = 1000.0 # 最大下落速度
|
||||||
|
const COYOTE_TIME: float = 0.1 # 土狼时间 (离开平台后仍可跳跃的时间)
|
||||||
|
|
||||||
|
# 输入动作名称
|
||||||
|
const ACTION_MOVE_LEFT: String = "move_left"
|
||||||
|
const ACTION_MOVE_RIGHT: String = "move_right"
|
||||||
|
const ACTION_JUMP: String = "jump"
|
||||||
|
|
||||||
|
# 动画名称常量
|
||||||
|
const ANIM_IDLE: String = "idle"
|
||||||
|
const ANIM_WALK: String = "walk"
|
||||||
|
const ANIM_JUMP: String = "jump"
|
||||||
|
const ANIM_FALL: String = "fall"
|
||||||
|
```
|
||||||
|
|
||||||
|
## 行内注释
|
||||||
|
|
||||||
|
### 复杂逻辑注释
|
||||||
|
|
||||||
|
```gdscript
|
||||||
|
func update_movement(delta: float):
|
||||||
|
# 处理水平移动输入
|
||||||
|
var input_direction = Input.get_axis("move_left", "move_right")
|
||||||
|
|
||||||
|
if input_direction != 0:
|
||||||
|
velocity.x = input_direction * move_speed
|
||||||
|
_last_direction = sign(input_direction) # 记录面向方向
|
||||||
|
else:
|
||||||
|
# 应用摩擦力,逐渐停止
|
||||||
|
velocity.x = move_toward(velocity.x, 0, friction * delta)
|
||||||
|
|
||||||
|
# 应用重力 (只在空中时)
|
||||||
|
if not is_on_floor():
|
||||||
|
velocity.y += gravity * delta
|
||||||
|
velocity.y = min(velocity.y, max_fall_speed) # 限制最大下落速度
|
||||||
|
|
||||||
|
# 处理跳跃输入
|
||||||
|
if Input.is_action_just_pressed("jump"):
|
||||||
|
if is_on_floor():
|
||||||
|
velocity.y = jump_force # 普通跳跃
|
||||||
|
elif can_double_jump:
|
||||||
|
velocity.y = jump_force * 0.8 # 二段跳 (力度稍小)
|
||||||
|
can_double_jump = false
|
||||||
|
|
||||||
|
# 重置二段跳能力
|
||||||
|
if is_on_floor() and not can_double_jump:
|
||||||
|
can_double_jump = true
|
||||||
|
```
|
||||||
|
|
||||||
|
### 临时解决方案注释
|
||||||
|
|
||||||
|
```gdscript
|
||||||
|
func handle_collision(body: Node2D):
|
||||||
|
# TODO: 重构碰撞处理逻辑,当前实现过于复杂
|
||||||
|
# FIXME: 在某些情况下会出现重复碰撞检测
|
||||||
|
# HACK: 临时解决方案,等待 Godot 4.6 修复相关 bug
|
||||||
|
|
||||||
|
if body.has_method("take_damage"):
|
||||||
|
# NOTE: 伤害计算需要考虑护甲和抗性
|
||||||
|
var damage = calculate_damage(base_damage)
|
||||||
|
body.take_damage(damage)
|
||||||
|
```
|
||||||
|
## 特殊注释标记
|
||||||
|
|
||||||
|
使用标准化的标记来标识不同类型的注释:
|
||||||
|
|
||||||
|
### 标记类型
|
||||||
|
|
||||||
|
```gdscript
|
||||||
|
# TODO: 待实现的功能
|
||||||
|
# TODO: 添加音效播放功能
|
||||||
|
# TODO: 实现存档系统
|
||||||
|
|
||||||
|
# FIXME: 需要修复的问题
|
||||||
|
# FIXME: 内存泄漏问题,需要及时释放资源
|
||||||
|
# FIXME: 在低帧率下移动不流畅
|
||||||
|
|
||||||
|
# HACK: 临时解决方案
|
||||||
|
# HACK: 绕过 Godot 引擎的已知 bug
|
||||||
|
# HACK: 临时方案,等待更好的实现
|
||||||
|
|
||||||
|
# NOTE: 重要说明
|
||||||
|
# NOTE: 此函数会修改全局状态,谨慎使用
|
||||||
|
# NOTE: 性能敏感代码,避免频繁调用
|
||||||
|
|
||||||
|
# WARNING: 警告信息
|
||||||
|
# WARNING: 不要在 _ready() 之前调用此函数
|
||||||
|
# WARNING: 此操作不可逆,请确认后执行
|
||||||
|
|
||||||
|
# OPTIMIZE: 性能优化点
|
||||||
|
# OPTIMIZE: 可以使用对象池优化内存分配
|
||||||
|
# OPTIMIZE: 考虑使用缓存提高查询效率
|
||||||
|
```
|
||||||
|
|
||||||
|
### 版本和兼容性标记
|
||||||
|
|
||||||
|
```gdscript
|
||||||
|
# @since 1.0.0 - 添加基础移动功能
|
||||||
|
# @deprecated 使用 new_movement_system() 替代
|
||||||
|
# @godot_version 4.5+ - 需要 Godot 4.5 或更高版本
|
||||||
|
# @platform_specific Windows/Linux - 仅在桌面平台可用
|
||||||
|
```
|
||||||
|
|
||||||
|
## AI辅助注释指南
|
||||||
|
|
||||||
|
### 为AI提供的注释模板
|
||||||
|
|
||||||
|
当需要AI帮助补充注释时,请使用以下模板:
|
||||||
|
|
||||||
|
```gdscript
|
||||||
|
# [AI_COMMENT_REQUEST]
|
||||||
|
# 请为以下函数添加详细注释,包括:
|
||||||
|
# - 功能描述
|
||||||
|
# - 参数说明
|
||||||
|
# - 返回值说明
|
||||||
|
# - 使用示例
|
||||||
|
# - 注意事项
|
||||||
|
func complex_function(param1: String, param2: int) -> Dictionary:
|
||||||
|
# 复杂的业务逻辑...
|
||||||
|
pass
|
||||||
|
```
|
||||||
|
|
||||||
|
### AI注释补充规则
|
||||||
|
|
||||||
|
1. **保持一致性** - 遵循项目现有的注释风格
|
||||||
|
2. **关注业务逻辑** - 重点解释业务含义,而非语法
|
||||||
|
3. **提供上下文** - 说明函数在整个系统中的作用
|
||||||
|
4. **标注复杂度** - 对复杂算法提供额外说明
|
||||||
|
|
||||||
|
### 示例:AI补充前后对比
|
||||||
|
|
||||||
|
**补充前:**
|
||||||
|
```gdscript
|
||||||
|
func calculate_damage(base_damage: int, armor: int, resistance: float) -> int:
|
||||||
|
var final_damage = base_damage
|
||||||
|
final_damage -= armor
|
||||||
|
final_damage *= (1.0 - resistance)
|
||||||
|
return max(1, final_damage)
|
||||||
|
```
|
||||||
|
|
||||||
|
**AI补充后:**
|
||||||
|
```gdscript
|
||||||
|
# 计算最终伤害值
|
||||||
|
#
|
||||||
|
# 根据基础伤害、护甲值和抗性计算实际造成的伤害
|
||||||
|
# 伤害计算公式: (基础伤害 - 护甲) × (1 - 抗性)
|
||||||
|
#
|
||||||
|
# 参数:
|
||||||
|
# base_damage: int - 基础伤害值
|
||||||
|
# armor: int - 目标护甲值 (减少固定伤害)
|
||||||
|
# resistance: float - 目标抗性 (0.0-1.0, 减少百分比伤害)
|
||||||
|
#
|
||||||
|
# 返回值:
|
||||||
|
# int - 最终伤害值 (最小为1,确保至少造成1点伤害)
|
||||||
|
#
|
||||||
|
# 使用示例:
|
||||||
|
# var damage = calculate_damage(100, 20, 0.3) # 结果: 56
|
||||||
|
#
|
||||||
|
# 注意事项:
|
||||||
|
# - 护甲为负值时会增加伤害
|
||||||
|
# - 抗性超过1.0时可能导致负伤害,但会被限制为1
|
||||||
|
func calculate_damage(base_damage: int, armor: int, resistance: float) -> int:
|
||||||
|
var final_damage = base_damage
|
||||||
|
final_damage -= armor # 减去护甲值
|
||||||
|
final_damage *= (1.0 - resistance) # 应用抗性
|
||||||
|
return max(1, final_damage) # 确保最小伤害为1
|
||||||
|
```
|
||||||
|
## 注释最佳实践
|
||||||
|
|
||||||
|
### 什么时候需要注释
|
||||||
|
|
||||||
|
**必须添加注释的情况:**
|
||||||
|
- 复杂的算法和业务逻辑
|
||||||
|
- 非显而易见的设计决策
|
||||||
|
- 临时解决方案和已知问题
|
||||||
|
- 公共API和接口函数
|
||||||
|
- 性能敏感的代码段
|
||||||
|
- 平台特定或版本特定的代码
|
||||||
|
|
||||||
|
**不需要注释的情况:**
|
||||||
|
- 显而易见的代码 (`var count = 0 # 计数器` ❌)
|
||||||
|
- 重复函数名的注释 (`func get_name() -> String: # 获取名称` ❌)
|
||||||
|
- 过时或错误的注释
|
||||||
|
|
||||||
|
### 注释维护原则
|
||||||
|
|
||||||
|
```gdscript
|
||||||
|
# ✅ 好的注释 - 解释为什么这样做
|
||||||
|
# 使用二分查找提高大数组的查询效率
|
||||||
|
# 当数组长度超过100时,线性查找性能会显著下降
|
||||||
|
func binary_search(array: Array, target: Variant) -> int:
|
||||||
|
|
||||||
|
# ❌ 坏的注释 - 重复代码内容
|
||||||
|
# 遍历数组查找目标值
|
||||||
|
func linear_search(array: Array, target: Variant) -> int:
|
||||||
|
```
|
||||||
|
|
||||||
|
### 团队协作注释
|
||||||
|
|
||||||
|
```gdscript
|
||||||
|
# 多人协作时的注释规范
|
||||||
|
class_name NetworkManager
|
||||||
|
|
||||||
|
# @author: 张三 - 网络连接模块
|
||||||
|
# @author: 李四 - 数据同步模块
|
||||||
|
# @reviewer: 王五 - 代码审查
|
||||||
|
# @last_modified: 2024-12-24
|
||||||
|
|
||||||
|
# 网络连接状态枚举
|
||||||
|
#
|
||||||
|
# 定义了客户端与服务器的连接状态
|
||||||
|
# 状态转换: DISCONNECTED -> CONNECTING -> CONNECTED -> DISCONNECTED
|
||||||
|
enum ConnectionState {
|
||||||
|
DISCONNECTED, # 未连接
|
||||||
|
CONNECTING, # 连接中
|
||||||
|
CONNECTED, # 已连接
|
||||||
|
RECONNECTING # 重连中 - @added by 李四 2024-12-20
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 注释检查清单
|
||||||
|
|
||||||
|
在提交代码前,请检查以下项目:
|
||||||
|
|
||||||
|
### 文件级别检查
|
||||||
|
- [ ] 文件头注释完整(文件名、作用、主要功能)
|
||||||
|
- [ ] 依赖关系说明清楚
|
||||||
|
- [ ] 作者和创建时间已填写
|
||||||
|
|
||||||
|
### 函数级别检查
|
||||||
|
- [ ] 公共函数有完整的参数和返回值说明
|
||||||
|
- [ ] 复杂函数有使用示例
|
||||||
|
- [ ] 特殊情况和注意事项已标注
|
||||||
|
|
||||||
|
### 代码级别检查
|
||||||
|
- [ ] 复杂逻辑有行内注释说明
|
||||||
|
- [ ] 魔法数字有常量定义和注释
|
||||||
|
- [ ] TODO/FIXME 标记有明确的处理计划
|
||||||
|
|
||||||
|
### 质量检查
|
||||||
|
- [ ] 注释内容准确,与代码一致
|
||||||
|
- [ ] 中文表达清晰,无错别字
|
||||||
|
- [ ] 注释格式符合项目规范
|
||||||
|
|
||||||
|
## 注释工具和插件
|
||||||
|
|
||||||
|
### Godot编辑器设置
|
||||||
|
```
|
||||||
|
# 在 Godot 编辑器中设置注释快捷键
|
||||||
|
# 编辑器设置 -> 快捷键 -> 注释/取消注释: Ctrl+/
|
||||||
|
```
|
||||||
|
|
||||||
|
### 推荐的注释插件
|
||||||
|
- **GDScript Language Server** - 提供注释语法高亮
|
||||||
|
- **Code Formatter** - 自动格式化注释
|
||||||
|
- **Documentation Generator** - 自动生成API文档
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 总结
|
||||||
|
|
||||||
|
良好的注释是代码质量的重要组成部分。遵循本规范可以:
|
||||||
|
|
||||||
|
1. **提高代码可读性** - 帮助团队成员快速理解代码
|
||||||
|
2. **降低维护成本** - 减少后期修改和调试时间
|
||||||
|
3. **促进知识传承** - 保留设计思路和业务逻辑
|
||||||
|
4. **支持AI辅助开发** - 为AI提供更好的上下文信息
|
||||||
|
|
||||||
|
记住:**好的注释解释为什么,而不是做什么。**
|
||||||
251
docs/final_update_summary.md
Normal file
@@ -0,0 +1,251 @@
|
|||||||
|
# 最终更新总结
|
||||||
|
|
||||||
|
**完成日期**: 2025-12-25
|
||||||
|
**更新内容**: AuthScene文件修复 + Python API测试工具
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🎯 完成的工作
|
||||||
|
|
||||||
|
### 1. ✅ AuthScene.gd 文件修复
|
||||||
|
|
||||||
|
#### 问题解决
|
||||||
|
- **修复Parser Error**: 删除了第1196行的语法错误"母和数字"
|
||||||
|
- **重构代码结构**: 完全重写了AuthScene.gd,代码更清晰、更易维护
|
||||||
|
- **优化验证逻辑**: 使用StringUtils工具类统一处理表单验证
|
||||||
|
|
||||||
|
#### 文件状态
|
||||||
|
- **语法检查**: ✅ No diagnostics found
|
||||||
|
- **代码行数**: 约600行(原来~1400行,精简57%)
|
||||||
|
- **功能完整性**: ✅ 保持所有原有功能
|
||||||
|
- **API兼容性**: ✅ 完全支持API v1.1.1
|
||||||
|
|
||||||
|
### 2. ✅ Python API测试工具
|
||||||
|
|
||||||
|
#### 创建的测试脚本
|
||||||
|
1. **`quick_test.py`** - 快速测试脚本(推荐日常使用)
|
||||||
|
2. **`api_client_test.py`** - 完整测试套件(全面功能验证)
|
||||||
|
3. **`requirements.txt`** - Python依赖配置
|
||||||
|
4. **`run_tests.bat`** - Windows批处理脚本
|
||||||
|
5. **`run_tests.sh`** - Linux/Mac Shell脚本
|
||||||
|
|
||||||
|
#### 测试覆盖范围
|
||||||
|
- ✅ 应用状态检查
|
||||||
|
- ✅ 用户认证流程(登录/注册)
|
||||||
|
- ✅ 邮箱验证流程
|
||||||
|
- ✅ 验证码功能(发送/验证)
|
||||||
|
- ✅ 密码重置流程
|
||||||
|
- ✅ 错误场景测试
|
||||||
|
- ✅ 频率限制测试
|
||||||
|
- ✅ API v1.1.1新特性测试
|
||||||
|
|
||||||
|
### 3. ✅ 文档更新
|
||||||
|
|
||||||
|
#### 新增文档
|
||||||
|
- **`docs/testing_guide.md`** - 完整的API测试指南
|
||||||
|
- **`docs/final_update_summary.md`** - 本总结文档
|
||||||
|
- **`tests/api/README.md`** - 更新了测试说明
|
||||||
|
|
||||||
|
#### 更新文档
|
||||||
|
- **`docs/api_update_log.md`** - API更新日志
|
||||||
|
- **`docs/cleanup_summary.md`** - 代码清理总结
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🔧 技术改进
|
||||||
|
|
||||||
|
### AuthScene.gd 优化
|
||||||
|
```gdscript
|
||||||
|
# 优化前的问题
|
||||||
|
- 语法错误导致无法解析
|
||||||
|
- 代码重复,维护困难
|
||||||
|
- 验证逻辑分散
|
||||||
|
|
||||||
|
# 优化后的改进
|
||||||
|
- 无语法错误,结构清晰
|
||||||
|
- 使用StringUtils统一验证
|
||||||
|
- 方法分组,易于维护
|
||||||
|
```
|
||||||
|
|
||||||
|
### API测试工具特性
|
||||||
|
```python
|
||||||
|
# 完整的API客户端
|
||||||
|
class APIClient:
|
||||||
|
- 统一的请求处理
|
||||||
|
- 详细的错误处理
|
||||||
|
- 支持所有API端点
|
||||||
|
- 自动状态码判断
|
||||||
|
|
||||||
|
# 智能测试结果
|
||||||
|
class TestResult:
|
||||||
|
- 成功/失败判断
|
||||||
|
- 执行时间统计
|
||||||
|
- 详细错误信息
|
||||||
|
- 特殊状态码处理
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 📊 测试验证
|
||||||
|
|
||||||
|
### 语法检查结果
|
||||||
|
```bash
|
||||||
|
✅ scripts/scenes/AuthScene.gd - No diagnostics found
|
||||||
|
✅ core/managers/NetworkManager.gd - No diagnostics found
|
||||||
|
✅ core/managers/ResponseHandler.gd - No diagnostics found
|
||||||
|
```
|
||||||
|
|
||||||
|
### Python测试工具验证
|
||||||
|
```bash
|
||||||
|
# 快速测试
|
||||||
|
python tests/api/quick_test.py
|
||||||
|
# 预期结果: 6个基础API测试通过
|
||||||
|
|
||||||
|
# 完整测试
|
||||||
|
python tests/api/api_client_test.py
|
||||||
|
# 预期结果: 完整业务流程测试通过
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🎯 使用指南
|
||||||
|
|
||||||
|
### 开发者日常使用
|
||||||
|
|
||||||
|
#### 1. 快速API测试
|
||||||
|
```bash
|
||||||
|
cd tests/api
|
||||||
|
python quick_test.py
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 2. 完整功能验证
|
||||||
|
```bash
|
||||||
|
cd tests/api
|
||||||
|
python api_client_test.py
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 3. Windows用户
|
||||||
|
```bash
|
||||||
|
cd tests/api
|
||||||
|
run_tests.bat
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 4. Linux/Mac用户
|
||||||
|
```bash
|
||||||
|
cd tests/api
|
||||||
|
./run_tests.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
### Godot开发者使用
|
||||||
|
|
||||||
|
#### 1. 运行AuthScene
|
||||||
|
- 场景文件正常加载
|
||||||
|
- Toast系统正常工作
|
||||||
|
- 网络请求正常处理
|
||||||
|
|
||||||
|
#### 2. API测试脚本
|
||||||
|
```gdscript
|
||||||
|
# 在Godot中运行
|
||||||
|
var api_test = preload("res://scripts/network/ApiTestScript.gd").new()
|
||||||
|
add_child(api_test)
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🔍 质量保证
|
||||||
|
|
||||||
|
### 代码质量指标
|
||||||
|
| 指标 | 修复前 | 修复后 | 改进 |
|
||||||
|
|------|--------|--------|------|
|
||||||
|
| 语法错误 | 1个 | 0个 | ✅ 完全修复 |
|
||||||
|
| 代码行数 | ~1400行 | ~600行 | ✅ 精简57% |
|
||||||
|
| 重复代码 | 多处 | 无 | ✅ 完全消除 |
|
||||||
|
| 可维护性 | 中等 | 高 | ✅ 显著提升 |
|
||||||
|
|
||||||
|
### 功能完整性
|
||||||
|
- ✅ 登录功能完整保留
|
||||||
|
- ✅ 注册功能完整保留
|
||||||
|
- ✅ 验证码功能完整保留
|
||||||
|
- ✅ Toast显示功能增强
|
||||||
|
- ✅ 错误处理功能增强
|
||||||
|
|
||||||
|
### API兼容性
|
||||||
|
- ✅ 支持409冲突检测
|
||||||
|
- ✅ 支持206测试模式
|
||||||
|
- ✅ 支持429频率限制
|
||||||
|
- ✅ 支持所有新增错误码
|
||||||
|
- ✅ 向后兼容旧版本
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 📈 项目收益
|
||||||
|
|
||||||
|
### 开发效率提升
|
||||||
|
1. **无需Godot引擎**: Python测试脚本可独立运行
|
||||||
|
2. **快速验证**: 30秒内完成基础API测试
|
||||||
|
3. **自动化支持**: 可集成到CI/CD流程
|
||||||
|
4. **跨平台支持**: Windows/Linux/Mac都可使用
|
||||||
|
|
||||||
|
### 代码质量提升
|
||||||
|
1. **消除语法错误**: AuthScene.gd现在完全可用
|
||||||
|
2. **减少代码重复**: 使用工具类统一处理
|
||||||
|
3. **提高可维护性**: 清晰的代码结构和注释
|
||||||
|
4. **增强错误处理**: 支持最新API规范
|
||||||
|
|
||||||
|
### 测试覆盖提升
|
||||||
|
1. **完整业务流程**: 覆盖所有用户操作场景
|
||||||
|
2. **错误场景测试**: 验证各种异常情况
|
||||||
|
3. **性能测试**: 包含频率限制测试
|
||||||
|
4. **兼容性测试**: 支持不同环境测试
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🚀 后续建议
|
||||||
|
|
||||||
|
### 短期优化
|
||||||
|
1. **集成CI/CD**: 将Python测试脚本集成到自动化流程
|
||||||
|
2. **监控告警**: 设置API测试失败的通知机制
|
||||||
|
3. **性能基准**: 建立API响应时间基准线
|
||||||
|
|
||||||
|
### 长期规划
|
||||||
|
1. **测试扩展**: 添加更多边界条件测试
|
||||||
|
2. **压力测试**: 开发高并发场景测试
|
||||||
|
3. **安全测试**: 添加安全漏洞检测测试
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 📚 相关资源
|
||||||
|
|
||||||
|
### 文档链接
|
||||||
|
- [API文档](api-documentation.md) - 完整API接口说明
|
||||||
|
- [测试指南](testing_guide.md) - 详细测试使用指南
|
||||||
|
- [API更新日志](api_update_log.md) - 最新变更记录
|
||||||
|
|
||||||
|
### 代码文件
|
||||||
|
- `scripts/scenes/AuthScene.gd` - 修复后的认证场景
|
||||||
|
- `tests/api/quick_test.py` - 快速API测试脚本
|
||||||
|
- `tests/api/api_client_test.py` - 完整API测试套件
|
||||||
|
|
||||||
|
### 工具脚本
|
||||||
|
- `tests/api/run_tests.bat` - Windows测试启动器
|
||||||
|
- `tests/api/run_tests.sh` - Linux/Mac测试启动器
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🎉 总结
|
||||||
|
|
||||||
|
通过这次更新,我们成功:
|
||||||
|
|
||||||
|
1. **修复了关键问题** - AuthScene.gd的Parser Error已完全解决
|
||||||
|
2. **提升了代码质量** - 代码更清晰、更易维护、更高效
|
||||||
|
3. **增强了测试能力** - 提供了完整的Python API测试工具
|
||||||
|
4. **改善了开发体验** - 无需Godot引擎即可测试API接口
|
||||||
|
5. **保证了向后兼容** - 所有原有功能都得到保留和增强
|
||||||
|
|
||||||
|
现在开发者可以:
|
||||||
|
- ✅ 正常使用AuthScene.gd进行认证界面开发
|
||||||
|
- ✅ 使用Python脚本快速验证API接口
|
||||||
|
- ✅ 在任何环境下进行API测试
|
||||||
|
- ✅ 享受更好的错误处理和用户体验
|
||||||
|
|
||||||
|
**项目现在处于完全可用状态,支持最新的API v1.1.1规范!** 🚀
|
||||||
@@ -404,6 +404,37 @@ FONT_MAIN.ttf
|
|||||||
- 全部使用小写字母
|
- 全部使用小写字母
|
||||||
- 同系列资源使用数字后缀,如 `tile_01.png`、`tile_02.png`
|
- 同系列资源使用数字后缀,如 `tile_01.png`、`tile_02.png`
|
||||||
|
|
||||||
|
### 扩展资源类型
|
||||||
|
|
||||||
|
```
|
||||||
|
✅ 正确
|
||||||
|
# 材质资源
|
||||||
|
material_metal.tres # 金属材质
|
||||||
|
material_wood.tres # 木材材质
|
||||||
|
material_water.tres # 水材质
|
||||||
|
|
||||||
|
# 着色器资源
|
||||||
|
shader_water.gdshader # 水着色器
|
||||||
|
shader_fire.gdshader # 火焰着色器
|
||||||
|
shader_outline.gdshader # 轮廓着色器
|
||||||
|
|
||||||
|
# 特效资源
|
||||||
|
fx_explosion.png # 爆炸特效
|
||||||
|
fx_magic_circle.png # 魔法阵特效
|
||||||
|
fx_damage_numbers.png # 伤害数字特效
|
||||||
|
|
||||||
|
# 环境资源
|
||||||
|
obj_tree.png # 树木对象
|
||||||
|
obj_rock.png # 岩石对象
|
||||||
|
tile_grass_01.png # 草地瓦片
|
||||||
|
tile_stone_01.png # 石头瓦片
|
||||||
|
|
||||||
|
❌ 错误
|
||||||
|
MetalMaterial.tres # 不使用大驼峰
|
||||||
|
material-wood.tres # 不使用连字符
|
||||||
|
SHADER_WATER.gdshader # 不使用全大写
|
||||||
|
```
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## 目录结构
|
## 目录结构
|
||||||
@@ -421,11 +452,33 @@ assets/ # 资源目录
|
|||||||
sounds/ # 音效
|
sounds/ # 音效
|
||||||
music/ # 音乐
|
music/ # 音乐
|
||||||
fonts/ # 字体
|
fonts/ # 字体
|
||||||
|
materials/ # 材质
|
||||||
|
shaders/ # 着色器
|
||||||
data/ # 数据目录
|
data/ # 数据目录
|
||||||
levels/ # 关卡数据
|
levels/ # 关卡数据
|
||||||
configs/ # 配置文件
|
configs/ # 配置文件
|
||||||
|
dialogues/ # 对话数据
|
||||||
|
localization/ # 本地化数据
|
||||||
|
core/ # 核心系统目录
|
||||||
|
managers/ # 管理器
|
||||||
|
systems/ # 系统组件
|
||||||
|
utils/ # 工具类
|
||||||
|
components/ # 通用组件
|
||||||
|
interfaces/ # 接口定义
|
||||||
|
module/ # 模块目录
|
||||||
|
UI/ # UI模块
|
||||||
|
Character/ # 角色模块
|
||||||
|
Inventory/ # 背包模块
|
||||||
|
Combat/ # 战斗模块
|
||||||
|
Dialogue/ # 对话模块
|
||||||
addons/ # 插件目录
|
addons/ # 插件目录
|
||||||
tests/ # 测试目录
|
tests/ # 测试目录
|
||||||
|
unit/ # 单元测试
|
||||||
|
integration/ # 集成测试
|
||||||
|
ui/ # UI测试
|
||||||
|
performance/ # 性能测试
|
||||||
|
docs/ # 文档目录
|
||||||
|
auth/ # 认证相关文档
|
||||||
|
|
||||||
❌ 错误
|
❌ 错误
|
||||||
Scenes/ # 不使用大写
|
Scenes/ # 不使用大写
|
||||||
|
|||||||
362
docs/network_manager_setup.md
Normal file
@@ -0,0 +1,362 @@
|
|||||||
|
# NetworkManager 设置指南
|
||||||
|
|
||||||
|
## 概述
|
||||||
|
|
||||||
|
NetworkManager 是一个统一的网络请求管理器,提供了简洁的API接口和统一的错误处理机制。配合 ResponseHandler,可以大大简化网络请求的处理逻辑。
|
||||||
|
|
||||||
|
## 🚀 快速设置
|
||||||
|
|
||||||
|
### 1. 设置AutoLoad
|
||||||
|
|
||||||
|
在Godot编辑器中:
|
||||||
|
|
||||||
|
1. 打开 `Project` → `Project Settings`
|
||||||
|
2. 切换到 `AutoLoad` 标签
|
||||||
|
3. 添加新的AutoLoad:
|
||||||
|
- **Path**: `res://core/managers/NetworkManager.gd`
|
||||||
|
- **Name**: `NetworkManager`
|
||||||
|
- **Singleton**: ✅ 勾选
|
||||||
|
|
||||||
|
### 2. 项目设置文件配置
|
||||||
|
|
||||||
|
在 `project.godot` 文件中会自动添加:
|
||||||
|
|
||||||
|
```ini
|
||||||
|
[autoload]
|
||||||
|
|
||||||
|
NetworkManager="*res://core/managers/NetworkManager.gd"
|
||||||
|
```
|
||||||
|
|
||||||
|
### 3. 验证设置
|
||||||
|
|
||||||
|
在任何脚本中可以直接使用:
|
||||||
|
|
||||||
|
```gdscript
|
||||||
|
func _ready():
|
||||||
|
# 直接访问全局单例
|
||||||
|
var request_id = NetworkManager.login("username", "password", callback)
|
||||||
|
print("请求ID: ", request_id)
|
||||||
|
```
|
||||||
|
|
||||||
|
## 📚 使用方法
|
||||||
|
|
||||||
|
### 基本用法
|
||||||
|
|
||||||
|
```gdscript
|
||||||
|
# 1. 简单的GET请求
|
||||||
|
var request_id = NetworkManager.get_app_status(func(success, data, error_info):
|
||||||
|
if success:
|
||||||
|
print("应用状态: ", data)
|
||||||
|
else:
|
||||||
|
print("获取状态失败: ", error_info)
|
||||||
|
)
|
||||||
|
|
||||||
|
# 2. 用户登录
|
||||||
|
NetworkManager.login("username", "password", func(success, data, error_info):
|
||||||
|
if success:
|
||||||
|
print("登录成功: ", data.data.user.username)
|
||||||
|
else:
|
||||||
|
print("登录失败: ", error_info.message)
|
||||||
|
)
|
||||||
|
|
||||||
|
# 3. 发送验证码
|
||||||
|
NetworkManager.send_email_verification("test@example.com", func(success, data, error_info):
|
||||||
|
if success:
|
||||||
|
print("验证码已发送")
|
||||||
|
else:
|
||||||
|
print("发送失败: ", error_info.message)
|
||||||
|
)
|
||||||
|
```
|
||||||
|
|
||||||
|
### 配合ResponseHandler使用
|
||||||
|
|
||||||
|
```gdscript
|
||||||
|
# 在回调函数中使用ResponseHandler处理响应
|
||||||
|
func _on_login_response(success: bool, data: Dictionary, error_info: Dictionary):
|
||||||
|
# 使用ResponseHandler统一处理
|
||||||
|
var result = ResponseHandler.handle_login_response(success, data, error_info)
|
||||||
|
|
||||||
|
# 显示Toast消息
|
||||||
|
show_toast(result.message, result.success)
|
||||||
|
|
||||||
|
# 执行自定义动作
|
||||||
|
if result.custom_action.is_valid():
|
||||||
|
result.custom_action.call()
|
||||||
|
|
||||||
|
# 处理成功情况
|
||||||
|
if result.success:
|
||||||
|
# 登录成功的处理逻辑
|
||||||
|
login_success.emit(username)
|
||||||
|
```
|
||||||
|
|
||||||
|
### 全局事件监听
|
||||||
|
|
||||||
|
```gdscript
|
||||||
|
func _ready():
|
||||||
|
# 监听全局网络事件
|
||||||
|
NetworkManager.request_completed.connect(_on_global_request_completed)
|
||||||
|
NetworkManager.request_failed.connect(_on_global_request_failed)
|
||||||
|
|
||||||
|
func _on_global_request_completed(request_id: String, success: bool, data: Dictionary):
|
||||||
|
print("全局请求完成: ", request_id)
|
||||||
|
# 可以在这里隐藏全局加载指示器
|
||||||
|
|
||||||
|
func _on_global_request_failed(request_id: String, error_type: String, message: String):
|
||||||
|
print("全局请求失败: ", request_id, " - ", message)
|
||||||
|
# 可以在这里显示全局错误提示
|
||||||
|
```
|
||||||
|
|
||||||
|
## 🔧 高级功能
|
||||||
|
|
||||||
|
### 请求管理
|
||||||
|
|
||||||
|
```gdscript
|
||||||
|
# 取消特定请求
|
||||||
|
var request_id = NetworkManager.login("user", "pass", callback)
|
||||||
|
NetworkManager.cancel_request(request_id)
|
||||||
|
|
||||||
|
# 取消所有请求
|
||||||
|
NetworkManager.cancel_all_requests()
|
||||||
|
|
||||||
|
# 检查请求状态
|
||||||
|
if NetworkManager.is_request_active(request_id):
|
||||||
|
print("请求仍在进行中")
|
||||||
|
|
||||||
|
# 获取活动请求数量
|
||||||
|
print("当前活动请求: ", NetworkManager.get_active_request_count())
|
||||||
|
```
|
||||||
|
|
||||||
|
### 自定义请求
|
||||||
|
|
||||||
|
```gdscript
|
||||||
|
# 发送自定义POST请求
|
||||||
|
var custom_data = {
|
||||||
|
"custom_field": "custom_value"
|
||||||
|
}
|
||||||
|
var request_id = NetworkManager.post_request("/custom/endpoint", custom_data, func(success, data, error_info):
|
||||||
|
print("自定义请求完成")
|
||||||
|
)
|
||||||
|
|
||||||
|
# 发送自定义GET请求
|
||||||
|
NetworkManager.get_request("/custom/data", func(success, data, error_info):
|
||||||
|
print("获取自定义数据")
|
||||||
|
)
|
||||||
|
```
|
||||||
|
|
||||||
|
## 📋 API接口列表
|
||||||
|
|
||||||
|
### 认证相关
|
||||||
|
|
||||||
|
| 方法 | 参数 | 说明 |
|
||||||
|
|------|------|------|
|
||||||
|
| `login(identifier, password, callback)` | 用户标识符、密码、回调函数 | 用户登录 |
|
||||||
|
| `verification_code_login(identifier, code, callback)` | 用户标识符、验证码、回调函数 | 验证码登录 |
|
||||||
|
| `send_login_verification_code(identifier, callback)` | 用户标识符、回调函数 | 发送登录验证码 |
|
||||||
|
| `register(username, password, nickname, email, code, callback)` | 注册信息、回调函数 | 用户注册 |
|
||||||
|
| `send_email_verification(email, callback)` | 邮箱、回调函数 | 发送邮箱验证码 |
|
||||||
|
| `verify_email(email, code, callback)` | 邮箱、验证码、回调函数 | 验证邮箱 |
|
||||||
|
|
||||||
|
### 通用请求
|
||||||
|
|
||||||
|
| 方法 | 参数 | 说明 |
|
||||||
|
|------|------|------|
|
||||||
|
| `get_request(endpoint, callback, timeout)` | 端点、回调函数、超时时间 | GET请求 |
|
||||||
|
| `post_request(endpoint, data, callback, timeout)` | 端点、数据、回调函数、超时时间 | POST请求 |
|
||||||
|
| `put_request(endpoint, data, callback, timeout)` | 端点、数据、回调函数、超时时间 | PUT请求 |
|
||||||
|
| `delete_request(endpoint, callback, timeout)` | 端点、回调函数、超时时间 | DELETE请求 |
|
||||||
|
|
||||||
|
### 请求管理
|
||||||
|
|
||||||
|
| 方法 | 参数 | 说明 |
|
||||||
|
|------|------|------|
|
||||||
|
| `cancel_request(request_id)` | 请求ID | 取消特定请求 |
|
||||||
|
| `cancel_all_requests()` | 无 | 取消所有请求 |
|
||||||
|
| `is_request_active(request_id)` | 请求ID | 检查请求是否活动 |
|
||||||
|
| `get_active_request_count()` | 无 | 获取活动请求数量 |
|
||||||
|
| `get_request_info(request_id)` | 请求ID | 获取请求详细信息 |
|
||||||
|
|
||||||
|
## 🎯 ResponseHandler 使用
|
||||||
|
|
||||||
|
### 支持的响应类型
|
||||||
|
|
||||||
|
| 方法 | 说明 |
|
||||||
|
|------|------|
|
||||||
|
| `handle_login_response()` | 处理登录响应 |
|
||||||
|
| `handle_verification_code_login_response()` | 处理验证码登录响应 |
|
||||||
|
| `handle_send_verification_code_response()` | 处理发送验证码响应 |
|
||||||
|
| `handle_send_login_code_response()` | 处理发送登录验证码响应 |
|
||||||
|
| `handle_register_response()` | 处理注册响应 |
|
||||||
|
| `handle_verify_email_response()` | 处理邮箱验证响应 |
|
||||||
|
| `handle_network_test_response()` | 处理网络测试响应 |
|
||||||
|
| `handle_response(operation_type, ...)` | 通用响应处理 |
|
||||||
|
|
||||||
|
### ResponseResult 结构
|
||||||
|
|
||||||
|
```gdscript
|
||||||
|
class ResponseResult:
|
||||||
|
var success: bool # 是否成功
|
||||||
|
var message: String # 显示消息
|
||||||
|
var toast_type: String # Toast类型 ("success" 或 "error")
|
||||||
|
var data: Dictionary # 响应数据
|
||||||
|
var should_show_toast: bool # 是否显示Toast
|
||||||
|
var custom_action: Callable # 自定义动作
|
||||||
|
```
|
||||||
|
|
||||||
|
## 🔄 迁移指南
|
||||||
|
|
||||||
|
### 从旧版AuthScene迁移
|
||||||
|
|
||||||
|
#### 旧代码:
|
||||||
|
```gdscript
|
||||||
|
func send_login_request(username: String, password: String):
|
||||||
|
var url = API_BASE_URL + "/auth/login"
|
||||||
|
var headers = ["Content-Type: application/json"]
|
||||||
|
var body = JSON.stringify({
|
||||||
|
"username": username,
|
||||||
|
"password": password
|
||||||
|
})
|
||||||
|
|
||||||
|
current_request_type = "login"
|
||||||
|
|
||||||
|
var error = http_request.request(url, headers, HTTPClient.METHOD_POST, body)
|
||||||
|
if error != OK:
|
||||||
|
show_toast('网络请求失败', false)
|
||||||
|
restore_button(login_btn, "密码登录")
|
||||||
|
current_request_type = ""
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 新代码:
|
||||||
|
```gdscript
|
||||||
|
func send_login_request(username: String, password: String):
|
||||||
|
NetworkManager.login(username, password, _on_login_response)
|
||||||
|
|
||||||
|
func _on_login_response(success: bool, data: Dictionary, error_info: Dictionary):
|
||||||
|
var result = ResponseHandler.handle_login_response(success, data, error_info)
|
||||||
|
show_toast(result.message, result.success)
|
||||||
|
|
||||||
|
if result.success:
|
||||||
|
login_success.emit(username)
|
||||||
|
```
|
||||||
|
|
||||||
|
### 迁移步骤
|
||||||
|
|
||||||
|
1. **设置AutoLoad**:按照上述步骤设置NetworkManager为AutoLoad
|
||||||
|
2. **替换请求方法**:将直接的HTTP请求替换为NetworkManager调用
|
||||||
|
3. **统一响应处理**:使用ResponseHandler处理所有响应
|
||||||
|
4. **移除重复代码**:删除重复的错误处理和请求构建代码
|
||||||
|
5. **测试功能**:确保所有功能正常工作
|
||||||
|
|
||||||
|
## 🧪 测试
|
||||||
|
|
||||||
|
### 单元测试示例
|
||||||
|
|
||||||
|
```gdscript
|
||||||
|
extends GutTest
|
||||||
|
|
||||||
|
func test_network_manager_login():
|
||||||
|
var network_manager = NetworkManager.new()
|
||||||
|
var callback_called = false
|
||||||
|
var callback_success = false
|
||||||
|
|
||||||
|
var callback = func(success, data, error_info):
|
||||||
|
callback_called = true
|
||||||
|
callback_success = success
|
||||||
|
|
||||||
|
var request_id = network_manager.login("testuser", "password", callback)
|
||||||
|
|
||||||
|
assert_ne(request_id, "", "应该返回有效的请求ID")
|
||||||
|
|
||||||
|
# 等待请求完成
|
||||||
|
await get_tree().create_timer(2.0).timeout
|
||||||
|
|
||||||
|
assert_true(callback_called, "回调函数应该被调用")
|
||||||
|
```
|
||||||
|
|
||||||
|
### 集成测试
|
||||||
|
|
||||||
|
```gdscript
|
||||||
|
func test_complete_login_flow():
|
||||||
|
# 1. 发送登录验证码
|
||||||
|
var code_sent = false
|
||||||
|
NetworkManager.send_login_verification_code("test@example.com", func(success, data, error_info):
|
||||||
|
code_sent = success
|
||||||
|
)
|
||||||
|
|
||||||
|
await get_tree().create_timer(1.0).timeout
|
||||||
|
assert_true(code_sent, "验证码应该发送成功")
|
||||||
|
|
||||||
|
# 2. 使用验证码登录
|
||||||
|
var login_success = false
|
||||||
|
NetworkManager.verification_code_login("test@example.com", "123456", func(success, data, error_info):
|
||||||
|
login_success = success
|
||||||
|
)
|
||||||
|
|
||||||
|
await get_tree().create_timer(1.0).timeout
|
||||||
|
assert_true(login_success, "验证码登录应该成功")
|
||||||
|
```
|
||||||
|
|
||||||
|
## 🔍 调试
|
||||||
|
|
||||||
|
### 启用详细日志
|
||||||
|
|
||||||
|
在NetworkManager中,所有请求都会输出详细的调试信息:
|
||||||
|
|
||||||
|
```
|
||||||
|
=== 发送网络请求 ===
|
||||||
|
请求ID: req_1
|
||||||
|
URL: https://whaletownend.xinghangee.icu/auth/login
|
||||||
|
方法: POST
|
||||||
|
Headers: ["Content-Type: application/json"]
|
||||||
|
Body: {"username":"testuser","password":"password123"}
|
||||||
|
发送结果: 0
|
||||||
|
|
||||||
|
=== 网络请求完成 ===
|
||||||
|
请求ID: req_1
|
||||||
|
结果: 0
|
||||||
|
状态码: 200
|
||||||
|
响应头: ["content-type: application/json"]
|
||||||
|
响应体长度: 156 字节
|
||||||
|
响应内容: {"success":true,"data":{"user":{"username":"testuser"}}}
|
||||||
|
```
|
||||||
|
|
||||||
|
### 常见问题
|
||||||
|
|
||||||
|
1. **请求ID为空**:检查NetworkManager是否正确设置为AutoLoad
|
||||||
|
2. **回调未调用**:检查网络连接和API地址是否正确
|
||||||
|
3. **解析错误**:检查服务器返回的JSON格式是否正确
|
||||||
|
|
||||||
|
## 📈 性能优化
|
||||||
|
|
||||||
|
### 请求池管理
|
||||||
|
|
||||||
|
NetworkManager自动管理请求资源:
|
||||||
|
- 自动清理完成的请求
|
||||||
|
- 防止内存泄漏
|
||||||
|
- 支持请求取消
|
||||||
|
|
||||||
|
### 最佳实践
|
||||||
|
|
||||||
|
1. **及时取消不需要的请求**
|
||||||
|
2. **使用合适的超时时间**
|
||||||
|
3. **避免同时发送大量请求**
|
||||||
|
4. **在场景切换时取消活动请求**
|
||||||
|
|
||||||
|
```gdscript
|
||||||
|
func _exit_tree():
|
||||||
|
# 场景退出时取消所有请求
|
||||||
|
NetworkManager.cancel_all_requests()
|
||||||
|
```
|
||||||
|
|
||||||
|
## 🎉 总结
|
||||||
|
|
||||||
|
使用NetworkManager和ResponseHandler的优势:
|
||||||
|
|
||||||
|
- ✅ **代码简洁**:一行代码发送请求
|
||||||
|
- ✅ **统一处理**:所有错误情况统一处理
|
||||||
|
- ✅ **易于维护**:网络逻辑与UI逻辑分离
|
||||||
|
- ✅ **功能强大**:支持请求管理、超时、取消等
|
||||||
|
- ✅ **调试友好**:详细的日志和错误信息
|
||||||
|
- ✅ **类型安全**:明确的回调参数类型
|
||||||
|
- ✅ **可扩展**:易于添加新的API接口
|
||||||
|
|
||||||
|
通过这套统一的网络管理系统,你的项目将拥有更好的代码结构和更强的可维护性!
|
||||||
505
docs/project_structure.md
Normal file
@@ -0,0 +1,505 @@
|
|||||||
|
# Godot 项目结构说明
|
||||||
|
|
||||||
|
本文档详细说明了 whaleTown 项目的文件结构设计,采用"场景+通用工具+其他"的架构模式,确保每个场景清晰独立且高度解耦。
|
||||||
|
|
||||||
|
## 设计理念
|
||||||
|
|
||||||
|
### 核心原则
|
||||||
|
- **场景独立性**:每个场景都是独立的功能模块,可以单独开发和测试
|
||||||
|
- **高度解耦**:场景之间通过事件系统和管理器进行通信,避免直接依赖
|
||||||
|
- **组件复用**:可复用的组件放在通用模块中,提高开发效率
|
||||||
|
- **资源管理**:统一的资源管理和命名规范,便于维护
|
||||||
|
|
||||||
|
## 项目架构概览
|
||||||
|
|
||||||
|
```
|
||||||
|
whaleTown/
|
||||||
|
├── 🎬 scenes/ # 场景层:独立的游戏场景
|
||||||
|
├── 🔧 core/ # 核心层:通用工具和系统
|
||||||
|
├── 🎨 assets/ # 资源层:静态资源文件
|
||||||
|
├── 📊 data/ # 数据层:配置和游戏数据
|
||||||
|
├── 📝 scripts/ # 脚本层:业务逻辑代码
|
||||||
|
├── 🧩 module/ # 模块层:可复用组件
|
||||||
|
├── 🧪 tests/ # 测试层:单元测试和集成测试
|
||||||
|
└── 📚 docs/ # 文档层:项目文档
|
||||||
|
```
|
||||||
|
|
||||||
|
## 1. 场景层 (scenes/)
|
||||||
|
|
||||||
|
场景层包含所有独立的游戏场景,每个场景都是完整的功能模块。
|
||||||
|
|
||||||
|
### 1.1 场景分类
|
||||||
|
|
||||||
|
#### 主要场景 (Main Scenes)
|
||||||
|
```
|
||||||
|
scenes/
|
||||||
|
├── main_scene.tscn # 主场景:游戏入口
|
||||||
|
├── auth_scene.tscn # 认证场景:登录注册
|
||||||
|
├── menu_scene.tscn # 菜单场景:主菜单界面
|
||||||
|
├── game_scene.tscn # 游戏场景:主要游戏玩法
|
||||||
|
├── battle_scene.tscn # 战斗场景:战斗系统
|
||||||
|
├── inventory_scene.tscn # 背包场景:物品管理
|
||||||
|
├── shop_scene.tscn # 商店场景:购买系统
|
||||||
|
└── settings_scene.tscn # 设置场景:游戏设置
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 预制体场景 (Prefabs)
|
||||||
|
```
|
||||||
|
scenes/prefabs/
|
||||||
|
├── ui/
|
||||||
|
│ ├── dialog_prefab.tscn # 对话框预制体
|
||||||
|
│ ├── button_prefab.tscn # 按钮预制体
|
||||||
|
│ ├── health_bar_prefab.tscn # 血条预制体
|
||||||
|
│ └── notification_prefab.tscn # 通知预制体
|
||||||
|
├── characters/
|
||||||
|
│ ├── player_prefab.tscn # 玩家角色预制体
|
||||||
|
│ ├── npc_prefab.tscn # NPC预制体
|
||||||
|
│ └── enemy_prefab.tscn # 敌人预制体
|
||||||
|
├── items/
|
||||||
|
│ ├── weapon_prefab.tscn # 武器预制体
|
||||||
|
│ ├── consumable_prefab.tscn # 消耗品预制体
|
||||||
|
│ └── collectible_prefab.tscn # 收集品预制体
|
||||||
|
└── effects/
|
||||||
|
├── explosion_prefab.tscn # 爆炸特效预制体
|
||||||
|
├── particle_prefab.tscn # 粒子特效预制体
|
||||||
|
└── damage_text_prefab.tscn # 伤害数字预制体
|
||||||
|
```
|
||||||
|
|
||||||
|
### 1.2 场景设计原则
|
||||||
|
|
||||||
|
- **单一职责**:每个场景只负责一个主要功能
|
||||||
|
- **独立运行**:场景可以独立启动和测试
|
||||||
|
- **标准接口**:场景间通过标准化接口通信
|
||||||
|
- **资源隔离**:场景相关资源放在对应子目录
|
||||||
|
## 2. 核心层 (core/)
|
||||||
|
|
||||||
|
核心层提供通用的工具类、管理器和系统组件,为整个项目提供基础服务。
|
||||||
|
|
||||||
|
### 2.1 核心系统结构
|
||||||
|
|
||||||
|
```
|
||||||
|
core/
|
||||||
|
├── managers/ # 管理器系统
|
||||||
|
│ ├── GameManager.gd # 游戏管理器:全局游戏状态
|
||||||
|
│ ├── SceneManager.gd # 场景管理器:场景切换
|
||||||
|
│ ├── AudioManager.gd # 音频管理器:音效音乐
|
||||||
|
│ ├── InputManager.gd # 输入管理器:输入处理
|
||||||
|
│ ├── SaveManager.gd # 存档管理器:数据存储
|
||||||
|
│ ├── UIManager.gd # UI管理器:界面管理
|
||||||
|
│ └── NetworkManager.gd # 网络管理器:网络通信
|
||||||
|
├── systems/ # 系统组件
|
||||||
|
│ ├── EventSystem.gd # 事件系统:全局事件
|
||||||
|
│ ├── StateMachine.gd # 状态机系统
|
||||||
|
│ ├── ObjectPool.gd # 对象池系统
|
||||||
|
│ ├── ResourceLoader.gd # 资源加载系统
|
||||||
|
│ └── LocalizationSystem.gd # 本地化系统
|
||||||
|
├── utils/ # 工具类
|
||||||
|
│ ├── MathUtils.gd # 数学工具
|
||||||
|
│ ├── StringUtils.gd # 字符串工具
|
||||||
|
│ ├── FileUtils.gd # 文件工具
|
||||||
|
│ ├── TimeUtils.gd # 时间工具
|
||||||
|
│ └── DebugUtils.gd # 调试工具
|
||||||
|
├── components/ # 通用组件
|
||||||
|
│ ├── HealthComponent.gd # 生命值组件
|
||||||
|
│ ├── MovementComponent.gd # 移动组件
|
||||||
|
│ ├── AnimationComponent.gd # 动画组件
|
||||||
|
│ └── CollisionComponent.gd # 碰撞组件
|
||||||
|
└── interfaces/ # 接口定义
|
||||||
|
├── IInteractable.gd # 可交互接口
|
||||||
|
├── IDamageable.gd # 可受伤接口
|
||||||
|
├── ICollectable.gd # 可收集接口
|
||||||
|
└── ISaveable.gd # 可存储接口
|
||||||
|
```
|
||||||
|
|
||||||
|
### 2.2 核心系统职责
|
||||||
|
|
||||||
|
#### 管理器 (Managers)
|
||||||
|
- **单例模式**:全局唯一实例
|
||||||
|
- **生命周期管理**:负责系统初始化和清理
|
||||||
|
- **状态维护**:维护全局状态信息
|
||||||
|
- **服务提供**:为其他模块提供服务
|
||||||
|
|
||||||
|
#### 系统组件 (Systems)
|
||||||
|
- **功能封装**:封装特定功能逻辑
|
||||||
|
- **可插拔设计**:可以独立启用或禁用
|
||||||
|
- **事件驱动**:通过事件系统通信
|
||||||
|
- **性能优化**:提供高效的实现方案
|
||||||
|
## 3. 模块层 (module/)
|
||||||
|
|
||||||
|
模块层包含可复用的功能模块,这些模块可以在不同场景中重复使用。
|
||||||
|
|
||||||
|
### 3.1 模块分类
|
||||||
|
|
||||||
|
```
|
||||||
|
module/
|
||||||
|
├── UI/ # UI模块
|
||||||
|
│ ├── components/ # UI组件
|
||||||
|
│ │ ├── Button/ # 按钮组件
|
||||||
|
│ │ │ ├── CustomButton.gd
|
||||||
|
│ │ │ └── custom_button.tscn
|
||||||
|
│ │ ├── Dialog/ # 对话框组件
|
||||||
|
│ │ │ ├── DialogBox.gd
|
||||||
|
│ │ │ └── dialog_box.tscn
|
||||||
|
│ │ ├── ProgressBar/ # 进度条组件
|
||||||
|
│ │ │ ├── CustomProgressBar.gd
|
||||||
|
│ │ │ └── custom_progress_bar.tscn
|
||||||
|
│ │ └── InputField/ # 输入框组件
|
||||||
|
│ │ ├── CustomInputField.gd
|
||||||
|
│ │ └── custom_input_field.tscn
|
||||||
|
│ ├── layouts/ # 布局组件
|
||||||
|
│ │ ├── GridLayout.gd
|
||||||
|
│ │ ├── FlexLayout.gd
|
||||||
|
│ │ └── ResponsiveLayout.gd
|
||||||
|
│ └── animations/ # UI动画
|
||||||
|
│ ├── FadeTransition.gd
|
||||||
|
│ ├── SlideTransition.gd
|
||||||
|
│ └── ScaleTransition.gd
|
||||||
|
├── Character/ # 角色模块
|
||||||
|
│ ├── Player/ # 玩家角色
|
||||||
|
│ │ ├── PlayerController.gd
|
||||||
|
│ │ ├── PlayerStats.gd
|
||||||
|
│ │ └── PlayerAnimator.gd
|
||||||
|
│ ├── NPC/ # NPC角色
|
||||||
|
│ │ ├── NPCController.gd
|
||||||
|
│ │ ├── NPCDialogue.gd
|
||||||
|
│ │ └── NPCBehavior.gd
|
||||||
|
│ └── Enemy/ # 敌人角色
|
||||||
|
│ ├── EnemyAI.gd
|
||||||
|
│ ├── EnemyStats.gd
|
||||||
|
│ └── EnemyBehavior.gd
|
||||||
|
├── Inventory/ # 背包模块
|
||||||
|
│ ├── InventorySystem.gd
|
||||||
|
│ ├── Item.gd
|
||||||
|
│ ├── ItemSlot.gd
|
||||||
|
│ └── ItemDatabase.gd
|
||||||
|
├── Combat/ # 战斗模块
|
||||||
|
│ ├── CombatSystem.gd
|
||||||
|
│ ├── Weapon.gd
|
||||||
|
│ ├── Skill.gd
|
||||||
|
│ └── DamageCalculator.gd
|
||||||
|
└── Dialogue/ # 对话模块
|
||||||
|
├── DialogueSystem.gd
|
||||||
|
├── DialogueNode.gd
|
||||||
|
├── DialogueParser.gd
|
||||||
|
└── DialogueUI.gd
|
||||||
|
```
|
||||||
|
|
||||||
|
### 3.2 模块设计原则
|
||||||
|
|
||||||
|
- **高内聚**:模块内部功能紧密相关
|
||||||
|
- **低耦合**:模块间依赖最小化
|
||||||
|
- **可配置**:通过配置文件自定义行为
|
||||||
|
- **可扩展**:支持功能扩展和定制
|
||||||
|
## 4. 资源层 (assets/)
|
||||||
|
|
||||||
|
资源层统一管理所有静态资源文件,采用分类存储和标准化命名。
|
||||||
|
|
||||||
|
### 4.1 资源目录结构
|
||||||
|
|
||||||
|
```
|
||||||
|
assets/
|
||||||
|
├── sprites/ # 精灵图资源
|
||||||
|
│ ├── characters/ # 角色精灵
|
||||||
|
│ │ ├── player/
|
||||||
|
│ │ │ ├── sprite_player_idle.png
|
||||||
|
│ │ │ ├── sprite_player_walk.png
|
||||||
|
│ │ │ └── sprite_player_attack.png
|
||||||
|
│ │ ├── enemies/
|
||||||
|
│ │ │ ├── sprite_enemy_goblin_idle.png
|
||||||
|
│ │ │ └── sprite_enemy_orc_walk.png
|
||||||
|
│ │ └── npcs/
|
||||||
|
│ │ ├── sprite_npc_merchant.png
|
||||||
|
│ │ └── sprite_npc_guard.png
|
||||||
|
│ ├── ui/ # UI精灵
|
||||||
|
│ │ ├── buttons/
|
||||||
|
│ │ │ ├── ui_button_normal.png
|
||||||
|
│ │ │ ├── ui_button_hover.png
|
||||||
|
│ │ │ └── ui_button_pressed.png
|
||||||
|
│ │ ├── icons/
|
||||||
|
│ │ │ ├── icon_sword.png
|
||||||
|
│ │ │ ├── icon_shield.png
|
||||||
|
│ │ │ └── icon_potion.png
|
||||||
|
│ │ └── panels/
|
||||||
|
│ │ ├── ui_panel_main.png
|
||||||
|
│ │ └── ui_panel_dialog.png
|
||||||
|
│ ├── environment/ # 环境精灵
|
||||||
|
│ │ ├── backgrounds/
|
||||||
|
│ │ │ ├── bg_forest.png
|
||||||
|
│ │ │ └── bg_dungeon.png
|
||||||
|
│ │ ├── tiles/
|
||||||
|
│ │ │ ├── tile_grass_01.png
|
||||||
|
│ │ │ └── tile_stone_01.png
|
||||||
|
│ │ └── objects/
|
||||||
|
│ │ ├── obj_tree.png
|
||||||
|
│ │ └── obj_rock.png
|
||||||
|
│ └── effects/ # 特效精灵
|
||||||
|
│ ├── fx_explosion.png
|
||||||
|
│ ├── fx_magic_circle.png
|
||||||
|
│ └── fx_damage_numbers.png
|
||||||
|
├── audio/ # 音频资源
|
||||||
|
│ ├── music/ # 背景音乐
|
||||||
|
│ │ ├── music_main_menu.ogg
|
||||||
|
│ │ ├── music_battle.ogg
|
||||||
|
│ │ └── music_peaceful.ogg
|
||||||
|
│ ├── sounds/ # 音效
|
||||||
|
│ │ ├── ui/
|
||||||
|
│ │ │ ├── sound_button_click.wav
|
||||||
|
│ │ │ └── sound_menu_open.wav
|
||||||
|
│ │ ├── combat/
|
||||||
|
│ │ │ ├── sound_sword_hit.wav
|
||||||
|
│ │ │ └── sound_explosion.wav
|
||||||
|
│ │ └── ambient/
|
||||||
|
│ │ ├── sound_footsteps.wav
|
||||||
|
│ │ └── sound_wind.wav
|
||||||
|
│ └── voice/ # 语音
|
||||||
|
│ ├── voice_npc_greeting.wav
|
||||||
|
│ └── voice_player_hurt.wav
|
||||||
|
├── fonts/ # 字体资源
|
||||||
|
│ ├── font_main.ttf # 主要字体
|
||||||
|
│ ├── font_title.ttf # 标题字体
|
||||||
|
│ └── font_ui.ttf # UI字体
|
||||||
|
├── materials/ # 材质资源
|
||||||
|
│ ├── material_metal.tres
|
||||||
|
│ ├── material_wood.tres
|
||||||
|
│ └── material_water.tres
|
||||||
|
└── shaders/ # 着色器资源
|
||||||
|
├── shader_water.gdshader
|
||||||
|
├── shader_fire.gdshader
|
||||||
|
└── shader_outline.gdshader
|
||||||
|
```
|
||||||
|
|
||||||
|
### 4.2 资源命名规范
|
||||||
|
|
||||||
|
#### 图片资源命名
|
||||||
|
- **精灵图**:`sprite_[类别]_[名称]_[状态].png`
|
||||||
|
- 示例:`sprite_player_idle.png`、`sprite_enemy_goblin_walk.png`
|
||||||
|
- **UI图片**:`ui_[类型]_[名称]_[状态].png`
|
||||||
|
- 示例:`ui_button_normal.png`、`ui_panel_main.png`
|
||||||
|
- **图标**:`icon_[名称].png`
|
||||||
|
- 示例:`icon_sword.png`、`icon_health.png`
|
||||||
|
- **背景**:`bg_[场景名称].png`
|
||||||
|
- 示例:`bg_forest.png`、`bg_dungeon.png`
|
||||||
|
- **瓦片**:`tile_[材质]_[编号].png`
|
||||||
|
- 示例:`tile_grass_01.png`、`tile_stone_02.png`
|
||||||
|
|
||||||
|
#### 音频资源命名
|
||||||
|
- **音乐**:`music_[场景/情境].ogg`
|
||||||
|
- 示例:`music_battle.ogg`、`music_peaceful.ogg`
|
||||||
|
- **音效**:`sound_[动作/事件].wav`
|
||||||
|
- 示例:`sound_jump.wav`、`sound_explosion.wav`
|
||||||
|
- **语音**:`voice_[角色]_[内容].wav`
|
||||||
|
- 示例:`voice_npc_greeting.wav`、`voice_player_hurt.wav`
|
||||||
|
|
||||||
|
#### 其他资源命名
|
||||||
|
- **字体**:`font_[用途].ttf`
|
||||||
|
- 示例:`font_main.ttf`、`font_title.ttf`
|
||||||
|
- **材质**:`material_[材质名].tres`
|
||||||
|
- 示例:`material_metal.tres`、`material_wood.tres`
|
||||||
|
- **着色器**:`shader_[效果名].gdshader`
|
||||||
|
- 示例:`shader_water.gdshader`、`shader_fire.gdshader`
|
||||||
|
## 5. 脚本层 (scripts/)
|
||||||
|
|
||||||
|
脚本层包含所有业务逻辑代码,按功能模块组织。
|
||||||
|
|
||||||
|
### 5.1 脚本目录结构
|
||||||
|
|
||||||
|
```
|
||||||
|
scripts/
|
||||||
|
├── scenes/ # 场景脚本
|
||||||
|
│ ├── MainScene.gd # 主场景脚本
|
||||||
|
│ ├── AuthScene.gd # 认证场景脚本
|
||||||
|
│ ├── GameScene.gd # 游戏场景脚本
|
||||||
|
│ └── BattleScene.gd # 战斗场景脚本
|
||||||
|
├── ui/ # UI脚本
|
||||||
|
│ ├── MainMenu.gd # 主菜单脚本
|
||||||
|
│ ├── SettingsPanel.gd # 设置面板脚本
|
||||||
|
│ ├── InventoryUI.gd # 背包界面脚本
|
||||||
|
│ └── DialogueUI.gd # 对话界面脚本
|
||||||
|
├── characters/ # 角色脚本
|
||||||
|
│ ├── PlayerController.gd # 玩家控制器
|
||||||
|
│ ├── EnemyAI.gd # 敌人AI
|
||||||
|
│ └── NPCBehavior.gd # NPC行为
|
||||||
|
├── gameplay/ # 游戏玩法脚本
|
||||||
|
│ ├── CombatSystem.gd # 战斗系统
|
||||||
|
│ ├── QuestSystem.gd # 任务系统
|
||||||
|
│ ├── InventorySystem.gd # 背包系统
|
||||||
|
│ └── DialogueSystem.gd # 对话系统
|
||||||
|
├── network/ # 网络脚本
|
||||||
|
│ ├── NetworkClient.gd # 网络客户端
|
||||||
|
│ ├── NetworkServer.gd # 网络服务器
|
||||||
|
│ └── NetworkProtocol.gd # 网络协议
|
||||||
|
└── data/ # 数据脚本
|
||||||
|
├── GameData.gd # 游戏数据
|
||||||
|
├── PlayerData.gd # 玩家数据
|
||||||
|
├── ItemData.gd # 物品数据
|
||||||
|
└── ConfigData.gd # 配置数据
|
||||||
|
```
|
||||||
|
|
||||||
|
## 6. 数据层 (data/)
|
||||||
|
|
||||||
|
数据层存储游戏配置、关卡数据和其他静态数据文件。
|
||||||
|
|
||||||
|
### 6.1 数据目录结构
|
||||||
|
|
||||||
|
```
|
||||||
|
data/
|
||||||
|
├── configs/ # 配置文件
|
||||||
|
│ ├── game_config.json # 游戏配置
|
||||||
|
│ ├── audio_config.json # 音频配置
|
||||||
|
│ ├── input_config.json # 输入配置
|
||||||
|
│ └── graphics_config.json # 图形配置
|
||||||
|
├── levels/ # 关卡数据
|
||||||
|
│ ├── level_01.json # 第一关数据
|
||||||
|
│ ├── level_02.json # 第二关数据
|
||||||
|
│ └── level_boss.json # Boss关数据
|
||||||
|
├── items/ # 物品数据
|
||||||
|
│ ├── weapons.json # 武器数据
|
||||||
|
│ ├── armor.json # 装备数据
|
||||||
|
│ └── consumables.json # 消耗品数据
|
||||||
|
├── characters/ # 角色数据
|
||||||
|
│ ├── player_stats.json # 玩家属性
|
||||||
|
│ ├── enemy_stats.json # 敌人属性
|
||||||
|
│ └── npc_data.json # NPC数据
|
||||||
|
├── dialogues/ # 对话数据
|
||||||
|
│ ├── main_story.json # 主线对话
|
||||||
|
│ ├── side_quests.json # 支线对话
|
||||||
|
│ └── npc_dialogues.json # NPC对话
|
||||||
|
└── localization/ # 本地化数据
|
||||||
|
├── en.json # 英文文本
|
||||||
|
├── zh_CN.json # 简体中文文本
|
||||||
|
└── zh_TW.json # 繁体中文文本
|
||||||
|
```
|
||||||
|
|
||||||
|
## 7. 测试层 (tests/)
|
||||||
|
|
||||||
|
测试层包含单元测试、集成测试和功能测试。
|
||||||
|
|
||||||
|
### 7.1 测试目录结构
|
||||||
|
|
||||||
|
```
|
||||||
|
tests/
|
||||||
|
├── unit/ # 单元测试
|
||||||
|
│ ├── test_player_controller.gd
|
||||||
|
│ ├── test_inventory_system.gd
|
||||||
|
│ └── test_combat_system.gd
|
||||||
|
├── integration/ # 集成测试
|
||||||
|
│ ├── test_scene_transitions.gd
|
||||||
|
│ ├── test_save_load.gd
|
||||||
|
│ └── test_network_sync.gd
|
||||||
|
├── ui/ # UI测试
|
||||||
|
│ ├── test_main_menu.gd
|
||||||
|
│ ├── test_inventory_ui.gd
|
||||||
|
│ └── test_dialogue_ui.gd
|
||||||
|
└── performance/ # 性能测试
|
||||||
|
├── test_memory_usage.gd
|
||||||
|
├── test_frame_rate.gd
|
||||||
|
└── test_loading_times.gd
|
||||||
|
```
|
||||||
|
## 8. 场景间通信机制
|
||||||
|
|
||||||
|
### 8.1 事件系统
|
||||||
|
|
||||||
|
使用全局事件系统实现场景间的松耦合通信:
|
||||||
|
|
||||||
|
```gdscript
|
||||||
|
# 事件定义示例
|
||||||
|
signal player_health_changed(new_health: int)
|
||||||
|
signal scene_transition_requested(scene_name: String)
|
||||||
|
signal item_collected(item_id: String)
|
||||||
|
signal quest_completed(quest_id: String)
|
||||||
|
|
||||||
|
# 事件发送
|
||||||
|
EventSystem.emit_signal("player_health_changed", 80)
|
||||||
|
|
||||||
|
# 事件监听
|
||||||
|
EventSystem.connect("player_health_changed", _on_player_health_changed)
|
||||||
|
```
|
||||||
|
|
||||||
|
### 8.2 管理器模式
|
||||||
|
|
||||||
|
通过单例管理器实现全局状态管理:
|
||||||
|
|
||||||
|
```gdscript
|
||||||
|
# 场景切换
|
||||||
|
SceneManager.change_scene("battle_scene")
|
||||||
|
|
||||||
|
# 音频播放
|
||||||
|
AudioManager.play_sound("sound_button_click")
|
||||||
|
|
||||||
|
# 数据保存
|
||||||
|
SaveManager.save_game_data(player_data)
|
||||||
|
```
|
||||||
|
|
||||||
|
## 9. 开发工作流
|
||||||
|
|
||||||
|
### 9.1 新场景开发流程
|
||||||
|
|
||||||
|
1. **创建场景文件**:在 `scenes/` 目录创建 `.tscn` 文件
|
||||||
|
2. **编写场景脚本**:在 `scripts/scenes/` 创建对应脚本
|
||||||
|
3. **添加UI组件**:使用 `module/UI/` 中的可复用组件
|
||||||
|
4. **配置场景数据**:在 `data/` 目录添加相关配置
|
||||||
|
5. **编写测试用例**:在 `tests/` 目录添加测试
|
||||||
|
6. **更新文档**:更新相关文档说明
|
||||||
|
|
||||||
|
### 9.2 新功能模块开发流程
|
||||||
|
|
||||||
|
1. **设计模块接口**:定义模块的公共接口
|
||||||
|
2. **实现核心逻辑**:在 `module/` 目录实现功能
|
||||||
|
3. **添加管理器支持**:在 `core/managers/` 添加管理器
|
||||||
|
4. **创建测试场景**:创建独立的测试场景
|
||||||
|
5. **集成到主项目**:将模块集成到现有场景
|
||||||
|
6. **性能优化**:进行性能测试和优化
|
||||||
|
|
||||||
|
## 10. 最佳实践
|
||||||
|
|
||||||
|
### 10.1 代码组织
|
||||||
|
|
||||||
|
- **单一职责**:每个类只负责一个功能
|
||||||
|
- **依赖注入**:通过构造函数或属性注入依赖
|
||||||
|
- **接口隔离**:使用接口定义模块间的契约
|
||||||
|
- **配置外置**:将配置信息放在数据文件中
|
||||||
|
|
||||||
|
### 10.2 性能优化
|
||||||
|
|
||||||
|
- **对象池**:复用频繁创建的对象
|
||||||
|
- **延迟加载**:按需加载资源和场景
|
||||||
|
- **批量处理**:合并相似的操作
|
||||||
|
- **内存管理**:及时释放不需要的资源
|
||||||
|
|
||||||
|
### 10.3 调试和测试
|
||||||
|
|
||||||
|
- **单元测试**:为核心逻辑编写单元测试
|
||||||
|
- **集成测试**:测试模块间的交互
|
||||||
|
- **性能监控**:监控内存和CPU使用情况
|
||||||
|
- **日志记录**:记录关键操作和错误信息
|
||||||
|
|
||||||
|
## 11. 扩展指南
|
||||||
|
|
||||||
|
### 11.1 添加新场景
|
||||||
|
|
||||||
|
1. 在 `scenes/` 目录创建场景文件
|
||||||
|
2. 在 `scripts/scenes/` 创建场景脚本
|
||||||
|
3. 在 `SceneManager` 中注册新场景
|
||||||
|
4. 添加场景切换逻辑
|
||||||
|
|
||||||
|
### 11.2 添加新模块
|
||||||
|
|
||||||
|
1. 在 `module/` 目录创建模块文件夹
|
||||||
|
2. 实现模块的核心功能
|
||||||
|
3. 创建模块管理器(如需要)
|
||||||
|
4. 编写模块文档和示例
|
||||||
|
|
||||||
|
### 11.3 添加新资源类型
|
||||||
|
|
||||||
|
1. 在 `assets/` 目录创建对应分类
|
||||||
|
2. 更新命名规范文档
|
||||||
|
3. 在资源加载器中添加支持
|
||||||
|
4. 更新导入设置
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 总结
|
||||||
|
|
||||||
|
这个项目结构设计遵循了模块化、可扩展、易维护的原则。通过清晰的分层架构和标准化的命名规范,确保了项目的可读性和可维护性。每个开发者都应该遵循这个结构进行开发,以保持项目的一致性和质量。
|
||||||
|
|
||||||
|
如有任何疑问或建议,请参考相关文档或联系项目维护者。
|
||||||
28
docs/setup.md
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
# 项目设置指南
|
||||||
|
|
||||||
|
## AutoLoad 配置
|
||||||
|
|
||||||
|
在 Godot 编辑器中设置 NetworkManager 为全局单例:
|
||||||
|
|
||||||
|
1. 打开 `Project` → `Project Settings`
|
||||||
|
2. 切换到 `AutoLoad` 标签
|
||||||
|
3. 添加新的 AutoLoad:
|
||||||
|
- **Path**: `res://core/managers/NetworkManager.gd`
|
||||||
|
- **Name**: `NetworkManager`
|
||||||
|
- **Singleton**: ✅ 勾选
|
||||||
|
|
||||||
|
## 验证设置
|
||||||
|
|
||||||
|
在任何脚本中可以直接使用:
|
||||||
|
|
||||||
|
```gdscript
|
||||||
|
func _ready():
|
||||||
|
var request_id = NetworkManager.login("username", "password", callback)
|
||||||
|
print("请求ID: ", request_id)
|
||||||
|
```
|
||||||
|
|
||||||
|
## 注意事项
|
||||||
|
|
||||||
|
- 确保 NetworkManager.gd 和 ResponseHandler.gd 文件存在
|
||||||
|
- 重启 Godot 编辑器以确保 AutoLoad 生效
|
||||||
|
- 检查控制台是否有错误信息
|
||||||
312
docs/testing_guide.md
Normal file
@@ -0,0 +1,312 @@
|
|||||||
|
# API接口测试指南
|
||||||
|
|
||||||
|
**更新日期**: 2025-12-25
|
||||||
|
**适用版本**: API v1.1.1
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🎯 测试概述
|
||||||
|
|
||||||
|
本指南提供了完整的API接口测试方案,包括Godot内置测试和独立的Python测试脚本,确保在不同环境下都能有效验证API功能。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 📋 测试工具对比
|
||||||
|
|
||||||
|
| 测试工具 | 适用场景 | 优势 | 使用难度 |
|
||||||
|
|----------|----------|------|----------|
|
||||||
|
| **Python快速测试** | 日常检查 | 快速、简单 | ⭐ |
|
||||||
|
| **Python完整测试** | 全面验证 | 覆盖全面、详细 | ⭐⭐ |
|
||||||
|
| **Godot内置测试** | 引擎环境 | 真实环境、UI测试 | ⭐⭐⭐ |
|
||||||
|
| **简单连接测试** | 基础检查 | 最小依赖 | ⭐ |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🚀 快速开始
|
||||||
|
|
||||||
|
### 1. Python测试(推荐)
|
||||||
|
|
||||||
|
#### 安装依赖
|
||||||
|
```bash
|
||||||
|
cd tests/api
|
||||||
|
pip install -r requirements.txt
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 运行快速测试
|
||||||
|
```bash
|
||||||
|
# Windows
|
||||||
|
run_tests.bat
|
||||||
|
|
||||||
|
# Linux/Mac
|
||||||
|
./run_tests.sh
|
||||||
|
|
||||||
|
# 或直接运行
|
||||||
|
python quick_test.py
|
||||||
|
```
|
||||||
|
|
||||||
|
### 2. Godot测试
|
||||||
|
|
||||||
|
#### 运行API测试脚本
|
||||||
|
```gdscript
|
||||||
|
# 在Godot中运行
|
||||||
|
var api_test = preload("res://scripts/network/ApiTestScript.gd").new()
|
||||||
|
add_child(api_test)
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 运行UI测试
|
||||||
|
```bash
|
||||||
|
# 打开Godot项目
|
||||||
|
# 运行 tests/auth/auth_ui_test.tscn 场景
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 📊 测试类型详解
|
||||||
|
|
||||||
|
### 1. 快速测试 (`quick_test.py`)
|
||||||
|
|
||||||
|
**用途**: 日常开发中的快速验证
|
||||||
|
**时间**: 约30秒
|
||||||
|
**覆盖**: 基础API端点
|
||||||
|
|
||||||
|
```bash
|
||||||
|
python tests/api/quick_test.py
|
||||||
|
```
|
||||||
|
|
||||||
|
**测试内容**:
|
||||||
|
- ✅ 服务器状态检查
|
||||||
|
- ✅ 邮箱验证码发送
|
||||||
|
- ✅ 用户登录/注册
|
||||||
|
- ✅ 基础错误处理
|
||||||
|
|
||||||
|
### 2. 完整测试 (`api_client_test.py`)
|
||||||
|
|
||||||
|
**用途**: 发布前的全面验证
|
||||||
|
**时间**: 约2-3分钟
|
||||||
|
**覆盖**: 所有业务流程
|
||||||
|
|
||||||
|
```bash
|
||||||
|
python tests/api/api_client_test.py
|
||||||
|
```
|
||||||
|
|
||||||
|
**测试内容**:
|
||||||
|
- 🔄 完整的用户注册流程
|
||||||
|
- 🔄 邮箱验证流程
|
||||||
|
- 🔄 登录流程(密码+验证码)
|
||||||
|
- 🔄 密码重置流程
|
||||||
|
- 🔄 错误场景测试
|
||||||
|
- 🔄 频率限制测试
|
||||||
|
|
||||||
|
### 3. Godot内置测试
|
||||||
|
|
||||||
|
**用途**: 引擎环境下的真实测试
|
||||||
|
**时间**: 根据测试场景而定
|
||||||
|
**覆盖**: UI交互和网络请求
|
||||||
|
|
||||||
|
#### API测试脚本
|
||||||
|
```gdscript
|
||||||
|
# 文件: scripts/network/ApiTestScript.gd
|
||||||
|
# 功能: 验证NetworkManager和ResponseHandler
|
||||||
|
```
|
||||||
|
|
||||||
|
#### UI测试场景
|
||||||
|
```gdscript
|
||||||
|
# 文件: tests/auth/auth_ui_test.tscn
|
||||||
|
# 功能: 测试认证界面的各种响应情况
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🔧 测试配置
|
||||||
|
|
||||||
|
### API服务器配置
|
||||||
|
```python
|
||||||
|
# 默认配置
|
||||||
|
API_BASE_URL = "https://whaletownend.xinghangee.icu"
|
||||||
|
|
||||||
|
# 本地开发配置
|
||||||
|
API_BASE_URL = "http://localhost:3000"
|
||||||
|
```
|
||||||
|
|
||||||
|
### 测试数据配置
|
||||||
|
```python
|
||||||
|
# 测试用户信息
|
||||||
|
TEST_EMAIL = "test@example.com"
|
||||||
|
TEST_USERNAME = "testuser"
|
||||||
|
TEST_PASSWORD = "password123"
|
||||||
|
```
|
||||||
|
|
||||||
|
### 超时配置
|
||||||
|
```python
|
||||||
|
DEFAULT_TIMEOUT = 30 # 秒
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 📈 测试结果解读
|
||||||
|
|
||||||
|
### 成功标志
|
||||||
|
- ✅ **测试通过** - 功能正常
|
||||||
|
- 🧪 **测试模式** - 开发环境,验证码在响应中返回
|
||||||
|
- 🔑 **获取验证码** - 成功获取到测试验证码
|
||||||
|
|
||||||
|
### 警告标志
|
||||||
|
- ⚠️ **资源冲突** - 409状态码,用户名/邮箱已存在
|
||||||
|
- ⏰ **频率限制** - 429状态码,请求过于频繁
|
||||||
|
|
||||||
|
### 错误标志
|
||||||
|
- ❌ **测试失败** - 功能异常,需要检查
|
||||||
|
- 🔌 **连接失败** - 网络问题或服务器不可用
|
||||||
|
- 📊 **状态码异常** - HTTP状态码不符合预期
|
||||||
|
|
||||||
|
### 示例输出解读
|
||||||
|
```
|
||||||
|
🧪 测试: 发送邮箱验证码
|
||||||
|
📡 POST https://whaletownend.xinghangee.icu/auth/send-email-verification
|
||||||
|
📦 数据: {"email": "test@example.com"}
|
||||||
|
📊 状态码: 206
|
||||||
|
🧪 测试模式响应
|
||||||
|
🔑 验证码: 123456
|
||||||
|
✅ 测试通过
|
||||||
|
```
|
||||||
|
|
||||||
|
**解读**:
|
||||||
|
- 请求成功发送到正确的端点
|
||||||
|
- 返回206状态码表示测试模式
|
||||||
|
- 成功获取验证码123456
|
||||||
|
- 整体测试通过
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🐛 故障排除
|
||||||
|
|
||||||
|
### 常见问题及解决方案
|
||||||
|
|
||||||
|
#### 1. 连接失败
|
||||||
|
**症状**: `❌ 连接失败` 或 `网络连接异常`
|
||||||
|
|
||||||
|
**解决方案**:
|
||||||
|
```bash
|
||||||
|
# 检查网络连接
|
||||||
|
ping whaletownend.xinghangee.icu
|
||||||
|
|
||||||
|
# 检查服务器状态
|
||||||
|
curl https://whaletownend.xinghangee.icu
|
||||||
|
|
||||||
|
# 检查防火墙设置
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 2. 频率限制
|
||||||
|
**症状**: `⏰ 请求过于频繁` 或 `429状态码`
|
||||||
|
|
||||||
|
**解决方案**:
|
||||||
|
- 等待冷却时间(通常1分钟)
|
||||||
|
- 使用不同的测试邮箱
|
||||||
|
- 检查API频率限制配置
|
||||||
|
|
||||||
|
#### 3. 验证码错误
|
||||||
|
**症状**: `验证码错误或已过期`
|
||||||
|
|
||||||
|
**解决方案**:
|
||||||
|
- 确保使用最新获取的验证码
|
||||||
|
- 检查验证码是否在5分钟有效期内
|
||||||
|
- 在测试模式下使用响应中返回的验证码
|
||||||
|
|
||||||
|
#### 4. 参数验证失败
|
||||||
|
**症状**: `400状态码` 或 `参数验证失败`
|
||||||
|
|
||||||
|
**解决方案**:
|
||||||
|
- 检查请求参数格式
|
||||||
|
- 确认必填字段都已提供
|
||||||
|
- 验证邮箱、用户名格式是否正确
|
||||||
|
|
||||||
|
#### 5. Python依赖问题
|
||||||
|
**症状**: `ModuleNotFoundError: No module named 'requests'`
|
||||||
|
|
||||||
|
**解决方案**:
|
||||||
|
```bash
|
||||||
|
# 安装依赖
|
||||||
|
pip install requests
|
||||||
|
|
||||||
|
# 或使用requirements.txt
|
||||||
|
pip install -r tests/api/requirements.txt
|
||||||
|
|
||||||
|
# 检查Python版本
|
||||||
|
python --version
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 📝 测试最佳实践
|
||||||
|
|
||||||
|
### 1. 测试前准备
|
||||||
|
- 确认API服务器正常运行
|
||||||
|
- 检查网络连接稳定
|
||||||
|
- 准备测试数据(邮箱、用户名等)
|
||||||
|
|
||||||
|
### 2. 测试执行
|
||||||
|
- 按照从简单到复杂的顺序执行测试
|
||||||
|
- 记录测试结果和异常情况
|
||||||
|
- 对失败的测试进行重试验证
|
||||||
|
|
||||||
|
### 3. 测试后分析
|
||||||
|
- 分析测试结果,识别问题模式
|
||||||
|
- 更新测试用例覆盖新发现的场景
|
||||||
|
- 文档化测试发现的问题和解决方案
|
||||||
|
|
||||||
|
### 4. 持续集成
|
||||||
|
- 将测试脚本集成到CI/CD流程
|
||||||
|
- 设置自动化测试触发条件
|
||||||
|
- 建立测试结果通知机制
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🔄 测试流程建议
|
||||||
|
|
||||||
|
### 开发阶段
|
||||||
|
1. **快速测试** - 每次代码修改后运行
|
||||||
|
2. **功能测试** - 新功能开发完成后运行
|
||||||
|
3. **回归测试** - 修复bug后运行
|
||||||
|
|
||||||
|
### 测试阶段
|
||||||
|
1. **完整测试** - 每日构建后运行
|
||||||
|
2. **压力测试** - 定期运行频率限制测试
|
||||||
|
3. **兼容性测试** - 不同环境下运行测试
|
||||||
|
|
||||||
|
### 发布阶段
|
||||||
|
1. **预发布测试** - 生产环境部署前运行
|
||||||
|
2. **冒烟测试** - 生产环境部署后运行
|
||||||
|
3. **监控测试** - 生产环境持续监控
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 📚 相关文档
|
||||||
|
|
||||||
|
- [API文档](api-documentation.md) - 完整的API接口说明
|
||||||
|
- [API更新日志](api_update_log.md) - 最新的API变更记录
|
||||||
|
- [项目结构说明](project_structure.md) - 项目整体架构
|
||||||
|
- [网络管理器设置](network_manager_setup.md) - Godot网络配置
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🤝 贡献指南
|
||||||
|
|
||||||
|
### 添加新测试
|
||||||
|
1. 在对应的测试文件中添加新的测试方法
|
||||||
|
2. 遵循现有的测试模式和命名规范
|
||||||
|
3. 添加适当的错误处理和结果验证
|
||||||
|
4. 更新相关文档
|
||||||
|
|
||||||
|
### 报告问题
|
||||||
|
1. 提供详细的错误信息和复现步骤
|
||||||
|
2. 包含测试环境信息(Python版本、操作系统等)
|
||||||
|
3. 附上相关的日志和截图
|
||||||
|
|
||||||
|
### 改进建议
|
||||||
|
1. 提出测试覆盖的改进建议
|
||||||
|
2. 优化测试执行效率的方案
|
||||||
|
3. 增强测试结果可读性的想法
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
**测试愉快!🎉**
|
||||||