38 Commits

Author SHA1 Message Date
51e79c6c6d Merge branch 'main' into fix/verification-code-button-state 2025-12-31 19:00:09 +08:00
0edd1c740b docs: 完善项目文档和README,修复字符显示问题
- 修复README.md中的emoji字符显示问题
- 移除文档质量评级系统
- 添加贡献者致谢部分,创建详细的CONTRIBUTORS.md
- 创建核心系统文件EventNames.gd和ProjectPaths.gd
- 更新项目配置文件project.godot,添加输入映射
- 完善各模块文档,修正路径引用问题
- 创建文档更新日志CHANGELOG.md
- 优化文档结构和导航系统
2025-12-31 18:58:38 +08:00
a85a7b4d0e docs: 完善项目入门README,强调输入映射配置的重要性
发现的关键问题:
- 项目代码中使用了输入映射,但project.godot中未配置
- 缺少输入映射会导致游戏无法正常运行

 主要改进:
- 强调输入映射配置为必需步骤
- 添加重要提醒和警告标识
- 新增常见启动问题排查指南
- 明确列出必需的6个输入动作
- 完善完成检查清单

 问题排查:
- 游戏无法响应输入  输入映射未配置
- Invalid action错误  缺少必需输入动作
- AutoLoad单例报错  配置验证问题

 确保新人成功:
- 明确标注必需步骤的优先级
- 提供具体的错误解决方案
- 强调验证配置的重要性
2025-12-31 18:17:58 +08:00
51d2ad1629 docs: 修正项目设置指南,确保信息准确
修正的问题:
- 路径错误: core/managers/  _Core/managers/
- 补充完整的AutoLoad配置列表 (5个单例)
- 修正NetworkManager.login()方法调用方式
- 添加实际的project.godot配置验证

 新增内容:
- 完整的AutoLoad配置表格
- 其他重要项目设置 (主题、渲染、窗口)
- 详细的验证测试代码
- 常见问题排查指南
- 配置检查清单

 确保准确性:
- 所有路径基于实际项目结构验证
- 代码示例基于实际API接口
- 配置信息与project.godot文件一致
2025-12-31 18:13:08 +08:00
6f545b04e9 docs: 更新项目结构说明,匹配实际项目结构
主要更新:
- 根据实际项目目录结构重写文档
- 明确三类团队协作模式:开发、美术、策划
- 详细说明每个目录的职责和使用方式
- 添加团队协作指南和工作流程
- 提供实际的代码示例和配置示例

 新增内容:
- 团队协作模式说明 (开发/美术/策划)
- 详细的目录结构和文件说明
- 开发工作流和版本发布流程
- 最佳实践和规范要求

 确保准确性:
- 所有目录结构都基于实际项目检查
- 文件路径和命名完全匹配当前状态
- 团队职责划分清晰明确
2025-12-31 18:08:31 +08:00
1ff677b3b2 docs: 重新组织文档结构,按开发阶段分类
新的目录结构:
  01-项目入门/     # 新人必读,项目基础
  02-开发规范/     # 编码标准和规范
  03-技术实现/     # 具体开发指导
  04-高级开发/     # 进阶开发技巧
  05-部署运维/     # 发布和部署
  06-功能模块/     # 特定功能文档

 新增导航文档:
- docs/README.md - 完整的文档导航和使用指南
- 各目录下的README.md - 分类说明和使用指导

 优化效果:
- 开发者可以按阶段快速定位需要的文档
- 新人有清晰的学习路径
- 不同角色有针对性的文档推荐
- 提供了问题导向的快速查找功能
2025-12-31 18:02:16 +08:00
2998fd2d11 docs: 补充开发规范相关文档
新增文档:
- docs/输入映射配置.md - 游戏输入配置指南
- docs/架构与通信规范.md - 项目架构和组件通信规范
- docs/实现细节规范.md - 游戏对象具体实现要求
- docs/开发哲学与最佳实践.md - 开发理念和编程最佳实践

 覆盖内容:
- 输入映射的配置方法和验证
- EventSystem事件系统使用规范
- 玩家、NPC、TileMap的实现标准
- 代码质量标准和审查清单
- 性能优化和资源管理指导

这些文档补充了开发规范.md中提到但在docs目录中缺失的内容
2025-12-31 17:50:19 +08:00
60edcc9868 docs: 文档中文化和清理
新增:
- 开发规范.md (翻译自CLAUDE.md)

 重命名为中文:
- project_structure.md  项目结构说明.md
- naming_convention.md  命名规范.md
- code_comment_guide.md  代码注释规范.md
- git_commit_guide.md  Git提交规范.md
- api-documentation.md  API接口文档.md
- network_manager_setup.md  网络管理器设置.md
- setup.md  项目设置指南.md
- testing_guide.md  测试指南.md
- web_deployment_guide.md  Web部署指南.md
- module_development.md  模块开发指南.md
- performance_optimization.md  性能优化指南.md
- scene_design.md  场景设计规范.md
- auth/form_validation.md  auth/表单验证规范.md
- auth/testing_guide.md  auth/认证测试指南.md

 删除总结性文档:
