Compare commits
78 Commits
feature/lo
...
449cd1e8f3
| Author | SHA1 | Date | |
|---|---|---|---|
| 449cd1e8f3 | |||
| 8a5a4a0005 | |||
| ed7d89e39d | |||
| ce47bd6eeb | |||
| 7cca58cb07 | |||
| 13e6553748 | |||
| 6a3823ad16 | |||
| 4bfe49d5b1 | |||
| 1d3f580560 | |||
| 9259865e72 | |||
| 7b85147994 | |||
| e3c4d08021 | |||
|
|
3bdda47191 | ||
| 43e0c2b928 | |||
| 3d6c4e5356 | |||
| c621d70475 | |||
| f527fa3c38 | |||
| e9fa21280e | |||
| a3d384d39d | |||
| ced69fd4b6 | |||
| 7a6e5be4f8 | |||
| ba5b0daa13 | |||
| 83404d031e | |||
| 709242d223 | |||
| 2f1ccbc2cd | |||
| aaaf2b31a8 | |||
| 93baf1a5b5 | |||
| 5f915c61b6 | |||
| d256249789 | |||
| 29c6740870 | |||
| 7b1affa360 | |||
| fa360e1c78 | |||
| d80feaa02b | |||
| f1a60137e1 | |||
| 3175c98ea3 | |||
| a18c7a54b1 | |||
| fca3eb79dd | |||
| e128328d93 | |||
| fdedb21cbd | |||
| d49983079a | |||
| 51e79c6c6d | |||
| 0edd1c740b | |||
| a85a7b4d0e | |||
| 51d2ad1629 | |||
| 6f545b04e9 | |||
| 1ff677b3b2 | |||
| 2998fd2d11 | |||
| 60edcc9868 | |||
| d25d8d4dd3 | |||
| 190b6c9a66 | |||
| 899bc5d5d0 | |||
| e657cfce0e | |||
|
|
b9182bbc2e | ||
|
|
642a99970c | ||
|
|
0b533189ec | ||
| b1f3c0feff | |||
| 021c8623f8 | |||
| a1b867dfd7 | |||
| d17c766246 | |||
| 92c4eaed07 | |||
| abd683c766 | |||
| a05bac6f05 | |||
| 77af0bda39 | |||
| 8980e3d558 | |||
| 1294529d13 | |||
| 0935c5fd76 | |||
| 405710bdde | |||
| 7413574672 | |||
| c0f5d6a537 | |||
| 0b6b1c2040 | |||
| 8d071cb2ed | |||
| 370cffbdd8 | |||
| 5b67771bbc | |||
| 73478c0500 | |||
| 15548ebb52 | |||
| 47cfc14f68 | |||
| c6bcca4e7f | |||
| f11479f2cc |
@@ -1,13 +1,7 @@
|
||||
{
|
||||
"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:*)"
|
||||
"Skill(whaletown-developer)"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
335
.claude/skills/whaletown-developer/SKILL.md
Normal file
@@ -0,0 +1,335 @@
|
||||
---
|
||||
name: whaletown-developer
|
||||
description: Automate WhaleTown project's standard development workflow. Use this skill when implementing features, fixing bugs, creating scenes, or any code development tasks. Guides through 7-step process - architecture analysis, implementation, comment/naming validation, testing, and Git commit generation following project conventions.
|
||||
---
|
||||
|
||||
# WhaleTown Standard Development Workflow Skill
|
||||
|
||||
This skill automates the standard development workflow for the WhaleTown project, ensuring all developers follow unified specifications and quality standards.
|
||||
|
||||
## When to Use This Skill
|
||||
|
||||
Activate this skill when:
|
||||
- Implementing new features ("实现XX功能", "添加XX系统")
|
||||
- Fixing bugs ("修复XX Bug", "解决XX问题")
|
||||
- Creating scenes ("创建XX场景", "设计XX界面")
|
||||
- Developing modules ("开发XX模块", "构建XX组件")
|
||||
- Any code development task requiring adherence to project standards
|
||||
|
||||
## Development Workflow Overview
|
||||
|
||||
```
|
||||
Step 1: Architecture Analysis (读取架构规范)
|
||||
↓
|
||||
Step 2: Implementation (按规范编码)
|
||||
↓
|
||||
Step 3: Comment Validation (注释规范检查)
|
||||
↓
|
||||
Step 4: Naming Validation (命名规范检查)
|
||||
↓
|
||||
Step 5: Test Writing (编写测试代码)
|
||||
↓
|
||||
Step 6: Test Execution (运行测试验证)
|
||||
↓
|
||||
Step 7: Git Commit (生成规范提交信息)
|
||||
```
|
||||
|
||||
## Step-by-Step Workflow
|
||||
|
||||
### Step 1: Architecture Analysis
|
||||
|
||||
Read and apply the architecture specifications before implementation.
|
||||
|
||||
**Actions:**
|
||||
1. Read `docs/02-开发规范/架构与通信规范.md`
|
||||
2. Determine file location based on feature type:
|
||||
- Core systems → `_Core/managers/` or `_Core/systems/`
|
||||
- Game scenes → `scenes/Maps/`, `scenes/Entities/`, `scenes/Components/`
|
||||
- UI components → `scenes/ui/`
|
||||
3. Identify communication method (MUST use EventSystem for cross-module communication)
|
||||
4. List dependencies (required managers and systems)
|
||||
5. Design event definitions (add to `_Core/EventNames.gd`)
|
||||
|
||||
**Layered Architecture:**
|
||||
```
|
||||
UI Layer (界面层) → scenes/ui/
|
||||
↑
|
||||
Scenes Layer (游戏层) → scenes/Maps/, scenes/Entities/
|
||||
↑
|
||||
_Core Layer (框架层) → _Core/managers/, _Core/systems/
|
||||
```
|
||||
|
||||
**Communication Principle:** "Signal Up, Call Down"
|
||||
- Parents call child methods (downward calls)
|
||||
- Children emit signals to notify parents (upward signals)
|
||||
- Cross-module communication MUST use EventSystem
|
||||
|
||||
### Step 2: Implementation
|
||||
|
||||
Implement the feature following strict project conventions.
|
||||
|
||||
**Requirements:**
|
||||
- **Type Safety**: All variables and functions MUST have type annotations
|
||||
```gdscript
|
||||
var speed: float = 200.0
|
||||
func move(delta: float) -> void:
|
||||
```
|
||||
- **Godot 4.2+ Syntax**: NO `yield()`, use `await`
|
||||
- **Node Caching**: Use `@onready` to cache node references, avoid `get_node()` in `_process()`
|
||||
- **EventSystem Communication**: Use EventSystem for cross-module messaging
|
||||
```gdscript
|
||||
EventSystem.emit_event(EventNames.PLAYER_MOVED, {"position": global_position})
|
||||
EventSystem.connect_event(EventNames.INTERACT_PRESSED, _on_interact_pressed)
|
||||
```
|
||||
- **Nearest Filter**: All Sprite2D/TileMap resources MUST use Nearest filter (no Linear filter)
|
||||
- **AutoLoad Restrictions**: Only GameManager, SceneManager, EventSystem, NetworkManager, ResponseHandler allowed as autoloads
|
||||
- **Low-level Entities**: Do NOT directly reference GameManager in Player/NPC entities, use events instead
|
||||
|
||||
### Step 3: Comment Validation
|
||||
|
||||
Ensure code comments meet project standards.
|
||||
|
||||
**Actions:**
|
||||
1. Read `docs/02-开发规范/代码注释规范.md`
|
||||
2. Verify file header comment is complete:
|
||||
```gdscript
|
||||
# ============================================================================
|
||||
# 文件名: FeatureName.gd
|
||||
# 作用: 简短描述功能
|
||||
#
|
||||
# 主要功能:
|
||||
# - 功能点1
|
||||
# - 功能点2
|
||||
#
|
||||
# 依赖: 列出依赖的管理器/系统
|
||||
# 作者: [开发者名称]
|
||||
# 创建时间: YYYY-MM-DD
|
||||
# ============================================================================
|
||||
```
|
||||
3. Verify all public functions have complete documentation:
|
||||
```gdscript
|
||||
# 函数功能描述
|
||||
#
|
||||
# 参数:
|
||||
# param_name: Type - 参数说明
|
||||
#
|
||||
# 返回值:
|
||||
# Type - 返回值说明
|
||||
#
|
||||
# 使用示例:
|
||||
# var result = function_name(param)
|
||||
func function_name(param: Type) -> ReturnType:
|
||||
```
|
||||
4. Ensure complex logic has inline comments explaining WHY, not WHAT
|
||||
|
||||
### Step 4: Naming Validation
|
||||
|
||||
Verify all naming follows project conventions.
|
||||
|
||||
**Actions:**
|
||||
1. Read `docs/02-开发规范/命名规范.md`
|
||||
2. Validate naming conventions:
|
||||
- **Class names**: PascalCase (`class_name PlayerController`)
|
||||
- **Variables/Functions**: camelCase (`var moveSpeed: float`, `func updateMovement()`)
|
||||
- **Constants**: UPPER_CASE (`const MAX_HEALTH: int = 100`)
|
||||
- **Private members**: Underscore prefix (`var _velocity: Vector2`)
|
||||
- **Scene files**: snake_case with suffix (`player_scene.tscn`, `enemy_prefab.tscn`)
|
||||
- **Script files**: PascalCase.gd (`PlayerController.gd`, `GameManager.gd`)
|
||||
|
||||
**Common Patterns:**
|
||||
```gdscript
|
||||
# ✅ Correct
|
||||
const MAX_SPEED: float = 300.0
|
||||
var currentHealth: int
|
||||
var _isInitialized: bool = false
|
||||
func getPlayerPosition() -> Vector2:
|
||||
func _calculateDamage(baseDamage: int) -> int:
|
||||
|
||||
# ❌ Incorrect
|
||||
const maxSpeed: float = 300.0 # Constants must be UPPER_CASE
|
||||
var CurrentHealth: int # Variables must be camelCase
|
||||
var is_initialized: bool = false # No snake_case for variables
|
||||
func GetPlayerPosition() -> Vector2: # Functions must be camelCase
|
||||
```
|
||||
|
||||
### Step 5: Test Writing
|
||||
|
||||
Create unit tests for the implemented functionality.
|
||||
|
||||
**Actions:**
|
||||
1. Read `docs/03-技术实现/测试指南.md`
|
||||
2. For _Core/ managers/systems, MUST create corresponding test file in `tests/unit/`
|
||||
3. Test file naming: `test_[name].gd`
|
||||
4. Test file structure:
|
||||
```gdscript
|
||||
extends GutTest
|
||||
|
||||
## [FeatureName] 单元测试
|
||||
|
||||
var feature: FeatureName
|
||||
|
||||
func before_each():
|
||||
feature = preload("res://_Core/managers/FeatureName.gd").new()
|
||||
add_child(feature)
|
||||
|
||||
func after_each():
|
||||
feature.queue_free()
|
||||
|
||||
func test_initialization():
|
||||
var result = feature.initialize()
|
||||
assert_true(result, "Feature should initialize successfully")
|
||||
|
||||
func test_core_functionality():
|
||||
# Test core functionality
|
||||
pass
|
||||
```
|
||||
|
||||
### Step 6: Test Execution
|
||||
|
||||
Run tests to ensure code quality.
|
||||
|
||||
**Actions:**
|
||||
1. Run GUT tests using Bash tool:
|
||||
```bash
|
||||
godot --headless -s addons/gut/gut_cmdline.gd -gdir=res://tests/ -ginclude_subdirs
|
||||
```
|
||||
2. Verify all tests pass
|
||||
3. If tests fail:
|
||||
- Identify the root cause
|
||||
- Fix the implementation or test
|
||||
- Re-run tests until all pass
|
||||
|
||||
### Step 7: Git Commit
|
||||
|
||||
Generate standardized Git commit message.
|
||||
|
||||
**Actions:**
|
||||
1. Read `docs/02-开发规范/Git提交规范.md`
|
||||
2. Determine commit type based on changes:
|
||||
- `feat` - New features
|
||||
- `fix` - Bug fixes
|
||||
- `docs` - Documentation updates
|
||||
- `refactor` - Code refactoring
|
||||
- `perf` - Performance optimization
|
||||
- `test` - Test additions/modifications
|
||||
- `scene` - Scene file changes
|
||||
- `ui` - UI related changes
|
||||
3. Generate commit message using Chinese colon (:):
|
||||
```
|
||||
<类型>:<简短描述>
|
||||
|
||||
[可选的详细描述]
|
||||
```
|
||||
4. Follow principles:
|
||||
- **One commit, one change** - Most important rule
|
||||
- Use imperative verbs (添加, 修复, 更新)
|
||||
- Keep description concise (< 50 characters)
|
||||
- If multiple types of changes, split into separate commits
|
||||
|
||||
**Examples:**
|
||||
```bash
|
||||
# ✅ Good commits
|
||||
git commit -m "feat:实现玩家二段跳功能"
|
||||
git commit -m "fix:修复角色跳跃时的碰撞检测问题"
|
||||
git commit -m "test:添加角色控制器单元测试"
|
||||
|
||||
# ❌ Bad commits
|
||||
git commit -m "fix + feat:修复Bug并添加新功能" # Mixed types
|
||||
git commit -m "update player" # Vague, English
|
||||
```
|
||||
|
||||
## Progress Tracking
|
||||
|
||||
Use TodoWrite tool to track workflow progress:
|
||||
|
||||
```gdscript
|
||||
TodoWrite.create_todos([
|
||||
"Step 1: 架构分析 - 读取架构规范",
|
||||
"Step 2: 功能实现 - 按规范编码",
|
||||
"Step 3: 注释规范检查",
|
||||
"Step 4: 命名规范检查",
|
||||
"Step 5: 测试代码编写",
|
||||
"Step 6: 测试验证 - 运行测试",
|
||||
"Step 7: Git 提交 - 生成提交信息"
|
||||
])
|
||||
```
|
||||
|
||||
Mark each step as `completed` immediately after finishing.
|
||||
|
||||
## Quality Checklist
|
||||
|
||||
Before completing the workflow, verify:
|
||||
|
||||
- [ ] File location follows layered architecture (_Core, scenes, UI)
|
||||
- [ ] Uses EventSystem for cross-module communication
|
||||
- [ ] Event names added to EventNames.gd
|
||||
- [ ] All variables and functions have type annotations
|
||||
- [ ] Naming conventions correct (PascalCase/camelCase/UPPER_CASE)
|
||||
- [ ] File header comment complete
|
||||
- [ ] Public functions have complete documentation
|
||||
- [ ] Unit tests created and passing
|
||||
- [ ] Git commit message follows specification
|
||||
- [ ] No Godot 3.x syntax (yield → await)
|
||||
- [ ] Node references cached with @onready
|
||||
- [ ] Sprite2D/TileMap use Nearest filter
|
||||
|
||||
## Reference Documents
|
||||
|
||||
The skill automatically reads these documents at appropriate steps:
|
||||
|
||||
- Architecture: `docs/02-开发规范/架构与通信规范.md`
|
||||
- Comments: `docs/02-开发规范/代码注释规范.md`
|
||||
- Naming: `docs/02-开发规范/命名规范.md`
|
||||
- Testing: `docs/03-技术实现/测试指南.md`
|
||||
- Git: `docs/02-开发规范/Git提交规范.md`
|
||||
- Project Instructions: `claude.md` (root directory)
|
||||
|
||||
For detailed checklist reference, see `references/checklist.md` in this skill directory.
|
||||
|
||||
## Example Workflow
|
||||
|
||||
User request: "实现玩家二段跳功能"
|
||||
|
||||
1. **Architecture Analysis** ✅
|
||||
- Read architecture spec
|
||||
- Target: `scenes/Entities/Player/Player.gd`
|
||||
- Communication: Emit `PLAYER_DOUBLE_JUMPED` event
|
||||
- Dependencies: EventSystem, Input
|
||||
- Event: Add `PLAYER_DOUBLE_JUMPED` to EventNames.gd
|
||||
|
||||
2. **Implementation** ✅
|
||||
- Create double jump logic with type annotations
|
||||
- Use EventSystem.emit_event() for notifications
|
||||
- Cache references with @onready
|
||||
- Use await instead of yield
|
||||
|
||||
3. **Comment Validation** ✅
|
||||
- Add file header with feature description
|
||||
- Document double jump function parameters
|
||||
- Add inline comments for jump logic
|
||||
|
||||
4. **Naming Validation** ✅
|
||||
- Verify: `var canDoubleJump: bool` (camelCase)
|
||||
- Verify: `const MAX_DOUBLE_JUMPS: int` (UPPER_CASE)
|
||||
- Verify: `func performDoubleJump()` (camelCase)
|
||||
|
||||
5. **Test Writing** ✅
|
||||
- Create `tests/unit/test_player_double_jump.gd`
|
||||
- Test initialization, jump execution, limits
|
||||
|
||||
6. **Test Execution** ✅
|
||||
- Run: `godot --headless -s addons/gut/gut_cmdline.gd`
|
||||
- All tests pass ✅
|
||||
|
||||
7. **Git Commit** ✅
|
||||
```bash
|
||||
git add scenes/Entities/Player/Player.gd _Core/EventNames.gd tests/unit/test_player_double_jump.gd
|
||||
git commit -m "feat:实现玩家二段跳功能"
|
||||
```
|
||||
|
||||
## Notes
|
||||
|
||||
- This skill enforces quality standards through automated validation
|
||||
- Each step builds upon the previous, ensuring comprehensive quality control
|
||||
- Skipping steps will result in incomplete or non-compliant code
|
||||
- The 7-step workflow is designed for team consistency and maintainability
|
||||
285
.claude/skills/whaletown-developer/references/checklist.md
Normal file
@@ -0,0 +1,285 @@
|
||||
# WhaleTown Development Quality Checklist
|
||||
|
||||
快速参考检查清单,用于验证代码是否符合项目规范。
|
||||
|
||||
## 架构检查清单
|
||||
|
||||
### 文件位置
|
||||
- [ ] 核心系统文件位于 `_Core/managers/` 或 `_Core/systems/`
|
||||
- [ ] 游戏场景文件位于 `scenes/Maps/`, `scenes/Entities/`, `scenes/Components/`
|
||||
- [ ] UI 组件文件位于 `scenes/ui/`
|
||||
- [ ] 测试文件位于 `tests/unit/` 或 `tests/integration/`
|
||||
|
||||
### 通信方式
|
||||
- [ ] 跨模块通信使用 EventSystem
|
||||
- [ ] 新增事件定义在 `_Core/EventNames.gd` 中
|
||||
- [ ] 遵循 "Signal Up, Call Down" 原则
|
||||
- [ ] 父节点调用子节点方法(向下调用)
|
||||
- [ ] 子节点发出信号通知父节点(向上信号)
|
||||
|
||||
### 依赖管理
|
||||
- [ ] 仅使用允许的自动加载:GameManager, SceneManager, EventSystem, NetworkManager, ResponseHandler
|
||||
- [ ] 底层实体(Player, NPC)不直接访问 GameManager
|
||||
- [ ] 底层实体通过事件系统与全局管理器通信
|
||||
|
||||
---
|
||||
|
||||
## 代码规范检查清单
|
||||
|
||||
### 类型安全
|
||||
- [ ] 所有变量都有类型注解:`var speed: float = 200.0`
|
||||
- [ ] 所有函数都有参数和返回值类型:`func move(delta: float) -> void:`
|
||||
- [ ] 常量都有类型注解:`const MAX_HEALTH: int = 100`
|
||||
|
||||
### Godot 4.2+ 语法
|
||||
- [ ] 使用 `await` 代替 `yield()`
|
||||
- [ ] 使用 `@onready` 缓存节点引用
|
||||
- [ ] 避免在 `_process()` 中使用 `get_node()`
|
||||
- [ ] 信号连接使用 `.connect()` 语法
|
||||
|
||||
### 资源设置
|
||||
- [ ] 所有 Sprite2D 使用 Nearest 滤镜(不使用 Linear)
|
||||
- [ ] 所有 TileMap 使用 Nearest 滤镜
|
||||
|
||||
---
|
||||
|
||||
## 命名规范检查清单
|
||||
|
||||
### 类名
|
||||
- [ ] 使用 PascalCase:`class_name PlayerController`
|
||||
- [ ] 文件名与类名一致:`PlayerController.gd`
|
||||
|
||||
### 变量
|
||||
- [ ] 公共变量使用 camelCase:`var moveSpeed: float`
|
||||
- [ ] 私有变量使用下划线前缀:`var _velocity: Vector2`
|
||||
- [ ] 布尔变量使用 is/has/can 前缀:`var isJumping: bool`
|
||||
|
||||
### 函数
|
||||
- [ ] 使用 camelCase:`func updateMovement()`
|
||||
- [ ] 获取函数使用 `get` 前缀:`func getPlayerPosition()`
|
||||
- [ ] 设置函数使用 `set` 前缀:`func setHealth(value: int)`
|
||||
- [ ] 判断函数使用 `is/has/can` 前缀:`func isAlive()`, `func canJump()`
|
||||
- [ ] 私有函数使用下划线前缀:`func _calculateDamage()`
|
||||
|
||||
### 常量
|
||||
- [ ] 使用 UPPER_CASE:`const MAX_HEALTH: int = 100`
|
||||
- [ ] 使用下划线分隔:`const JUMP_FORCE: float = -400.0`
|
||||
|
||||
### 枚举
|
||||
- [ ] 枚举类型使用 PascalCase:`enum PlayerState`
|
||||
- [ ] 枚举值使用 UPPER_CASE:`IDLE, WALKING, RUNNING`
|
||||
|
||||
### 文件命名
|
||||
- [ ] 脚本文件:PascalCase.gd (`PlayerController.gd`)
|
||||
- [ ] 场景文件:snake_case_scene.tscn (`main_scene.tscn`)
|
||||
- [ ] 预制体文件:snake_case_prefab.tscn (`player_prefab.tscn`)
|
||||
- [ ] 资源文件:snake_case (`sprite_player_idle.png`)
|
||||
|
||||
---
|
||||
|
||||
## 注释规范检查清单
|
||||
|
||||
### 文件头注释
|
||||
- [ ] 包含文件名
|
||||
- [ ] 包含作用描述
|
||||
- [ ] 列出主要功能
|
||||
- [ ] 列出依赖的管理器/系统
|
||||
- [ ] 包含作者和创建时间
|
||||
|
||||
示例:
|
||||
```gdscript
|
||||
# ============================================================================
|
||||
# 文件名: PlayerController.gd
|
||||
# 作用: 玩家角色控制器,处理玩家输入和移动逻辑
|
||||
#
|
||||
# 主要功能:
|
||||
# - 处理键盘和手柄输入
|
||||
# - 控制角色移动和跳跃
|
||||
# - 管理角色状态切换
|
||||
#
|
||||
# 依赖: EventSystem, InputManager
|
||||
# 作者: [开发者名称]
|
||||
# 创建时间: 2025-01-03
|
||||
# ============================================================================
|
||||
```
|
||||
|
||||
### 函数注释
|
||||
- [ ] 公共函数有完整注释
|
||||
- [ ] 包含功能描述
|
||||
- [ ] 列出参数说明(名称、类型、含义)
|
||||
- [ ] 说明返回值(类型、含义)
|
||||
- [ ] 提供使用示例(对于复杂函数)
|
||||
- [ ] 标注注意事项(如果有)
|
||||
|
||||
示例:
|
||||
```gdscript
|
||||
# 处理玩家输入并更新移动状态
|
||||
#
|
||||
# 参数:
|
||||
# delta: float - 帧时间间隔
|
||||
#
|
||||
# 返回值: 无
|
||||
#
|
||||
# 注意事项:
|
||||
# - 需要在 _physics_process 中调用
|
||||
# - 会自动处理重力和碰撞
|
||||
func handleMovement(delta: float) -> void:
|
||||
```
|
||||
|
||||
### 行内注释
|
||||
- [ ] 复杂逻辑有注释说明
|
||||
- [ ] 注释解释 WHY(为什么),不解释 WHAT(是什么)
|
||||
- [ ] 避免显而易见的注释
|
||||
- [ ] 使用 TODO/FIXME/NOTE 等标记
|
||||
|
||||
---
|
||||
|
||||
## 测试规范检查清单
|
||||
|
||||
### 测试文件
|
||||
- [ ] _Core/ 中的管理器/系统都有对应测试文件
|
||||
- [ ] 测试文件位于 `tests/unit/` 或 `tests/integration/`
|
||||
- [ ] 测试文件命名:`test_[name].gd`
|
||||
- [ ] 测试文件继承自 GutTest:`extends GutTest`
|
||||
|
||||
### 测试结构
|
||||
- [ ] 包含测试类注释
|
||||
- [ ] 实现 `before_each()` 进行测试前置设置
|
||||
- [ ] 实现 `after_each()` 进行测试清理
|
||||
- [ ] 测试方法命名:`test_[功能名称]()`
|
||||
|
||||
### 测试覆盖
|
||||
- [ ] 测试核心功能的正常流程
|
||||
- [ ] 测试错误处理和边界条件
|
||||
- [ ] 测试初始化和清理逻辑
|
||||
- [ ] 所有测试都能通过
|
||||
|
||||
示例:
|
||||
```gdscript
|
||||
extends GutTest
|
||||
|
||||
## PlayerController 单元测试
|
||||
|
||||
var player: PlayerController
|
||||
|
||||
func before_each():
|
||||
player = preload("res://scenes/Entities/Player/PlayerController.gd").new()
|
||||
add_child(player)
|
||||
|
||||
func after_each():
|
||||
player.queue_free()
|
||||
|
||||
func test_initialization():
|
||||
var result = player.initialize()
|
||||
assert_true(result, "Player should initialize successfully")
|
||||
|
||||
func test_movement():
|
||||
# 测试移动功能
|
||||
pass
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Git 提交规范检查清单
|
||||
|
||||
### 提交类型
|
||||
- [ ] 使用正确的提交类型:
|
||||
- `feat` - 新功能
|
||||
- `fix` - Bug 修复
|
||||
- `docs` - 文档更新
|
||||
- `refactor` - 代码重构
|
||||
- `test` - 测试相关
|
||||
- `scene` - 场景文件
|
||||
- `ui` - UI 相关
|
||||
|
||||
### 提交格式
|
||||
- [ ] 使用中文冒号(:)
|
||||
- [ ] 描述简洁明了(< 50 字符)
|
||||
- [ ] 使用动词开头(添加、修复、更新)
|
||||
- [ ] 一次提交只包含一种类型的改动
|
||||
|
||||
### 提交原则
|
||||
- [ ] 一次提交只做一件事
|
||||
- [ ] 提交的代码能够正常运行
|
||||
- [ ] 避免 fix + feat 混合提交
|
||||
- [ ] 如需多种改动,拆分成多次提交
|
||||
|
||||
示例:
|
||||
```bash
|
||||
# ✅ 正确
|
||||
git commit -m "feat:实现玩家二段跳功能"
|
||||
git commit -m "fix:修复角色跳跃时的碰撞检测问题"
|
||||
git commit -m "test:添加角色控制器单元测试"
|
||||
|
||||
# ❌ 错误
|
||||
git commit -m "fix + feat:修复Bug并添加新功能" # 混合类型
|
||||
git commit -m "update player" # 描述不清晰,使用英文
|
||||
git commit -m "fix: 修复Bug" # 使用英文冒号
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 完整工作流检查清单
|
||||
|
||||
使用此清单验证开发任务是否完整执行 7 步工作流:
|
||||
|
||||
### Step 1: 架构分析
|
||||
- [ ] 已读取 `docs/02-开发规范/架构与通信规范.md`
|
||||
- [ ] 已确定文件位置(_Core, scenes, UI)
|
||||
- [ ] 已确定通信方式(EventSystem)
|
||||
- [ ] 已列出依赖的管理器/系统
|
||||
- [ ] 已设计事件定义(如需要)
|
||||
|
||||
### Step 2: 功能实现
|
||||
- [ ] 代码遵循分层架构
|
||||
- [ ] 所有变量和函数有类型注解
|
||||
- [ ] 使用 Godot 4.2+ 语法
|
||||
- [ ] 使用 EventSystem 进行跨模块通信
|
||||
- [ ] 使用 @onready 缓存节点引用
|
||||
|
||||
### Step 3: 注释规范检查
|
||||
- [ ] 已读取 `docs/02-开发规范/代码注释规范.md`
|
||||
- [ ] 文件头注释完整
|
||||
- [ ] 公共函数有完整注释
|
||||
- [ ] 复杂逻辑有行内注释
|
||||
|
||||
### Step 4: 命名规范检查
|
||||
- [ ] 已读取 `docs/02-开发规范/命名规范.md`
|
||||
- [ ] 类名使用 PascalCase
|
||||
- [ ] 变量/函数使用 camelCase
|
||||
- [ ] 常量使用 UPPER_CASE
|
||||
- [ ] 私有成员使用下划线前缀
|
||||
|
||||
### Step 5: 测试代码编写
|
||||
- [ ] 已读取 `docs/03-技术实现/测试指南.md`
|
||||
- [ ] 创建了测试文件 `tests/unit/test_[name].gd`
|
||||
- [ ] 测试文件继承自 GutTest
|
||||
- [ ] 编写了核心功能测试
|
||||
|
||||
### Step 6: 测试验证
|
||||
- [ ] 运行了 GUT 测试命令
|
||||
- [ ] 所有测试通过
|
||||
- [ ] 如有失败,已修复并重新测试
|
||||
|
||||
### Step 7: Git 提交
|
||||
- [ ] 已读取 `docs/02-开发规范/Git提交规范.md`
|
||||
- [ ] 生成了符合规范的提交信息
|
||||
- [ ] 提交类型正确
|
||||
- [ ] 使用中文冒号
|
||||
- [ ] 遵循"一次提交只做一件事"原则
|
||||
|
||||
---
|
||||
|
||||
## 快速自检问题
|
||||
|
||||
在提交代码前,问自己以下问题:
|
||||
|
||||
1. **架构**: 文件放在正确的位置了吗?
|
||||
2. **通信**: 是否使用 EventSystem 进行跨模块通信?
|
||||
3. **类型**: 所有变量和函数都有类型注解吗?
|
||||
4. **命名**: 命名是否符合规范(PascalCase/camelCase/UPPER_CASE)?
|
||||
5. **注释**: 文件头和公共函数有完整注释吗?
|
||||
6. **测试**: 创建并运行测试了吗?所有测试都通过了吗?
|
||||
7. **提交**: Git 提交信息符合规范吗?
|
||||
|
||||
如果以上问题都能回答"是",那么代码已经符合 WhaleTown 项目的质量标准!✅
|
||||
312
.claude/skills/whaletown-developer/使用说明.md
Normal file
@@ -0,0 +1,312 @@
|
||||
# WhaleTown Developer Skill 使用说明
|
||||
|
||||
## 📖 简介
|
||||
|
||||
`whaletown-developer` 是 WhaleTown 项目的标准开发工作流自动化技能,确保所有开发任务都遵循统一的项目规范和质量标准。
|
||||
|
||||
## 🎯 适用场景
|
||||
|
||||
在以下情况下使用此 skill:
|
||||
|
||||
- ✅ 实现新功能("实现玩家二段跳"、"添加存档系统")
|
||||
- ✅ 修复 Bug("修复角色碰撞问题"、"解决UI显示错误")
|
||||
- ✅ 创建场景("创建商店场景"、"设计背包界面")
|
||||
- ✅ 开发模块("开发任务系统"、"构建战斗组件")
|
||||
- ✅ 任何需要遵循项目规范的代码开发任务
|
||||
|
||||
## 🚀 调用方式
|
||||
|
||||
### 方式一:通过 Claude(推荐)
|
||||
|
||||
```
|
||||
用户:帮我实现一个 NPC
|
||||
Claude:/whaletown-developer 实现一个 NPC
|
||||
```
|
||||
|
||||
### 方式二:直接请求
|
||||
|
||||
```
|
||||
用户:使用 whaletown-developer skill 创建玩家移动系统
|
||||
```
|
||||
|
||||
## 📋 7 步工作流程
|
||||
|
||||
skill 会自动执行以下标准化流程:
|
||||
|
||||
```
|
||||
Step 1: 架构分析
|
||||
↓ 读取架构规范,确定文件位置、通信方式、依赖关系
|
||||
|
||||
Step 2: 功能实现
|
||||
↓ 按照类型安全、命名规范、EventSystem 通信等要求编码
|
||||
|
||||
Step 3: 注释规范检查
|
||||
↓ 验证文件头、函数文档、行内注释是否完整
|
||||
|
||||
Step 4: 命名规范检查
|
||||
↓ 验证 PascalCase/camelCase/UPPER_CASE 命名规范
|
||||
|
||||
Step 5: 测试代码编写
|
||||
↓ 为核心功能创建 GUT 单元测试
|
||||
|
||||
Step 6: 测试验证
|
||||
↓ 运行测试确保功能正常
|
||||
|
||||
Step 7: Git 提交
|
||||
↓ 生成符合规范的提交信息
|
||||
```
|
||||
|
||||
## 💡 使用示例
|
||||
|
||||
### 示例 1:创建玩家控制器
|
||||
|
||||
**用户输入:**
|
||||
```
|
||||
帮我创建一个玩家角色控制器
|
||||
```
|
||||
|
||||
**Skill 执行:**
|
||||
1. 分析架构 → 确定放在 `scenes/Entities/Player/PlayerController.gd`
|
||||
2. 实现功能 → 创建带类型注解的移动、跳跃逻辑
|
||||
3. 检查注释 → 添加完整的文件头和函数文档
|
||||
4. 检查命名 → 确保 `moveSpeed`、`MAX_HEALTH` 等命名正确
|
||||
5. 编写测试 → 创建 `tests/unit/test_player_controller.gd`
|
||||
6. 运行测试 → 验证功能正常
|
||||
7. 生成提交 → `feat:实现玩家角色控制器`
|
||||
|
||||
### 示例 2:修复跳跃 Bug
|
||||
|
||||
**用户输入:**
|
||||
```
|
||||
修复玩家跳跃时的碰撞检测问题
|
||||
```
|
||||
|
||||
**Skill 执行:**
|
||||
1. 分析架构 → 定位到 `scenes/Entities/Player/Player.gd`
|
||||
2. 实现修复 → 修改碰撞检测逻辑
|
||||
3. 检查注释 → 添加修复说明注释
|
||||
4. 检查命名 → 确保变量命名规范
|
||||
5. 编写测试 → 添加碰撞测试用例
|
||||
6. 运行测试 → 确认 Bug 已修复
|
||||
7. 生成提交 → `fix:修复玩家跳跃时的碰撞检测问题`
|
||||
|
||||
### 示例 3:添加事件通信
|
||||
|
||||
**用户输入:**
|
||||
```
|
||||
实现 NPC 对话系统的事件通信
|
||||
```
|
||||
|
||||
**Skill 执行:**
|
||||
1. 分析架构 → 使用 EventSystem 跨模块通信
|
||||
2. 实现功能 → 在 EventNames.gd 添加 `NPC_DIALOG_STARTED` 事件
|
||||
3. 检查注释 → 文档化事件数据格式
|
||||
4. 检查命名 → 确保事件名称符合规范
|
||||
5. 编写测试 → 测试事件发送和接收
|
||||
6. 运行测试 → 验证通信正常
|
||||
7. 生成提交 → `feat:实现NPC对话系统的事件通信`
|
||||
|
||||
## ✅ 质量保证
|
||||
|
||||
每次使用 skill 后,代码都会符合以下标准:
|
||||
|
||||
### 架构层面
|
||||
- ✅ 文件位置符合分层架构(_Core、scenes、UI)
|
||||
- ✅ 使用 EventSystem 实现跨模块通信
|
||||
- ✅ 事件名称已添加到 EventNames.gd
|
||||
- ✅ 遵循"Signal Up, Call Down"原则
|
||||
|
||||
### 代码质量
|
||||
- ✅ 所有变量和函数都有类型注解
|
||||
- ✅ 命名规范正确(PascalCase/camelCase/UPPER_CASE)
|
||||
- ✅ 使用 Godot 4.2+ 语法(await 而非 yield)
|
||||
- ✅ 节点引用使用 @onready 缓存
|
||||
|
||||
### 文档规范
|
||||
- ✅ 文件头注释完整(文件名、作用、功能、依赖)
|
||||
- ✅ 公共函数有完整文档(参数、返回值、示例)
|
||||
- ✅ 复杂逻辑有行内注释说明
|
||||
|
||||
### 测试覆盖
|
||||
- ✅ 核心功能有单元测试
|
||||
- ✅ 测试文件命名规范(test_*.gd)
|
||||
- ✅ 测试通过验证
|
||||
|
||||
### Git 规范
|
||||
- ✅ 提交信息格式正确(类型:描述)
|
||||
- ✅ 遵循"一次提交只做一件事"原则
|
||||
- ✅ 使用中文冒号和动词开头
|
||||
|
||||
## 📚 相关文档
|
||||
|
||||
Skill 会自动读取以下规范文档:
|
||||
|
||||
- `docs/02-开发规范/架构与通信规范.md` - 分层架构和 EventSystem
|
||||
- `docs/02-开发规范/代码注释规范.md` - 注释格式要求
|
||||
- `docs/02-开发规范/命名规范.md` - 命名约定
|
||||
- `docs/03-技术实现/测试指南.md` - 测试框架使用
|
||||
- `docs/02-开发规范/Git提交规范.md` - 提交信息格式
|
||||
- `CLAUDE.md` - 项目总体指导
|
||||
|
||||
## ⚙️ 配置文件
|
||||
|
||||
Skill 相关配置文件位置:
|
||||
|
||||
```
|
||||
.claude/skills/whaletown-developer/
|
||||
├── SKILL.md # Skill 定义文件
|
||||
├── 使用说明.md # 本文档
|
||||
└── references/
|
||||
└── checklist.md # 质量检查清单
|
||||
```
|
||||
|
||||
## 🔄 工作流程可视化
|
||||
|
||||
```
|
||||
用户请求
|
||||
↓
|
||||
调用 whaletown-developer skill
|
||||
↓
|
||||
[Step 1] 架构分析
|
||||
├─ 读取架构规范文档
|
||||
├─ 确定文件位置
|
||||
├─ 识别通信方式
|
||||
└─ 设计事件定义
|
||||
↓
|
||||
[Step 2] 功能实现
|
||||
├─ 遵循类型安全
|
||||
├─ 使用 EventSystem
|
||||
├─ 缓存节点引用
|
||||
└─ 使用 Godot 4.2+ 语法
|
||||
↓
|
||||
[Step 3] 注释规范检查
|
||||
├─ 验证文件头注释
|
||||
├─ 验证函数文档
|
||||
└─ 检查行内注释
|
||||
↓
|
||||
[Step 4] 命名规范检查
|
||||
├─ 类名 PascalCase
|
||||
├─ 变量/函数 camelCase
|
||||
├─ 常量 UPPER_CASE
|
||||
└─ 私有成员 _prefix
|
||||
↓
|
||||
[Step 5] 测试代码编写
|
||||
├─ 创建测试文件
|
||||
├─ 编写测试用例
|
||||
└─ 覆盖核心功能
|
||||
↓
|
||||
[Step 6] 测试验证
|
||||
├─ 运行 GUT 测试
|
||||
├─ 验证测试通过
|
||||
└─ 修复失败测试
|
||||
↓
|
||||
[Step 7] Git 提交
|
||||
├─ 确定提交类型
|
||||
├─ 生成提交信息
|
||||
└─ 遵循提交规范
|
||||
↓
|
||||
完成 ✅
|
||||
```
|
||||
|
||||
## 🎓 最佳实践
|
||||
|
||||
### 1. 明确任务描述
|
||||
```bash
|
||||
# ✅ 好的描述
|
||||
"实现玩家二段跳功能"
|
||||
"修复敌人AI路径寻找Bug"
|
||||
"创建商店购买界面"
|
||||
|
||||
# ❌ 模糊描述
|
||||
"改一下玩家"
|
||||
"修复Bug"
|
||||
"做个界面"
|
||||
```
|
||||
|
||||
### 2. 一次处理一个功能
|
||||
```bash
|
||||
# ✅ 推荐
|
||||
用户:实现玩家移动
|
||||
用户:实现玩家跳跃
|
||||
|
||||
# ❌ 不推荐
|
||||
用户:实现玩家移动、跳跃、攻击、技能系统
|
||||
```
|
||||
|
||||
### 3. 信任 Skill 流程
|
||||
- Skill 会按照 7 步流程确保质量
|
||||
- 不需要手动检查命名、注释等细节
|
||||
- 专注于功能需求和业务逻辑
|
||||
|
||||
### 4. 查看生成的提交信息
|
||||
- Skill 会在 Step 7 生成规范的提交信息
|
||||
- 可以直接使用或根据需要微调
|
||||
|
||||
## ⚠️ 注意事项
|
||||
|
||||
1. **首次使用**
|
||||
- 确保已阅读 `CLAUDE.md` 了解项目规范
|
||||
- 确认所有规范文档都已存在
|
||||
|
||||
2. **测试环境**
|
||||
- 确保 GUT 测试框架已安装(如需运行测试)
|
||||
- Godot 可执行文件在 PATH 中(Step 6 测试执行)
|
||||
|
||||
3. **中断处理**
|
||||
- 如果工作流被中断,可以继续执行剩余步骤
|
||||
- Skill 使用 TodoWrite 追踪进度
|
||||
|
||||
4. **规范更新**
|
||||
- 项目规范文档更新时,Skill 会自动读取最新版本
|
||||
- 无需手动同步
|
||||
|
||||
## 🤝 反馈与改进
|
||||
|
||||
如果遇到问题或有改进建议:
|
||||
|
||||
1. 检查是否所有规范文档都已更新
|
||||
2. 确认任务描述清晰明确
|
||||
3. 查看 Skill 执行日志定位问题
|
||||
4. 向团队报告问题或建议
|
||||
|
||||
## 📊 效果对比
|
||||
|
||||
### 不使用 Skill
|
||||
```
|
||||
开发者手动:
|
||||
1. 不确定文件放哪里 ❌
|
||||
2. 可能忘记类型注解 ❌
|
||||
3. 注释不完整 ❌
|
||||
4. 命名不一致 ❌
|
||||
5. 没有测试 ❌
|
||||
6. 提交信息格式错误 ❌
|
||||
结果:代码质量参差不齐
|
||||
```
|
||||
|
||||
### 使用 Skill
|
||||
```
|
||||
Skill 自动化:
|
||||
1. 自动确定正确位置 ✅
|
||||
2. 强制类型安全 ✅
|
||||
3. 完整注释文档 ✅
|
||||
4. 统一命名规范 ✅
|
||||
5. 自动生成测试 ✅
|
||||
6. 规范提交信息 ✅
|
||||
结果:高质量、一致性代码
|
||||
```
|
||||
|
||||
## 🎯 总结
|
||||
|
||||
whaletown-developer skill 是你的开发助手,它会:
|
||||
|
||||
- 🤖 **自动化** 7 步标准流程
|
||||
- 📏 **标准化** 代码质量
|
||||
- 🔒 **保证** 规范遵循
|
||||
- ⚡ **加速** 开发效率
|
||||
- 🧪 **确保** 测试覆盖
|
||||
|
||||
**记住:专注于功能实现,让 Skill 处理规范和质量!**
|
||||
|
||||
---
|
||||
|
||||
**开始使用:** 只需告诉 Claude "帮我实现 XXX 功能" 即可!
|
||||
55
.gitignore
vendored
@@ -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
@@ -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
|
||||
}
|
||||
]
|
||||
}
|
||||
3
.vscode/settings.json
vendored
@@ -1,3 +0,0 @@
|
||||
{
|
||||
"godotTools.editorPath.godot4": "d:\\software\\godot\\Godot_v4.5.1-stable_win64.exe"
|
||||
}
|
||||
29
Config/game_config.json
Normal file
@@ -0,0 +1,29 @@
|
||||
{
|
||||
"game": {
|
||||
"name": "whaleTown",
|
||||
"version": "1.0.0",
|
||||
"debug_mode": true
|
||||
},
|
||||
"network": {
|
||||
"api_base_url": "https://whaletownend.xinghangee.icu",
|
||||
"timeout": 30,
|
||||
"retry_count": 3
|
||||
},
|
||||
"ui": {
|
||||
"default_font_size": 14,
|
||||
"toast_duration": 2.0,
|
||||
"transition_duration": 0.3
|
||||
},
|
||||
"gameplay": {
|
||||
"auto_save_interval": 300,
|
||||
"max_inventory_slots": 50,
|
||||
"default_player_stats": {
|
||||
"level": 1,
|
||||
"coins": 100,
|
||||
"exp": 0,
|
||||
"max_exp": 100,
|
||||
"energy": 100,
|
||||
"max_energy": 100
|
||||
}
|
||||
}
|
||||
}
|
||||
36
Config/zh_CN.json
Normal file
@@ -0,0 +1,36 @@
|
||||
{
|
||||
"ui": {
|
||||
"login": "登录",
|
||||
"register": "注册",
|
||||
"username": "用户名",
|
||||
"password": "密码",
|
||||
"email": "邮箱",
|
||||
"confirm_password": "确认密码",
|
||||
"verification_code": "验证码",
|
||||
"send_code": "发送验证码",
|
||||
"forgot_password": "忘记密码",
|
||||
"enter_town": "进入小镇",
|
||||
"logout": "退出登录"
|
||||
},
|
||||
"messages": {
|
||||
"login_success": "登录成功!正在进入鲸鱼镇...",
|
||||
"register_success": "注册成功!欢迎加入鲸鱼镇",
|
||||
"network_error": "网络连接失败,请检查网络连接",
|
||||
"invalid_username": "用户名只能包含字母、数字和下划线",
|
||||
"invalid_email": "请输入有效的邮箱地址",
|
||||
"password_too_short": "密码长度至少8位",
|
||||
"password_mismatch": "两次输入的密码不一致",
|
||||
"verification_code_sent": "验证码已发送到您的邮箱,请查收"
|
||||
},
|
||||
"game": {
|
||||
"level": "等级",
|
||||
"coins": "金币",
|
||||
"experience": "经验",
|
||||
"energy": "体力",
|
||||
"explore": "探索小镇",
|
||||
"inventory": "背包",
|
||||
"shop": "商店",
|
||||
"friends": "好友",
|
||||
"settings": "设置"
|
||||
}
|
||||
}
|
||||
460
README.md
@@ -1,101 +1,395 @@
|
||||
# whaleTown
|
||||
# 🐋 WhaleTown - 现代化像素游戏
|
||||
|
||||
一个使用 Godot 4.5 引擎开发的游戏项目。
|
||||
> 一个基于 Godot 4.5 引擎开发的企业级 2D 像素风游戏,采用模块化架构设计,集成完整的用户认证系统和游戏核心功能。
|
||||
|
||||
## 项目信息
|
||||
[](https://godotengine.org/)
|
||||
[](https://docs.godotengine.org/en/stable/tutorials/scripting/gdscript/index.html)
|
||||
[](./docs/)
|
||||
[](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)** - 配置开发环境
|
||||
4. **[🤖 AI开发指南](docs/AI_docs/README.md)** - AI编程助手专用文档
|
||||
|
||||
### 🎯 第二步:学习规范
|
||||
|
||||
**代码质量保证**
|
||||
|
||||
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-功能模块/ # 🎮 功能文档
|
||||
│ └── AI_docs/ # 🤖 AI专用文档(执行规范、代码模板)
|
||||
├── 🔧 _Core/ # ⚙️ 核心底层实现
|
||||
│ ├── managers/ # 🎯 全局管理器(游戏状态、场景、网络等)
|
||||
│ ├── systems/ # 🔄 系统组件(事件系统、输入系统等)
|
||||
│ ├── components/ # 🧩 基础组件实现
|
||||
│ ├── utils/ # <20> 核件心工具类(字符串处理、数学计算等)
|
||||
│ ├── EventNames.gd # 📝 事件名称定义
|
||||
│ └── ProjectPaths.gd # <20> 路径组统一管理
|
||||
├── 🎬 scenes/ # 🎭 场景与视觉呈现
|
||||
│ ├── maps/ # <20>️ 地图一场景(游戏关卡、世界地图)
|
||||
│ ├── characters/ # 👤 人物场景(角色、NPC、敌人)
|
||||
│ ├── ui/ # 🖼️ UI界面场景(菜单、HUD、对话框)
|
||||
│ ├── effects/ # ✨ 特效场景(粒子效果、动画)
|
||||
│ └── prefabs/ # 🧩 预制体组件
|
||||
├── 🎨 assets/ # 🖼️ 静态资源存储
|
||||
│ ├── sprites/ # 🎨 精灵图片(角色、物品、环境)
|
||||
│ ├── audio/ # 🎵 音频资源(音乐、音效)
|
||||
│ ├── fonts/ # 🔤 字体文件
|
||||
│ ├── materials/ # 🎭 材质资源
|
||||
│ ├── shaders/ # 🌈 着色器文件
|
||||
│ ├── ui/ # 🖼️ UI素材(按钮、图标、背景)
|
||||
│ └── icon/ # 📱 应用图标
|
||||
├── ⚙️ Config/ # 📋 配置文件管理
|
||||
│ ├── game_config.json # 🎮 游戏配置(难度、设置等)
|
||||
│ ├── zh_CN.json # 🌐 本地化配置
|
||||
│ └── environment/ # 🔧 环境配置(开发、测试、生产)
|
||||
├── 🧪 tests/ # 🔬 测试文件系统
|
||||
│ ├── unit/ # 🔍 单元测试(组件功能测试)
|
||||
│ ├── integration/ # 🔗 集成测试(系统交互测试)
|
||||
│ ├── performance/ # ⚡ 性能测试(帧率、内存优化)
|
||||
│ └── api/ # 🌐 API接口测试
|
||||
└── 🌐 web_assets/ # 🌍 Web导出资源
|
||||
├── html/ # 📄 HTML模板文件
|
||||
├── css/ # 🎨 样式文件
|
||||
└── js/ # 📜 JavaScript脚本
|
||||
```
|
||||
|
||||
### 🔧 核心架构说明
|
||||
|
||||
| 目录 | 作用 | 详细说明 |
|
||||
|------|------|----------|
|
||||
| **_Core** | 🔧 功能实现与组件实现 | 项目最基本的底层实现,包含所有核心系统和基础组件 |
|
||||
| **scenes** | 🎭 场景与视觉呈现 | 包含地图场景、人物场景等一系列视觉呈现部分,主要是UI的实现 |
|
||||
| **assets** | 🎨 静态资源存储 | 所有静态资源的存储,包括图片、音乐、视频、贴图等素材 |
|
||||
| **Config** | ⚙️ 配置文件管理 | 主要用来配置各类环境,包括游戏设置、本地化等配置 |
|
||||
| **tests** | 🧪 测试文件系统 | 放置所有对应组件的测试代码,方便快速进行功能性与性能测试 |
|
||||
| **web_assets** | 🌐 Web导出资源 | 专门用于Web平台导出的相关资源和配置文件 |
|
||||
| **docs/AI_docs** | 🤖 AI专用文档 | 专门为AI编程助手准备的执行规范和代码模板,提升vibe coding效率 |
|
||||
|
||||
### 🎮 核心组件
|
||||
|
||||
| 组件 | 位置 | 作用 | 文档链接 |
|
||||
|------|------|------|----------|
|
||||
| **EventSystem** | _Core/systems/ | 全局事件通信系统 | [架构规范](docs/02-开发规范/架构与通信规范.md) |
|
||||
| **GameManager** | _Core/managers/ | 游戏状态管理器 | [实现细节](docs/03-技术实现/实现细节规范.md) |
|
||||
| **SceneManager** | _Core/managers/ | 场景切换管理器 | [场景设计](docs/04-高级开发/场景设计规范.md) |
|
||||
| **NetworkManager** | _Core/managers/ | 网络请求管理器 | [网络管理器](docs/03-技术实现/网络管理器设置.md) |
|
||||
| **ProjectPaths** | _Core/ | 路径统一管理工具 | [项目结构](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>
|
||||
60
_Core/EventNames.gd
Normal file
@@ -0,0 +1,60 @@
|
||||
# ============================================================================
|
||||
# 事件名称定义 - EventNames.gd
|
||||
#
|
||||
# 定义项目中所有事件的名称常量,确保事件名称的一致性和可维护性
|
||||
#
|
||||
# 使用方式:
|
||||
# EventSystem.emit_event(EventNames.PLAYER_MOVED, data)
|
||||
# EventSystem.connect_event(EventNames.INTERACT_PRESSED, callback)
|
||||
# ============================================================================
|
||||
|
||||
class_name EventNames
|
||||
|
||||
# ============================================================================
|
||||
# 玩家相关事件
|
||||
# ============================================================================
|
||||
const PLAYER_MOVED = "player_moved"
|
||||
const PLAYER_SPAWNED = "player_spawned"
|
||||
const PLAYER_HEALTH_CHANGED = "player_health_changed"
|
||||
const PLAYER_DIED = "player_died"
|
||||
const PLAYER_RESPAWNED = "player_respawned"
|
||||
const PLAYER_ATTACK = "player_attack"
|
||||
|
||||
# ============================================================================
|
||||
# 交互事件
|
||||
# ============================================================================
|
||||
const INTERACT_PRESSED = "interact_pressed"
|
||||
const NPC_TALKED = "npc_talked"
|
||||
const ITEM_COLLECTED = "item_collected"
|
||||
const OBJECT_INTERACTED = "object_interacted"
|
||||
|
||||
# ============================================================================
|
||||
# UI事件
|
||||
# ============================================================================
|
||||
const UI_BUTTON_CLICKED = "ui_button_clicked"
|
||||
const DIALOG_OPENED = "dialog_opened"
|
||||
const DIALOG_CLOSED = "dialog_closed"
|
||||
const MENU_OPENED = "menu_opened"
|
||||
const MENU_CLOSED = "menu_closed"
|
||||
|
||||
# ============================================================================
|
||||
# 游戏状态事件
|
||||
# ============================================================================
|
||||
const GAME_PAUSED = "game_paused"
|
||||
const GAME_RESUMED = "game_resumed"
|
||||
const SCENE_CHANGED = "scene_changed"
|
||||
const SCENE_DATA_TRANSFER = "scene_data_transfer"
|
||||
|
||||
# ============================================================================
|
||||
# 系统事件
|
||||
# ============================================================================
|
||||
const TILEMAP_READY = "tilemap_ready"
|
||||
const COMPONENT_MESSAGE = "component_message"
|
||||
const POSITION_UPDATE = "position_update"
|
||||
const GRID_POSITION_CHANGED = "grid_position_changed"
|
||||
const GRID_SNAP_REQUESTED = "grid_snap_requested"
|
||||
|
||||
# ============================================================================
|
||||
# 测试事件
|
||||
# ============================================================================
|
||||
const TEST_EVENT = "test_event"
|
||||
1
_Core/EventNames.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://qn0imbklx1m0
|
||||
118
_Core/ProjectPaths.gd
Normal file
@@ -0,0 +1,118 @@
|
||||
# ============================================================================
|
||||
# 项目路径配置 - 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 CORE_COMPONENTS = CORE_ROOT + "components/"
|
||||
const CORE_UTILS = CORE_ROOT + "utils/"
|
||||
|
||||
# 系统文件路径
|
||||
const GRID_SYSTEM = CORE_SYSTEMS + "GridSystem.gd"
|
||||
const EVENT_SYSTEM = CORE_SYSTEMS + "EventSystem.gd"
|
||||
const TILE_SYSTEM = CORE_SYSTEMS + "TileSystem.gd"
|
||||
|
||||
# ============================================================================
|
||||
# 场景路径
|
||||
# ============================================================================
|
||||
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://scenes/ui/"
|
||||
const UI_WINDOWS = UI_ROOT
|
||||
|
||||
# ============================================================================
|
||||
# 资源路径
|
||||
# ============================================================================
|
||||
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 ASSETS_TERRAIN = ASSETS_SPRITES + "terrain/"
|
||||
const ASSETS_GRASS = ASSETS_TERRAIN + "grass/"
|
||||
|
||||
# ============================================================================
|
||||
# 数据路径
|
||||
# ============================================================================
|
||||
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://_Core/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"
|
||||
1
_Core/ProjectPaths.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://dybcuscku7tyl
|
||||
2
_Core/components/.gitkeep
Normal file
@@ -0,0 +1,2 @@
|
||||
# 基础组件实现目录
|
||||
# 存放项目的基础组件类
|
||||
605
_Core/managers/AuthManager.gd
Normal file
@@ -0,0 +1,605 @@
|
||||
class_name AuthManager
|
||||
|
||||
# ============================================================================
|
||||
# AuthManager.gd - 认证管理器
|
||||
# ============================================================================
|
||||
# 认证系统的业务逻辑管理器,负责处理所有认证相关的业务逻辑
|
||||
#
|
||||
# 核心职责:
|
||||
# - 用户登录业务逻辑(密码登录 + 验证码登录)
|
||||
# - 用户注册业务逻辑
|
||||
# - 表单验证逻辑
|
||||
# - 验证码管理逻辑
|
||||
# - 网络请求管理
|
||||
# - 响应处理和状态管理
|
||||
#
|
||||
# 使用方式:
|
||||
# var auth_manager = AuthManager.new()
|
||||
# auth_manager.login_success.connect(_on_login_success)
|
||||
# auth_manager.execute_password_login(username, password)
|
||||
#
|
||||
# 注意事项:
|
||||
# - 这是业务逻辑层,不包含任何UI相关代码
|
||||
# - 通过信号与UI层通信
|
||||
# - 所有验证逻辑都在这里实现
|
||||
# ============================================================================
|
||||
|
||||
extends RefCounted
|
||||
|
||||
# ============ 信号定义 ============
|
||||
|
||||
# 登录成功信号
|
||||
signal login_success(username: String, token: String)
|
||||
|
||||
# 登录失败信号
|
||||
signal login_failed(message: String)
|
||||
|
||||
# 注册成功信号
|
||||
signal register_success(message: String)
|
||||
|
||||
# 注册失败信号
|
||||
signal register_failed(message: String)
|
||||
|
||||
# 验证码发送成功信号
|
||||
signal verification_code_sent(message: String)
|
||||
|
||||
# 验证码发送失败信号
|
||||
signal verification_code_failed(message: String)
|
||||
|
||||
# 表单验证失败信号
|
||||
signal form_validation_failed(field: String, message: String)
|
||||
|
||||
# 网络状态变化信号
|
||||
signal network_status_changed(is_connected: bool, message: String)
|
||||
|
||||
# 按钮状态变化信号
|
||||
signal button_state_changed(button_name: String, is_loading: bool, text: String)
|
||||
|
||||
# Toast消息信号
|
||||
signal show_toast_message(message: String, is_success: bool)
|
||||
|
||||
# ============ 枚举定义 ============
|
||||
|
||||
# 登录模式枚举
|
||||
enum LoginMode {
|
||||
PASSWORD, # 密码登录模式
|
||||
VERIFICATION # 验证码登录模式
|
||||
}
|
||||
|
||||
# ============ 成员变量 ============
|
||||
|
||||
# 登录状态
|
||||
var current_login_mode: LoginMode = LoginMode.PASSWORD
|
||||
var is_processing: bool = false
|
||||
|
||||
# 验证码管理
|
||||
var verification_codes_sent: Dictionary = {}
|
||||
var code_cooldown: float = 60.0
|
||||
var current_email: String = ""
|
||||
|
||||
# 网络请求管理
|
||||
var active_request_ids: Array = []
|
||||
|
||||
# 当前登录用户ID (静态变量,全局访问)
|
||||
static var current_user_id: String = ""
|
||||
|
||||
# ============ 生命周期方法 ============
|
||||
|
||||
# 初始化管理器
|
||||
func _init():
|
||||
print("AuthManager 初始化完成")
|
||||
|
||||
# 清理资源
|
||||
func cleanup():
|
||||
# 取消所有活动的网络请求
|
||||
for request_id in active_request_ids:
|
||||
NetworkManager.cancel_request(request_id)
|
||||
active_request_ids.clear()
|
||||
|
||||
# ============ 登录相关方法 ============
|
||||
|
||||
# 执行密码登录
|
||||
#
|
||||
# 参数:
|
||||
# username: String - 用户名/邮箱
|
||||
# password: String - 密码
|
||||
#
|
||||
# 功能:
|
||||
# - 验证输入参数
|
||||
# - 发送登录请求
|
||||
# - 处理响应结果
|
||||
func execute_password_login(username: String, password: String):
|
||||
if is_processing:
|
||||
show_toast_message.emit("请等待当前操作完成", false)
|
||||
return
|
||||
|
||||
# 验证输入
|
||||
var validation_result = validate_login_inputs(username, password)
|
||||
if not validation_result.valid:
|
||||
form_validation_failed.emit(validation_result.field, validation_result.message)
|
||||
return
|
||||
|
||||
# 设置处理状态
|
||||
is_processing = true
|
||||
button_state_changed.emit("main_btn", true, "登录中...")
|
||||
show_toast_message.emit("正在验证登录信息...", true)
|
||||
|
||||
# 发送网络请求
|
||||
var request_id = NetworkManager.login(username, password, _on_login_response)
|
||||
if request_id != "":
|
||||
active_request_ids.append(request_id)
|
||||
else:
|
||||
_reset_login_state()
|
||||
show_toast_message.emit("网络请求失败", false)
|
||||
|
||||
# 执行验证码登录
|
||||
#
|
||||
# 参数:
|
||||
# identifier: String - 用户标识符
|
||||
# verification_code: String - 验证码
|
||||
func execute_verification_login(identifier: String, verification_code: String):
|
||||
if is_processing:
|
||||
show_toast_message.emit("请等待当前操作完成", false)
|
||||
return
|
||||
|
||||
# 验证输入
|
||||
if identifier.is_empty():
|
||||
form_validation_failed.emit("username", "请输入用户名/手机/邮箱")
|
||||
return
|
||||
|
||||
if verification_code.is_empty():
|
||||
form_validation_failed.emit("verification", "请输入验证码")
|
||||
return
|
||||
|
||||
# 设置处理状态
|
||||
is_processing = true
|
||||
button_state_changed.emit("main_btn", true, "登录中...")
|
||||
show_toast_message.emit("正在验证验证码...", true)
|
||||
|
||||
# 发送网络请求
|
||||
var request_id = NetworkManager.verification_code_login(identifier, verification_code, _on_verification_login_response)
|
||||
if request_id != "":
|
||||
active_request_ids.append(request_id)
|
||||
else:
|
||||
_reset_login_state()
|
||||
show_toast_message.emit("网络请求失败", false)
|
||||
|
||||
# 切换登录模式
|
||||
func toggle_login_mode():
|
||||
if current_login_mode == LoginMode.PASSWORD:
|
||||
current_login_mode = LoginMode.VERIFICATION
|
||||
else:
|
||||
current_login_mode = LoginMode.PASSWORD
|
||||
|
||||
# 获取当前登录模式
|
||||
func get_current_login_mode() -> LoginMode:
|
||||
return current_login_mode
|
||||
|
||||
# ============ 注册相关方法 ============
|
||||
|
||||
# 执行用户注册
|
||||
#
|
||||
# 参数:
|
||||
# username: String - 用户名
|
||||
# email: String - 邮箱
|
||||
# password: String - 密码
|
||||
# confirm_password: String - 确认密码
|
||||
# verification_code: String - 邮箱验证码
|
||||
func execute_register(username: String, email: String, password: String, confirm_password: String, verification_code: String):
|
||||
if is_processing:
|
||||
show_toast_message.emit("请等待当前操作完成", false)
|
||||
return
|
||||
|
||||
# 验证注册表单
|
||||
var validation_result = validate_register_form(username, email, password, confirm_password, verification_code)
|
||||
if not validation_result.valid:
|
||||
form_validation_failed.emit(validation_result.field, validation_result.message)
|
||||
return
|
||||
|
||||
# 设置处理状态
|
||||
is_processing = true
|
||||
button_state_changed.emit("register_btn", true, "注册中...")
|
||||
show_toast_message.emit("正在创建账户...", true)
|
||||
|
||||
# 发送注册请求
|
||||
var request_id = NetworkManager.register(username, password, username, email, verification_code, _on_register_response)
|
||||
if request_id != "":
|
||||
active_request_ids.append(request_id)
|
||||
else:
|
||||
_reset_register_state()
|
||||
show_toast_message.emit("网络请求失败", false)
|
||||
|
||||
# ============ 验证码相关方法 ============
|
||||
|
||||
# 发送邮箱验证码
|
||||
#
|
||||
# 参数:
|
||||
# email: String - 邮箱地址
|
||||
func send_email_verification_code(email: String):
|
||||
# 验证邮箱格式
|
||||
var email_validation = validate_email(email)
|
||||
if not email_validation.valid:
|
||||
form_validation_failed.emit("email", email_validation.message)
|
||||
return
|
||||
|
||||
# 检查冷却时间
|
||||
if not _can_send_verification_code(email):
|
||||
var remaining = get_remaining_cooldown_time(email)
|
||||
show_toast_message.emit("该邮箱请等待 %d 秒后再次发送" % remaining, false)
|
||||
return
|
||||
|
||||
# 记录发送状态
|
||||
_record_verification_code_sent(email)
|
||||
|
||||
# 发送请求
|
||||
var request_id = NetworkManager.send_email_verification(email, _on_send_code_response)
|
||||
if request_id != "":
|
||||
active_request_ids.append(request_id)
|
||||
else:
|
||||
_reset_verification_code_state(email)
|
||||
show_toast_message.emit("网络请求失败", false)
|
||||
|
||||
# 发送登录验证码
|
||||
#
|
||||
# 参数:
|
||||
# identifier: String - 用户标识符
|
||||
func send_login_verification_code(identifier: String):
|
||||
if identifier.is_empty():
|
||||
form_validation_failed.emit("username", "请先输入用户名/手机/邮箱")
|
||||
return
|
||||
|
||||
button_state_changed.emit("get_code_btn", true, "发送中...")
|
||||
show_toast_message.emit("正在发送登录验证码...", true)
|
||||
|
||||
var request_id = NetworkManager.send_login_verification_code(identifier, _on_send_login_code_response)
|
||||
if request_id != "":
|
||||
active_request_ids.append(request_id)
|
||||
else:
|
||||
button_state_changed.emit("get_code_btn", false, "获取验证码")
|
||||
show_toast_message.emit("网络请求失败", false)
|
||||
|
||||
# 发送密码重置验证码
|
||||
#
|
||||
# 参数:
|
||||
# identifier: String - 用户标识符
|
||||
func send_password_reset_code(identifier: String):
|
||||
if identifier.is_empty():
|
||||
show_toast_message.emit("请先输入邮箱或手机号", false)
|
||||
return
|
||||
|
||||
if not _is_valid_identifier(identifier):
|
||||
show_toast_message.emit("请输入有效的邮箱或手机号", false)
|
||||
return
|
||||
|
||||
button_state_changed.emit("forgot_password_btn", true, "发送中...")
|
||||
show_toast_message.emit("正在发送密码重置验证码...", true)
|
||||
|
||||
var request_id = NetworkManager.forgot_password(identifier, _on_forgot_password_response)
|
||||
if request_id != "":
|
||||
active_request_ids.append(request_id)
|
||||
else:
|
||||
button_state_changed.emit("forgot_password_btn", false, "忘记密码")
|
||||
show_toast_message.emit("网络请求失败", false)
|
||||
|
||||
# ============ 验证方法 ============
|
||||
|
||||
# 验证登录输入
|
||||
func validate_login_inputs(username: String, password: String) -> Dictionary:
|
||||
var result = {"valid": false, "field": "", "message": ""}
|
||||
|
||||
if username.is_empty():
|
||||
result.field = "username"
|
||||
result.message = "用户名不能为空"
|
||||
return result
|
||||
|
||||
if password.is_empty():
|
||||
result.field = "password"
|
||||
result.message = "密码不能为空"
|
||||
return result
|
||||
|
||||
result.valid = true
|
||||
return result
|
||||
|
||||
# 验证注册表单
|
||||
func validate_register_form(username: String, email: String, password: String, confirm_password: String, verification_code: String) -> Dictionary:
|
||||
var result = {"valid": false, "field": "", "message": ""}
|
||||
|
||||
# 验证用户名
|
||||
var username_validation = validate_username(username)
|
||||
if not username_validation.valid:
|
||||
result.field = "username"
|
||||
result.message = username_validation.message
|
||||
return result
|
||||
|
||||
# 验证邮箱
|
||||
var email_validation = validate_email(email)
|
||||
if not email_validation.valid:
|
||||
result.field = "email"
|
||||
result.message = email_validation.message
|
||||
return result
|
||||
|
||||
# 验证密码
|
||||
var password_validation = validate_password(password)
|
||||
if not password_validation.valid:
|
||||
result.field = "password"
|
||||
result.message = password_validation.message
|
||||
return result
|
||||
|
||||
# 验证确认密码
|
||||
var confirm_validation = validate_confirm_password(password, confirm_password)
|
||||
if not confirm_validation.valid:
|
||||
result.field = "confirm"
|
||||
result.message = confirm_validation.message
|
||||
return result
|
||||
|
||||
# 验证验证码
|
||||
var code_validation = validate_verification_code(verification_code)
|
||||
if not code_validation.valid:
|
||||
result.field = "verification"
|
||||
result.message = code_validation.message
|
||||
return result
|
||||
|
||||
# 检查是否已发送验证码
|
||||
if not _has_sent_verification_code(email):
|
||||
result.field = "verification"
|
||||
result.message = "请先获取邮箱验证码"
|
||||
return result
|
||||
|
||||
result.valid = true
|
||||
return result
|
||||
|
||||
# 验证用户名
|
||||
func validate_username(username: String) -> Dictionary:
|
||||
var result = {"valid": false, "message": ""}
|
||||
|
||||
if username.is_empty():
|
||||
result.message = "用户名不能为空"
|
||||
return result
|
||||
|
||||
if not StringUtils.is_valid_username(username):
|
||||
if username.length() > 50:
|
||||
result.message = "用户名长度不能超过50字符"
|
||||
else:
|
||||
result.message = "用户名只能包含字母、数字和下划线"
|
||||
return result
|
||||
|
||||
result.valid = true
|
||||
return result
|
||||
|
||||
# 验证邮箱
|
||||
func validate_email(email: String) -> Dictionary:
|
||||
var result = {"valid": false, "message": ""}
|
||||
|
||||
if email.is_empty():
|
||||
result.message = "邮箱不能为空"
|
||||
return result
|
||||
|
||||
if not StringUtils.is_valid_email(email):
|
||||
result.message = "请输入有效的邮箱地址"
|
||||
return result
|
||||
|
||||
result.valid = true
|
||||
return result
|
||||
|
||||
# 验证密码
|
||||
func validate_password(password: String) -> Dictionary:
|
||||
return StringUtils.validate_password_strength(password)
|
||||
|
||||
# 验证确认密码
|
||||
func validate_confirm_password(password: String, confirm: String) -> Dictionary:
|
||||
var result = {"valid": false, "message": ""}
|
||||
|
||||
if confirm.is_empty():
|
||||
result.message = "确认密码不能为空"
|
||||
return result
|
||||
|
||||
if password != confirm:
|
||||
result.message = "两次输入的密码不一致"
|
||||
return result
|
||||
|
||||
result.valid = true
|
||||
return result
|
||||
|
||||
# 验证验证码
|
||||
func validate_verification_code(code: String) -> Dictionary:
|
||||
var result = {"valid": false, "message": ""}
|
||||
|
||||
if code.is_empty():
|
||||
result.message = "验证码不能为空"
|
||||
return result
|
||||
|
||||
if code.length() != 6:
|
||||
result.message = "验证码必须是6位数字"
|
||||
return result
|
||||
|
||||
for i in range(code.length()):
|
||||
var character = code[i]
|
||||
if not (character >= '0' and character <= '9'):
|
||||
result.message = "验证码必须是6位数字"
|
||||
return result
|
||||
|
||||
result.valid = true
|
||||
return result
|
||||
|
||||
# ============ 网络响应处理 ============
|
||||
|
||||
# 处理登录响应
|
||||
func _on_login_response(success: bool, data: Dictionary, error_info: Dictionary):
|
||||
_reset_login_state()
|
||||
|
||||
var result = ResponseHandler.handle_login_response(success, data, error_info)
|
||||
|
||||
if result.should_show_toast:
|
||||
show_toast_message.emit(result.message, result.success)
|
||||
|
||||
if result.success:
|
||||
var username = ""
|
||||
if data.has("data") and data.data.has("user"):
|
||||
var user_data = data.data.user
|
||||
if user_data.has("username"):
|
||||
username = user_data.username
|
||||
if user_data.has("id"):
|
||||
current_user_id = user_data.id
|
||||
print("AuthManager: Current User ID set to ", current_user_id)
|
||||
|
||||
# 延迟发送登录成功信号
|
||||
await Engine.get_main_loop().create_timer(1.0).timeout
|
||||
var token = ""
|
||||
if data.has("data") and data.data.has("access_token"):
|
||||
token = data.data.access_token
|
||||
login_success.emit(username, token)
|
||||
else:
|
||||
login_failed.emit(result.message)
|
||||
|
||||
# 处理验证码登录响应
|
||||
func _on_verification_login_response(success: bool, data: Dictionary, error_info: Dictionary):
|
||||
_reset_login_state()
|
||||
|
||||
var result = ResponseHandler.handle_verification_code_login_response(success, data, error_info)
|
||||
|
||||
if result.should_show_toast:
|
||||
show_toast_message.emit(result.message, result.success)
|
||||
|
||||
if result.success:
|
||||
var username = ""
|
||||
if data.has("data") and data.data.has("user"):
|
||||
var user_data = data.data.user
|
||||
if user_data.has("username"):
|
||||
username = user_data.username
|
||||
if user_data.has("id"):
|
||||
current_user_id = user_data.id
|
||||
print("AuthManager: Current User ID set to ", current_user_id)
|
||||
|
||||
await Engine.get_main_loop().create_timer(1.0).timeout
|
||||
login_success.emit(username, data.get("access_token", ""))
|
||||
else:
|
||||
login_failed.emit(result.message)
|
||||
|
||||
# 处理注册响应
|
||||
func _on_register_response(success: bool, data: Dictionary, error_info: Dictionary):
|
||||
_reset_register_state()
|
||||
|
||||
var result = ResponseHandler.handle_register_response(success, data, error_info)
|
||||
|
||||
if result.should_show_toast:
|
||||
show_toast_message.emit(result.message, result.success)
|
||||
|
||||
if result.success:
|
||||
register_success.emit(result.message)
|
||||
else:
|
||||
register_failed.emit(result.message)
|
||||
|
||||
# 处理发送验证码响应
|
||||
func _on_send_code_response(success: bool, data: Dictionary, error_info: Dictionary):
|
||||
var result = ResponseHandler.handle_send_verification_code_response(success, data, error_info)
|
||||
|
||||
if result.should_show_toast:
|
||||
show_toast_message.emit(result.message, result.success)
|
||||
|
||||
if result.success:
|
||||
verification_code_sent.emit(result.message)
|
||||
else:
|
||||
verification_code_failed.emit(result.message)
|
||||
_reset_verification_code_state(current_email)
|
||||
|
||||
# 处理发送登录验证码响应
|
||||
func _on_send_login_code_response(success: bool, data: Dictionary, error_info: Dictionary):
|
||||
button_state_changed.emit("get_code_btn", false, "获取验证码")
|
||||
|
||||
var result = ResponseHandler.handle_send_login_code_response(success, data, error_info)
|
||||
|
||||
if result.should_show_toast:
|
||||
show_toast_message.emit(result.message, result.success)
|
||||
|
||||
# 处理忘记密码响应
|
||||
func _on_forgot_password_response(success: bool, data: Dictionary, error_info: Dictionary):
|
||||
button_state_changed.emit("forgot_password_btn", false, "忘记密码")
|
||||
|
||||
var result = ResponseHandler.handle_send_login_code_response(success, data, error_info)
|
||||
|
||||
if result.should_show_toast:
|
||||
show_toast_message.emit(result.message, result.success)
|
||||
|
||||
# ============ 网络测试 ============
|
||||
|
||||
# 测试网络连接
|
||||
func test_network_connection():
|
||||
var request_id = NetworkManager.get_app_status(_on_network_test_response)
|
||||
if request_id != "":
|
||||
active_request_ids.append(request_id)
|
||||
|
||||
# 处理网络测试响应
|
||||
func _on_network_test_response(success: bool, data: Dictionary, error_info: Dictionary):
|
||||
var result = ResponseHandler.handle_network_test_response(success, data, error_info)
|
||||
network_status_changed.emit(result.success, result.message)
|
||||
|
||||
# ============ 私有辅助方法 ============
|
||||
|
||||
# 重置登录状态
|
||||
func _reset_login_state():
|
||||
is_processing = false
|
||||
button_state_changed.emit("main_btn", false, "进入小镇")
|
||||
|
||||
# 重置注册状态
|
||||
func _reset_register_state():
|
||||
is_processing = false
|
||||
button_state_changed.emit("register_btn", false, "注册")
|
||||
|
||||
# 检查是否可以发送验证码
|
||||
func _can_send_verification_code(email: String) -> bool:
|
||||
if not verification_codes_sent.has(email):
|
||||
return true
|
||||
|
||||
var email_data = verification_codes_sent[email]
|
||||
if not email_data.sent:
|
||||
return true
|
||||
|
||||
var current_time = Time.get_time_dict_from_system()
|
||||
var current_timestamp = current_time.hour * 3600 + current_time.minute * 60 + current_time.second
|
||||
|
||||
return (current_timestamp - email_data.time) >= code_cooldown
|
||||
|
||||
# 获取剩余冷却时间
|
||||
func get_remaining_cooldown_time(email: String) -> int:
|
||||
if not verification_codes_sent.has(email):
|
||||
return 0
|
||||
|
||||
var email_data = verification_codes_sent[email]
|
||||
var current_time = Time.get_time_dict_from_system()
|
||||
var current_timestamp = current_time.hour * 3600 + current_time.minute * 60 + current_time.second
|
||||
|
||||
return int(code_cooldown - (current_timestamp - email_data.time))
|
||||
|
||||
# 记录验证码发送状态
|
||||
func _record_verification_code_sent(email: String):
|
||||
var current_time = Time.get_time_dict_from_system()
|
||||
var current_timestamp = current_time.hour * 3600 + current_time.minute * 60 + current_time.second
|
||||
|
||||
if not verification_codes_sent.has(email):
|
||||
verification_codes_sent[email] = {}
|
||||
|
||||
verification_codes_sent[email].sent = true
|
||||
verification_codes_sent[email].time = current_timestamp
|
||||
current_email = email
|
||||
|
||||
# 重置验证码状态
|
||||
func _reset_verification_code_state(email: String):
|
||||
if verification_codes_sent.has(email):
|
||||
verification_codes_sent[email].sent = false
|
||||
|
||||
# 检查是否已发送验证码
|
||||
func _has_sent_verification_code(email: String) -> bool:
|
||||
if not verification_codes_sent.has(email):
|
||||
return false
|
||||
|
||||
return verification_codes_sent[email].get("sent", false)
|
||||
|
||||
# 验证标识符格式
|
||||
func _is_valid_identifier(identifier: String) -> bool:
|
||||
return StringUtils.is_valid_email(identifier) or _is_valid_phone(identifier)
|
||||
|
||||
# 验证手机号格式
|
||||
func _is_valid_phone(phone: String) -> bool:
|
||||
var regex = RegEx.new()
|
||||
regex.compile("^\\+?[1-9]\\d{1,14}$")
|
||||
return regex.search(phone) != null
|
||||
1
_Core/managers/AuthManager.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://bpdyraefv0yta
|
||||
142
_Core/managers/GameManager.gd
Normal file
@@ -0,0 +1,142 @@
|
||||
extends Node
|
||||
|
||||
# ============================================================================
|
||||
# GameManager.gd - 游戏管理器
|
||||
# ============================================================================
|
||||
# 全局单例管理器,负责游戏状态管理和生命周期控制
|
||||
#
|
||||
# 核心职责:
|
||||
# - 游戏状态切换 (加载、认证、游戏中、暂停等)
|
||||
# - 用户信息管理
|
||||
# - 全局配置访问
|
||||
# - 系统初始化和清理
|
||||
#
|
||||
# 使用方式:
|
||||
# GameManager.change_state(GameManager.GameState.IN_GAME)
|
||||
# GameManager.set_current_user("player123")
|
||||
#
|
||||
# 注意事项:
|
||||
# - 作为自动加载单例,全局可访问
|
||||
# - 状态变更会触发 game_state_changed 信号
|
||||
# - 状态切换应该通过 change_state() 方法进行
|
||||
# ============================================================================
|
||||
|
||||
# ============ 信号定义 ============
|
||||
|
||||
# 游戏状态变更信号
|
||||
# 参数: new_state - 新的游戏状态
|
||||
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) # 启动时进入认证状态
|
||||
|
||||
# ============ 状态管理方法 ============
|
||||
|
||||
# 切换游戏状态
|
||||
#
|
||||
# 参数:
|
||||
# new_state: GameState - 要切换到的新状态
|
||||
#
|
||||
# 功能:
|
||||
# - 检查状态是否需要切换
|
||||
# - 记录状态变更历史
|
||||
# - 发送状态变更信号
|
||||
# - 输出状态变更日志
|
||||
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)
|
||||
|
||||
# 获取当前游戏状态
|
||||
#
|
||||
# 返回值:
|
||||
# GameState - 当前的游戏状态
|
||||
func get_current_state() -> GameState:
|
||||
return current_state
|
||||
|
||||
# 获取上一个游戏状态
|
||||
#
|
||||
# 返回值:
|
||||
# GameState - 上一个游戏状态
|
||||
#
|
||||
# 使用场景:
|
||||
# - 从暂停状态恢复时,返回到之前的状态
|
||||
# - 错误处理时回退到安全状态
|
||||
func get_previous_state() -> GameState:
|
||||
return previous_state
|
||||
|
||||
# ============ 用户管理方法 ============
|
||||
|
||||
# 设置当前登录用户
|
||||
#
|
||||
# 参数:
|
||||
# username: String - 用户名
|
||||
#
|
||||
# 功能:
|
||||
# - 存储当前登录用户信息
|
||||
# - 输出用户设置日志
|
||||
#
|
||||
# 注意事项:
|
||||
# - 用户登录成功后调用此方法
|
||||
# - 用户登出时应传入空字符串
|
||||
func set_current_user(username: String):
|
||||
current_user = username
|
||||
print("当前用户设置为: ", username)
|
||||
|
||||
# 获取当前登录用户
|
||||
#
|
||||
# 返回值:
|
||||
# String - 当前登录的用户名,未登录时为空字符串
|
||||
func get_current_user() -> String:
|
||||
return current_user
|
||||
|
||||
# 检查用户是否已登录
|
||||
#
|
||||
# 返回值:
|
||||
# bool - true表示已登录,false表示未登录
|
||||
#
|
||||
# 使用场景:
|
||||
# - 进入需要登录的功能前检查
|
||||
# - UI显示逻辑判断
|
||||
func is_user_logged_in() -> bool:
|
||||
return not current_user.is_empty()
|
||||
1
_Core/managers/GameManager.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://cd8fn73ysjxh8
|
||||
706
_Core/managers/NetworkManager.gd
Normal file
@@ -0,0 +1,706 @@
|
||||
extends Node
|
||||
|
||||
# ============================================================================
|
||||
# NetworkManager.gd - 网络请求管理器
|
||||
# ============================================================================
|
||||
# 全局单例管理器,统一处理所有HTTP请求
|
||||
#
|
||||
# 核心职责:
|
||||
# - 统一的HTTP请求接口 (GET, POST, PUT, DELETE, PATCH)
|
||||
# - 认证相关API封装 (登录、注册、验证码等)
|
||||
# - 请求状态管理和错误处理
|
||||
# - 支持API v1.1.1规范的响应处理
|
||||
#
|
||||
# 使用方式:
|
||||
# NetworkManager.login("user@example.com", "password", callback)
|
||||
# var request_id = NetworkManager.get_request("/api/data", callback)
|
||||
#
|
||||
# 注意事项:
|
||||
# - 作为自动加载单例,全局可访问
|
||||
# - 所有请求都是异步的,通过回调函数或信号处理结果
|
||||
# - 支持请求超时和取消功能
|
||||
# - 自动处理JSON序列化和反序列化
|
||||
# ============================================================================
|
||||
|
||||
# ============ 信号定义 ============
|
||||
|
||||
# 请求完成信号
|
||||
# 参数:
|
||||
# request_id: String - 请求唯一标识符
|
||||
# success: bool - 请求是否成功
|
||||
# data: Dictionary - 响应数据
|
||||
signal request_completed(request_id: String, success: bool, data: Dictionary)
|
||||
|
||||
# 请求失败信号
|
||||
# 参数:
|
||||
# request_id: String - 请求唯一标识符
|
||||
# error_type: String - 错误类型名称
|
||||
# message: String - 错误消息
|
||||
signal request_failed(request_id: String, error_type: String, message: String)
|
||||
|
||||
# ============ 常量定义 ============
|
||||
|
||||
# API基础URL - 所有请求的根地址
|
||||
# [Remote] 正式环境地址 (实际正式项目用此地址)
|
||||
# [Remote] 正式环境地址 (实际正式项目用此地址)
|
||||
const API_BASE_URL = "https://whaletownend.xinghangee.icu"
|
||||
|
||||
# [Local] 本地调试地址 (本地调试用此地址)
|
||||
# const API_BASE_URL = "http://localhost:3000"
|
||||
|
||||
# 默认请求超时时间(秒)
|
||||
const DEFAULT_TIMEOUT = 30.0
|
||||
|
||||
# ============ 枚举定义 ============
|
||||
|
||||
# HTTP请求方法枚举
|
||||
enum RequestType {
|
||||
GET, # 获取数据
|
||||
POST, # 创建数据
|
||||
PUT, # 更新数据
|
||||
DELETE, # 删除数据
|
||||
PATCH # 部分更新数据
|
||||
}
|
||||
|
||||
# 错误类型枚举
|
||||
# 用于分类不同类型的网络错误
|
||||
enum ErrorType {
|
||||
NETWORK_ERROR, # 网络连接错误 - 无法连接到服务器
|
||||
TIMEOUT_ERROR, # 请求超时 - 服务器响应时间过长
|
||||
PARSE_ERROR, # JSON解析错误 - 服务器返回格式错误
|
||||
HTTP_ERROR, # HTTP状态码错误 - 4xx, 5xx状态码
|
||||
BUSINESS_ERROR # 业务逻辑错误 - API返回的业务错误
|
||||
}
|
||||
|
||||
# ============ 请求信息类 ============
|
||||
|
||||
# 请求信息封装类
|
||||
# 存储单个HTTP请求的所有相关信息
|
||||
class RequestInfo:
|
||||
var id: String # 请求唯一标识符
|
||||
var url: String # 完整的请求URL
|
||||
var method: RequestType # HTTP请求方法
|
||||
var headers: PackedStringArray # 请求头数组
|
||||
var body: String # 请求体内容
|
||||
var timeout: float # 超时时间(秒)
|
||||
var start_time: float # 请求开始时间戳
|
||||
var http_request: HTTPRequest # Godot HTTPRequest节点引用
|
||||
var callback: Callable # 完成时的回调函数
|
||||
|
||||
# 构造函数
|
||||
#
|
||||
# 参数:
|
||||
# request_id: String - 请求唯一标识符
|
||||
# request_url: String - 请求URL
|
||||
# request_method: RequestType - HTTP方法
|
||||
# request_headers: PackedStringArray - 请求头(可选)
|
||||
# request_body: String - 请求体(可选)
|
||||
# request_timeout: float - 超时时间(可选,默认使用DEFAULT_TIMEOUT)
|
||||
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 = {} # 存储所有活动请求 {request_id: RequestInfo}
|
||||
var request_counter: int = 0 # 请求计数器,用于生成唯一ID
|
||||
|
||||
# ============ 生命周期方法 ============
|
||||
|
||||
# 初始化网络管理器
|
||||
# 在节点准备就绪时调用
|
||||
func _ready():
|
||||
print("NetworkManager 已初始化")
|
||||
|
||||
# ============ 公共API接口 ============
|
||||
|
||||
# 发送GET请求
|
||||
#
|
||||
# 参数:
|
||||
# endpoint: String - API端点路径(如: "/api/users")
|
||||
# callback: Callable - 完成时的回调函数(可选)
|
||||
# timeout: float - 超时时间(可选,默认30秒)
|
||||
#
|
||||
# 返回值:
|
||||
# String - 请求ID,可用于取消请求或跟踪状态
|
||||
#
|
||||
# 使用示例:
|
||||
# var request_id = NetworkManager.get_request("/api/users", my_callback)
|
||||
func get_request(endpoint: String, callback: Callable = Callable(), timeout: float = DEFAULT_TIMEOUT) -> String:
|
||||
return send_request(endpoint, RequestType.GET, [], "", callback, timeout)
|
||||
|
||||
# 发送POST请求
|
||||
#
|
||||
# 参数:
|
||||
# endpoint: String - API端点路径
|
||||
# data: Dictionary - 要发送的数据(将自动转换为JSON)
|
||||
# callback: Callable - 完成时的回调函数(可选)
|
||||
# timeout: float - 超时时间(可选)
|
||||
#
|
||||
# 返回值:
|
||||
# String - 请求ID
|
||||
#
|
||||
# 使用示例:
|
||||
# var data = {"name": "张三", "age": 25}
|
||||
# var request_id = NetworkManager.post_request("/api/users", data, my_callback)
|
||||
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请求
|
||||
#
|
||||
# 参数:
|
||||
# endpoint: String - API端点路径
|
||||
# data: Dictionary - 要更新的数据
|
||||
# callback: Callable - 完成时的回调函数(可选)
|
||||
# timeout: float - 超时时间(可选)
|
||||
#
|
||||
# 返回值:
|
||||
# String - 请求ID
|
||||
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请求
|
||||
#
|
||||
# 参数:
|
||||
# endpoint: String - API端点路径
|
||||
# callback: Callable - 完成时的回调函数(可选)
|
||||
# timeout: float - 超时时间(可选)
|
||||
#
|
||||
# 返回值:
|
||||
# String - 请求ID
|
||||
func delete_request(endpoint: String, callback: Callable = Callable(), timeout: float = DEFAULT_TIMEOUT) -> String:
|
||||
return send_request(endpoint, RequestType.DELETE, [], "", callback, timeout)
|
||||
|
||||
# ============ 认证相关API ============
|
||||
|
||||
# 用户登录
|
||||
#
|
||||
# 参数:
|
||||
# identifier: String - 用户标识符(邮箱或手机号)
|
||||
# password: String - 用户密码
|
||||
# callback: Callable - 完成时的回调函数(可选)
|
||||
#
|
||||
# 返回值:
|
||||
# String - 请求ID
|
||||
#
|
||||
# 回调函数签名:
|
||||
# func callback(success: bool, data: Dictionary, error_info: Dictionary)
|
||||
#
|
||||
# 使用示例:
|
||||
# NetworkManager.login("user@example.com", "password123", func(success, data, error):
|
||||
# if success:
|
||||
# print("登录成功: ", data)
|
||||
# else:
|
||||
# print("登录失败: ", error.message)
|
||||
# )
|
||||
func login(identifier: String, password: String, callback: Callable = Callable()) -> String:
|
||||
var data = {
|
||||
"identifier": identifier,
|
||||
"password": password
|
||||
}
|
||||
return post_request("/auth/login", data, callback)
|
||||
|
||||
# 验证码登录
|
||||
#
|
||||
# 参数:
|
||||
# identifier: String - 用户标识符(邮箱或手机号)
|
||||
# verification_code: String - 验证码
|
||||
# callback: Callable - 完成时的回调函数(可选)
|
||||
#
|
||||
# 返回值:
|
||||
# String - 请求ID
|
||||
#
|
||||
# 使用场景:
|
||||
# - 用户忘记密码时的替代登录方式
|
||||
# - 提供更安全的登录选项
|
||||
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)
|
||||
|
||||
# 发送登录验证码
|
||||
#
|
||||
# 参数:
|
||||
# identifier: String - 用户标识符(邮箱或手机号)
|
||||
# callback: Callable - 完成时的回调函数(可选)
|
||||
#
|
||||
# 返回值:
|
||||
# String - 请求ID
|
||||
#
|
||||
# 功能:
|
||||
# - 向已注册用户发送登录验证码
|
||||
# - 支持邮箱和手机号
|
||||
# - 有频率限制保护
|
||||
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)
|
||||
|
||||
# 用户注册
|
||||
#
|
||||
# 参数:
|
||||
# username: String - 用户名
|
||||
# password: String - 密码
|
||||
# nickname: String - 昵称
|
||||
# email: String - 邮箱地址(可选)
|
||||
# email_verification_code: String - 邮箱验证码(可选)
|
||||
# callback: Callable - 完成时的回调函数(可选)
|
||||
#
|
||||
# 返回值:
|
||||
# String - 请求ID
|
||||
#
|
||||
# 注意事项:
|
||||
# - 如果提供邮箱,建议同时提供验证码
|
||||
# - 用户名和邮箱必须唯一
|
||||
# - 密码需要符合安全要求
|
||||
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)
|
||||
|
||||
# 发送邮箱验证码
|
||||
#
|
||||
# 参数:
|
||||
# email: String - 邮箱地址
|
||||
# callback: Callable - 完成时的回调函数(可选)
|
||||
#
|
||||
# 返回值:
|
||||
# String - 请求ID
|
||||
#
|
||||
# 功能:
|
||||
# - 向指定邮箱发送验证码
|
||||
# - 用于注册时的邮箱验证
|
||||
# - 支持测试模式(开发环境)
|
||||
func send_email_verification(email: String, callback: Callable = Callable()) -> String:
|
||||
var data = {"email": email}
|
||||
return post_request("/auth/send-email-verification", data, callback)
|
||||
|
||||
# 验证邮箱
|
||||
#
|
||||
# 参数:
|
||||
# email: String - 邮箱地址
|
||||
# verification_code: String - 验证码
|
||||
# callback: Callable - 完成时的回调函数(可选)
|
||||
#
|
||||
# 返回值:
|
||||
# String - 请求ID
|
||||
#
|
||||
# 功能:
|
||||
# - 验证邮箱验证码的有效性
|
||||
# - 通常在注册流程中使用
|
||||
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)
|
||||
|
||||
# 获取应用状态
|
||||
#
|
||||
# 参数:
|
||||
# callback: Callable - 完成时的回调函数(可选)
|
||||
#
|
||||
# 返回值:
|
||||
# String - 请求ID
|
||||
#
|
||||
# 功能:
|
||||
# - 检查API服务器状态
|
||||
# - 获取应用基本信息
|
||||
# - 用于网络连接测试
|
||||
func get_app_status(callback: Callable = Callable()) -> String:
|
||||
return get_request("/", callback)
|
||||
|
||||
# 重新发送邮箱验证码
|
||||
#
|
||||
# 参数:
|
||||
# email: String - 邮箱地址
|
||||
# callback: Callable - 完成时的回调函数(可选)
|
||||
#
|
||||
# 返回值:
|
||||
# String - 请求ID
|
||||
#
|
||||
# 使用场景:
|
||||
# - 用户未收到验证码时重新发送
|
||||
# - 验证码过期后重新获取
|
||||
func resend_email_verification(email: String, callback: Callable = Callable()) -> String:
|
||||
var data = {"email": email}
|
||||
return post_request("/auth/resend-email-verification", data, callback)
|
||||
|
||||
# 忘记密码 - 发送重置验证码
|
||||
#
|
||||
# 参数:
|
||||
# identifier: String - 用户标识符(邮箱或手机号)
|
||||
# callback: Callable - 完成时的回调函数(可选)
|
||||
#
|
||||
# 返回值:
|
||||
# String - 请求ID
|
||||
#
|
||||
# 功能:
|
||||
# - 向用户发送密码重置验证码
|
||||
# - 用于密码找回流程的第一步
|
||||
func forgot_password(identifier: String, callback: Callable = Callable()) -> String:
|
||||
var data = {"identifier": identifier}
|
||||
return post_request("/auth/forgot-password", data, callback)
|
||||
|
||||
# 重置密码
|
||||
#
|
||||
# 参数:
|
||||
# identifier: String - 用户标识符
|
||||
# verification_code: String - 重置验证码
|
||||
# new_password: String - 新密码
|
||||
# callback: Callable - 完成时的回调函数(可选)
|
||||
#
|
||||
# 返回值:
|
||||
# String - 请求ID
|
||||
#
|
||||
# 功能:
|
||||
# - 使用验证码重置用户密码
|
||||
# - 密码找回流程的第二步
|
||||
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)
|
||||
|
||||
# 修改密码
|
||||
#
|
||||
# 参数:
|
||||
# user_id: String - 用户ID
|
||||
# old_password: String - 旧密码
|
||||
# new_password: String - 新密码
|
||||
# callback: Callable - 完成时的回调函数(可选)
|
||||
#
|
||||
# 返回值:
|
||||
# String - 请求ID
|
||||
#
|
||||
# 功能:
|
||||
# - 已登录用户修改密码
|
||||
# - 需要验证旧密码
|
||||
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登录
|
||||
#
|
||||
# 参数:
|
||||
# github_id: String - GitHub用户ID
|
||||
# username: String - GitHub用户名
|
||||
# nickname: String - 显示昵称
|
||||
# email: String - GitHub邮箱
|
||||
# avatar_url: String - 头像URL(可选)
|
||||
# callback: Callable - 完成时的回调函数(可选)
|
||||
#
|
||||
# 返回值:
|
||||
# String - 请求ID
|
||||
#
|
||||
# 功能:
|
||||
# - 通过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
|
||||
}
|
||||
|
||||
# 可选头像URL
|
||||
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, response_headers: PackedStringArray, response_body: PackedByteArray):
|
||||
_on_request_completed(request_id, result, response_code, response_headers, response_body)
|
||||
)
|
||||
|
||||
# 发送请求
|
||||
var godot_method = _convert_to_godot_method(method)
|
||||
var error = http_request.request(full_url, headers, godot_method, body)
|
||||
|
||||
print("=== 发送网络请求 ===")
|
||||
print("请求ID: ", request_id)
|
||||
print("URL: ", full_url)
|
||||
print("方法: ", RequestType.keys()[method])
|
||||
print("Headers: ", headers)
|
||||
print("Body: ", body if body.length() < 200 else body.substr(0, 200) + "...")
|
||||
print("发送结果: ", error)
|
||||
|
||||
if error != OK:
|
||||
print("请求发送失败,错误代码: ", error)
|
||||
_handle_request_error(request_id, ErrorType.NETWORK_ERROR, "网络请求发送失败: " + str(error))
|
||||
return ""
|
||||
|
||||
return request_id
|
||||
|
||||
# 请求完成回调
|
||||
func _on_request_completed(request_id: String, result: int, response_code: int,
|
||||
headers: PackedStringArray, body: PackedByteArray):
|
||||
print("=== 网络请求完成 ===")
|
||||
print("请求ID: ", request_id)
|
||||
print("结果: ", result)
|
||||
print("状态码: ", response_code)
|
||||
print("响应头: ", headers)
|
||||
|
||||
# 获取请求信息
|
||||
if not active_requests.has(request_id):
|
||||
print("警告: 未找到请求ID ", request_id)
|
||||
return
|
||||
|
||||
var _request_info = active_requests[request_id]
|
||||
var response_text = body.get_string_from_utf8()
|
||||
|
||||
print("响应体长度: ", body.size(), " 字节")
|
||||
print("响应内容: ", response_text if response_text.length() < 500 else response_text.substr(0, 500) + "...")
|
||||
|
||||
# 处理网络连接失败
|
||||
if response_code == 0:
|
||||
_handle_request_error(request_id, ErrorType.NETWORK_ERROR, "网络连接失败,请检查网络连接")
|
||||
return
|
||||
|
||||
# 解析JSON响应
|
||||
var json = JSON.new()
|
||||
var parse_result = json.parse(response_text)
|
||||
if parse_result != OK:
|
||||
_handle_request_error(request_id, ErrorType.PARSE_ERROR, "服务器响应格式错误")
|
||||
return
|
||||
|
||||
var response_data = json.data
|
||||
|
||||
# 处理响应
|
||||
_handle_response(request_id, response_code, response_data)
|
||||
|
||||
# 处理响应 - 支持API v1.1.1的状态码
|
||||
func _handle_response(request_id: String, response_code: int, data: Dictionary):
|
||||
var request_info = active_requests[request_id]
|
||||
|
||||
# 检查业务成功标志
|
||||
var success = data.get("success", true) # 默认true保持向后兼容
|
||||
var error_code = data.get("error_code", "")
|
||||
var message = data.get("message", "")
|
||||
|
||||
# 判断请求是否成功
|
||||
var is_success = false
|
||||
|
||||
# HTTP成功状态码且业务成功
|
||||
if (response_code >= 200 and response_code < 300) and success:
|
||||
is_success = true
|
||||
# 特殊情况:206测试模式 - 根据API文档,这是成功的测试模式响应
|
||||
elif response_code == 206 and error_code == "TEST_MODE_ONLY":
|
||||
is_success = true
|
||||
print("🧪 测试模式响应: ", message)
|
||||
# 201创建成功
|
||||
elif response_code == 201:
|
||||
is_success = true
|
||||
|
||||
if is_success:
|
||||
print("✅ 请求成功: ", request_id)
|
||||
# 发送成功信号
|
||||
request_completed.emit(request_id, true, data)
|
||||
|
||||
# 调用回调函数
|
||||
if request_info.callback.is_valid():
|
||||
request_info.callback.call(true, data, {})
|
||||
else:
|
||||
print("❌ 请求失败: ", request_id, " - HTTP:", response_code, " 错误码:", error_code, " 消息:", message)
|
||||
|
||||
# 确定错误类型
|
||||
var error_type = _determine_error_type(response_code, error_code)
|
||||
|
||||
# 发送失败信号
|
||||
request_failed.emit(request_id, ErrorType.keys()[error_type], message)
|
||||
|
||||
# 调用回调函数
|
||||
if request_info.callback.is_valid():
|
||||
var error_info = {
|
||||
"response_code": response_code,
|
||||
"error_code": error_code,
|
||||
"message": message,
|
||||
"error_type": error_type
|
||||
}
|
||||
request_info.callback.call(false, data, error_info)
|
||||
|
||||
# 清理请求
|
||||
_cleanup_request(request_id)
|
||||
|
||||
# 处理请求错误
|
||||
func _handle_request_error(request_id: String, error_type: ErrorType, message: String):
|
||||
print("❌ 请求错误: ", request_id, " - ", message)
|
||||
|
||||
# 发送错误信号
|
||||
request_failed.emit(request_id, ErrorType.keys()[error_type], message)
|
||||
|
||||
# 调用回调函数
|
||||
if active_requests.has(request_id):
|
||||
var request_info = active_requests[request_id]
|
||||
if request_info.callback.is_valid():
|
||||
var error_info = {
|
||||
"error_type": error_type,
|
||||
"message": message
|
||||
}
|
||||
request_info.callback.call(false, {}, error_info)
|
||||
|
||||
# 清理请求
|
||||
_cleanup_request(request_id)
|
||||
|
||||
# 确定错误类型 - 支持更多状态码
|
||||
func _determine_error_type(response_code: int, error_code: String) -> ErrorType:
|
||||
# 根据错误码判断
|
||||
match error_code:
|
||||
"SERVICE_UNAVAILABLE":
|
||||
return ErrorType.BUSINESS_ERROR
|
||||
"TOO_MANY_REQUESTS":
|
||||
return ErrorType.BUSINESS_ERROR
|
||||
"TEST_MODE_ONLY":
|
||||
return ErrorType.BUSINESS_ERROR
|
||||
"SEND_EMAIL_VERIFICATION_FAILED", "REGISTER_FAILED":
|
||||
# 这些可能是409冲突或其他业务错误
|
||||
return ErrorType.BUSINESS_ERROR
|
||||
_:
|
||||
# 根据HTTP状态码判断
|
||||
match response_code:
|
||||
409: # 资源冲突
|
||||
return ErrorType.BUSINESS_ERROR
|
||||
206: # 测试模式
|
||||
return ErrorType.BUSINESS_ERROR
|
||||
429: # 频率限制
|
||||
return ErrorType.BUSINESS_ERROR
|
||||
_:
|
||||
if response_code >= 400 and response_code < 500:
|
||||
return ErrorType.HTTP_ERROR
|
||||
elif response_code >= 500:
|
||||
return ErrorType.HTTP_ERROR
|
||||
else:
|
||||
return ErrorType.BUSINESS_ERROR
|
||||
|
||||
# 清理请求资源
|
||||
func _cleanup_request(request_id: String):
|
||||
if active_requests.has(request_id):
|
||||
var request_info = active_requests[request_id]
|
||||
|
||||
# 移除HTTPRequest节点
|
||||
if is_instance_valid(request_info.http_request):
|
||||
request_info.http_request.queue_free()
|
||||
|
||||
# 从活动请求中移除
|
||||
active_requests.erase(request_id)
|
||||
|
||||
print("🧹 清理请求: ", request_id)
|
||||
|
||||
# 转换请求方法
|
||||
func _convert_to_godot_method(method: RequestType) -> HTTPClient.Method:
|
||||
match method:
|
||||
RequestType.GET:
|
||||
return HTTPClient.METHOD_GET
|
||||
RequestType.POST:
|
||||
return HTTPClient.METHOD_POST
|
||||
RequestType.PUT:
|
||||
return HTTPClient.METHOD_PUT
|
||||
RequestType.DELETE:
|
||||
return HTTPClient.METHOD_DELETE
|
||||
RequestType.PATCH:
|
||||
return HTTPClient.METHOD_PATCH
|
||||
_:
|
||||
return HTTPClient.METHOD_GET
|
||||
|
||||
# ============ 工具方法 ============
|
||||
|
||||
# 取消请求
|
||||
func cancel_request(request_id: String) -> bool:
|
||||
if active_requests.has(request_id):
|
||||
print("🚫 取消请求: ", request_id)
|
||||
_cleanup_request(request_id)
|
||||
return true
|
||||
return false
|
||||
|
||||
# 取消所有请求
|
||||
func cancel_all_requests():
|
||||
print("🚫 取消所有请求")
|
||||
var request_ids = active_requests.keys()
|
||||
for request_id in request_ids:
|
||||
cancel_request(request_id)
|
||||
|
||||
# 获取活动请求数量
|
||||
func get_active_request_count() -> int:
|
||||
return active_requests.size()
|
||||
|
||||
# 检查请求是否活动
|
||||
func is_request_active(request_id: String) -> bool:
|
||||
return active_requests.has(request_id)
|
||||
|
||||
# 获取请求信息
|
||||
func get_request_info(request_id: String) -> Dictionary:
|
||||
if active_requests.has(request_id):
|
||||
var info = active_requests[request_id]
|
||||
return {
|
||||
"id": info.id,
|
||||
"url": info.url,
|
||||
"method": RequestType.keys()[info.method],
|
||||
"start_time": info.start_time,
|
||||
"timeout": info.timeout
|
||||
}
|
||||
return {}
|
||||
|
||||
func _notification(what):
|
||||
if what == NOTIFICATION_WM_CLOSE_REQUEST:
|
||||
# 应用关闭时取消所有请求
|
||||
cancel_all_requests()
|
||||
1
_Core/managers/NetworkManager.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://dr7v30wheetca
|
||||
590
_Core/managers/ResponseHandler.gd
Normal file
@@ -0,0 +1,590 @@
|
||||
extends Node
|
||||
|
||||
# 响应处理器 - 统一处理API响应和错误
|
||||
|
||||
# 响应处理结果
|
||||
class ResponseResult:
|
||||
var success: bool
|
||||
var message: String
|
||||
var toast_type: String # "success" 或 "error"
|
||||
var data: Dictionary
|
||||
var should_show_toast: bool
|
||||
var custom_action: Callable
|
||||
|
||||
func _init():
|
||||
success = false
|
||||
message = ""
|
||||
toast_type = "error"
|
||||
data = {}
|
||||
should_show_toast = true
|
||||
custom_action = Callable()
|
||||
|
||||
# 错误码映射表 - 根据API v1.1.1更新
|
||||
const ERROR_CODE_MESSAGES = {
|
||||
# 登录相关
|
||||
"LOGIN_FAILED": "登录失败",
|
||||
"VERIFICATION_CODE_LOGIN_FAILED": "验证码错误或已过期",
|
||||
"EMAIL_NOT_VERIFIED": "请先验证邮箱",
|
||||
|
||||
# 注册相关
|
||||
"REGISTER_FAILED": "注册失败",
|
||||
|
||||
# 验证码相关
|
||||
"SEND_CODE_FAILED": "发送验证码失败",
|
||||
"SEND_LOGIN_CODE_FAILED": "发送登录验证码失败",
|
||||
"SEND_EMAIL_VERIFICATION_FAILED": "发送邮箱验证码失败",
|
||||
"RESEND_EMAIL_VERIFICATION_FAILED": "重新发送验证码失败",
|
||||
"EMAIL_VERIFICATION_FAILED": "邮箱验证失败",
|
||||
"RESET_PASSWORD_FAILED": "重置密码失败",
|
||||
"CHANGE_PASSWORD_FAILED": "修改密码失败",
|
||||
"VERIFICATION_CODE_EXPIRED": "验证码已过期",
|
||||
"VERIFICATION_CODE_INVALID": "验证码无效",
|
||||
"VERIFICATION_CODE_ATTEMPTS_EXCEEDED": "验证码尝试次数过多",
|
||||
"VERIFICATION_CODE_RATE_LIMITED": "验证码发送过于频繁",
|
||||
"VERIFICATION_CODE_HOURLY_LIMIT": "验证码每小时发送次数已达上限",
|
||||
|
||||
# 用户状态相关
|
||||
"USER_NOT_FOUND": "用户不存在",
|
||||
"INVALID_IDENTIFIER": "请输入有效的邮箱或手机号",
|
||||
"USER_STATUS_UPDATE_FAILED": "用户状态更新失败",
|
||||
|
||||
# 系统状态相关
|
||||
"TEST_MODE_ONLY": "测试模式",
|
||||
"TOO_MANY_REQUESTS": "请求过于频繁,请稍后再试",
|
||||
"SERVICE_UNAVAILABLE": "系统维护中,请稍后再试",
|
||||
|
||||
# 权限相关
|
||||
"UNAUTHORIZED": "未授权访问",
|
||||
"FORBIDDEN": "权限不足",
|
||||
"ADMIN_LOGIN_FAILED": "管理员登录失败",
|
||||
|
||||
# 其他
|
||||
"VALIDATION_FAILED": "参数验证失败",
|
||||
"UNSUPPORTED_MEDIA_TYPE": "不支持的请求格式",
|
||||
"REQUEST_TIMEOUT": "请求超时"
|
||||
}
|
||||
|
||||
# HTTP状态码消息映射 - 根据API v1.1.1更新
|
||||
const HTTP_STATUS_MESSAGES = {
|
||||
200: "请求成功",
|
||||
201: "创建成功",
|
||||
206: "测试模式",
|
||||
400: "请求参数错误",
|
||||
401: "认证失败",
|
||||
403: "权限不足",
|
||||
404: "资源不存在",
|
||||
408: "请求超时",
|
||||
409: "资源冲突",
|
||||
415: "不支持的媒体类型",
|
||||
429: "请求过于频繁",
|
||||
500: "服务器内部错误",
|
||||
503: "服务不可用"
|
||||
}
|
||||
|
||||
# ============ 主要处理方法 ============
|
||||
|
||||
# 处理登录响应
|
||||
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
|
||||
|
||||
# 处理验证码登录响应
|
||||
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
|
||||
|
||||
# 处理发送验证码响应 - 支持邮箱冲突检测
|
||||
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
|
||||
|
||||
# 处理发送登录验证码响应
|
||||
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
|
||||
|
||||
# 处理注册响应
|
||||
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
|
||||
|
||||
# 处理邮箱验证响应
|
||||
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
|
||||
|
||||
# 处理重新发送邮箱验证码响应
|
||||
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
|
||||
|
||||
# 处理忘记密码响应
|
||||
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
|
||||
|
||||
# 处理重置密码响应
|
||||
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
|
||||
|
||||
# ============ 错误处理方法 ============
|
||||
|
||||
# 处理登录错误
|
||||
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
|
||||
|
||||
# 处理验证码登录错误
|
||||
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
|
||||
|
||||
# 处理发送验证码错误 - 支持邮箱冲突检测和频率限制
|
||||
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
|
||||
|
||||
# 处理发送登录验证码错误
|
||||
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冲突状态码
|
||||
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
|
||||
|
||||
# 处理邮箱验证错误
|
||||
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
|
||||
|
||||
# 处理网络测试响应
|
||||
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
|
||||
|
||||
# 处理重新发送邮箱验证码错误
|
||||
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
|
||||
|
||||
# 处理忘记密码错误
|
||||
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
|
||||
|
||||
# 处理重置密码错误
|
||||
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
|
||||
|
||||
# ============ 工具方法 ============
|
||||
|
||||
# 获取错误消息 - 支持更多状态码和错误处理
|
||||
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 "操作失败"
|
||||
|
||||
# 处理频率限制消息
|
||||
func _handle_rate_limit_message(message: String, _error_info: Dictionary) -> String:
|
||||
# 可以根据throttle_info提供更详细的信息
|
||||
return message + ",请稍后再试"
|
||||
|
||||
# 处理维护模式消息
|
||||
func _handle_maintenance_message(_message: String, _error_info: Dictionary) -> String:
|
||||
# 可以根据maintenance_info提供更详细的信息
|
||||
return "系统维护中,请稍后再试"
|
||||
|
||||
# 通用响应处理器 - 支持更多操作类型
|
||||
func handle_response(operation_type: String, success: bool, data: Dictionary, error_info: Dictionary = {}) -> ResponseResult:
|
||||
match operation_type:
|
||||
"login":
|
||||
return handle_login_response(success, data, error_info)
|
||||
"verification_code_login":
|
||||
return handle_verification_code_login_response(success, data, error_info)
|
||||
"send_code":
|
||||
return handle_send_verification_code_response(success, data, error_info)
|
||||
"send_login_code":
|
||||
return handle_send_login_code_response(success, data, error_info)
|
||||
"register":
|
||||
return handle_register_response(success, data, error_info)
|
||||
"verify_email":
|
||||
return handle_verify_email_response(success, data, error_info)
|
||||
"resend_email_verification":
|
||||
return handle_resend_email_verification_response(success, data, error_info)
|
||||
"forgot_password":
|
||||
return handle_forgot_password_response(success, data, error_info)
|
||||
"reset_password":
|
||||
return handle_reset_password_response(success, data, error_info)
|
||||
"network_test":
|
||||
return handle_network_test_response(success, data, error_info)
|
||||
_:
|
||||
# 通用处理
|
||||
var result = ResponseResult.new()
|
||||
if success:
|
||||
result.success = true
|
||||
result.message = "✅ 操作成功"
|
||||
result.toast_type = "success"
|
||||
else:
|
||||
result.success = false
|
||||
result.message = _get_error_message(data.get("error_code", ""), data.get("message", "操作失败"), error_info)
|
||||
result.toast_type = "error"
|
||||
return result
|
||||
1
_Core/managers/ResponseHandler.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://nseguk2ytiw6
|
||||
215
_Core/managers/SceneManager.gd
Normal file
@@ -0,0 +1,215 @@
|
||||
extends Node
|
||||
|
||||
# ============================================================================
|
||||
# SceneManager.gd - 场景管理器
|
||||
# ============================================================================
|
||||
# 全局单例管理器,负责场景切换和管理
|
||||
#
|
||||
# 核心职责:
|
||||
# - 场景切换的统一接口
|
||||
# - 场景路径映射管理
|
||||
# - 场景切换过渡效果
|
||||
# - 场景状态跟踪
|
||||
#
|
||||
# 使用方式:
|
||||
# SceneManager.change_scene("main")
|
||||
# SceneManager.register_scene("custom", "res://scenes/custom.tscn")
|
||||
#
|
||||
# 注意事项:
|
||||
# - 作为自动加载单例,全局可访问
|
||||
# - 场景切换是异步操作,支持过渡效果
|
||||
# - 场景名称必须在 scene_paths 中注册
|
||||
# ============================================================================
|
||||
|
||||
# ============ 信号定义 ============
|
||||
|
||||
# 场景切换完成信号
|
||||
# 参数: scene_name - 切换到的场景名称
|
||||
signal scene_changed(scene_name: String)
|
||||
|
||||
# 场景切换开始信号
|
||||
# 参数: scene_name - 即将切换到的场景名称
|
||||
signal scene_change_started(scene_name: String)
|
||||
|
||||
# ============ 成员变量 ============
|
||||
|
||||
# 场景状态
|
||||
var current_scene_name: String = "" # 当前场景名称
|
||||
var is_changing_scene: bool = false # 是否正在切换场景
|
||||
var _next_scene_position: Variant = null # 下一个场景的初始位置 (Vector2 or null)
|
||||
var _next_spawn_name: String = "" # 下一个场景的出生点名称 (String)
|
||||
|
||||
# 场景路径映射表
|
||||
# 将场景名称映射到实际的文件路径
|
||||
# 便于统一管理和修改场景路径
|
||||
var scene_paths: Dictionary = {
|
||||
"main": "res://scenes/MainScene.tscn", # 主场景 - 游戏入口
|
||||
"auth": "res://scenes/ui/LoginWindow.tscn", # 认证场景 - 登录窗口
|
||||
"game": "res://scenes/maps/game_scene.tscn", # 游戏场景 - 主要游戏内容
|
||||
"battle": "res://scenes/maps/battle_scene.tscn", # 战斗场景 - 战斗系统
|
||||
"inventory": "res://scenes/ui/InventoryWindow.tscn", # 背包界面
|
||||
"shop": "res://scenes/ui/ShopWindow.tscn", # 商店界面
|
||||
"settings": "res://scenes/ui/SettingsWindow.tscn", # 设置界面
|
||||
"room": "res://scenes/Maps/room.tscn", # 房间场景
|
||||
"square": "res://scenes/Maps/square.tscn" # 广场场景
|
||||
}
|
||||
|
||||
# ============ 生命周期方法 ============
|
||||
|
||||
# 初始化场景管理器
|
||||
# 在节点准备就绪时调用
|
||||
func _ready():
|
||||
print("SceneManager 初始化完成")
|
||||
|
||||
# ============ 场景切换方法 ============
|
||||
|
||||
# 切换到指定场景
|
||||
#
|
||||
# 参数:
|
||||
# scene_name: String - 要切换到的场景名称(必须在scene_paths中注册)
|
||||
# use_transition: bool - 是否使用过渡效果,默认为true
|
||||
#
|
||||
# 返回值:
|
||||
# bool - 切换是否成功
|
||||
#
|
||||
# 功能:
|
||||
# - 检查场景切换状态和场景是否存在
|
||||
# - 显示过渡效果(可选)
|
||||
# - 执行场景切换
|
||||
# - 更新当前场景状态
|
||||
# - 发送相关信号
|
||||
#
|
||||
# 使用示例:
|
||||
# var success = SceneManager.change_scene("main", true)
|
||||
# if success:
|
||||
# print("场景切换成功")
|
||||
#
|
||||
# 注意事项:
|
||||
# - 场景切换是异步操作
|
||||
# - 切换过程中会阻止新的切换请求
|
||||
# - 场景名称必须预先注册
|
||||
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()
|
||||
|
||||
# 更新场景名称(在切换之前设置,确保新场景的 _ready 能获取正确的名称)
|
||||
current_scene_name = scene_name
|
||||
|
||||
# 执行场景切换
|
||||
var error = get_tree().change_scene_to_file(scene_path)
|
||||
if error != OK:
|
||||
print("场景切换失败: ", error)
|
||||
current_scene_name = "" # 恢复为空
|
||||
is_changing_scene = false
|
||||
return false
|
||||
|
||||
# 更新状态
|
||||
is_changing_scene = false
|
||||
scene_changed.emit(scene_name)
|
||||
|
||||
# 隐藏过渡效果
|
||||
if use_transition:
|
||||
await hide_transition()
|
||||
|
||||
print("场景切换完成: ", scene_name)
|
||||
return true
|
||||
|
||||
# ============ 查询方法 ============
|
||||
|
||||
# 获取当前场景名称
|
||||
#
|
||||
# 返回值:
|
||||
# String - 当前场景的名称
|
||||
func get_current_scene_name() -> String:
|
||||
return current_scene_name
|
||||
|
||||
# 设置下一个场景的初始位置
|
||||
func set_next_scene_position(pos: Vector2) -> void:
|
||||
_next_scene_position = pos
|
||||
|
||||
# 获取并清除下一个场景的初始位置
|
||||
func get_next_scene_position() -> Variant:
|
||||
var pos = _next_scene_position
|
||||
_next_scene_position = null
|
||||
return pos
|
||||
|
||||
# 设置下一个场景的出生点名称
|
||||
func set_next_spawn_name(spawn_name: String) -> void:
|
||||
_next_spawn_name = spawn_name
|
||||
|
||||
# 获取并清除下一个场景的出生点名称
|
||||
func get_next_spawn_name() -> String:
|
||||
var name = _next_spawn_name
|
||||
_next_spawn_name = ""
|
||||
return name
|
||||
|
||||
|
||||
# ============ 场景注册方法 ============
|
||||
|
||||
# 注册新场景
|
||||
#
|
||||
# 参数:
|
||||
# scene_name: String - 场景名称(用于切换时引用)
|
||||
# scene_path: String - 场景文件路径
|
||||
#
|
||||
# 功能:
|
||||
# - 将场景名称和路径添加到映射表
|
||||
# - 支持运行时动态注册场景
|
||||
#
|
||||
# 使用示例:
|
||||
# SceneManager.register_scene("boss_battle", "res://scenes/boss/boss_battle.tscn")
|
||||
func register_scene(scene_name: String, scene_path: String):
|
||||
scene_paths[scene_name] = scene_path
|
||||
print("注册场景: ", scene_name, " -> ", scene_path)
|
||||
|
||||
# ============ 过渡效果方法 ============
|
||||
|
||||
# 显示场景切换过渡效果
|
||||
#
|
||||
# 功能:
|
||||
# - 显示场景切换时的过渡动画
|
||||
# - 为用户提供视觉反馈
|
||||
#
|
||||
# 注意事项:
|
||||
# - 这是异步方法,需要await等待完成
|
||||
# - 当前实现为简单的延时,可扩展为复杂动画
|
||||
#
|
||||
# TODO: 实现淡入淡出、滑动等过渡效果
|
||||
func show_transition():
|
||||
# TODO: 实现场景切换过渡效果
|
||||
print("显示场景切换过渡效果")
|
||||
await get_tree().create_timer(0.2).timeout
|
||||
|
||||
# 隐藏场景切换过渡效果
|
||||
#
|
||||
# 功能:
|
||||
# - 隐藏场景切换完成后的过渡动画
|
||||
# - 恢复正常的游戏显示
|
||||
#
|
||||
# 注意事项:
|
||||
# - 这是异步方法,需要await等待完成
|
||||
# - 与show_transition()配对使用
|
||||
#
|
||||
# TODO: 实现与show_transition()对应的隐藏效果
|
||||
func hide_transition():
|
||||
# TODO: 隐藏场景切换过渡效果
|
||||
print("隐藏场景切换过渡效果")
|
||||
await get_tree().create_timer(0.2).timeout
|
||||
1
_Core/managers/SceneManager.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://d3l286ti5gqhw
|
||||
234
_Core/managers/ToastManager.gd
Normal file
@@ -0,0 +1,234 @@
|
||||
class_name ToastManager
|
||||
|
||||
# ============================================================================
|
||||
# ToastManager.gd - Toast消息管理器
|
||||
# ============================================================================
|
||||
# 负责创建和管理Toast消息的显示
|
||||
#
|
||||
# 核心功能:
|
||||
# - 创建Toast消息实例
|
||||
# - 管理Toast动画和生命周期
|
||||
# - 支持多个Toast同时显示
|
||||
# - 自动排列和清理Toast
|
||||
# - 支持中文字体显示
|
||||
#
|
||||
# 使用方式:
|
||||
# var toast_manager = ToastManager.new()
|
||||
# toast_manager.setup(toast_container)
|
||||
# toast_manager.show_toast("消息内容", true)
|
||||
#
|
||||
# 注意事项:
|
||||
# - 需要提供一个容器节点来承载Toast
|
||||
# - 自动处理Toast的位置计算和动画
|
||||
# - 支持Web平台的字体处理
|
||||
# ============================================================================
|
||||
|
||||
extends RefCounted
|
||||
|
||||
# ============ 成员变量 ============
|
||||
|
||||
# Toast容器和管理
|
||||
var toast_container: Control # Toast消息容器
|
||||
var active_toasts: Array = [] # 当前显示的Toast消息列表
|
||||
var toast_counter: int = 0 # Toast计数器,用于生成唯一ID
|
||||
|
||||
# ============ 初始化方法 ============
|
||||
|
||||
# 设置Toast管理器
|
||||
#
|
||||
# 参数:
|
||||
# container: Control - Toast消息的容器节点
|
||||
func setup(container: Control):
|
||||
toast_container = container
|
||||
print("ToastManager 初始化完成")
|
||||
|
||||
# ============ 公共方法 ============
|
||||
|
||||
# 显示Toast消息
|
||||
#
|
||||
# 参数:
|
||||
# message: String - 消息内容
|
||||
# is_success: bool - 是否为成功消息(影响颜色)
|
||||
func show_toast(message: String, is_success: bool = true):
|
||||
if toast_container == null:
|
||||
print("错误: toast_container 节点不存在")
|
||||
return
|
||||
|
||||
print("显示Toast消息: ", message, " 成功: ", is_success)
|
||||
_create_toast_instance(message, is_success)
|
||||
|
||||
# 清理所有Toast
|
||||
func clear_all_toasts():
|
||||
for toast in active_toasts:
|
||||
if is_instance_valid(toast):
|
||||
toast.queue_free()
|
||||
active_toasts.clear()
|
||||
|
||||
# ============ 私有方法 ============
|
||||
|
||||
# 创建Toast实例
|
||||
func _create_toast_instance(message: String, is_success: bool):
|
||||
toast_counter += 1
|
||||
|
||||
# Web平台字体处理
|
||||
var is_web = OS.get_name() == "Web"
|
||||
|
||||
# 1. 创建Toast Panel(方框UI)
|
||||
var toast_panel = Panel.new()
|
||||
toast_panel.name = "Toast_" + str(toast_counter)
|
||||
|
||||
# 设置Toast样式
|
||||
var style = StyleBoxFlat.new()
|
||||
if is_success:
|
||||
style.bg_color = Color(0.15, 0.7, 0.15, 0.95)
|
||||
style.border_color = Color(0.2, 0.9, 0.2, 0.9)
|
||||
else:
|
||||
style.bg_color = Color(0.7, 0.15, 0.15, 0.95)
|
||||
style.border_color = Color(0.9, 0.2, 0.2, 0.9)
|
||||
|
||||
style.border_width_left = 3
|
||||
style.border_width_top = 3
|
||||
style.border_width_right = 3
|
||||
style.border_width_bottom = 3
|
||||
style.corner_radius_top_left = 12
|
||||
style.corner_radius_top_right = 12
|
||||
style.corner_radius_bottom_left = 12
|
||||
style.corner_radius_bottom_right = 12
|
||||
style.shadow_color = Color(0, 0, 0, 0.3)
|
||||
style.shadow_size = 4
|
||||
style.shadow_offset = Vector2(2, 2)
|
||||
|
||||
toast_panel.add_theme_stylebox_override("panel", style)
|
||||
|
||||
# 设置Toast基本尺寸
|
||||
var toast_width = 320
|
||||
toast_panel.size = Vector2(toast_width, 60)
|
||||
|
||||
# 2. 创建VBoxContainer
|
||||
var vbox = VBoxContainer.new()
|
||||
vbox.add_theme_constant_override("separation", 0)
|
||||
vbox.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
|
||||
vbox.alignment = BoxContainer.ALIGNMENT_CENTER
|
||||
|
||||
# 3. 创建CenterContainer
|
||||
var center_container = CenterContainer.new()
|
||||
center_container.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
||||
center_container.size_flags_vertical = Control.SIZE_SHRINK_CENTER
|
||||
|
||||
# 4. 创建Label(文字控件)
|
||||
var text_label = Label.new()
|
||||
text_label.text = message
|
||||
text_label.add_theme_color_override("font_color", Color(1, 1, 1, 1))
|
||||
text_label.add_theme_font_size_override("font_size", 14)
|
||||
|
||||
# 平台特定的字体处理
|
||||
if is_web:
|
||||
print("Web平台Toast字体处理")
|
||||
# Web平台使用主题文件
|
||||
var chinese_theme = load("res://assets/ui/chinese_theme.tres")
|
||||
if chinese_theme:
|
||||
text_label.theme = chinese_theme
|
||||
print("Web平台应用中文主题")
|
||||
else:
|
||||
print("Web平台中文主题加载失败")
|
||||
else:
|
||||
print("桌面平台Toast字体处理")
|
||||
# 桌面平台直接加载中文字体
|
||||
var desktop_chinese_font = load("res://assets/fonts/msyh.ttc")
|
||||
if desktop_chinese_font:
|
||||
text_label.add_theme_font_override("font", desktop_chinese_font)
|
||||
print("桌面平台使用中文字体")
|
||||
|
||||
text_label.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART
|
||||
text_label.custom_minimum_size = Vector2(280, 0)
|
||||
text_label.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
|
||||
text_label.vertical_alignment = VERTICAL_ALIGNMENT_CENTER
|
||||
|
||||
# 组装控件层级
|
||||
center_container.add_child(text_label)
|
||||
vbox.add_child(center_container)
|
||||
toast_panel.add_child(vbox)
|
||||
|
||||
# 计算位置
|
||||
var margin = 20
|
||||
var start_x = toast_container.get_viewport().get_visible_rect().size.x
|
||||
var final_x = toast_container.get_viewport().get_visible_rect().size.x - toast_width - margin
|
||||
|
||||
# 计算Y位置
|
||||
var y_position = margin
|
||||
for existing_toast in active_toasts:
|
||||
if is_instance_valid(existing_toast):
|
||||
y_position += existing_toast.size.y + 15
|
||||
|
||||
# 设置初始位置
|
||||
toast_panel.position = Vector2(start_x, y_position)
|
||||
|
||||
# 添加到容器
|
||||
toast_container.add_child(toast_panel)
|
||||
active_toasts.append(toast_panel)
|
||||
|
||||
# 等待一帧让布局系统计算尺寸
|
||||
await toast_container.get_tree().process_frame
|
||||
|
||||
# 让Toast高度自适应内容
|
||||
var content_size = vbox.get_combined_minimum_size()
|
||||
var final_height = max(60, content_size.y + 20) # 最小60,加20像素边距
|
||||
toast_panel.size.y = final_height
|
||||
|
||||
# 重新排列所有Toast
|
||||
_rearrange_toasts()
|
||||
|
||||
# 开始动画
|
||||
_animate_toast_in(toast_panel, final_x)
|
||||
|
||||
# Toast入场动画
|
||||
func _animate_toast_in(toast_panel: Panel, final_x: float):
|
||||
var tween = toast_container.create_tween()
|
||||
tween.set_ease(Tween.EASE_OUT)
|
||||
tween.set_trans(Tween.TRANS_BACK)
|
||||
|
||||
tween.parallel().tween_property(toast_panel, "position:x", final_x, 0.6)
|
||||
tween.parallel().tween_property(toast_panel, "modulate:a", 1.0, 0.4)
|
||||
|
||||
toast_panel.modulate.a = 0.0
|
||||
|
||||
# 等待3秒后开始退场动画
|
||||
await toast_container.get_tree().create_timer(3.0).timeout
|
||||
_animate_toast_out(toast_panel)
|
||||
|
||||
# Toast退场动画
|
||||
func _animate_toast_out(toast_panel: Panel):
|
||||
if not is_instance_valid(toast_panel):
|
||||
return
|
||||
|
||||
var tween = toast_container.create_tween()
|
||||
tween.set_ease(Tween.EASE_IN)
|
||||
tween.set_trans(Tween.TRANS_QUART)
|
||||
|
||||
var end_x = toast_container.get_viewport().get_visible_rect().size.x + 50
|
||||
tween.parallel().tween_property(toast_panel, "position:x", end_x, 0.4)
|
||||
tween.parallel().tween_property(toast_panel, "modulate:a", 0.0, 0.3)
|
||||
|
||||
await tween.finished
|
||||
_cleanup_toast(toast_panel)
|
||||
|
||||
# 清理Toast
|
||||
func _cleanup_toast(toast_panel: Panel):
|
||||
if not is_instance_valid(toast_panel):
|
||||
return
|
||||
|
||||
active_toasts.erase(toast_panel)
|
||||
_rearrange_toasts()
|
||||
toast_panel.queue_free()
|
||||
|
||||
# 重新排列Toast位置
|
||||
func _rearrange_toasts():
|
||||
var margin = 20
|
||||
var current_y = margin
|
||||
|
||||
for i in range(active_toasts.size()):
|
||||
var toast = active_toasts[i]
|
||||
if is_instance_valid(toast):
|
||||
var tween = toast_container.create_tween()
|
||||
tween.tween_property(toast, "position:y", current_y, 0.2)
|
||||
current_y += toast.size.y + 15
|
||||
1
_Core/managers/ToastManager.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://buk7d21cag262
|
||||
172
_Core/managers/WebSocketManager.gd
Normal file
@@ -0,0 +1,172 @@
|
||||
extends Node
|
||||
|
||||
# ============================================================================
|
||||
# WebSocketManager.gd - WebSocket连接管理器
|
||||
# ============================================================================
|
||||
# 负责与后端 Native WebSocket 服务进行实时通信
|
||||
#
|
||||
# 协议文档: new_docs/game_architecture_design.md
|
||||
# 后端地址: ws://localhost:3000/location-broadcast
|
||||
# ============================================================================
|
||||
|
||||
signal connected_to_server()
|
||||
signal connection_closed()
|
||||
signal connection_error()
|
||||
signal session_joined(data: Dictionary)
|
||||
signal user_joined(data: Dictionary)
|
||||
signal user_left(data: Dictionary)
|
||||
signal position_updated(data: Dictionary)
|
||||
|
||||
const WS_URL = "wss://whaletownend.xinghangee.icu/location-broadcast"
|
||||
const PING_INTERVAL = 25.0 # 秒
|
||||
|
||||
var _socket: WebSocketPeer
|
||||
var _connected: bool = false
|
||||
var _ping_timer: float = 0.0
|
||||
var _auth_token: String = ""
|
||||
|
||||
func _ready():
|
||||
_socket = WebSocketPeer.new()
|
||||
process_mode = Node.PROCESS_MODE_ALWAYS # 保证暂停时也能处理网络
|
||||
print("WebSocketManager Initialized")
|
||||
|
||||
func _process(delta):
|
||||
_socket.poll()
|
||||
var state = _socket.get_ready_state()
|
||||
|
||||
if state == WebSocketPeer.STATE_OPEN:
|
||||
if not _connected:
|
||||
_on_connected()
|
||||
|
||||
# 处理接收到的数据包
|
||||
while _socket.get_available_packet_count() > 0:
|
||||
var packet = _socket.get_packet()
|
||||
_handle_packet(packet)
|
||||
|
||||
# 心跳处理
|
||||
_ping_timer += delta
|
||||
if _ping_timer >= PING_INTERVAL:
|
||||
_send_heartbeat()
|
||||
_ping_timer = 0.0
|
||||
|
||||
elif state == WebSocketPeer.STATE_CLOSED:
|
||||
if _connected:
|
||||
_on_disconnected()
|
||||
|
||||
func connect_to_server():
|
||||
if _socket.get_ready_state() == WebSocketPeer.STATE_OPEN:
|
||||
print("WebSocket 已经是连接状态")
|
||||
return
|
||||
|
||||
print("正在连接 WebSocket: ", WS_URL)
|
||||
var err = _socket.connect_to_url(WS_URL)
|
||||
if err != OK:
|
||||
print("WebSocket 连接请求失败: ", err)
|
||||
connection_error.emit()
|
||||
else:
|
||||
# Godot WebSocket connect is non-blocking, wait for state change in _process
|
||||
pass
|
||||
|
||||
func close_connection():
|
||||
_socket.close()
|
||||
|
||||
func set_auth_token(token: String):
|
||||
_auth_token = token
|
||||
|
||||
# ============ 协议发送 ============
|
||||
|
||||
func send_packet(event: String, data: Dictionary):
|
||||
if _socket.get_ready_state() != WebSocketPeer.STATE_OPEN:
|
||||
return
|
||||
|
||||
var message = {
|
||||
"event": event,
|
||||
"data": data
|
||||
}
|
||||
var json_str = JSON.stringify(message)
|
||||
_socket.put_packet(json_str.to_utf8_buffer())
|
||||
|
||||
func join_session(map_id: String, initial_pos: Vector2):
|
||||
var data = {
|
||||
"sessionId": map_id,
|
||||
"initialPosition": {
|
||||
"x": initial_pos.x,
|
||||
"y": initial_pos.y,
|
||||
"mapId": map_id
|
||||
},
|
||||
"token": _auth_token
|
||||
}
|
||||
print("发送加入会话请求: ", map_id, " mapId Payload: ", data.initialPosition.mapId)
|
||||
send_packet("join_session", data)
|
||||
|
||||
func leave_session(map_id: String):
|
||||
print("发送离开会话请求: ", map_id)
|
||||
send_packet("leave_session", {"sessionId": map_id})
|
||||
|
||||
func send_position_update(map_id: String, pos: Vector2, anim_data: Dictionary = {}):
|
||||
var data = {
|
||||
"x": pos.x,
|
||||
"y": pos.y,
|
||||
"mapId": map_id,
|
||||
"metadata": anim_data
|
||||
}
|
||||
# print("发送位置更新: ", map_id)
|
||||
if map_id == "":
|
||||
print("WARNING: Sending position update with EMPTY mapId! Pos: ", pos)
|
||||
send_packet("position_update", data)
|
||||
|
||||
func _send_heartbeat():
|
||||
send_packet("heartbeat", {"timestamp": Time.get_unix_time_from_system()})
|
||||
|
||||
# ============ 事件处理 ============
|
||||
|
||||
func _on_connected():
|
||||
_connected = true
|
||||
print("WebSocket 连接成功!")
|
||||
connected_to_server.emit()
|
||||
|
||||
func _on_disconnected():
|
||||
_connected = false
|
||||
var code = _socket.get_close_code()
|
||||
var reason = _socket.get_close_reason()
|
||||
print("WebSocket 连接断开. Code: %d, Reason: %s" % [code, reason])
|
||||
connection_closed.emit()
|
||||
|
||||
func _handle_packet(packet: PackedByteArray):
|
||||
var json_str = packet.get_string_from_utf8()
|
||||
var json = JSON.new()
|
||||
var err = json.parse(json_str)
|
||||
|
||||
if err != OK:
|
||||
print("JSON 解析失败: ", json.get_error_message())
|
||||
return
|
||||
|
||||
var message = json.data
|
||||
if not message is Dictionary or not message.has("event"):
|
||||
return
|
||||
|
||||
var event = message["event"]
|
||||
var data = message.get("data", {})
|
||||
|
||||
if event != "heartbeat_response":
|
||||
print("WebSocket Rx: ", event) # Debug logs for all events
|
||||
|
||||
match event:
|
||||
"session_joined":
|
||||
session_joined.emit(data)
|
||||
print("加入会话成功,当前房间人数: ", data.get("users", []).size())
|
||||
"user_joined":
|
||||
user_joined.emit(data)
|
||||
print("用户加入: ", data.get("userId"))
|
||||
"user_left":
|
||||
user_left.emit(data)
|
||||
print("用户离开: ", data.get("userId"))
|
||||
"position_update":
|
||||
print("WebSocket Rx position_update: ", data.get("userId", "unknown"))
|
||||
position_updated.emit(data)
|
||||
"heartbeat_response":
|
||||
pass # 静默处理
|
||||
"error":
|
||||
print("WebSocket 错误事件: ", JSON.stringify(data))
|
||||
_:
|
||||
print("未处理的 WebSocket 事件: ", event)
|
||||
1
_Core/managers/WebSocketManager.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://stpl2jdeqo0d
|
||||
195
_Core/systems/EventSystem.gd
Normal file
@@ -0,0 +1,195 @@
|
||||
extends Node
|
||||
|
||||
# ============================================================================
|
||||
# EventSystem.gd - 全局事件系统
|
||||
# ============================================================================
|
||||
# 全局单例管理器,提供解耦的事件通信机制
|
||||
#
|
||||
# 核心职责:
|
||||
# - 事件监听器注册和管理
|
||||
# - 事件发送和分发
|
||||
# - 自动清理无效监听器
|
||||
# - 支持带参数的事件通信
|
||||
#
|
||||
# 使用方式:
|
||||
# EventSystem.connect_event("player_moved", _on_player_moved)
|
||||
# EventSystem.emit_event("player_moved", {"position": Vector2(100, 200)})
|
||||
#
|
||||
# 注意事项:
|
||||
# - 作为自动加载单例,全局可访问
|
||||
# - 监听器会自动检查目标节点的有效性
|
||||
# - 建议使用EventNames类中定义的事件名称常量
|
||||
# ============================================================================
|
||||
|
||||
# ============ 成员变量 ============
|
||||
|
||||
# 事件监听器存储
|
||||
# 结构: {event_name: [{"callback": Callable, "target": Node}, ...]}
|
||||
var event_listeners: Dictionary = {}
|
||||
|
||||
# ============ 生命周期方法 ============
|
||||
|
||||
# 初始化事件系统
|
||||
# 在节点准备就绪时调用
|
||||
func _ready():
|
||||
print("EventSystem 初始化完成")
|
||||
|
||||
# ============ 事件监听器管理 ============
|
||||
|
||||
# 注册事件监听器
|
||||
#
|
||||
# 参数:
|
||||
# event_name: String - 事件名称(建议使用EventNames中的常量)
|
||||
# callback: Callable - 回调函数
|
||||
# target: Node - 目标节点(可选,用于自动清理)
|
||||
#
|
||||
# 功能:
|
||||
# - 将回调函数注册到指定事件
|
||||
# - 支持同一事件多个监听器
|
||||
# - 自动管理监听器生命周期
|
||||
#
|
||||
# 使用示例:
|
||||
# EventSystem.connect_event(EventNames.PLAYER_MOVED, _on_player_moved, self)
|
||||
#
|
||||
# 注意事项:
|
||||
# - 如果提供target参数,当target节点被销毁时会自动清理监听器
|
||||
# - 同一个callback可以监听多个事件
|
||||
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)
|
||||
|
||||
# 移除事件监听器
|
||||
#
|
||||
# 参数:
|
||||
# event_name: String - 事件名称
|
||||
# callback: Callable - 要移除的回调函数
|
||||
# target: Node - 目标节点(可选,用于精确匹配)
|
||||
#
|
||||
# 功能:
|
||||
# - 从指定事件中移除特定的监听器
|
||||
# - 支持精确匹配(callback + target)
|
||||
#
|
||||
# 使用示例:
|
||||
# EventSystem.disconnect_event(EventNames.PLAYER_MOVED, _on_player_moved, self)
|
||||
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]
|
||||
# 匹配callback和target
|
||||
if listener.callback == callback and listener.target == target:
|
||||
listeners.remove_at(i)
|
||||
print("移除事件监听器: ", event_name, " -> ", callback)
|
||||
break
|
||||
|
||||
# ============ 事件发送 ============
|
||||
|
||||
# 发送事件
|
||||
#
|
||||
# 参数:
|
||||
# event_name: String - 事件名称
|
||||
# data: Variant - 事件数据(可选)
|
||||
#
|
||||
# 功能:
|
||||
# - 向所有注册的监听器发送事件
|
||||
# - 自动跳过无效的监听器
|
||||
# - 支持任意类型的事件数据
|
||||
#
|
||||
# 使用示例:
|
||||
# EventSystem.emit_event(EventNames.PLAYER_MOVED, {"position": Vector2(100, 200)})
|
||||
# EventSystem.emit_event(EventNames.GAME_PAUSED) # 无数据事件
|
||||
#
|
||||
# 注意事项:
|
||||
# - 事件发送是同步的,所有监听器会立即执行
|
||||
# - 如果监听器执行出错,不会影响其他监听器
|
||||
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)
|
||||
|
||||
# ============ 查询方法 ============
|
||||
|
||||
# 获取事件监听器数量
|
||||
#
|
||||
# 参数:
|
||||
# event_name: String - 事件名称
|
||||
#
|
||||
# 返回值:
|
||||
# int - 监听器数量
|
||||
#
|
||||
# 使用场景:
|
||||
# - 调试时检查监听器数量
|
||||
# - 性能分析
|
||||
func get_listener_count(event_name: String) -> int:
|
||||
if not event_listeners.has(event_name):
|
||||
return 0
|
||||
return event_listeners[event_name].size()
|
||||
|
||||
# 清空所有事件监听器
|
||||
#
|
||||
# 功能:
|
||||
# - 移除所有已注册的事件监听器
|
||||
# - 通常在游戏重置或退出时使用
|
||||
#
|
||||
# 警告:
|
||||
# - 这是一个危险操作,会影响所有模块
|
||||
# - 使用前请确保所有模块都能正确处理监听器丢失
|
||||
func clear_all_listeners():
|
||||
event_listeners.clear()
|
||||
print("清空所有事件监听器")
|
||||
1
_Core/systems/EventSystem.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://bfheblucmti24
|
||||
143
_Core/systems/GridSystem.gd
Normal file
@@ -0,0 +1,143 @@
|
||||
# ============================================================================
|
||||
# 网格系统 - GridSystem.gd
|
||||
#
|
||||
# 提供32x32像素的最小网格单元控制,用于规范地图大小和位置计算
|
||||
#
|
||||
# 使用方式:
|
||||
# var grid_pos = GridSystem.world_to_grid(world_position)
|
||||
# var world_pos = GridSystem.grid_to_world(grid_position)
|
||||
# var snapped_pos = GridSystem.snap_to_grid(position)
|
||||
# ============================================================================
|
||||
|
||||
class_name GridSystem
|
||||
extends RefCounted
|
||||
|
||||
# ============================================================================
|
||||
# 常量定义
|
||||
# ============================================================================
|
||||
const GRID_SIZE: int = 32 # 网格单元大小 32x32 像素
|
||||
const HALF_GRID_SIZE: float = GRID_SIZE * 0.5 # 网格中心偏移
|
||||
|
||||
# ============================================================================
|
||||
# 坐标转换方法
|
||||
# ============================================================================
|
||||
|
||||
# 世界坐标转换为网格坐标
|
||||
static func world_to_grid(world_pos: Vector2) -> Vector2i:
|
||||
return Vector2i(
|
||||
int(world_pos.x / GRID_SIZE),
|
||||
int(world_pos.y / GRID_SIZE)
|
||||
)
|
||||
|
||||
# 网格坐标转换为世界坐标(返回网格左上角)
|
||||
static func grid_to_world(grid_pos: Vector2i) -> Vector2:
|
||||
return Vector2(
|
||||
grid_pos.x * GRID_SIZE,
|
||||
grid_pos.y * GRID_SIZE
|
||||
)
|
||||
|
||||
# 网格坐标转换为世界坐标(返回网格中心)
|
||||
static func grid_to_world_center(grid_pos: Vector2i) -> Vector2:
|
||||
return Vector2(
|
||||
grid_pos.x * GRID_SIZE + HALF_GRID_SIZE,
|
||||
grid_pos.y * GRID_SIZE + HALF_GRID_SIZE
|
||||
)
|
||||
|
||||
# 将位置吸附到最近的网格点(左上角)
|
||||
static func snap_to_grid(position: Vector2) -> Vector2:
|
||||
return Vector2(
|
||||
floor(position.x / GRID_SIZE) * GRID_SIZE,
|
||||
floor(position.y / GRID_SIZE) * GRID_SIZE
|
||||
)
|
||||
|
||||
# 将位置吸附到最近的网格中心
|
||||
static func snap_to_grid_center(position: Vector2) -> Vector2:
|
||||
var grid_pos = world_to_grid(position)
|
||||
return grid_to_world_center(grid_pos)
|
||||
|
||||
# ============================================================================
|
||||
# 距离和区域计算
|
||||
# ============================================================================
|
||||
|
||||
# 计算两个网格坐标之间的曼哈顿距离
|
||||
static func grid_distance_manhattan(grid_pos1: Vector2i, grid_pos2: Vector2i) -> int:
|
||||
return abs(grid_pos1.x - grid_pos2.x) + abs(grid_pos1.y - grid_pos2.y)
|
||||
|
||||
# 计算两个网格坐标之间的欧几里得距离
|
||||
static func grid_distance_euclidean(grid_pos1: Vector2i, grid_pos2: Vector2i) -> float:
|
||||
var diff = grid_pos1 - grid_pos2
|
||||
return sqrt(diff.x * diff.x + diff.y * diff.y)
|
||||
|
||||
# 获取指定网格坐标周围的邻居网格(4方向)
|
||||
static func get_grid_neighbors_4(grid_pos: Vector2i) -> Array[Vector2i]:
|
||||
return [
|
||||
Vector2i(grid_pos.x, grid_pos.y - 1), # 上
|
||||
Vector2i(grid_pos.x + 1, grid_pos.y), # 右
|
||||
Vector2i(grid_pos.x, grid_pos.y + 1), # 下
|
||||
Vector2i(grid_pos.x - 1, grid_pos.y) # 左
|
||||
]
|
||||
|
||||
# 获取指定网格坐标周围的邻居网格(8方向)
|
||||
static func get_grid_neighbors_8(grid_pos: Vector2i) -> Array[Vector2i]:
|
||||
var neighbors: Array[Vector2i] = []
|
||||
for x in range(-1, 2):
|
||||
for y in range(-1, 2):
|
||||
if x == 0 and y == 0:
|
||||
continue
|
||||
neighbors.append(Vector2i(grid_pos.x + x, grid_pos.y + y))
|
||||
return neighbors
|
||||
|
||||
# ============================================================================
|
||||
# 区域和边界检查
|
||||
# ============================================================================
|
||||
|
||||
# 检查网格坐标是否在指定矩形区域内
|
||||
static func is_grid_in_bounds(grid_pos: Vector2i, min_grid: Vector2i, max_grid: Vector2i) -> bool:
|
||||
return (grid_pos.x >= min_grid.x and grid_pos.x <= max_grid.x and
|
||||
grid_pos.y >= min_grid.y and grid_pos.y <= max_grid.y)
|
||||
|
||||
# 获取矩形区域内的所有网格坐标
|
||||
static func get_grids_in_rect(min_grid: Vector2i, max_grid: Vector2i) -> Array[Vector2i]:
|
||||
var grids: Array[Vector2i] = []
|
||||
for x in range(min_grid.x, max_grid.x + 1):
|
||||
for y in range(min_grid.y, max_grid.y + 1):
|
||||
grids.append(Vector2i(x, y))
|
||||
return grids
|
||||
|
||||
# ============================================================================
|
||||
# 地图尺寸规范化
|
||||
# ============================================================================
|
||||
|
||||
# 将像素尺寸规范化为网格尺寸的倍数
|
||||
static func normalize_size_to_grid(pixel_size: Vector2i) -> Vector2i:
|
||||
return Vector2i(
|
||||
int(ceil(float(pixel_size.x) / GRID_SIZE)) * GRID_SIZE,
|
||||
int(ceil(float(pixel_size.y) / GRID_SIZE)) * GRID_SIZE
|
||||
)
|
||||
|
||||
# 计算指定像素尺寸需要多少个网格单元
|
||||
static func get_grid_count(pixel_size: Vector2i) -> Vector2i:
|
||||
return Vector2i(
|
||||
int(ceil(float(pixel_size.x) / GRID_SIZE)),
|
||||
int(ceil(float(pixel_size.y) / GRID_SIZE))
|
||||
)
|
||||
|
||||
# ============================================================================
|
||||
# 调试和可视化辅助
|
||||
# ============================================================================
|
||||
|
||||
# 获取网格的边界矩形(用于调试绘制)
|
||||
static func get_grid_rect(grid_pos: Vector2i) -> Rect2:
|
||||
var world_pos = grid_to_world(grid_pos)
|
||||
return Rect2(world_pos, Vector2(GRID_SIZE, GRID_SIZE))
|
||||
|
||||
# 打印网格信息(调试用)
|
||||
static func print_grid_info(world_pos: Vector2) -> void:
|
||||
var grid_pos = world_to_grid(world_pos)
|
||||
var snapped_pos = snap_to_grid(world_pos)
|
||||
var center_pos = grid_to_world_center(grid_pos)
|
||||
|
||||
print("世界坐标: ", world_pos)
|
||||
print("网格坐标: ", grid_pos)
|
||||
print("吸附位置: ", snapped_pos)
|
||||
print("网格中心: ", center_pos)
|
||||
1
_Core/systems/GridSystem.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://dceqpffgti4jb
|
||||
2
_Core/utils/.gitkeep
Normal file
@@ -0,0 +1,2 @@
|
||||
# 核心工具类目录
|
||||
# 存放字符串处理、数学计算等工具类
|
||||
386
_Core/utils/StringUtils.gd
Normal file
@@ -0,0 +1,386 @@
|
||||
class_name StringUtils
|
||||
|
||||
# ============================================================================
|
||||
# StringUtils.gd - 字符串工具类
|
||||
# ============================================================================
|
||||
# 静态工具类,提供常用的字符串处理功能
|
||||
#
|
||||
# 核心功能:
|
||||
# - 输入验证(邮箱、用户名、密码)
|
||||
# - 字符串格式化和转换
|
||||
# - 时间格式化和相对时间计算
|
||||
# - 文件大小格式化
|
||||
#
|
||||
# 使用方式:
|
||||
# var is_valid = StringUtils.is_valid_email("user@example.com")
|
||||
# var formatted_time = StringUtils.format_utc_to_local_time(utc_string)
|
||||
#
|
||||
# 注意事项:
|
||||
# - 所有方法都是静态的,无需实例化
|
||||
# - 验证方法返回布尔值或包含详细信息的字典
|
||||
# - 时间处理方法支持UTC到本地时间的转换
|
||||
# ============================================================================
|
||||
|
||||
# ============ 输入验证方法 ============
|
||||
|
||||
# 验证邮箱格式
|
||||
#
|
||||
# 参数:
|
||||
# email: String - 待验证的邮箱地址
|
||||
#
|
||||
# 返回值:
|
||||
# bool - true表示格式正确,false表示格式错误
|
||||
#
|
||||
# 验证规则:
|
||||
# - 必须包含@符号
|
||||
# - @前后都必须有内容
|
||||
# - 域名部分必须包含至少一个点
|
||||
# - 顶级域名至少2个字符
|
||||
#
|
||||
# 使用示例:
|
||||
# if StringUtils.is_valid_email("user@example.com"):
|
||||
# print("邮箱格式正确")
|
||||
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
|
||||
|
||||
# 验证用户名格式
|
||||
#
|
||||
# 参数:
|
||||
# username: String - 待验证的用户名
|
||||
#
|
||||
# 返回值:
|
||||
# bool - true表示格式正确,false表示格式错误
|
||||
#
|
||||
# 验证规则:
|
||||
# - 只能包含字母、数字、下划线
|
||||
# - 长度不能为空且不超过50个字符
|
||||
# - 不能包含空格或特殊字符
|
||||
#
|
||||
# 使用示例:
|
||||
# if StringUtils.is_valid_username("user_123"):
|
||||
# print("用户名格式正确")
|
||||
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
|
||||
|
||||
# 验证密码强度
|
||||
#
|
||||
# 参数:
|
||||
# password: String - 待验证的密码
|
||||
#
|
||||
# 返回值:
|
||||
# Dictionary - 包含验证结果的详细信息
|
||||
# {
|
||||
# "valid": bool, # 是否符合最低要求
|
||||
# "message": String, # 验证结果消息
|
||||
# "strength": int # 强度等级 (1-4)
|
||||
# }
|
||||
#
|
||||
# 验证规则:
|
||||
# - 最少8位,最多128位
|
||||
# - 必须包含字母和数字
|
||||
# - 强度评级:包含字母(+1)、数字(+1)、特殊字符(+1)、长度>=12(+1)
|
||||
#
|
||||
# 使用示例:
|
||||
# var result = StringUtils.validate_password_strength("MyPass123!")
|
||||
# if result.valid:
|
||||
# print("密码强度: ", result.message)
|
||||
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 character = password[i]
|
||||
if character >= 'a' and character <= 'z' or character >= 'A' and character <= 'Z':
|
||||
has_letter = true
|
||||
elif character >= '0' and character <= '9':
|
||||
has_digit = true
|
||||
elif character 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
|
||||
|
||||
# ============ 字符串格式化方法 ============
|
||||
|
||||
# 截断字符串
|
||||
#
|
||||
# 参数:
|
||||
# text: String - 原始字符串
|
||||
# max_length: int - 最大长度
|
||||
# suffix: String - 截断后缀(默认为"...")
|
||||
#
|
||||
# 返回值:
|
||||
# String - 截断后的字符串
|
||||
#
|
||||
# 功能:
|
||||
# - 如果字符串长度超过限制,截断并添加后缀
|
||||
# - 如果字符串长度未超过限制,返回原字符串
|
||||
#
|
||||
# 使用示例:
|
||||
# var short_text = StringUtils.truncate("这是一个很长的文本", 10, "...")
|
||||
# # 结果: "这是一个很长..."
|
||||
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
|
||||
|
||||
# 首字母大写
|
||||
#
|
||||
# 参数:
|
||||
# text: String - 原始字符串
|
||||
#
|
||||
# 返回值:
|
||||
# String - 首字母大写的字符串
|
||||
#
|
||||
# 使用示例:
|
||||
# var capitalized = StringUtils.capitalize_first("hello world")
|
||||
# # 结果: "Hello world"
|
||||
static func capitalize_first(text: String) -> String:
|
||||
if text.is_empty():
|
||||
return text
|
||||
return text[0].to_upper() + text.substr(1)
|
||||
|
||||
# 转换为标题格式
|
||||
#
|
||||
# 参数:
|
||||
# text: String - 原始字符串
|
||||
#
|
||||
# 返回值:
|
||||
# String - 每个单词首字母大写的字符串
|
||||
#
|
||||
# 功能:
|
||||
# - 将每个单词的首字母转换为大写
|
||||
# - 其余字母转换为小写
|
||||
# - 以空格分隔单词
|
||||
#
|
||||
# 使用示例:
|
||||
# var title = StringUtils.to_title_case("hello world game")
|
||||
# # 结果: "Hello World Game"
|
||||
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标签
|
||||
#
|
||||
# 参数:
|
||||
# html: String - 包含HTML标签的字符串
|
||||
#
|
||||
# 返回值:
|
||||
# String - 移除HTML标签后的纯文本
|
||||
#
|
||||
# 功能:
|
||||
# - 使用正则表达式移除所有HTML标签
|
||||
# - 保留标签之间的文本内容
|
||||
#
|
||||
# 使用示例:
|
||||
# var plain_text = StringUtils.strip_html_tags("<p>Hello <b>World</b></p>")
|
||||
# # 结果: "Hello World"
|
||||
static func strip_html_tags(html: String) -> String:
|
||||
var regex = RegEx.new()
|
||||
regex.compile("<[^>]*>")
|
||||
return regex.sub(html, "", true)
|
||||
|
||||
# 格式化文件大小
|
||||
#
|
||||
# 参数:
|
||||
# bytes: int - 文件大小(字节)
|
||||
#
|
||||
# 返回值:
|
||||
# String - 格式化后的文件大小字符串
|
||||
#
|
||||
# 功能:
|
||||
# - 自动选择合适的单位(B, KB, MB, GB, TB)
|
||||
# - 保留一位小数(除了字节)
|
||||
# - 使用1024作为换算基数
|
||||
#
|
||||
# 使用示例:
|
||||
# var size_text = StringUtils.format_file_size(1536)
|
||||
# # 结果: "1.5 KB"
|
||||
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时间字符串转换为本地时间显示
|
||||
#
|
||||
# 参数:
|
||||
# utc_time_str: String - UTC时间字符串(格式: 2025-12-25T11:23:52.175Z)
|
||||
#
|
||||
# 返回值:
|
||||
# String - 格式化的本地时间字符串
|
||||
#
|
||||
# 功能:
|
||||
# - 解析ISO 8601格式的UTC时间
|
||||
# - 转换为本地时区时间
|
||||
# - 格式化为易读的中文时间格式
|
||||
#
|
||||
# 使用示例:
|
||||
# var local_time = StringUtils.format_utc_to_local_time("2025-12-25T11:23:52.175Z")
|
||||
# # 结果: "2025年12月25日 19:23:52" (假设本地时区为UTC+8)
|
||||
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
|
||||
]
|
||||
|
||||
# 获取相对时间描述
|
||||
#
|
||||
# 参数:
|
||||
# utc_time_str: String - UTC时间字符串
|
||||
#
|
||||
# 返回值:
|
||||
# String - 相对时间描述(如"5分钟后"、"2小时30分钟后")
|
||||
#
|
||||
# 功能:
|
||||
# - 计算指定时间与当前时间的差值
|
||||
# - 返回人性化的相对时间描述
|
||||
# - 支持秒、分钟、小时的组合显示
|
||||
#
|
||||
# 使用示例:
|
||||
# var relative_time = StringUtils.get_relative_time_until("2025-12-25T12:00:00Z")
|
||||
# # 结果: "30分钟后" 或 "现在可以重试"
|
||||
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
_Core/utils/StringUtils.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://bu8onmk6q8wic
|
||||
1
assets/audio/audio/music/.gitkeep
Normal file
@@ -0,0 +1 @@
|
||||
# 保持目录结构 - 音乐资源目录
|
||||
1
assets/audio/audio/sounds/.gitkeep
Normal file
@@ -0,0 +1 @@
|
||||
# 保持目录结构 - 音效资源目录
|
||||
1
assets/audio/audio/voice/.gitkeep
Normal file
@@ -0,0 +1 @@
|
||||
# 保持目录结构 - 语音资源目录
|
||||
1
assets/audio/music/.gitkeep
Normal file
@@ -0,0 +1 @@
|
||||
# 保持目录结构 - 音乐资源目录
|
||||
1
assets/audio/sounds/.gitkeep
Normal file
@@ -0,0 +1 @@
|
||||
# 保持目录结构 - 音效资源目录
|
||||
1
assets/audio/voice/.gitkeep
Normal file
@@ -0,0 +1 @@
|
||||
# 保持目录结构 - 语音资源目录
|
||||
BIN
assets/characters/npc_286_241.png
Normal file
|
After Width: | Height: | Size: 96 KiB |
40
assets/characters/npc_286_241.png.import
Normal file
@@ -0,0 +1,40 @@
|
||||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://brko2ik6t6ib5"
|
||||
path="res://.godot/imported/npc_286_241.png-dfe6daef11d0f27f7902e69d6057828f.ctex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://assets/characters/npc_286_241.png"
|
||||
dest_files=["res://.godot/imported/npc_286_241.png-dfe6daef11d0f27f7902e69d6057828f.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/characters/payer_44_30.png
Normal file
|
After Width: | Height: | Size: 43 KiB |
40
assets/characters/payer_44_30.png.import
Normal file
@@ -0,0 +1,40 @@
|
||||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://krfed1r4qmnp"
|
||||
path="res://.godot/imported/payer_44_30.png-100395b4756c93dec9ce9baa5c5df0f3.ctex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://assets/characters/payer_44_30.png"
|
||||
dest_files=["res://.godot/imported/payer_44_30.png-100395b4756c93dec9ce9baa5c5df0f3.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/characters/player_spritesheet.png
Normal file
|
After Width: | Height: | Size: 43 KiB |
40
assets/characters/player_spritesheet.png.import
Normal file
@@ -0,0 +1,40 @@
|
||||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://cghab1hkx5lg5"
|
||||
path="res://.godot/imported/player_spritesheet.png-7e76f97a17946ec512358d45f2527da8.ctex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://assets/characters/player_spritesheet.png"
|
||||
dest_files=["res://.godot/imported/player_spritesheet.png-7e76f97a17946ec512358d45f2527da8.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/characters/player_spritesheet_backup.png
Normal file
|
After Width: | Height: | Size: 856 KiB |
40
assets/characters/player_spritesheet_backup.png.import
Normal file
@@ -0,0 +1,40 @@
|
||||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://dyimi462hj6r2"
|
||||
path="res://.godot/imported/player_spritesheet_backup.png-6d8c966a56b0ced39cf1ecf0c772847f.ctex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://assets/characters/player_spritesheet_backup.png"
|
||||
dest_files=["res://.godot/imported/player_spritesheet_backup.png-6d8c966a56b0ced39cf1ecf0c772847f.ctex"]
|
||||
|
||||
[params]
|
||||
|
||||
compress/mode=0
|
||||
compress/high_quality=false
|
||||
compress/lossy_quality=0.7
|
||||
compress/uastc_level=0
|
||||
compress/rdo_quality_loss=0.0
|
||||
compress/hdr_compression=1
|
||||
compress/normal_map=0
|
||||
compress/channel_pack=0
|
||||
mipmaps/generate=false
|
||||
mipmaps/limit=-1
|
||||
roughness/mode=0
|
||||
roughness/src_normal=""
|
||||
process/channel_remap/red=0
|
||||
process/channel_remap/green=1
|
||||
process/channel_remap/blue=2
|
||||
process/channel_remap/alpha=3
|
||||
process/fix_alpha_border=true
|
||||
process/premult_alpha=false
|
||||
process/normal_map_invert_y=false
|
||||
process/hdr_as_srgb=false
|
||||
process/hdr_clamp_exposure=false
|
||||
process/size_limit=0
|
||||
detect_3d/compress_to=1
|
||||
1
assets/fonts/.gitkeep
Normal file
@@ -0,0 +1 @@
|
||||
# 保持目录结构 - 字体资源目录
|
||||
BIN
assets/fonts/msyh.ttc
Normal file
41
assets/fonts/msyh.ttc.import
Normal file
@@ -0,0 +1,41 @@
|
||||
[remap]
|
||||
|
||||
importer="font_data_dynamic"
|
||||
type="FontFile"
|
||||
uid="uid://ce7ujbeobblyr"
|
||||
path="res://.godot/imported/msyh.ttc-1f7944f6d1cff8092894a3525ec5156c.fontdata"
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://assets/fonts/msyh.ttc"
|
||||
dest_files=["res://.godot/imported/msyh.ttc-1f7944f6d1cff8092894a3525ec5156c.fontdata"]
|
||||
|
||||
[params]
|
||||
|
||||
Rendering=null
|
||||
antialiasing=1
|
||||
generate_mipmaps=false
|
||||
disable_embedded_bitmaps=true
|
||||
multichannel_signed_distance_field=false
|
||||
msdf_pixel_range=8
|
||||
msdf_size=48
|
||||
allow_system_fallback=true
|
||||
force_autohinter=false
|
||||
modulate_color_glyphs=false
|
||||
hinting=1
|
||||
subpixel_positioning=4
|
||||
keep_rounding_remainders=true
|
||||
oversampling=0.0
|
||||
Fallbacks=null
|
||||
fallbacks=[]
|
||||
Compress=null
|
||||
compress=false
|
||||
preload=[{
|
||||
"chars": "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz!@#$%^&*()_+-=[]{}|;':\",./<>?`~一二三四五六七八九十百千万亿用户名密码登录注册验证码邮箱小镇鲸鱼欢迎来到开始你的之旅请输入不能为空获取发送忘记返回居民身份确认再次已被使用换个等待分钟后试稍后正在创建账户测试模式生成查看控制台网络连接失败系统维护中升级稍后再试频繁联系管理员禁用审核先邮箱后使用成功进入镇错误或过期未找到存在",
|
||||
"glyphs": [],
|
||||
"name": "Web预加载",
|
||||
"size": Vector2i(16, 0)
|
||||
}]
|
||||
language_support={}
|
||||
script_support={}
|
||||
opentype_features={}
|
||||
BIN
assets/icon/icon144.png
Normal file
|
After Width: | Height: | Size: 13 KiB |
@@ -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
|
After Width: | Height: | Size: 644 B |
@@ -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
|
After Width: | Height: | Size: 18 KiB |
40
assets/icon/icon180.png.import
Normal file
@@ -0,0 +1,40 @@
|
||||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://drpllpsjdiaex"
|
||||
path="res://.godot/imported/icon180.png-20a9d7b98bfb315dd470e3635f315a17.ctex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://assets/icon/icon180.png"
|
||||
dest_files=["res://.godot/imported/icon180.png-20a9d7b98bfb315dd470e3635f315a17.ctex"]
|
||||
|
||||
[params]
|
||||
|
||||
compress/mode=0
|
||||
compress/high_quality=false
|
||||
compress/lossy_quality=0.7
|
||||
compress/uastc_level=0
|
||||
compress/rdo_quality_loss=0.0
|
||||
compress/hdr_compression=1
|
||||
compress/normal_map=0
|
||||
compress/channel_pack=0
|
||||
mipmaps/generate=false
|
||||
mipmaps/limit=-1
|
||||
roughness/mode=0
|
||||
roughness/src_normal=""
|
||||
process/channel_remap/red=0
|
||||
process/channel_remap/green=1
|
||||
process/channel_remap/blue=2
|
||||
process/channel_remap/alpha=3
|
||||
process/fix_alpha_border=true
|
||||
process/premult_alpha=false
|
||||
process/normal_map_invert_y=false
|
||||
process/hdr_as_srgb=false
|
||||
process/hdr_clamp_exposure=false
|
||||
process/size_limit=0
|
||||
detect_3d/compress_to=1
|
||||
BIN
assets/icon/icon32.png
Normal file
|
After Width: | Height: | Size: 1.7 KiB |
40
assets/icon/icon32.png.import
Normal file
@@ -0,0 +1,40 @@
|
||||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://dt24j6p0cijqo"
|
||||
path="res://.godot/imported/icon32.png-9a0aceb23d191139c34540a188bf8c91.ctex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://assets/icon/icon32.png"
|
||||
dest_files=["res://.godot/imported/icon32.png-9a0aceb23d191139c34540a188bf8c91.ctex"]
|
||||
|
||||
[params]
|
||||
|
||||
compress/mode=0
|
||||
compress/high_quality=false
|
||||
compress/lossy_quality=0.7
|
||||
compress/uastc_level=0
|
||||
compress/rdo_quality_loss=0.0
|
||||
compress/hdr_compression=1
|
||||
compress/normal_map=0
|
||||
compress/channel_pack=0
|
||||
mipmaps/generate=false
|
||||
mipmaps/limit=-1
|
||||
roughness/mode=0
|
||||
roughness/src_normal=""
|
||||
process/channel_remap/red=0
|
||||
process/channel_remap/green=1
|
||||
process/channel_remap/blue=2
|
||||
process/channel_remap/alpha=3
|
||||
process/fix_alpha_border=true
|
||||
process/premult_alpha=false
|
||||
process/normal_map_invert_y=false
|
||||
process/hdr_as_srgb=false
|
||||
process/hdr_clamp_exposure=false
|
||||
process/size_limit=0
|
||||
detect_3d/compress_to=1
|
||||
BIN
assets/icon/icon512.png
Normal file
|
After Width: | Height: | Size: 78 KiB |
40
assets/icon/icon512.png.import
Normal file
@@ -0,0 +1,40 @@
|
||||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://dt817lem3dwee"
|
||||
path="res://.godot/imported/icon512.png-1c1c4b424489de87a542c89bec6eb15b.ctex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://assets/icon/icon512.png"
|
||||
dest_files=["res://.godot/imported/icon512.png-1c1c4b424489de87a542c89bec6eb15b.ctex"]
|
||||
|
||||
[params]
|
||||
|
||||
compress/mode=0
|
||||
compress/high_quality=false
|
||||
compress/lossy_quality=0.7
|
||||
compress/uastc_level=0
|
||||
compress/rdo_quality_loss=0.0
|
||||
compress/hdr_compression=1
|
||||
compress/normal_map=0
|
||||
compress/channel_pack=0
|
||||
mipmaps/generate=false
|
||||
mipmaps/limit=-1
|
||||
roughness/mode=0
|
||||
roughness/src_normal=""
|
||||
process/channel_remap/red=0
|
||||
process/channel_remap/green=1
|
||||
process/channel_remap/blue=2
|
||||
process/channel_remap/alpha=3
|
||||
process/fix_alpha_border=true
|
||||
process/premult_alpha=false
|
||||
process/normal_map_invert_y=false
|
||||
process/hdr_as_srgb=false
|
||||
process/hdr_clamp_exposure=false
|
||||
process/size_limit=0
|
||||
detect_3d/compress_to=1
|
||||
BIN
assets/icon/icon64.png
Normal file
|
After Width: | Height: | Size: 4.5 KiB |
40
assets/icon/icon64.png.import
Normal file
@@ -0,0 +1,40 @@
|
||||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://ci42rd5qe6icl"
|
||||
path="res://.godot/imported/icon64.png-da8a1a20e3bf4dcf06c8ff6c558caaff.ctex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://assets/icon/icon64.png"
|
||||
dest_files=["res://.godot/imported/icon64.png-da8a1a20e3bf4dcf06c8ff6c558caaff.ctex"]
|
||||
|
||||
[params]
|
||||
|
||||
compress/mode=0
|
||||
compress/high_quality=false
|
||||
compress/lossy_quality=0.7
|
||||
compress/uastc_level=0
|
||||
compress/rdo_quality_loss=0.0
|
||||
compress/hdr_compression=1
|
||||
compress/normal_map=0
|
||||
compress/channel_pack=0
|
||||
mipmaps/generate=false
|
||||
mipmaps/limit=-1
|
||||
roughness/mode=0
|
||||
roughness/src_normal=""
|
||||
process/channel_remap/red=0
|
||||
process/channel_remap/green=1
|
||||
process/channel_remap/blue=2
|
||||
process/channel_remap/alpha=3
|
||||
process/fix_alpha_border=true
|
||||
process/premult_alpha=false
|
||||
process/normal_map_invert_y=false
|
||||
process/hdr_as_srgb=false
|
||||
process/hdr_clamp_exposure=false
|
||||
process/size_limit=0
|
||||
detect_3d/compress_to=1
|
||||
BIN
assets/icon/image(1).png
Normal file
|
After Width: | Height: | Size: 150 KiB |
40
assets/icon/image(1).png.import
Normal file
@@ -0,0 +1,40 @@
|
||||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://cnw6e3wmy0ea4"
|
||||
path="res://.godot/imported/image(1).png-c89cc92103e50aaba40bf38c797be77f.ctex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://assets/icon/image(1).png"
|
||||
dest_files=["res://.godot/imported/image(1).png-c89cc92103e50aaba40bf38c797be77f.ctex"]
|
||||
|
||||
[params]
|
||||
|
||||
compress/mode=0
|
||||
compress/high_quality=false
|
||||
compress/lossy_quality=0.7
|
||||
compress/uastc_level=0
|
||||
compress/rdo_quality_loss=0.0
|
||||
compress/hdr_compression=1
|
||||
compress/normal_map=0
|
||||
compress/channel_pack=0
|
||||
mipmaps/generate=false
|
||||
mipmaps/limit=-1
|
||||
roughness/mode=0
|
||||
roughness/src_normal=""
|
||||
process/channel_remap/red=0
|
||||
process/channel_remap/green=1
|
||||
process/channel_remap/blue=2
|
||||
process/channel_remap/alpha=3
|
||||
process/fix_alpha_border=true
|
||||
process/premult_alpha=false
|
||||
process/normal_map_invert_y=false
|
||||
process/hdr_as_srgb=false
|
||||
process/hdr_clamp_exposure=false
|
||||
process/size_limit=0
|
||||
detect_3d/compress_to=1
|
||||
BIN
assets/icon/image.png
Normal file
|
After Width: | Height: | Size: 91 KiB |
@@ -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]
|
||||
|
||||
|
Before Width: | Height: | Size: 183 KiB |
|
Before Width: | Height: | Size: 840 KiB |
|
Before Width: | Height: | Size: 218 KiB |
1
assets/materials/.gitkeep
Normal file
@@ -0,0 +1 @@
|
||||
# 保持目录结构 - 材质资源目录
|
||||
BIN
assets/materials/WelcomeBoard.png
Normal file
|
After Width: | Height: | Size: 179 KiB |
40
assets/materials/WelcomeBoard.png.import
Normal file
@@ -0,0 +1,40 @@
|
||||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://v7loa3smfkrd"
|
||||
path="res://.godot/imported/WelcomeBoard.png-bcff7f9bf968cb5d7630e2ad47f2fb42.ctex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://assets/materials/WelcomeBoard.png"
|
||||
dest_files=["res://.godot/imported/WelcomeBoard.png-bcff7f9bf968cb5d7630e2ad47f2fb42.ctex"]
|
||||
|
||||
[params]
|
||||
|
||||
compress/mode=0
|
||||
compress/high_quality=false
|
||||
compress/lossy_quality=0.7
|
||||
compress/uastc_level=0
|
||||
compress/rdo_quality_loss=0.0
|
||||
compress/hdr_compression=1
|
||||
compress/normal_map=0
|
||||
compress/channel_pack=0
|
||||
mipmaps/generate=false
|
||||
mipmaps/limit=-1
|
||||
roughness/mode=0
|
||||
roughness/src_normal=""
|
||||
process/channel_remap/red=0
|
||||
process/channel_remap/green=1
|
||||
process/channel_remap/blue=2
|
||||
process/channel_remap/alpha=3
|
||||
process/fix_alpha_border=true
|
||||
process/premult_alpha=false
|
||||
process/normal_map_invert_y=false
|
||||
process/hdr_as_srgb=false
|
||||
process/hdr_clamp_exposure=false
|
||||
process/size_limit=0
|
||||
detect_3d/compress_to=1
|
||||
1
assets/shaders/.gitkeep
Normal file
@@ -0,0 +1 @@
|
||||
# 保持目录结构 - 着色器资源目录
|
||||
1
assets/sprites/characters/.gitkeep
Normal file
@@ -0,0 +1 @@
|
||||
# 保持目录结构 - 角色精灵资源目录
|
||||
1
assets/sprites/effects/.gitkeep
Normal file
@@ -0,0 +1 @@
|
||||
# 保持目录结构 - 特效精灵资源目录
|
||||
1
assets/sprites/environment/.gitkeep
Normal file
@@ -0,0 +1 @@
|
||||
# 保持目录结构 - 环境精灵资源目录
|
||||
BIN
assets/sprites/environment/board.png
Normal file
|
After Width: | Height: | Size: 1.1 MiB |
40
assets/sprites/environment/board.png.import
Normal file
@@ -0,0 +1,40 @@
|
||||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://c7jx40leuy6q1"
|
||||
path="res://.godot/imported/board.png-4f7a101e7a1b1cbdc8a75666c78e8907.ctex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://assets/sprites/environment/board.png"
|
||||
dest_files=["res://.godot/imported/board.png-4f7a101e7a1b1cbdc8a75666c78e8907.ctex"]
|
||||
|
||||
[params]
|
||||
|
||||
compress/mode=0
|
||||
compress/high_quality=false
|
||||
compress/lossy_quality=0.7
|
||||
compress/uastc_level=0
|
||||
compress/rdo_quality_loss=0.0
|
||||
compress/hdr_compression=1
|
||||
compress/normal_map=0
|
||||
compress/channel_pack=0
|
||||
mipmaps/generate=false
|
||||
mipmaps/limit=-1
|
||||
roughness/mode=0
|
||||
roughness/src_normal=""
|
||||
process/channel_remap/red=0
|
||||
process/channel_remap/green=1
|
||||
process/channel_remap/blue=2
|
||||
process/channel_remap/alpha=3
|
||||
process/fix_alpha_border=true
|
||||
process/premult_alpha=false
|
||||
process/normal_map_invert_y=false
|
||||
process/hdr_as_srgb=false
|
||||
process/hdr_clamp_exposure=false
|
||||
process/size_limit=0
|
||||
detect_3d/compress_to=1
|
||||
BIN
assets/sprites/environment/community.png
Normal file
|
After Width: | Height: | Size: 5.6 MiB |
40
assets/sprites/environment/community.png.import
Normal file
@@ -0,0 +1,40 @@
|
||||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://7j3n0nhg8atb"
|
||||
path="res://.godot/imported/community.png-a8c4bd53b7eaad8a751801ba0eb4ea69.ctex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://assets/sprites/environment/community.png"
|
||||
dest_files=["res://.godot/imported/community.png-a8c4bd53b7eaad8a751801ba0eb4ea69.ctex"]
|
||||
|
||||
[params]
|
||||
|
||||
compress/mode=0
|
||||
compress/high_quality=false
|
||||
compress/lossy_quality=0.7
|
||||
compress/uastc_level=0
|
||||
compress/rdo_quality_loss=0.0
|
||||
compress/hdr_compression=1
|
||||
compress/normal_map=0
|
||||
compress/channel_pack=0
|
||||
mipmaps/generate=false
|
||||
mipmaps/limit=-1
|
||||
roughness/mode=0
|
||||
roughness/src_normal=""
|
||||
process/channel_remap/red=0
|
||||
process/channel_remap/green=1
|
||||
process/channel_remap/blue=2
|
||||
process/channel_remap/alpha=3
|
||||
process/fix_alpha_border=true
|
||||
process/premult_alpha=false
|
||||
process/normal_map_invert_y=false
|
||||
process/hdr_as_srgb=false
|
||||
process/hdr_clamp_exposure=false
|
||||
process/size_limit=0
|
||||
detect_3d/compress_to=1
|
||||
BIN
assets/sprites/environment/community_512_512.png
Normal file
|
After Width: | Height: | Size: 458 KiB |
40
assets/sprites/environment/community_512_512.png.import
Normal file
@@ -0,0 +1,40 @@
|
||||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://cle66our01dq1"
|
||||
path="res://.godot/imported/community_512_512.png-fa162180b6884ce89074ec9b8b445a11.ctex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://assets/sprites/environment/community_512_512.png"
|
||||
dest_files=["res://.godot/imported/community_512_512.png-fa162180b6884ce89074ec9b8b445a11.ctex"]
|
||||
|
||||
[params]
|
||||
|
||||
compress/mode=0
|
||||
compress/high_quality=false
|
||||
compress/lossy_quality=0.7
|
||||
compress/uastc_level=0
|
||||
compress/rdo_quality_loss=0.0
|
||||
compress/hdr_compression=1
|
||||
compress/normal_map=0
|
||||
compress/channel_pack=0
|
||||
mipmaps/generate=false
|
||||
mipmaps/limit=-1
|
||||
roughness/mode=0
|
||||
roughness/src_normal=""
|
||||
process/channel_remap/red=0
|
||||
process/channel_remap/green=1
|
||||
process/channel_remap/blue=2
|
||||
process/channel_remap/alpha=3
|
||||
process/fix_alpha_border=true
|
||||
process/premult_alpha=false
|
||||
process/normal_map_invert_y=false
|
||||
process/hdr_as_srgb=false
|
||||
process/hdr_clamp_exposure=false
|
||||
process/size_limit=0
|
||||
detect_3d/compress_to=1
|
||||
BIN
assets/sprites/environment/curb.png
Normal file
|
After Width: | Height: | Size: 351 KiB |
40
assets/sprites/environment/curb.png.import
Normal file
@@ -0,0 +1,40 @@
|
||||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://b2gci3tcylfiw"
|
||||
path="res://.godot/imported/curb.png-aea973bea0e48d7135256b05941024a3.ctex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://assets/sprites/environment/curb.png"
|
||||
dest_files=["res://.godot/imported/curb.png-aea973bea0e48d7135256b05941024a3.ctex"]
|
||||
|
||||
[params]
|
||||
|
||||
compress/mode=0
|
||||
compress/high_quality=false
|
||||
compress/lossy_quality=0.7
|
||||
compress/uastc_level=0
|
||||
compress/rdo_quality_loss=0.0
|
||||
compress/hdr_compression=1
|
||||
compress/normal_map=0
|
||||
compress/channel_pack=0
|
||||
mipmaps/generate=false
|
||||
mipmaps/limit=-1
|
||||
roughness/mode=0
|
||||
roughness/src_normal=""
|
||||
process/channel_remap/red=0
|
||||
process/channel_remap/green=1
|
||||
process/channel_remap/blue=2
|
||||
process/channel_remap/alpha=3
|
||||
process/fix_alpha_border=true
|
||||
process/premult_alpha=false
|
||||
process/normal_map_invert_y=false
|
||||
process/hdr_as_srgb=false
|
||||
process/hdr_clamp_exposure=false
|
||||
process/size_limit=0
|
||||
detect_3d/compress_to=1
|
||||
BIN
assets/sprites/environment/deck_256_111.png
Normal file
|
After Width: | Height: | Size: 28 KiB |
40
assets/sprites/environment/deck_256_111.png.import
Normal file
@@ -0,0 +1,40 @@
|
||||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://bxk7qx15ks23n"
|
||||
path="res://.godot/imported/deck_256_111.png-1f5516606f281e4ce47eda14a0f195f6.ctex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://assets/sprites/environment/deck_256_111.png"
|
||||
dest_files=["res://.godot/imported/deck_256_111.png-1f5516606f281e4ce47eda14a0f195f6.ctex"]
|
||||
|
||||
[params]
|
||||
|
||||
compress/mode=0
|
||||
compress/high_quality=false
|
||||
compress/lossy_quality=0.7
|
||||
compress/uastc_level=0
|
||||
compress/rdo_quality_loss=0.0
|
||||
compress/hdr_compression=1
|
||||
compress/normal_map=0
|
||||
compress/channel_pack=0
|
||||
mipmaps/generate=false
|
||||
mipmaps/limit=-1
|
||||
roughness/mode=0
|
||||
roughness/src_normal=""
|
||||
process/channel_remap/red=0
|
||||
process/channel_remap/green=1
|
||||
process/channel_remap/blue=2
|
||||
process/channel_remap/alpha=3
|
||||
process/fix_alpha_border=true
|
||||
process/premult_alpha=false
|
||||
process/normal_map_invert_y=false
|
||||
process/hdr_as_srgb=false
|
||||
process/hdr_clamp_exposure=false
|
||||
process/size_limit=0
|
||||
detect_3d/compress_to=1
|
||||
BIN
assets/sprites/environment/deck_256_93.png
Normal file
|
After Width: | Height: | Size: 29 KiB |
40
assets/sprites/environment/deck_256_93.png.import
Normal file
@@ -0,0 +1,40 @@
|
||||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://cuoondqo7wpvm"
|
||||
path="res://.godot/imported/deck_256_93.png-53cc7596920e943ad680f551cecde9c5.ctex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://assets/sprites/environment/deck_256_93.png"
|
||||
dest_files=["res://.godot/imported/deck_256_93.png-53cc7596920e943ad680f551cecde9c5.ctex"]
|
||||
|
||||
[params]
|
||||
|
||||
compress/mode=0
|
||||
compress/high_quality=false
|
||||
compress/lossy_quality=0.7
|
||||
compress/uastc_level=0
|
||||
compress/rdo_quality_loss=0.0
|
||||
compress/hdr_compression=1
|
||||
compress/normal_map=0
|
||||
compress/channel_pack=0
|
||||
mipmaps/generate=false
|
||||
mipmaps/limit=-1
|
||||
roughness/mode=0
|
||||
roughness/src_normal=""
|
||||
process/channel_remap/red=0
|
||||
process/channel_remap/green=1
|
||||
process/channel_remap/blue=2
|
||||
process/channel_remap/alpha=3
|
||||
process/fix_alpha_border=true
|
||||
process/premult_alpha=false
|
||||
process/normal_map_invert_y=false
|
||||
process/hdr_as_srgb=false
|
||||
process/hdr_clamp_exposure=false
|
||||
process/size_limit=0
|
||||
detect_3d/compress_to=1
|
||||
BIN
assets/sprites/environment/deck_2784_1536.png
Normal file
|
After Width: | Height: | Size: 1.5 MiB |
40
assets/sprites/environment/deck_2784_1536.png.import
Normal file
@@ -0,0 +1,40 @@
|
||||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://dth4pwye1huv1"
|
||||
path="res://.godot/imported/deck_2784_1536.png-7209e3c01bcb29b96850c5bfe2118eb5.ctex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://assets/sprites/environment/deck_2784_1536.png"
|
||||
dest_files=["res://.godot/imported/deck_2784_1536.png-7209e3c01bcb29b96850c5bfe2118eb5.ctex"]
|
||||
|
||||
[params]
|
||||
|
||||
compress/mode=0
|
||||
compress/high_quality=false
|
||||
compress/lossy_quality=0.7
|
||||
compress/uastc_level=0
|
||||
compress/rdo_quality_loss=0.0
|
||||
compress/hdr_compression=1
|
||||
compress/normal_map=0
|
||||
compress/channel_pack=0
|
||||
mipmaps/generate=false
|
||||
mipmaps/limit=-1
|
||||
roughness/mode=0
|
||||
roughness/src_normal=""
|
||||
process/channel_remap/red=0
|
||||
process/channel_remap/green=1
|
||||
process/channel_remap/blue=2
|
||||
process/channel_remap/alpha=3
|
||||
process/fix_alpha_border=true
|
||||
process/premult_alpha=false
|
||||
process/normal_map_invert_y=false
|
||||
process/hdr_as_srgb=false
|
||||
process/hdr_clamp_exposure=false
|
||||
process/size_limit=0
|
||||
detect_3d/compress_to=1
|
||||
BIN
assets/sprites/environment/deck_384_167.png
Normal file
|
After Width: | Height: | Size: 57 KiB |
40
assets/sprites/environment/deck_384_167.png.import
Normal file
@@ -0,0 +1,40 @@
|
||||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://d3w3fncsm32oi"
|
||||
path="res://.godot/imported/deck_384_167.png-f28a21a5574e4d3fa7c0565d6c292757.ctex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://assets/sprites/environment/deck_384_167.png"
|
||||
dest_files=["res://.godot/imported/deck_384_167.png-f28a21a5574e4d3fa7c0565d6c292757.ctex"]
|
||||
|
||||
[params]
|
||||
|
||||
compress/mode=0
|
||||
compress/high_quality=false
|
||||
compress/lossy_quality=0.7
|
||||
compress/uastc_level=0
|
||||
compress/rdo_quality_loss=0.0
|
||||
compress/hdr_compression=1
|
||||
compress/normal_map=0
|
||||
compress/channel_pack=0
|
||||
mipmaps/generate=false
|
||||
mipmaps/limit=-1
|
||||
roughness/mode=0
|
||||
roughness/src_normal=""
|
||||
process/channel_remap/red=0
|
||||
process/channel_remap/green=1
|
||||
process/channel_remap/blue=2
|
||||
process/channel_remap/alpha=3
|
||||
process/fix_alpha_border=true
|
||||
process/premult_alpha=false
|
||||
process/normal_map_invert_y=false
|
||||
process/hdr_as_srgb=false
|
||||
process/hdr_clamp_exposure=false
|
||||
process/size_limit=0
|
||||
detect_3d/compress_to=1
|
||||
BIN
assets/sprites/environment/deck_512_164.png
Normal file
|
After Width: | Height: | Size: 83 KiB |
40
assets/sprites/environment/deck_512_164.png.import
Normal file
@@ -0,0 +1,40 @@
|
||||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://j0twhfkpj15i"
|
||||
path="res://.godot/imported/deck_512_164.png-c98703495d73d104671911f6dada9aca.ctex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://assets/sprites/environment/deck_512_164.png"
|
||||
dest_files=["res://.godot/imported/deck_512_164.png-c98703495d73d104671911f6dada9aca.ctex"]
|
||||
|
||||
[params]
|
||||
|
||||
compress/mode=0
|
||||
compress/high_quality=false
|
||||
compress/lossy_quality=0.7
|
||||
compress/uastc_level=0
|
||||
compress/rdo_quality_loss=0.0
|
||||
compress/hdr_compression=1
|
||||
compress/normal_map=0
|
||||
compress/channel_pack=0
|
||||
mipmaps/generate=false
|
||||
mipmaps/limit=-1
|
||||
roughness/mode=0
|
||||
roughness/src_normal=""
|
||||
process/channel_remap/red=0
|
||||
process/channel_remap/green=1
|
||||
process/channel_remap/blue=2
|
||||
process/channel_remap/alpha=3
|
||||
process/fix_alpha_border=true
|
||||
process/premult_alpha=false
|
||||
process/normal_map_invert_y=false
|
||||
process/hdr_as_srgb=false
|
||||
process/hdr_clamp_exposure=false
|
||||
process/size_limit=0
|
||||
detect_3d/compress_to=1
|
||||
BIN
assets/sprites/environment/deck_512_282.png
Normal file
|
After Width: | Height: | Size: 37 KiB |
40
assets/sprites/environment/deck_512_282.png.import
Normal file
@@ -0,0 +1,40 @@
|
||||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://blre1srim52hs"
|
||||
path="res://.godot/imported/deck_512_282.png-ec2cdd543ebb499e3623cd89dff86aa4.ctex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://assets/sprites/environment/deck_512_282.png"
|
||||
dest_files=["res://.godot/imported/deck_512_282.png-ec2cdd543ebb499e3623cd89dff86aa4.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
|
||||