refactor:重构项目架构为分层结构
## 🏗️ 主要变更 ### 目录结构重构 - 将 core/ 迁移到 _Core/(框架层) - 将 scenes/ 重构为 Scenes/(玩法层)和 UI/(界面层) - 将 data/ 迁移到 Config/(配置层) - 添加 Assets/ 资源层和 Utils/ 工具层 - 将 scripts/ 迁移到 tools/(开发工具) ### 架构分层 - **_Core/**: 框架层 - 全局单例和管理器 - **Scenes/**: 玩法层 - 游戏场景和实体 - **UI/**: 界面层 - HUD、窗口、对话系统 - **Assets/**: 资源层 - 精灵图、音频、字体 - **Config/**: 配置层 - 游戏配置和本地化 - **Utils/**: 工具层 - 通用辅助脚本 ### 文件更新 - 更新 project.godot 中的所有路径引用 - 更新自动加载脚本路径 - 更新测试文件的引用路径 - 添加 REFACTORING.md 详细说明 - 添加 MIGRATION_COMPLETE.md 迁移完成标记 - 更新 README.md 反映新架构 ### 设计原则 - ✅ 清晰的分层(框架/玩法/界面) - ✅ 场景内聚(脚本紧邻场景文件) - ✅ 组件化设计(可复用组件) - ✅ 职责单一(每个目录职责明确) ## 📋 详细信息 查看 REFACTORING.md 了解完整的重构说明和迁移映射表 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
191
tools/README.md
Normal file
191
tools/README.md
Normal file
@@ -0,0 +1,191 @@
|
||||
# 🛠️ 构建和部署工具
|
||||
|
||||
本目录包含项目的构建和部署脚本。
|
||||
|
||||
---
|
||||
|
||||
## 📦 Web 构建工具
|
||||
|
||||
### build_web.sh (Linux/macOS)
|
||||
### build_web.bat (Windows)
|
||||
|
||||
**功能**: 将 Godot 项目导出为 Web 版本
|
||||
|
||||
#### 使用方法
|
||||
|
||||
**macOS/Linux:**
|
||||
```bash
|
||||
chmod +x tools/build_web.sh
|
||||
./tools/build_web.sh
|
||||
```
|
||||
|
||||
**Windows:**
|
||||
```cmd
|
||||
tools\build_web.bat
|
||||
```
|
||||
|
||||
#### 输出目录
|
||||
- `build/web/` - 导出的 Web 游戏文件
|
||||
|
||||
#### 导出内容包括:
|
||||
- `index.html` - Web 入口文件
|
||||
- `index.js` - 游戏主逻辑
|
||||
- `index.wasm` - WebAssembly 文件
|
||||
- `index.pck` - 游戏资源包
|
||||
|
||||
---
|
||||
|
||||
## 🌐 Web 测试服务器
|
||||
|
||||
### serve_web.sh (Linux/macOS)
|
||||
### serve_web.bat (Windows)
|
||||
|
||||
**功能**: 启动本地 HTTP 服务器预览 Web 游戏
|
||||
|
||||
#### 使用方法
|
||||
|
||||
**macOS/Linux:**
|
||||
```bash
|
||||
chmod +x tools/serve_web.sh
|
||||
./tools/serve_web.sh
|
||||
```
|
||||
|
||||
**Windows:**
|
||||
```cmd
|
||||
tools\serve_web.bat
|
||||
```
|
||||
|
||||
#### 访问地址
|
||||
- 默认: `http://localhost:8000`
|
||||
- 浏览器会自动打开
|
||||
|
||||
#### 注意事项
|
||||
⚠️ **必须使用 HTTP 服务器**
|
||||
- 不能直接用 `file://` 打开 `index.html`
|
||||
- Godot Web 版本需要 HTTP 环境
|
||||
- 本服务器已配置正确的 CORS 头
|
||||
|
||||
---
|
||||
|
||||
## 🔧 配置说明
|
||||
|
||||
### 修改 Godot 路径
|
||||
|
||||
编辑脚本中的 `GODOT_PATH` 变量:
|
||||
|
||||
**macOS:**
|
||||
```bash
|
||||
GODOT_PATH="/usr/local/bin/godot" # Homebrew
|
||||
# 或
|
||||
GODOT_PATH="$HOME/Applications/Godot.app/Contents/MacOS/Godot" # 应用程序
|
||||
```
|
||||
|
||||
**Windows:**
|
||||
```batch
|
||||
set GODOT_PATH=C:\Program Files\Godot\godot.exe
|
||||
```
|
||||
|
||||
**Linux:**
|
||||
```bash
|
||||
GODOT_PATH="/usr/bin/godot" # 包管理器
|
||||
# 或
|
||||
GODOT_PATH="$HOME/bin/godot" # 手动安装
|
||||
```
|
||||
|
||||
### 修改端口
|
||||
|
||||
编辑 `serve_web.sh` 或 `serve_web.bat` 中的端口配置:
|
||||
```bash
|
||||
PORT=8080 # 改为其他端口
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 📋 典型工作流程
|
||||
|
||||
### 1. 开发阶段
|
||||
在 Godot 编辑器中开发和测试游戏
|
||||
|
||||
### 2. 导出 Web 版本
|
||||
```bash
|
||||
./tools/build_web.sh
|
||||
```
|
||||
|
||||
### 3. 本地测试
|
||||
```bash
|
||||
./tools/serve_web.sh
|
||||
# 浏览器访问 http://localhost:8000
|
||||
```
|
||||
|
||||
### 4. 部署到服务器
|
||||
将 `build/web/` 目录的内容上传到你的 Web 服务器
|
||||
|
||||
---
|
||||
|
||||
## 🌍 部署平台示例
|
||||
|
||||
### GitHub Pages
|
||||
```bash
|
||||
./tools/build_web.sh
|
||||
# 将 build/web/ 推送到 gh-pages 分支
|
||||
```
|
||||
|
||||
### Netlify
|
||||
```bash
|
||||
# 直接拖拽 build/web/ 目录到 Netlify
|
||||
```
|
||||
|
||||
### Vercel
|
||||
```bash
|
||||
./tools/build_web.sh
|
||||
vercel --prod build/web/
|
||||
```
|
||||
|
||||
### 自己的服务器
|
||||
```bash
|
||||
scp -r build/web/* user@server:/var/www/html/
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## ⚠️ 常见问题
|
||||
|
||||
### 问题 1: 找不到 Godot
|
||||
**解决方案**: 修改脚本中的 `GODOT_PATH` 变量
|
||||
|
||||
### 问题 2: 权限不足 (macOS/Linux)
|
||||
**解决方案**:
|
||||
```bash
|
||||
chmod +x tools/build_web.sh tools/serve_web.sh
|
||||
```
|
||||
|
||||
### 问题 3: 浏览器无法加载游戏
|
||||
**原因**: 必须使用 HTTP 服务器,不能用 `file://`
|
||||
**解决方案**: 使用 `serve_web.sh` 启动本地服务器
|
||||
|
||||
### 问题 4: 游戏黑屏
|
||||
**检查**:
|
||||
- 浏览器控制台是否有错误
|
||||
- WebAssembly 是否启用
|
||||
- 是否在 HTTPS 或 localhost 环境下运行
|
||||
|
||||
---
|
||||
|
||||
## 📚 相关文档
|
||||
|
||||
- [Godot Web 导出文档](https://docs.godotengine.org/en/stable/tutorials/export/exporting_for_web.html)
|
||||
- [Web 服务器配置](https://docs.godotengine.org/en/stable/tutorials/export/binary_files_for_web_games.html)
|
||||
- [项目 Web 部署指南](../docs/web_deployment_guide.md)
|
||||
|
||||
---
|
||||
|
||||
## 🎯 下一步
|
||||
|
||||
1. 确保安装了 Godot 4.5+
|
||||
2. 运行 `./tools/build_web.sh` 测试导出
|
||||
3. 运行 `./tools/serve_web.sh` 本地预览
|
||||
4. 根据需要修改配置参数
|
||||
|
||||
---
|
||||
|
||||
**祝你发布顺利!** 🚀
|
||||
Reference in New Issue
Block a user