- final_update_summary.md
- web_deployment_changelog.md
- CLAUDE.md
2025-12-31 17:45:04 +08:00
d25d8d4dd3 Merge pull request 'fix/verification-code-button-state' (#4) from fix/verification-code-button-state into main
Reviewed-on: #4
2025-12-31 17:28:45 +08:00
190b6c9a66 docs: 清理总结性文档,保留规范类文档
- 删除 docs/CONTRIBUTORS.md (总结性文档)
- 删除 docs/api_update_log.md (已不存在)
- 删除 docs/cleanup_summary.md (已不存在)
- 保留 docs/module_development.md (开发规范)
- 保留 docs/performance_optimization.md (性能规范)
- 保留 docs/scene_design.md (设计规范)
2025-12-31 17:27:13 +08:00
899bc5d5d0 merge: 解决README.md合并冲突,保留main分支内容并整合当前分支特性 2025-12-31 17:21:53 +08:00
e657cfce0e Merge pull request 'refactor:重构项目架构为分层结构' (#3) from qbb0530/whale-town-front:refactor/项目结构重构 into main
Reviewed-on: #3
2025-12-31 16:35:24 +08:00
王浩
b9182bbc2e docs:完善 CLAUDE.md 为 AI 开发规范文档
## 🎯 主要改进

### 1. 明确项目定位
- 清晰定义 "WhaleTown" 为 2D 俯视像素风 RPG
- 指定 Godot 4.2+ 引擎(禁止 3.x 语法)
- 强调分层架构:`_Core`(框架)、`Scenes`(玩法)、`UI`(界面)

### 2. 完善开发规范
-  添加 Input Map 配置(WASD、交互键、暂停键)
-  明确文件路径规则(STRICT LOWERCASE)
-  添加 EventNames.gd 示例代码
-  完善测试代码示例(GUT 框架)
-  优化代码模板(分区注释)

### 3. 强化技术约束
- 📋 严格类型系统(强制静态类型)
- 🏛 事件驱动架构(EventSystem 解耦)
- 🚫 禁止模式列表(yield、Linear Filter 等)
-  必须测试覆盖(所有 Core 管理器)

### 4. 代码模板改进
- 添加结构化注释(Exports、References、Lifecycle、Methods)
- 展示最佳实践(@onready、%UniqueName、私有方法前缀)
- 包含完整的玩家移动示例

### 5. AI 指令优化
- 直接对 AI 说话("Claude: Root folders MUST be lowercase")
- 明确的优先级(STRICT、The Law、MANDATORY)
- 提供决策指南(Area2D vs Body、Enum vs StateChart)

## 📊 文档结构
- 90 行,精炼完整
- Emoji 视觉层级(🛠 命令、📂 文件、📋 标准、🏛 架构)
- 覆盖:文件组织、编码标准、架构设计、测试要求、代码模板

##  质量提升
- 统一路径大小写(tests/ 而非 Tests/)
- 添加 EventNames.gd 完整示例
- 完善测试代码(watch_signals、assert_signal_emitted)
- 明确 Godot 版本约束(4.2+)

## 🎯 目标
为 AI 提供清晰、严格、可执行的开发规范,
确保代码质量和架构一致性。

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-31 16:32:54 +08:00
王浩
642a99970c docs:添加项目开发规范文档 CLAUDE.md
## 📋 新增内容

添加了完整的 Claude Code 开发规范文档,包括:

### 核心规范
- **项目概述**: 2D 俯视像素风 RPG 游戏架构
- **编码标准**:
  - 严格类型系统
  - 统一命名规范(PascalCase, snake_case, SCREAMING_SNAKE_CASE)
  - 节点访问规范(@onready, %UniqueName)
  - 最佳实践(await, Callable, Signal Up/Call Down)

### 架构规则
- **解耦原则**: 低层级实体通过 EventSystem 通信
- **场景管理**: 统一使用 SceneManager.change_scene()
- **组件化**: 可复用逻辑封装到 Scenes/Components/

### 实现规范
- **实体结构**:
  - Player: CharacterBody2D + Camera2D
  - NPC: StaticBody2D/CharacterBody2D + InteractionArea
  - Interactables: 共享 InteractableComponent
- **交互系统**: 通过 EventSystem.notify_interaction_triggered()
- **TileMap 规则**: 分层设计(地面、障碍、装饰)

### 文件组织
- 地图: Scenes/Maps/[map_name].tscn
- 实体: Scenes/Entities/[entity_name]/[entity_name].tscn
- 脚本: 与场景文件同目录
- 资源: res://Assets/Sprites/

### 测试标准
- 使用 GUT 测试框架
- 测试文件位置: res://test/unit/ 或 res://test/integration/
- 文件命名: test_*.gd
- 核心逻辑必须有单元测试
- 玩家移动和 NPC 交互需要集成测试

### 开发理念
- 简约至上:函数单一职责
- "栅栏后规则": 即使不可见的代码也要干净优美
- 反馈循环:每个交互都要有特效/音效占位
- 零硬编码:所有路径和配置使用常量或 @export
- "自动工作"的相机:自动检测 TileMap 边界

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-31 16:07:54 +08:00
王浩
0b533189ec refactor:重构项目架构为分层结构
## 🏗️ 主要变更

### 目录结构重构
- 将 core/ 迁移到 _Core/(框架层)
- 将 scenes/ 重构为 Scenes/(玩法层)和 UI/(界面层)
- 将 data/ 迁移到 Config/(配置层)
- 添加 Assets/ 资源层和 Utils/ 工具层
- 将 scripts/ 迁移到 tools/(开发工具)

### 架构分层
- **_Core/**: 框架层 - 全局单例和管理器
- **Scenes/**: 玩法层 - 游戏场景和实体
- **UI/**: 界面层 - HUD、窗口、对话系统
- **Assets/**: 资源层 - 精灵图、音频、字体
- **Config/**: 配置层 - 游戏配置和本地化
- **Utils/**: 工具层 - 通用辅助脚本

### 文件更新
- 更新 project.godot 中的所有路径引用
- 更新自动加载脚本路径
- 更新测试文件的引用路径
- 添加 REFACTORING.md 详细说明
- 添加 MIGRATION_COMPLETE.md 迁移完成标记
- 更新 README.md 反映新架构

### 设计原则
-  清晰的分层(框架/玩法/界面)
-  场景内聚(脚本紧邻场景文件)
-  组件化设计(可复用组件)
-  职责单一(每个目录职责明确)

## 📋 详细信息
查看 REFACTORING.md 了解完整的重构说明和迁移映射表

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-31 11:36:01 +08:00
b1f3c0feff Merge pull request 'feature/网络管理和Web部署系统' (#2) from feature/网络管理和Web部署系统 into main
Reviewed-on: #2
2025-12-25 23:17:30 +08:00
021c8623f8 docs:更新主要项目文档
- 更新README添加Web部署说明
- 精简API文档,移除冗余内容
- 添加新功能使用指南
- 完善项目架构说明
2025-12-25 23:14:29 +08:00
a1b867dfd7 chore:清理废弃的网络测试文件
- 删除旧的NetworkTest.gd测试文件
- 移除对应的UID文件
- 统一使用新的ApiTestScript替代
2025-12-25 23:14:09 +08:00
d17c766246 test:增强认证模块测试覆盖
- 添加认证UI自动化测试
- 实现增强型Toast消息测试
- 完善用户交互测试用例
- 提高测试代码覆盖率
2025-12-25 23:13:49 +08:00
92c4eaed07 refactor:重构认证场景和网络集成
- 重构AuthScene脚本,集成新的NetworkManager
- 优化用户界面布局和交互逻辑
- 改进错误处理和用户反馈机制
- 统一网络请求处理流程
2025-12-25 23:12:49 +08:00
abd683c766 config:更新项目配置支持Web导出
- 启用Web导出功能
- 配置中文字体支持
- 更新项目设置和资源路径
- 优化Web版本性能配置
2025-12-25 23:10:28 +08:00
a05bac6f05 docs:添加完整的项目文档体系
- 添加Web部署完整指南和更新日志
- 创建网络管理器配置文档
- 完善项目设置和测试指南
- 添加API更新日志和清理总结
- 更新脚本使用说明文档
2025-12-25 23:09:59 +08:00
77af0bda39 test:完善API测试框架
- 添加Godot内置API测试脚本
- 实现Python API客户端测试套件
- 添加快速测试和完整测试脚本
- 支持跨平台测试运行(Windows/Linux)
- 更新测试文档和使用指南
2025-12-25 23:09:12 +08:00
8980e3d558 feat:添加字符串工具类
- 实现邮箱格式验证功能
- 添加密码强度检查
- 提供字符串清理和格式化方法
- 支持中文字符处理
2025-12-25 23:07:47 +08:00
1294529d13 asset:添加UI资源和中文字体支持
- 添加微软雅黑字体文件支持中文显示
- 导入Datawhale官方Logo图标
- 创建中文主题配置文件
- 完善游戏图标资源目录
2025-12-25 23:06:50 +08:00
0935c5fd76 feat:添加Web版本自动化部署系统
- 实现跨平台Web导出脚本(Windows/Linux/macOS)
- 添加本地测试服务器启动脚本
- 配置Godot Web导出预设
- 创建Web资源目录结构
- 支持一键导出和本地测试
2025-12-25 23:06:29 +08:00
405710bdde feat:实现统一网络请求管理系统
- 添加NetworkManager核心网络管理器
- 实现ResponseHandler统一响应处理
- 支持GET、POST、PUT、DELETE、PATCH请求类型
- 完善错误处理和超时机制
- 提供统一的信号回调接口
2025-12-25 23:05:49 +08:00
7413574672 Merge pull request 'fix/verification-code-button-state' (#1) from fix/verification-code-button-state into main
Reviewed-on: #1
2025-12-24 20:58:43 +08:00
c0f5d6a537 docs:添加性能优化指南
- 创建全面的性能优化文档
- 涵盖渲染、内存、脚本、网络等各方面优化
- 提供具体的代码示例和最佳实践
- 包含性能监控和调试工具使用方法
- 为开发者提供系统的性能优化指导
2025-12-24 20:51:45 +08:00
0b6b1c2040 docs:完善前端项目文档体系
- 重构README文档,参考后端结构优化内容组织
- 添加模块开发指南,详细说明模块化开发流程
- 创建场景设计规范,规范场景架构和最佳实践
- 建立贡献者名单,记录团队成员和贡献统计
- 完善技术栈介绍和功能特性说明
- 优化文档结构和导航,提升开发者体验
2025-12-24 20:50:31 +08:00
8d071cb2ed chore:清理空目录占位文件
- 删除不再需要的.gitkeep文件
- 目录结构已通过实际文件维护,无需占位符
2025-12-24 20:40:26 +08:00
370cffbdd8 config:更新项目配置和文档
- 更新Godot项目配置,添加自动加载脚本
- 完善.gitignore文件,排除不必要的文件
- 更新README文档,添加项目介绍和使用说明
- 更新主场景配置,集成认证系统
- 添加开发规范文档和项目结构说明
2025-12-24 20:39:33 +08:00
5b67771bbc asset:添加游戏资源目录和测试框架
- 创建音频、字体、材质、着色器等资源目录
- 添加精灵图片资源管理结构
- 建立集成测试、性能测试、单元测试框架
- 为后续资源导入和测试开发做准备
2025-12-24 20:39:14 +08:00
73478c0500 chore:完善项目目录结构和基础框架
- 添加核心系统框架目录结构
- 创建游戏模块化组织架构
- 添加数据配置和本地化支持
- 建立脚本分类管理体系
- 创建场景预制件管理目录
2025-12-24 20:38:57 +08:00
15548ebb52 docs:添加API接口文档
- 详细记录认证相关API接口规范
- 包含请求参数、响应格式和错误代码说明
- 提供完整的使用示例和测试用例
- 涵盖登录、注册、验证码等核心功能接口
2025-12-24 20:38:40 +08:00
47cfc14f68 test:添加认证系统测试套件
- 添加UI测试场景,支持模拟各种认证场景
- 实现API测试脚本,覆盖登录、注册、验证码等接口
- 添加测试文档,说明测试用例和预期结果
- 支持自动化测试和手动测试验证
2025-12-24 20:37:33 +08:00
c6bcca4e7f feat:实现用户认证系统核心功能
- 实现用户登录和注册的完整流程
- 添加邮箱验证码发送和验证功能
- 实现基于邮箱地址的验证码冷却机制
- 添加表单验证和错误提示系统
- 集成Toast消息提示系统
- 支持网络请求处理和错误处理
- 实现按钮状态管理和加载状态显示
2025-12-24 20:37:00 +08:00
f11479f2cc scene:创建用户认证场景和UI资源
- 添加认证场景 auth_scene.tscn,包含登录和注册界面
- 添加认证相关的UI背景图片和框架素材
- 实现响应式布局,支持登录/注册界面切换
- 包含完整的表单输入控件和验证码输入区域
2025-12-24 20:36:35 +08:00
196 changed files with 18486 additions and 1435 deletions

View File

@@ -1,13 +0,0 @@
{
"permissions": {
"allow": [
"WebFetch(domain:whaletownend.xinghangee.icu)",
"mcp__ide__getDiagnostics",
"Bash(dir /s /b *.gd)",
"Bash(findstr:*)",
"Bash(del nul)",
"Bash(git checkout:*)",
"Bash(git add:*)"
]
}
}

55
.gitignore vendored
View File

@@ -1,3 +1,58 @@
# Godot 4+ specific ignores
.godot/
/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/

15
.vscode/launch.json vendored
View File

@@ -1,15 +0,0 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "GDScript Godot",
"type": "godot",
"request": "launch",
"project": "${workspaceFolder}",
"port": 6007,
"address": "127.0.0.1",
"launch_game_instance": true,
"launch_scene": false
}
]
}

View File

@@ -1,3 +0,0 @@
{
"godotTools.editorPath.godot4": "d:\\software\\godot\\Godot_v4.5.1-stable_win64.exe"
}

29
Config/game_config.json Normal file
View 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
View 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
View 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 编辑器中打开项目并测试!** 🚀

428
README.md
View File

@@ -1,101 +1,363 @@
# whaleTown
# 🐋 WhaleTown - 现代化像素游戏
一个使用 Godot 4.5 引擎开发的游戏项目
> 一个基于 Godot 4.5 引擎开发的企业级 2D 像素风游戏,采用模块化架构设计,集成完整的用户认证系统和游戏核心功能
## 项目信息
[![Godot](https://img.shields.io/badge/Godot-4.5+-blue.svg)](https://godotengine.org/)
[![GDScript](https://img.shields.io/badge/GDScript-Latest-green.svg)](https://docs.godotengine.org/en/stable/tutorials/scripting/gdscript/index.html)
[![Documentation](https://img.shields.io/badge/Documentation-Complete-brightgreen.svg)](./docs/)
[![Platform](https://img.shields.io/badge/Platform-Windows%20%7C%20Linux%20%7C%20macOS%20%7C%20Web-lightgrey.svg)](https://godotengine.org/download)
- **引擎版本**: Godot 4.5
- **渲染器**: Forward Plus
- **项目类型**: 2D 游戏
## 🎯 项目简介
## 项目结构
WhaleTown 是一个功能完整的现代化像素游戏,具有以下特色:
```
whaleTown/
├── addons/ # Godot 插件目录
├── assets/ # 游戏资源文件(图片、音频等)
├── data/ # 游戏数据文件(配置、关卡数据等)
├── docs/ # 项目文档
├── scenes/ # 游戏场景文件
│ └── main_scene.tscn # 主场景
├── scripts/ # GDScript 脚本文件
├── tests/ # 测试文件
├── icon.svg # 项目图标
└── project.godot # Godot 项目配置文件
```
- 🏗️ **企业级架构** - 模块化设计,高度解耦,易于扩展
- 🔐 **完整认证系统** - 登录、注册、邮箱验证、密码管理
- 🎮 **丰富游戏功能** - 角色系统、场景管理、事件通信
- 🌐 **网络通信** - RESTful API集成支持实时数据交互
- 📚 **企业级文档** - 18个文档覆盖开发全流程
- 🧪 **完整测试体系** - API测试、UI测试、性能测试
- 🚀 **一键部署** - 支持Web、桌面多平台发布
## 开始使用
---
### 前置要求
## 🚀 5分钟快速体验
- [Godot Engine 4.5](https://godotengine.org/download) 或更高版本
### 📋 准备工作
### 运行项目
**你需要安装:**
- [Godot Engine 4.5+](https://godotengine.org/download) - 游戏引擎
- [Git](https://git-scm.com/) - 版本控制工具
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
git commit -m "init项目初始化搭建Godot文件结构"
git commit -m "feat实现玩家角色的移动和跳跃"
git commit -m "fix修复敌人穿墙的碰撞问题"
git commit -m "scene创建战斗场景并配置相机"
# 1⃣ 获取项目
git clone <repository-url>
cd whale-town
# 2⃣ 打开项目
# 双击 project.godot 文件或在Godot编辑器中选择"导入项目"
# 3⃣ 运行游戏
# 在Godot编辑器中按 F5 或点击"运行项目"按钮
```
📖 查看完整的 [Git 提交规范文档](docs/git_commit_guide.md)
🎉 **成功!** 你应该看到游戏的认证界面
## 贡献
### 🎮 体验功能
欢迎提交 Issue 和 Pull Request
1. **注册新用户** - 体验完整的邮箱验证流程
2. **登录系统** - 尝试用户名/邮箱登录
3. **游戏界面** - 探索主游戏场景
## 许可证
### 🧪 测试API可选
[在此添加许可证信息]
```bash
# 安装Python依赖
pip install requests
# 快速API测试
python tests/api/quick_test.py
# 完整功能测试
python tests/api/api_client_test.py
```
---
## 📚 新手开发指南
### 🎯 第一步:了解项目
**⚠️ 重要:开始开发前必读**
1. **[📖 项目入门总览](docs/01-项目入门/README.md)** - 5分钟了解项目
2. **[🏗️ 项目结构说明](docs/01-项目入门/项目结构说明.md)** - 理解架构设计
3. **[⚙️ 项目设置指南](docs/01-项目入门/项目设置指南.md)** - 配置开发环境
### 🎯 第二步:学习规范
**代码质量保证**
1. **[📝 命名规范](docs/02-开发规范/命名规范.md)** - 统一命名标准
2. **[🏛️ 架构与通信规范](docs/02-开发规范/架构与通信规范.md)** - 组件通信方式
3. **[💬 代码注释规范](docs/02-开发规范/代码注释规范.md)** - 注释标准
4. **[🔄 Git提交规范](docs/02-开发规范/Git提交规范.md)** - 版本控制规范
### 🎯 第三步:开始开发
**技术实现指导**
1. **[🔧 实现细节规范](docs/03-技术实现/实现细节规范.md)** - 游戏对象实现
2. **[🌐 API接口文档](docs/03-技术实现/API接口文档.md)** - 后端接口使用
3. **[🧪 测试指南](docs/03-技术实现/测试指南.md)** - 测试方法和工具
### 🎯 第四步:高级开发
**进阶技能**
1. **[🚀 性能优化指南](docs/04-高级开发/性能优化指南.md)** - 性能调优
2. **[🎬 场景设计规范](docs/04-高级开发/场景设计规范.md)** - 场景架构
3. **[🧩 模块开发指南](docs/04-高级开发/模块开发指南.md)** - 模块化开发
### 🎯 第五步:项目发布
**部署和运维**
1. **[🌐 Web部署指南](docs/05-部署运维/Web部署指南.md)** - 完整部署流程
---
## 🏗️ 项目架构一览
### 📁 目录结构
```
WhaleTown/ # 🐋 项目根目录
├── 📚 docs/ # 📖 完整文档系统18个文档
│ ├── 01-项目入门/ # 👋 新人必读
│ ├── 02-开发规范/ # 📋 编码标准
│ ├── 03-技术实现/ # 🔧 开发指导
│ ├── 04-高级开发/ # 🚀 进阶技巧
│ ├── 05-部署运维/ # 🌐 发布部署
│ └── 06-功能模块/ # 🎮 功能文档
├── 🎬 scenes/ # 🎭 游戏场景
│ ├── Maps/ # 🗺️ 地图场景
│ └── Components/ # 🧩 组件预制体
├── 🔧 _Core/ # ⚙️ 核心系统
│ ├── managers/ # 🎯 全局管理器
│ ├── systems/ # 🔄 系统组件
│ ├── EventNames.gd # 📝 事件名称定义
│ └── ProjectPaths.gd # 📂 路径统一管理
├── 🎨 UI/ # 🖼️ 用户界面
│ └── Windows/ # 🪟 窗口界面
├── 🔨 Utils/ # 🔨 工具类
├── 🎮 module/ # 🧩 功能模块
├── 🎨 assets/ # 🖼️ 游戏资源
├── ⚙️ Config/ # 📋 配置文件
├── 🧪 tests/ # 🔬 测试文件
└── 🌐 web_assets/ # 🌍 Web部署资源
```
### 🔧 核心组件
| 组件 | 作用 | 文档链接 |
|------|------|----------|
| **EventSystem** | 全局事件通信 | [架构规范](docs/02-开发规范/架构与通信规范.md) |
| **GameManager** | 游戏状态管理 | [实现细节](docs/03-技术实现/实现细节规范.md) |
| **SceneManager** | 场景切换管理 | [场景设计](docs/04-高级开发/场景设计规范.md) |
| **NetworkManager** | 网络请求管理 | [网络管理器](docs/03-技术实现/网络管理器设置.md) |
| **ProjectPaths** | 路径统一管理 | [项目结构](docs/01-项目入门/项目结构说明.md) |
---
## 🎮 核心功能
### 🔐 用户认证系统
**完整的用户管理功能**
- ✅ 用户注册(用户名+邮箱验证)
- ✅ 多方式登录(用户名/邮箱/验证码)
- ✅ 密码管理(修改/重置)
- ✅ 表单验证(实时验证+友好提示)
- ✅ 错误处理(网络异常+业务错误)
**技术特色**
- 📱 响应式UI设计
- 🔄 实时表单验证
- ⏰ 验证码冷却机制
- 🎨 流畅动画效果
### 🎮 游戏核心系统
**模块化游戏架构**
- 🎭 场景管理系统
- 🔄 事件通信系统
- 🎯 状态管理系统
- 🌐 网络通信系统
**开发友好特性**
- 🧩 高度模块化
- 📝 完整文档覆盖
- 🧪 测试用例齐全
- 🔧 开发工具完善
---
## 🧪 测试系统
### 🔬 测试类型
| 测试类型 | 工具 | 覆盖范围 | 文档 |
|----------|------|----------|------|
| **API测试** | Python脚本 | 17个接口全覆盖 | [测试指南](docs/03-技术实现/测试指南.md) |
| **UI测试** | Godot场景 | 认证流程完整测试 | [认证测试](docs/06-功能模块/auth/认证测试指南.md) |
| **单元测试** | GUT框架 | 核心组件测试 | [测试指南](docs/03-技术实现/测试指南.md) |
### 🚀 快速测试
```bash
# 🔌 API接口测试30秒
python tests/api/quick_test.py
# 🔍 完整功能测试2-3分钟
python tests/api/api_client_test.py
# 🎮 UI交互测试在Godot中运行
# 打开 tests/auth/auth_ui_test.tscn 场景
```
---
## 🚀 部署发布
### 🖥️ 桌面版本
```bash
# Windows
godot --export "Windows Desktop" build/WhaleTown.exe
# Linux
godot --export "Linux/X11" build/WhaleTown.x86_64
# macOS
godot --export "macOS" build/WhaleTown.app
```
### 🌐 Web版本
```bash
# 使用自动化脚本
scripts/build_web.bat # Windows
scripts/build_web.sh # Linux/macOS
# 本地测试
scripts/serve_web.bat # 启动本地服务器
```
**详细部署流程**: [Web部署指南](docs/05-部署运维/Web部署指南.md)
---
## 📊 项目统计
### 📚 文档系统
| 类别 | 文档数 | 完成度 |
|------|--------|--------|
| 项目入门 | 3 | 100% |
| 开发规范 | 5 | 100% |
| 技术实现 | 4 | 100% |
| 高级开发 | 3 | 100% |
| 部署运维 | 1 | 100% |
| 功能模块 | 2 | 100% |
| **总计** | **18** | **100%** |
### 🧪 测试覆盖
- **API接口**: 17个接口 ✅
- **认证流程**: 完整测试 ✅
- **错误处理**: 边界测试 ✅
- **性能监控**: 帧率/内存 ✅
---
## 🤝 参与贡献
### 🌟 贡献方式
1. **🐛 Bug修复** - 发现并修复问题
2. **✨ 新功能** - 添加有价值的功能
3. **📚 文档改进** - 完善项目文档
4. **🧪 测试用例** - 提高代码覆盖率
5. **🎨 UI/UX改进** - 提升用户体验
### 📋 贡献流程
```bash
# 1⃣ Fork项目到你的账户
# 2⃣ 克隆到本地
git clone <your-fork-url>
cd whale-town
# 3⃣ 创建功能分支
git checkout -b feature/your-feature
# 4⃣ 开发功能(遵循项目规范)
# 参考: docs/02-开发规范/
# 5⃣ 添加测试用例
# 参考: docs/03-技术实现/测试指南.md
# 6⃣ 提交代码
git commit -m "feat添加新功能"
# 参考: docs/02-开发规范/Git提交规范.md
# 7⃣ 推送分支
git push origin feature/your-feature
# 8⃣ 创建Pull Request
```
### 📖 开发规范
**必读文档**
- [命名规范](docs/02-开发规范/命名规范.md) - 代码命名标准
- [Git提交规范](docs/02-开发规范/Git提交规范.md) - 提交信息格式
- [代码注释规范](docs/02-开发规范/代码注释规范.md) - 注释标准
### 🙏 贡献者致谢
感谢所有为 WhaleTown 项目做出贡献的开发者们!详细的贡献者信息和统计请查看:
**[📖 贡献者详细信息](docs/CONTRIBUTORS.md)**
---
## 📞 获取帮助
### 🔍 问题解决
| 问题类型 | 解决方案 |
|----------|----------|
| **🤔 不知道从哪开始** | [项目入门总览](docs/01-项目入门/README.md) |
| **🏗️ 不理解项目架构** | [项目结构说明](docs/01-项目入门/项目结构说明.md) |
| **🔧 开发环境问题** | [项目设置指南](docs/01-项目入门/项目设置指南.md) |
| **📝 不知道怎么命名** | [命名规范](docs/02-开发规范/命名规范.md) |
| **🔄 组件通信问题** | [架构与通信规范](docs/02-开发规范/架构与通信规范.md) |
| **🌐 API调用问题** | [API接口文档](docs/03-技术实现/API接口文档.md) |
| **🧪 测试相关问题** | [测试指南](docs/03-技术实现/测试指南.md) |
| **🚀 部署发布问题** | [Web部署指南](docs/05-部署运维/Web部署指南.md) |
### 📚 文档导航
- **[📖 完整文档中心](docs/README.md)** - 所有文档的导航页面
- **[📋 文档更新日志](docs/CHANGELOG.md)** - 文档版本变更记录
### 💬 联系方式
- **项目地址**: [Gitea Repository](https://gitea.xinghangee.icu/datawhale/whale-town)
- **问题反馈**: [Issues](https://gitea.xinghangee.icu/datawhale/whale-town/issues)
- **功能建议**: [Discussions](https://gitea.xinghangee.icu/datawhale/whale-town/discussions)
---
## 📄 许可证
本项目采用 [MIT License](./LICENSE) 开源协议。
---
<div align="center">
**🐋 WhaleTown - 企业级像素游戏开发框架**
*让游戏开发更简单,让代码质量更优秀*
[⭐ Star](https://gitea.xinghangee.icu/datawhale/whale-town) | [🍴 Fork](https://gitea.xinghangee.icu/datawhale/whale-town/fork) | [📖 文档](./docs/) | [🐛 反馈](https://gitea.xinghangee.icu/datawhale/whale-town/issues)
**文档版本**: v1.2.0 | **最后更新**: 2025-12-31
</div>

222
REFACTORING.md Normal file
View 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
View 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

Binary file not shown.

View 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
View 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

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1 @@
uid://bs1vy3ierj66t

561
UI/Windows/LoginWindow.tscn Normal file
View 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
View 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
View File

@@ -0,0 +1 @@
uid://csxag1y8yq57j

58
_Core/EventNames.gd Normal file
View File

@@ -0,0 +1,58 @@
# ============================================================================
# 事件名称定义 - EventNames.gd
#
# 定义项目中所有事件的名称常量,确保事件名称的一致性和可维护性
#
# 使用方式:
# EventSystem.emit_event(EventNames.PLAYER_MOVED, data)
# EventSystem.connect_event(EventNames.INTERACT_PRESSED, callback)
# ============================================================================
class_name EventNames
# ============================================================================
# 玩家相关事件
# ============================================================================
const PLAYER_MOVED = "player_moved"
const PLAYER_SPAWNED = "player_spawned"
const PLAYER_HEALTH_CHANGED = "player_health_changed"
const PLAYER_DIED = "player_died"
const PLAYER_RESPAWNED = "player_respawned"
const PLAYER_ATTACK = "player_attack"
# ============================================================================
# 交互事件
# ============================================================================
const INTERACT_PRESSED = "interact_pressed"
const NPC_TALKED = "npc_talked"
const ITEM_COLLECTED = "item_collected"
const OBJECT_INTERACTED = "object_interacted"
# ============================================================================
# UI事件
# ============================================================================
const UI_BUTTON_CLICKED = "ui_button_clicked"
const DIALOG_OPENED = "dialog_opened"
const DIALOG_CLOSED = "dialog_closed"
const MENU_OPENED = "menu_opened"
const MENU_CLOSED = "menu_closed"
# ============================================================================
# 游戏状态事件
# ============================================================================
const GAME_PAUSED = "game_paused"
const GAME_RESUMED = "game_resumed"
const SCENE_CHANGED = "scene_changed"
const SCENE_DATA_TRANSFER = "scene_data_transfer"
# ============================================================================
# 系统事件
# ============================================================================
const TILEMAP_READY = "tilemap_ready"
const COMPONENT_MESSAGE = "component_message"
const POSITION_UPDATE = "position_update"
# ============================================================================
# 测试事件
# ============================================================================
const TEST_EVENT = "test_event"

1
_Core/EventNames.gd.uid Normal file
View File

@@ -0,0 +1 @@
uid://qn0imbklx1m0

107
_Core/ProjectPaths.gd Normal file
View File

@@ -0,0 +1,107 @@
# ============================================================================
# 项目路径配置 - ProjectPaths.gd
#
# 统一管理项目中所有路径常量,确保路径的一致性和可维护性
#
# 使用方式:
# var scene_path = ProjectPaths.SCENES_COMPONENTS + "ui/Button.tscn"
# var config_path = ProjectPaths.DATA_CONFIG + "game_config.json"
# ============================================================================
class_name ProjectPaths
# ============================================================================
# 核心系统路径
# ============================================================================
const CORE_ROOT = "res://_Core/"
const CORE_MANAGERS = CORE_ROOT + "managers/"
const CORE_SYSTEMS = CORE_ROOT + "systems/"
# ============================================================================
# 场景路径
# ============================================================================
const SCENES_ROOT = "res://scenes/"
const SCENES_MAPS = SCENES_ROOT + "Maps/"
const SCENES_COMPONENTS = SCENES_ROOT + "Components/"
const SCENES_UI_COMPONENTS = SCENES_COMPONENTS + "ui/"
const SCENES_CHARACTER_COMPONENTS = SCENES_COMPONENTS + "characters/"
const SCENES_EFFECT_COMPONENTS = SCENES_COMPONENTS + "effects/"
const SCENES_ITEM_COMPONENTS = SCENES_COMPONENTS + "items/"
# ============================================================================
# UI路径
# ============================================================================
const UI_ROOT = "res://UI/"
const UI_WINDOWS = UI_ROOT + "Windows/"
# ============================================================================
# 资源路径
# ============================================================================
const ASSETS_ROOT = "res://assets/"
const ASSETS_SPRITES = ASSETS_ROOT + "sprites/"
const ASSETS_AUDIO = ASSETS_ROOT + "audio/"
const ASSETS_FONTS = ASSETS_ROOT + "fonts/"
const ASSETS_MATERIALS = ASSETS_ROOT + "materials/"
const ASSETS_SHADERS = ASSETS_ROOT + "shaders/"
# ============================================================================
# 数据路径
# ============================================================================
const DATA_ROOT = "res://data/"
const DATA_CONFIG = "res://Config/"
const DATA_SCENES = DATA_ROOT + "scenes/"
const DATA_LEVELS = DATA_ROOT + "levels/"
const DATA_DIALOGUES = DATA_ROOT + "dialogues/"
# ============================================================================
# Web资源路径
# ============================================================================
const WEB_ASSETS = "res://web_assets/"
# ============================================================================
# 测试路径
# ============================================================================
const TESTS_ROOT = "res://tests/"
const TESTS_UNIT = TESTS_ROOT + "unit/"
const TESTS_INTEGRATION = TESTS_ROOT + "integration/"
const TESTS_AUTH = TESTS_ROOT + "auth/"
# ============================================================================
# 工具路径
# ============================================================================
const UTILS_ROOT = "res://Utils/"
# ============================================================================
# 模块路径
# ============================================================================
const MODULES_ROOT = "res://module/"
# ============================================================================
# 辅助方法
# ============================================================================
# 获取场景组件路径
static func get_component_path(category: String, component_name: String) -> String:
match category:
"ui":
return SCENES_UI_COMPONENTS + component_name + ".tscn"
"characters":
return SCENES_CHARACTER_COMPONENTS + component_name + ".tscn"
"effects":
return SCENES_EFFECT_COMPONENTS + component_name + ".tscn"
"items":
return SCENES_ITEM_COMPONENTS + component_name + ".tscn"
_:
return SCENES_COMPONENTS + component_name + ".tscn"
# 获取模块路径
static func get_module_path(module_name: String) -> String:
return MODULES_ROOT + module_name + "/"
# 获取模块配置路径
static func get_module_config_path(module_name: String) -> String:
return get_module_path(module_name) + "data/module_config.json"
# 获取场景数据路径
static func get_scene_data_path(scene_name: String) -> String:
return DATA_SCENES + scene_name.to_lower() + ".json"

View File

@@ -0,0 +1 @@
uid://dybcuscku7tyl

View 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()

View File

@@ -0,0 +1 @@
uid://cd8fn73ysjxh8

View 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()

View File

@@ -0,0 +1 @@
uid://dr7v30wheetca

View 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

View File

@@ -0,0 +1 @@
uid://nseguk2ytiw6

View 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

View File

@@ -0,0 +1 @@
uid://d3l286ti5gqhw

View 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("清空所有事件监听器")

View File

@@ -0,0 +1 @@
uid://bfheblucmti24

View File

View File

View File

@@ -0,0 +1 @@
# 保持目录结构 - 音乐资源目录

View File

@@ -0,0 +1 @@
# 保持目录结构 - 音效资源目录

View File

@@ -0,0 +1 @@
# 保持目录结构 - 语音资源目录

View File

@@ -0,0 +1 @@
# 保持目录结构 - 音乐资源目录

View File

@@ -0,0 +1 @@
# 保持目录结构 - 音效资源目录

View File

@@ -0,0 +1 @@
# 保持目录结构 - 语音资源目录

1
assets/fonts/.gitkeep Normal file
View File

@@ -0,0 +1 @@
# 保持目录结构 - 字体资源目录

BIN
assets/fonts/msyh.ttc Normal file

Binary file not shown.

View 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

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

View File

@@ -2,16 +2,16 @@
importer="texture"
type="CompressedTexture2D"
uid="uid://byw73r2dt6xb8"
path="res://.godot/imported/login-bg.png-3f4c0c8160ab08ab0791dc1de267dd7a.ctex"
uid="uid://bwy5r7soxi76a"
path="res://.godot/imported/icon144.png-ae9d1f30a88beaab449c2cad89283dd3.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://assets/login/login-bg.png"
dest_files=["res://.godot/imported/login-bg.png-3f4c0c8160ab08ab0791dc1de267dd7a.ctex"]
source_file="res://assets/icon/icon144.png"
dest_files=["res://.godot/imported/icon144.png-ae9d1f30a88beaab449c2cad89283dd3.ctex"]
[params]

BIN
assets/icon/icon16.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 644 B

View File

@@ -2,16 +2,16 @@
importer="texture"
type="CompressedTexture2D"
uid="uid://bqvel7n6dfo1d"
path="res://.godot/imported/whaletown.png-c44c9408e8b817d0db57fd8eec9de194.ctex"
uid="uid://bqg5e8qn1j74u"
path="res://.godot/imported/icon16.png-3099ad8a609f90c382508b9c073ffd76.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://assets/login/whaletown.png"
dest_files=["res://.godot/imported/whaletown.png-c44c9408e8b817d0db57fd8eec9de194.ctex"]
source_file="res://assets/icon/icon16.png"
dest_files=["res://.godot/imported/icon16.png-3099ad8a609f90c382508b9c073ffd76.ctex"]
[params]

BIN
assets/icon/icon180.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

View 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

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

View 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

Binary file not shown.

After

Width:  |  Height:  |  Size: 78 KiB

View 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

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

View 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

Binary file not shown.

After

Width:  |  Height:  |  Size: 150 KiB

View 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

Binary file not shown.

After

Width:  |  Height:  |  Size: 91 KiB

View File

@@ -2,16 +2,16 @@
importer="texture"
type="CompressedTexture2D"
uid="uid://cswuqnhiiypb2"
path="res://.godot/imported/enter.png-ed3d67e95e66053ad0fb61054985bfb8.ctex"
uid="uid://c7v22i1hgo1x6"
path="res://.godot/imported/image.png-3f16548595ba9fb08c5e50ef3251d148.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://assets/login/enter.png"
dest_files=["res://.godot/imported/enter.png-ed3d67e95e66053ad0fb61054985bfb8.ctex"]
source_file="res://assets/icon/image.png"
dest_files=["res://.godot/imported/image.png-3f16548595ba9fb08c5e50ef3251d148.ctex"]
[params]

Binary file not shown.

Before

Width:  |  Height:  |  Size: 183 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 840 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 218 KiB

View File

@@ -0,0 +1 @@
# 保持目录结构 - 材质资源目录

1
assets/shaders/.gitkeep Normal file
View File

@@ -0,0 +1 @@
# 保持目录结构 - 着色器资源目录

View File

@@ -0,0 +1 @@
# 保持目录结构 - 角色精灵资源目录

View File

@@ -0,0 +1 @@
# 保持目录结构 - 特效精灵资源目录

View File

@@ -0,0 +1 @@
# 保持目录结构 - 环境精灵资源目录

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

View 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

Binary file not shown.

After

Width:  |  Height:  |  Size: 644 B

View 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

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

View 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

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

View 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

Binary file not shown.

After

Width:  |  Height:  |  Size: 78 KiB

View 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

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

View 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

Binary file not shown.

After

Width:  |  Height:  |  Size: 150 KiB

View 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

Binary file not shown.

After

Width:  |  Height:  |  Size: 91 KiB

View 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

View File

@@ -0,0 +1 @@
# 保持目录结构 - 材质资源目录

View File

@@ -0,0 +1 @@
# 保持目录结构 - 着色器资源目录

View File

@@ -0,0 +1 @@
# 保持目录结构 - 角色精灵资源目录

View File

@@ -0,0 +1 @@
# 保持目录结构 - 特效精灵资源目录

View File

@@ -0,0 +1 @@
# 保持目录结构 - 环境精灵资源目录

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.7 MiB

View 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

Binary file not shown.

After

Width:  |  Height:  |  Size: 587 KiB

View 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

View 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://UI/Theme/Fonts/msyh.ttc" id="1_ftb5w"]
[resource]
resource_local_to_scene = true
default_font = ExtResource("1_ftb5w")

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.7 KiB

View 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

123
cloude.md Normal file
View File

@@ -0,0 +1,123 @@
# 🎯 WhaleTown 项目开发规范
## 1. 项目愿景与背景
- **项目名称**: "WhaleTown" - 一个2D俯视角像素风RPG游戏
- **引擎**: Godot 4.2+ (严格禁止使用Godot 3.x语法)
- **架构**: 严格分层架构:`_Core`(框架层)、`Scenes`(游戏层)、`UI`(界面层)
- **核心原则**: "信号向上,调用向下"。通过`EventSystem`实现高度解耦
## 2. 🛠 命令参考与设置
- **输入映射 (必需配置)**:
- `move_left`, `move_right`, `move_up`, `move_down` (WASD / 方向键)
- `interact` (E键 / 空格键)
- `pause` (ESC键)
- **运行游戏**: `godot --path .`
- **运行测试 (GUT)**: `godot --headless -s addons/gut/gut_cmdline.gd -gdir=res://tests/ -ginclude_subdirs`
- **初始化结构**: `mkdir -p _Core/managers _Core/systems Scenes/Maps Scenes/Entities Scenes/Components UI/Windows UI/HUD Assets/Sprites tests/unit tests/integration`
## 3. 📂 文件路径规则 (严格小写)
*注意:根目录文件夹必须小写。脚本和场景必须放在一起。*
- **核心管理器**: `_Core/managers/[Name].gd`
- **核心系统**: `_Core/systems/[Name].gd`
- **实体**: `Scenes/Entities/[EntityName]/[EntityName].tscn` (脚本`.gd`放在同一文件夹)
- **地图**: `Scenes/Maps/[map_name].tscn`
- **组件**: `Scenes/Components/[ComponentName].gd` (可复用逻辑节点)
- **UI窗口**: `UI/Windows/[WindowName].tscn`
- **测试**: `tests/[unit|integration]/test_[name].gd` (文件夹名为小写`tests`)
## 4. 📋 编码标准 (必须遵守)
- **类型安全**: 始终使用严格静态类型:`var speed: float = 100.0`, `func _ready() -> void`
- **命名约定**:
- 每个脚本顶部必须有`class_name PascalCase`
- 变量/函数:`snake_case`。常量:`SCREAMING_SNAKE_CASE`
- 私有成员:使用下划线前缀`_` (例如:`var _health: int`)
- **节点访问**: 对UI和内部场景组件使用`%UniqueName`
- **信号**: 使用"信号向上,调用向下"原则。父节点调用子节点方法;子节点发出信号
- **禁止模式**:
- ❌ 禁止使用`yield()` -> 使用`await`
- ❌ 禁止在`_process`中使用`get_node()` -> 使用`@onready`缓存
- ❌ 禁止线性过滤 -> 所有Sprite2D/TileMap资源必须使用**最近邻**过滤
## 5. 🏛 架构与通信
- **事件系统**: 使用`_Core/systems/EventSystem.gd`进行跨模块消息传递
- **事件注册**: 在`_Core/EventNames.gd`中使用`class_name EventNames`
```gdscript
class_name EventNames
const PLAYER_MOVED = "player_moved"
const INTERACT_PRESSED = "interact_pressed"
const NPC_TALKED = "npc_talked"
```
- **单例**: 只允许GameManager、SceneManager、EventSystem作为自动加载
- **解耦**: 底层实体不得直接引用GameManager。使用事件系统
## 6. 🏗 实现细节
- **玩家**: 使用CharacterBody2D。必须包含Camera2D设置`position_smoothing_enabled = true`
- **NPC/交互物**: 使用名为InteractionArea的Area2D。通过EventSystem触发
- **TileMap图层**:
- 图层0地面 (无碰撞)
- 图层1障碍物 (启用物理层)
- 图层2装饰 (启用Y排序)
- **相机**: 必须通过`TileMap.get_used_rect()`自动计算边界
## 7. 🧪 测试要求 (强制性)
- **覆盖率**: `_Core/`中的每个管理器/系统都必须有GUT测试
- **命名**: 测试文件必须以`test_`开头并继承`GutTest`
- **示例**:
```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. 🧘 开发哲学
- **流畅体验**: 每个交互(UI弹窗、NPC对话)都必须有Tween动画占位符
- **零魔法数字**: 所有速度/计时器必须使用`@export`或在`Config/`中定义
- **简洁性**: 如果一个函数做两件事,就拆分它
- **隐藏逻辑**: 隐藏的逻辑(如ResponseHandler.gd)必须和HUD一样干净
## 9. 📝 代码模板 (实体模式)
```gdscript
extends CharacterBody2D
class_name Player
# 1. 导出变量与常量
@export var move_speed: float = 200.0
# 2. 节点引用
@onready var sprite: Sprite2D = %Sprite2D
# 3. 生命周期
func _physics_process(delta: float) -> void:
_move(delta)
# 4. 私有方法
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()
```
## 10. 🎨 UI设计规范
- **响应式布局**: 使用Anchor和Margin实现自适应
- **主题统一**: 所有UI组件使用统一主题资源
- **动画效果**: 界面切换必须有过渡动画
- **无障碍支持**: 支持键盘导航
## 11. 🔧 性能优化
- **对象池**: 频繁创建销毁的对象使用对象池
- **视锥剔除**: 只渲染可见区域的对象
- **批量处理**: 合并相似的渲染调用
- **内存管理**: 及时释放不需要的资源
## 12. 📚 最佳实践
- **模块化**: 功能拆分为独立模块
- **可测试**: 设计易于测试的代码结构
- **文档化**: 为复杂逻辑添加详细注释
- **版本控制**: 遵循Git提交规范
---
**记住:代码质量是游戏成功的基础!**

View File

View File

View File

@@ -0,0 +1,85 @@
# 📖 项目入门
> **适用人群**: 新加入项目的开发者
> **使用时机**: 项目开始前,环境搭建阶段
> **质量等级**: A级 ⭐⭐⭐⭐⭐
这个目录包含了新人入门必读的基础文档,帮助你快速了解项目并搭建开发环境。
## 📋 阅读顺序
### 第一步:了解项目 🏗️
**[项目结构说明.md](项目结构说明.md)**
- 项目整体架构设计
- 目录组织规则和命名规范
- 各层级职责说明
- 核心组件介绍
### 第二步:配置环境 ⚙️
**[项目设置指南.md](项目设置指南.md)**
- Godot编辑器配置
- AutoLoad单例设置
- 输入映射配置(已预配置)
- 开发环境验证
## ✅ 完成检查
阅读完本目录的文档后,你应该能够:
- [ ] 理解项目的整体架构和设计理念
- [ ] 成功配置Godot开发环境
- [ ] 了解核心组件的作用和使用方式
- [ ] 运行项目并进行基本测试
- [ ] 验证所有AutoLoad单例正常工作
- [ ] 确认游戏输入控制正常响应
## 🎮 输入控制说明
项目已预配置以下输入映射:
- **移动控制**: `move_left` (A/←), `move_right` (D/→), `move_up` (W/↑), `move_down` (S/↓)
- **交互控制**: `interact` (E键), `jump` (空格键)
这些输入映射已经在 `project.godot` 中配置完成,无需额外设置。
## 🚨 常见启动问题
### 问题1: 游戏无法响应输入
**原因**: 项目文件损坏或配置丢失
**解决**: 重新克隆项目,确保 `project.godot` 文件完整
### 问题2: 控制台出现"Invalid action"错误
**原因**: 输入映射配置丢失
**解决**: 检查 `project.godot` 文件中的 `[input]` 部分是否完整
### 问题3: AutoLoad单例报错
**原因**: AutoLoad配置不正确或文件路径错误
**解决**: 参考 [项目设置指南.md](项目设置指南.md) 验证配置
### 问题4: EventSystem相关错误
**原因**: 缺少 `_Core/EventNames.gd` 文件
**解决**: 确保项目包含完整的 `_Core` 目录结构
## 🔗 下一步
完成项目入门后,建议继续阅读:
- [02-开发规范](../02-开发规范/) - 学习编码标准和架构规范
- [03-技术实现](../03-技术实现/) - 开始具体功能开发
## 💡 小贴士
- **项目已预配置完成** - 输入映射和核心组件都已设置好
- 遇到问题时,先查看对应文档的"常见问题"部分
- 建议在实际操作中边读边做,加深理解
- 可以将重要的配置信息做笔记备用
- 完成每个步骤后,建议运行项目验证配置是否正确
- 重点关注 `_Core` 目录中的核心组件,它们是项目的基础
## 🛠️ 核心组件预览
项目包含以下核心组件,在后续开发中会频繁使用:
- **EventSystem** - 全局事件通信系统
- **GameManager** - 游戏状态管理
- **SceneManager** - 场景切换管理
- **NetworkManager** - 网络请求管理
- **ProjectPaths** - 统一路径管理
详细使用方法请参考 [架构与通信规范](../02-开发规范/架构与通信规范.md)。

View File

@@ -0,0 +1,157 @@
# 输入映射配置指南
本文档说明了WhaleTown项目的输入映射配置要求和设置方法。
## 🎮 必需的输入映射
### 基础移动控制
- **`move_left`** - 向左移动
- 推荐按键A键、左方向键
- **`move_right`** - 向右移动
- 推荐按键D键、右方向键
- **`move_up`** - 向上移动
- 推荐按键W键、上方向键
- **`move_down`** - 向下移动
- 推荐按键S键、下方向键
### 交互控制
- **`interact`** - 交互动作
- 推荐按键E键、空格键
- **`pause`** - 暂停游戏
- 推荐按键ESC键
## ⚙️ Godot编辑器配置步骤
### 1. 打开输入映射设置
1. 在Godot编辑器中打开 `Project``Project Settings`
2. 切换到 `Input Map` 标签
### 2. 添加输入动作
对于每个必需的输入动作:
1.`Action` 输入框中输入动作名称(如 `move_left`
2. 点击 `Add` 按钮
3. 点击新添加动作右侧的 `+` 按钮
4. 按下对应的按键进行绑定
5. 重复步骤3-4添加备用按键
### 3. 配置示例
```
move_left:
- Key: A
- Key: Left Arrow
move_right:
- Key: D
- Key: Right Arrow
move_up:
- Key: W
- Key: Up Arrow
move_down:
- Key: S
- Key: Down Arrow
interact:
- Key: E
- Key: Space
pause:
- Key: Escape
```
## 🔧 代码中的使用方法
### 移动输入检测
```gdscript
func _physics_process(delta: float) -> void:
# 获取移动向量
var direction := Input.get_vector(
"move_left", "move_right",
"move_up", "move_down"
)
# 应用移动
velocity = direction * move_speed
move_and_slide()
```
### 交互输入检测
```gdscript
func _input(event: InputEvent) -> void:
if event.is_action_pressed("interact"):
_handle_interaction()
if event.is_action_pressed("pause"):
_toggle_pause()
```
### 连续输入检测
```gdscript
func _process(delta: float) -> void:
# 检测持续按下的按键
if Input.is_action_pressed("interact"):
_continuous_interaction(delta)
```
## 📱 手柄支持(可选)
### 推荐手柄映射
- **左摇杆** - 移动控制
- **A按钮/X按钮** - 交互
- **Start按钮** - 暂停
### 配置方法
1. 在Input Map中为每个动作添加手柄输入
2. 使用 `Joypad Button``Joypad Axis` 进行绑定
## ✅ 验证配置
### 测试脚本
创建一个简单的测试脚本验证输入配置:
```gdscript
extends Node
func _ready() -> void:
print("输入映射测试开始...")
_test_input_actions()
func _test_input_actions() -> void:
var required_actions = [
"move_left", "move_right", "move_up", "move_down",
"interact", "pause"
]
for action in required_actions:
if InputMap.has_action(action):
print("", action, " - 已配置")
else:
print("", action, " - 未配置")
func _input(event: InputEvent) -> void:
# 实时显示输入事件
for action in InputMap.get_actions():
if event.is_action_pressed(action):
print("按下: ", action)
```
## 🚨 常见问题
### Q: 输入没有响应怎么办?
A: 检查以下几点:
1. 确认输入动作名称拼写正确
2. 验证按键是否正确绑定
3. 检查代码中是否正确使用了动作名称
### Q: 如何添加自定义输入?
A: 按照相同步骤在Input Map中添加新的动作并在代码中使用对应的动作名称。
### Q: 手柄不工作怎么办?
A: 确保手柄已连接并在Input Map中正确配置了手柄按钮映射。
---
**注意:输入映射配置是游戏正常运行的基础,请确保所有必需的输入动作都已正确配置!**

Some files were not shown because too many files have changed in this diff Show More