zhanglei commited on
Commit ·
ab5909a
1
Parent(s): 11eb8d2
fix voice
Browse files- .dockerignore +35 -35
- 01HXBW1PHMD1MR2K7NHZT0AQVP.mp3 +0 -3
- DEPLOYMENT_CHECKLIST.md +109 -109
- Dockerfile +28 -28
- HUGGINGFACE_DEPLOYMENT.md +237 -237
- README.md +274 -274
- assets/images/ChatGPT Image 2025年9月22日 17_48_21.png +0 -3
- assets/images/ChatGPT Image 2025年9月22日 17_51_40.png +0 -3
- assets/images/ChatGPT Image 2025年9月22日 17_54_23.png +0 -3
- assets/images/README.md +31 -31
- assets/images/magic_potx.png +0 -3
- assets/sounds/README.md +18 -18
- assets/sounds/animal_appear.mp3 +0 -3
- assets/sounds/cookingmp3.mp3 +0 -3
- css/style.css +1124 -1124
- docker-README.md +179 -179
- index.html +164 -164
- js/audio.js +474 -474
- js/keyboard.js +684 -684
- js/particles.js +528 -528
- js/pot.js +471 -471
- js/textToImage.js +346 -346
- js/voice.js +584 -65
- nginx.conf +69 -69
- package-lock.json +0 -0
- package.json +36 -36
- style.css +1163 -1163
- voice.js +0 -667
.dockerignore
CHANGED
|
@@ -1,35 +1,35 @@
|
|
| 1 |
-
# Node.js 相关
|
| 2 |
-
node_modules/
|
| 3 |
-
npm-debug.log*
|
| 4 |
-
yarn-debug.log*
|
| 5 |
-
yarn-error.log*
|
| 6 |
-
|
| 7 |
-
# 包管理文件(Docker镜像中不需要)
|
| 8 |
-
package.json
|
| 9 |
-
package-lock.json
|
| 10 |
-
|
| 11 |
-
# 开发工具和文档
|
| 12 |
-
README.md
|
| 13 |
-
.git/
|
| 14 |
-
.gitignore
|
| 15 |
-
|
| 16 |
-
# 系统文件
|
| 17 |
-
.DS_Store
|
| 18 |
-
Thumbs.db
|
| 19 |
-
|
| 20 |
-
# IDE 文件
|
| 21 |
-
.vscode/
|
| 22 |
-
.idea/
|
| 23 |
-
*.swp
|
| 24 |
-
*.swo
|
| 25 |
-
|
| 26 |
-
# 日志文件
|
| 27 |
-
*.log
|
| 28 |
-
|
| 29 |
-
# Docker相关
|
| 30 |
-
Dockerfile
|
| 31 |
-
.dockerignore
|
| 32 |
-
|
| 33 |
-
# 临时文件
|
| 34 |
-
*.tmp
|
| 35 |
-
*.temp
|
|
|
|
| 1 |
+
# Node.js 相关
|
| 2 |
+
node_modules/
|
| 3 |
+
npm-debug.log*
|
| 4 |
+
yarn-debug.log*
|
| 5 |
+
yarn-error.log*
|
| 6 |
+
|
| 7 |
+
# 包管理文件(Docker镜像中不需要)
|
| 8 |
+
package.json
|
| 9 |
+
package-lock.json
|
| 10 |
+
|
| 11 |
+
# 开发工具和文档
|
| 12 |
+
README.md
|
| 13 |
+
.git/
|
| 14 |
+
.gitignore
|
| 15 |
+
|
| 16 |
+
# 系统文件
|
| 17 |
+
.DS_Store
|
| 18 |
+
Thumbs.db
|
| 19 |
+
|
| 20 |
+
# IDE 文件
|
| 21 |
+
.vscode/
|
| 22 |
+
.idea/
|
| 23 |
+
*.swp
|
| 24 |
+
*.swo
|
| 25 |
+
|
| 26 |
+
# 日志文件
|
| 27 |
+
*.log
|
| 28 |
+
|
| 29 |
+
# Docker相关
|
| 30 |
+
Dockerfile
|
| 31 |
+
.dockerignore
|
| 32 |
+
|
| 33 |
+
# 临时文件
|
| 34 |
+
*.tmp
|
| 35 |
+
*.temp
|
01HXBW1PHMD1MR2K7NHZT0AQVP.mp3
DELETED
|
@@ -1,3 +0,0 @@
|
|
| 1 |
-
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:f0e103049a8e25f57624af9dafd50abaa7e9537c6a3c46801ac50b1cb192002e
|
| 3 |
-
size 960788
|
|
|
|
|
|
|
|
|
|
|
|
DEPLOYMENT_CHECKLIST.md
CHANGED
|
@@ -1,109 +1,109 @@
|
|
| 1 |
-
# MagicPot Hugging Face Spaces 部署清单
|
| 2 |
-
|
| 3 |
-
## ✅ 必需文件(已准备好)
|
| 4 |
-
|
| 5 |
-
### 核心配置
|
| 6 |
-
- [x] `README.md` - 包含正确的 frontmatter 配置
|
| 7 |
-
- [x] `index.html` - 主游戏页面
|
| 8 |
-
|
| 9 |
-
### 游戏代码
|
| 10 |
-
- [x] `css/style.css` - 样式文件
|
| 11 |
-
- [x] `js/main.js` - 主游戏逻辑
|
| 12 |
-
- [x] `js/voice.js` - 语音识别
|
| 13 |
-
- [x] `js/pot.js` - 魔法锅类
|
| 14 |
-
- [x] `js/particles.js` - 粒子系统
|
| 15 |
-
- [x] `js/animals.js` - 动物系统
|
| 16 |
-
- [x] `js/textToImage.js` - 文生图API
|
| 17 |
-
- [x] `js/audio.js` - 音频系统
|
| 18 |
-
- [x] `js/keyboard.js` - 键盘控制
|
| 19 |
-
|
| 20 |
-
### 资源文件
|
| 21 |
-
- [x] `assets/images/` - 图片资源
|
| 22 |
-
- [x] `assets/sounds/` - 音效文件
|
| 23 |
-
- [x] `01HXBW1PHMD1MR2K7NHZT0AQVP.mp3` - 额外音频
|
| 24 |
-
|
| 25 |
-
## ❌ 不需要的文件(静态部署)
|
| 26 |
-
|
| 27 |
-
### Python 相关
|
| 28 |
-
- [ ] ~~`app.py`~~ - 静态部署不需要
|
| 29 |
-
- [ ] ~~`requirements.txt`~~ - 静态部署不需要
|
| 30 |
-
|
| 31 |
-
### Docker 相关(部署到 HF Spaces 时不需要)
|
| 32 |
-
- [ ] ~~`Dockerfile`~~ - HF Spaces 自动处理
|
| 33 |
-
- [ ] ~~`.dockerignore`~~ - HF Spaces 自动处理
|
| 34 |
-
- [ ] ~~`nginx.conf`~~ - HF Spaces 自动处理
|
| 35 |
-
|
| 36 |
-
### 开发工具
|
| 37 |
-
- [ ] ~~`node_modules/`~~ - 不要上传
|
| 38 |
-
- [ ] ~~`package.json`~~ - 静态部署不需要
|
| 39 |
-
- [ ] ~~`package-lock.json`~~ - 静态部署不需要
|
| 40 |
-
|
| 41 |
-
## 🚀 直接部署步骤
|
| 42 |
-
|
| 43 |
-
### 方法1:网页上传
|
| 44 |
-
1. 访问 https://huggingface.co/spaces
|
| 45 |
-
2. 创建新 Space,选择 **Static** SDK
|
| 46 |
-
3. 上传以下文件和文件夹:
|
| 47 |
-
```
|
| 48 |
-
README.md
|
| 49 |
-
index.html
|
| 50 |
-
css/
|
| 51 |
-
js/
|
| 52 |
-
assets/
|
| 53 |
-
01HXBW1PHMD1MR2K7NHZT0AQVP.mp3
|
| 54 |
-
```
|
| 55 |
-
|
| 56 |
-
### 方法2:Git 命令
|
| 57 |
-
```bash
|
| 58 |
-
# 克隆您的 Space
|
| 59 |
-
git clone https://huggingface.co/spaces/YOUR_USERNAME/magicpot-game
|
| 60 |
-
cd magicpot-game
|
| 61 |
-
|
| 62 |
-
# 复制必需文件
|
| 63 |
-
cp README.md index.html ./
|
| 64 |
-
cp -r css js assets ./
|
| 65 |
-
cp 01HXBW1PHMD1MR2K7NHZT0AQVP.mp3 ./
|
| 66 |
-
|
| 67 |
-
# 提交
|
| 68 |
-
git add .
|
| 69 |
-
git commit -m "Deploy MagicPot game to Hugging Face Spaces"
|
| 70 |
-
git push
|
| 71 |
-
```
|
| 72 |
-
|
| 73 |
-
##
|
| 74 |
-
|
| 75 |
-
只需要这些文件即可完整运行游戏:
|
| 76 |
-
|
| 77 |
-
```
|
| 78 |
-
magicpot-game/
|
| 79 |
-
├── README.md # frontmatter 配置
|
| 80 |
-
├── index.html # 主页面
|
| 81 |
-
├── css/
|
| 82 |
-
│ └── style.css # 样式
|
| 83 |
-
├── js/
|
| 84 |
-
│ ├── main.js # 主逻辑
|
| 85 |
-
│ ├── voice.js # 语音
|
| 86 |
-
│ ├── pot.js # 魔法锅
|
| 87 |
-
│ ├── particles.js # 粒子
|
| 88 |
-
│ ├── animals.js # 动物
|
| 89 |
-
│ ├── textToImage.js # 文生图
|
| 90 |
-
│ ├── audio.js # 音频
|
| 91 |
-
│ └── keyboard.js # 键盘
|
| 92 |
-
├── assets/
|
| 93 |
-
│ ├── images/ # 图片资源
|
| 94 |
-
│ └── sounds/ # 音效文件
|
| 95 |
-
└── 01HXBW1PHMD1MR2K7NHZT0AQVP.mp3
|
| 96 |
-
```
|
| 97 |
-
|
| 98 |
-
## ✨ 部署成功验证
|
| 99 |
-
|
| 100 |
-
部署后访问您的 Space,确认:
|
| 101 |
-
- [x] 页面正常加载
|
| 102 |
-
- [x] 魔法锅显示正确
|
| 103 |
-
- [x] 语音识别工作(需要麦克风权限)
|
| 104 |
-
- [x] 音效正常播放
|
| 105 |
-
- [x] 游戏交互正常
|
| 106 |
-
|
| 107 |
-
---
|
| 108 |
-
|
| 109 |
-
**总结**: 您的项目已经完美配置为静态部署,不需要 `app.py` 文件!🎉
|
|
|
|
| 1 |
+
# MagicPot Hugging Face Spaces 部署清单
|
| 2 |
+
|
| 3 |
+
## ✅ 必需文件(已准备好)
|
| 4 |
+
|
| 5 |
+
### 核心配置
|
| 6 |
+
- [x] `README.md` - 包含正确的 frontmatter 配置
|
| 7 |
+
- [x] `index.html` - 主游戏页面
|
| 8 |
+
|
| 9 |
+
### 游戏代码
|
| 10 |
+
- [x] `css/style.css` - 样式文件
|
| 11 |
+
- [x] `js/main.js` - 主游戏逻辑
|
| 12 |
+
- [x] `js/voice.js` - 语音识别
|
| 13 |
+
- [x] `js/pot.js` - 魔法锅类
|
| 14 |
+
- [x] `js/particles.js` - 粒子系统
|
| 15 |
+
- [x] `js/animals.js` - 动物系统
|
| 16 |
+
- [x] `js/textToImage.js` - 文生图API
|
| 17 |
+
- [x] `js/audio.js` - 音频系统
|
| 18 |
+
- [x] `js/keyboard.js` - 键盘控制
|
| 19 |
+
|
| 20 |
+
### 资源文件
|
| 21 |
+
- [x] `assets/images/` - 图片资源
|
| 22 |
+
- [x] `assets/sounds/` - 音效文件
|
| 23 |
+
- [x] `01HXBW1PHMD1MR2K7NHZT0AQVP.mp3` - 额外音频
|
| 24 |
+
|
| 25 |
+
## ❌ 不需要的文件(静态部署)
|
| 26 |
+
|
| 27 |
+
### Python 相关
|
| 28 |
+
- [ ] ~~`app.py`~~ - 静态部署不需要
|
| 29 |
+
- [ ] ~~`requirements.txt`~~ - 静态部署不需要
|
| 30 |
+
|
| 31 |
+
### Docker 相关(部署到 HF Spaces 时不需要)
|
| 32 |
+
- [ ] ~~`Dockerfile`~~ - HF Spaces 自动处理
|
| 33 |
+
- [ ] ~~`.dockerignore`~~ - HF Spaces 自动处理
|
| 34 |
+
- [ ] ~~`nginx.conf`~~ - HF Spaces 自动处理
|
| 35 |
+
|
| 36 |
+
### 开发工具
|
| 37 |
+
- [ ] ~~`node_modules/`~~ - 不要上传
|
| 38 |
+
- [ ] ~~`package.json`~~ - 静态部署不需要
|
| 39 |
+
- [ ] ~~`package-lock.json`~~ - 静态部署不需要
|
| 40 |
+
|
| 41 |
+
## 🚀 直接部署步骤
|
| 42 |
+
|
| 43 |
+
### 方法1:网页上传
|
| 44 |
+
1. 访问 https://huggingface.co/spaces
|
| 45 |
+
2. 创建新 Space,选择 **Static** SDK
|
| 46 |
+
3. 上传以下文件和文件夹:
|
| 47 |
+
```
|
| 48 |
+
README.md
|
| 49 |
+
index.html
|
| 50 |
+
css/
|
| 51 |
+
js/
|
| 52 |
+
assets/
|
| 53 |
+
01HXBW1PHMD1MR2K7NHZT0AQVP.mp3
|
| 54 |
+
```
|
| 55 |
+
|
| 56 |
+
### 方法2:Git 命令
|
| 57 |
+
```bash
|
| 58 |
+
# 克隆您的 Space
|
| 59 |
+
git clone https://huggingface.co/spaces/YOUR_USERNAME/magicpot-game
|
| 60 |
+
cd magicpot-game
|
| 61 |
+
|
| 62 |
+
# 复制必需文件
|
| 63 |
+
cp README.md index.html ./
|
| 64 |
+
cp -r css js assets ./
|
| 65 |
+
cp 01HXBW1PHMD1MR2K7NHZT0AQVP.mp3 ./
|
| 66 |
+
|
| 67 |
+
# 提交
|
| 68 |
+
git add .
|
| 69 |
+
git commit -m "Deploy MagicPot game to Hugging Face Spaces"
|
| 70 |
+
git push
|
| 71 |
+
```
|
| 72 |
+
|
| 73 |
+
## ���� 最小化部署包
|
| 74 |
+
|
| 75 |
+
只需要这些文件即可完整运行游戏:
|
| 76 |
+
|
| 77 |
+
```
|
| 78 |
+
magicpot-game/
|
| 79 |
+
├── README.md # frontmatter 配置
|
| 80 |
+
├── index.html # 主页面
|
| 81 |
+
├── css/
|
| 82 |
+
│ └── style.css # 样式
|
| 83 |
+
├── js/
|
| 84 |
+
│ ├── main.js # 主逻辑
|
| 85 |
+
│ ├── voice.js # 语音
|
| 86 |
+
│ ├── pot.js # 魔法锅
|
| 87 |
+
│ ├── particles.js # 粒子
|
| 88 |
+
│ ├── animals.js # 动物
|
| 89 |
+
│ ├── textToImage.js # 文生图
|
| 90 |
+
│ ├── audio.js # 音频
|
| 91 |
+
│ └── keyboard.js # 键盘
|
| 92 |
+
├── assets/
|
| 93 |
+
│ ├── images/ # 图片资源
|
| 94 |
+
│ └── sounds/ # 音效文件
|
| 95 |
+
└── 01HXBW1PHMD1MR2K7NHZT0AQVP.mp3
|
| 96 |
+
```
|
| 97 |
+
|
| 98 |
+
## ✨ 部署成功验证
|
| 99 |
+
|
| 100 |
+
部署后访问您的 Space,确认:
|
| 101 |
+
- [x] 页面正常加载
|
| 102 |
+
- [x] 魔法锅显示正确
|
| 103 |
+
- [x] 语音识别工作(需要麦克风权限)
|
| 104 |
+
- [x] 音效正常播放
|
| 105 |
+
- [x] 游戏交互正常
|
| 106 |
+
|
| 107 |
+
---
|
| 108 |
+
|
| 109 |
+
**总结**: 您的项目已经完美配置为静态部署,不需要 `app.py` 文件!🎉
|
Dockerfile
CHANGED
|
@@ -1,28 +1,28 @@
|
|
| 1 |
-
# 使用官方nginx镜像作为基础镜像
|
| 2 |
-
FROM nginx:alpine
|
| 3 |
-
|
| 4 |
-
# 设置维护者信息
|
| 5 |
-
LABEL maintainer="MagicPot Game Developer"
|
| 6 |
-
LABEL description="MagicPot - 魔法锅游戏 Docker镜像"
|
| 7 |
-
|
| 8 |
-
# 删除默认的nginx配置
|
| 9 |
-
RUN rm /etc/nginx/conf.d/default.conf
|
| 10 |
-
|
| 11 |
-
# 复制自定义nginx配置
|
| 12 |
-
COPY nginx.conf /etc/nginx/conf.d/
|
| 13 |
-
|
| 14 |
-
# 复制项目文件到nginx的html目录
|
| 15 |
-
COPY index.html /usr/share/nginx/html/
|
| 16 |
-
COPY css/ /usr/share/nginx/html/css/
|
| 17 |
-
COPY js/ /usr/share/nginx/html/js/
|
| 18 |
-
COPY assets/ /usr/share/nginx/html/assets/
|
| 19 |
-
COPY *.mp3 /usr/share/nginx/html/
|
| 20 |
-
|
| 21 |
-
# 设置正确的文件权限
|
| 22 |
-
RUN chmod -R 755 /usr/share/nginx/html
|
| 23 |
-
|
| 24 |
-
# 暴露80端口
|
| 25 |
-
EXPOSE 80
|
| 26 |
-
|
| 27 |
-
# 启动nginx
|
| 28 |
-
CMD ["nginx", "-g", "daemon off;"]
|
|
|
|
| 1 |
+
# 使用官方nginx镜像作为基础镜像
|
| 2 |
+
FROM nginx:alpine
|
| 3 |
+
|
| 4 |
+
# 设置维护者信息
|
| 5 |
+
LABEL maintainer="MagicPot Game Developer"
|
| 6 |
+
LABEL description="MagicPot - 魔法锅游戏 Docker镜像"
|
| 7 |
+
|
| 8 |
+
# 删除默认的nginx配置
|
| 9 |
+
RUN rm /etc/nginx/conf.d/default.conf
|
| 10 |
+
|
| 11 |
+
# 复制自定义nginx配置
|
| 12 |
+
COPY nginx.conf /etc/nginx/conf.d/
|
| 13 |
+
|
| 14 |
+
# 复制项目文件到nginx的html目录
|
| 15 |
+
COPY index.html /usr/share/nginx/html/
|
| 16 |
+
COPY css/ /usr/share/nginx/html/css/
|
| 17 |
+
COPY js/ /usr/share/nginx/html/js/
|
| 18 |
+
COPY assets/ /usr/share/nginx/html/assets/
|
| 19 |
+
COPY *.mp3 /usr/share/nginx/html/
|
| 20 |
+
|
| 21 |
+
# 设置正确的文件权限
|
| 22 |
+
RUN chmod -R 755 /usr/share/nginx/html
|
| 23 |
+
|
| 24 |
+
# 暴露80端口
|
| 25 |
+
EXPOSE 80
|
| 26 |
+
|
| 27 |
+
# 启动nginx
|
| 28 |
+
CMD ["nginx", "-g", "daemon off;"]
|
HUGGINGFACE_DEPLOYMENT.md
CHANGED
|
@@ -1,237 +1,237 @@
|
|
| 1 |
-
# MagicPot Hugging Face Spaces 部署指南
|
| 2 |
-
|
| 3 |
-
## 🚀 快速部署
|
| 4 |
-
|
| 5 |
-
### 1. 准备工作
|
| 6 |
-
确保您的项目根目录包含以下关键文件:
|
| 7 |
-
- `README.md` - 包含正确的frontmatter配置
|
| 8 |
-
- `index.html` - 主游戏页面
|
| 9 |
-
- 完整的项目文件结构
|
| 10 |
-
|
| 11 |
-
### 2. Hugging Face Spaces 配置
|
| 12 |
-
|
| 13 |
-
README.md 中的 frontmatter 配置已经正确设置:
|
| 14 |
-
|
| 15 |
-
```yaml
|
| 16 |
-
---
|
| 17 |
-
title: MagicPot - 魔法锅游戏
|
| 18 |
-
emoji: 🪄
|
| 19 |
-
colorFrom: purple
|
| 20 |
-
colorTo: pink
|
| 21 |
-
sdk: static
|
| 22 |
-
pinned: false
|
| 23 |
-
license: mit
|
| 24 |
-
---
|
| 25 |
-
```
|
| 26 |
-
|
| 27 |
-
### 3. 部署步骤
|
| 28 |
-
|
| 29 |
-
#### 方法一:通过 Hugging Face 网页界面
|
| 30 |
-
1. 访问 [Hugging Face Spaces](https://huggingface.co/spaces)
|
| 31 |
-
2. 点击 "Create new Space"
|
| 32 |
-
3. 填写以下信息:
|
| 33 |
-
- **Space name**: `magicpot-game`
|
| 34 |
-
- **License**: MIT
|
| 35 |
-
- **SDK**: Static
|
| 36 |
-
- **Visibility**: Public
|
| 37 |
-
4. 创建后,将项目文件上传到 Space
|
| 38 |
-
|
| 39 |
-
#### 方法二:通过 Git 命令行
|
| 40 |
-
```bash
|
| 41 |
-
# 1. 克隆您的 Hugging Face Space
|
| 42 |
-
git clone https://huggingface.co/spaces/YOUR_USERNAME/magicpot-game
|
| 43 |
-
cd magicpot-game
|
| 44 |
-
|
| 45 |
-
# 2. 复制项目文件
|
| 46 |
-
cp -r /path/to/MagicPot/* .
|
| 47 |
-
|
| 48 |
-
# 3. 提交和推送
|
| 49 |
-
git add .
|
| 50 |
-
git commit -m "Initial deployment of MagicPot game"
|
| 51 |
-
git push
|
| 52 |
-
```
|
| 53 |
-
|
| 54 |
-
#### 方法三:使用 Hugging Face CLI
|
| 55 |
-
```bash
|
| 56 |
-
# 安装 Hugging Face CLI
|
| 57 |
-
pip install huggingface_hub
|
| 58 |
-
|
| 59 |
-
# 登录
|
| 60 |
-
huggingface-cli login
|
| 61 |
-
|
| 62 |
-
# 上传项目
|
| 63 |
-
huggingface-cli upload YOUR_USERNAME/magicpot-game . --repo-type=space
|
| 64 |
-
```
|
| 65 |
-
|
| 66 |
-
## 📁 项目结构确认
|
| 67 |
-
|
| 68 |
-
确保项目根目录结构如下:
|
| 69 |
-
```
|
| 70 |
-
magicpot-game/
|
| 71 |
-
├── README.md # ✅ 包含正确的frontmatter
|
| 72 |
-
├── index.html # ✅ 主页面
|
| 73 |
-
├── css/
|
| 74 |
-
│ └── style.css # ✅ 样式文件
|
| 75 |
-
├── js/
|
| 76 |
-
│ ├── main.js # ✅ 主游戏逻辑
|
| 77 |
-
│ ├── voice.js # ✅ 语音识别
|
| 78 |
-
│ ├── pot.js # ✅ 魔法锅类
|
| 79 |
-
│ ├── particles.js # ✅ 粒子系统
|
| 80 |
-
│ ├── animals.js # ✅ 动物系统
|
| 81 |
-
│ ├── textToImage.js # ✅ 文生图API
|
| 82 |
-
│ ├── audio.js # ✅ 音频系统
|
| 83 |
-
│ └── keyboard.js # ✅ 键盘控制
|
| 84 |
-
├── assets/
|
| 85 |
-
│ ├── images/ # ✅ 图片资源
|
| 86 |
-
│ └── sounds/ # ✅ 音效文件
|
| 87 |
-
└── *.mp3 # ✅ 音频文件
|
| 88 |
-
```
|
| 89 |
-
|
| 90 |
-
## 🔧 Hugging Face Spaces 特殊注意事项
|
| 91 |
-
|
| 92 |
-
### HTTPS 要求
|
| 93 |
-
- Hugging Face Spaces 自动提供 HTTPS
|
| 94 |
-
- 语音识别功能需要 HTTPS 环境,在 Spaces 上会正常工作
|
| 95 |
-
|
| 96 |
-
### 跨域资源共享 (CORS)
|
| 97 |
-
- 静态文件自动配置正确的 CORS 头
|
| 98 |
-
- 音频和图片资源可以正常加载
|
| 99 |
-
|
| 100 |
-
### 文生图 API 配置
|
| 101 |
-
- 确保在游戏中配置有效的 API 密钥
|
| 102 |
-
- 用户可以通过 `Ctrl+Shift+I` 快捷键配置
|
| 103 |
-
|
| 104 |
-
### 性能优化
|
| 105 |
-
- Hugging Face Spaces 提供全球 CDN
|
| 106 |
-
- 静态资源会被自动缓存
|
| 107 |
-
- 建议文件大小保持合理(单个文件 < 10MB)
|
| 108 |
-
|
| 109 |
-
## 🌐 访问游戏
|
| 110 |
-
|
| 111 |
-
部署成功后,游戏将在以下地址可用:
|
| 112 |
-
```
|
| 113 |
-
https://huggingface.co/spaces/YOUR_USERNAME/magicpot-game
|
| 114 |
-
```
|
| 115 |
-
|
| 116 |
-
## 🎮 游戏功能验证
|
| 117 |
-
|
| 118 |
-
部署完成后,请验证以下功能:
|
| 119 |
-
|
| 120 |
-
### ✅ 基础功能
|
| 121 |
-
- [ ] 页面正常加载
|
| 122 |
-
- [ ] 魔法锅渲染正确
|
| 123 |
-
- [ ] CSS 样式正常应用
|
| 124 |
-
- [ ] 音效按钮可点击
|
| 125 |
-
|
| 126 |
-
### ✅ 语音功能
|
| 127 |
-
- [ ] 浏览器请求麦克风权限
|
| 128 |
-
- [ ] 语音状态指示器显示正常
|
| 129 |
-
- [ ] "cook cook cook pot" 命令有效
|
| 130 |
-
- [ ] 食物语音命令识别正常
|
| 131 |
-
- [ ] "stop stop stop pot" 命令有效
|
| 132 |
-
|
| 133 |
-
### ✅ 游戏机制
|
| 134 |
-
- [ ] 魔法锅激活动画
|
| 135 |
-
- [ ] 食物粒子涌出效果
|
| 136 |
-
- [ ] 动物出现和移动
|
| 137 |
-
- [ ] 彩蛋功能(草莓/西瓜)
|
| 138 |
-
- [ ] 性能监控显示
|
| 139 |
-
|
| 140 |
-
### ✅ 音效系统
|
| 141 |
-
- [ ] 魔法激活音效
|
| 142 |
-
- [ ] 烹饪冒泡音效
|
| 143 |
-
- [ ] 食物弹出
|
| 144 |
-
- [ ] 动物出现音效
|
| 145 |
-
- [ ] 庆祝音效
|
| 146 |
-
|
| 147 |
-
## 🐛 常见问题解决
|
| 148 |
-
|
| 149 |
-
### 问题1:语音识别不工作
|
| 150 |
-
**原因**: 浏览器不支持或权限问题
|
| 151 |
-
**解决方案**:
|
| 152 |
-
- 确保使用支持的浏览器(Chrome、Edge、Firefox)
|
| 153 |
-
- 检查麦克风权限设置
|
| 154 |
-
- HTTPS 环境自动满足(Hugging Face Spaces 提供)
|
| 155 |
-
|
| 156 |
-
### 问题2:音频文件无法播放
|
| 157 |
-
**原因**: 文件路径或格式问题
|
| 158 |
-
**解决方案**:
|
| 159 |
-
- 确保 .mp3 文件在根目录
|
| 160 |
-
- 检查文件名是否正确
|
| 161 |
-
- 验证文件格式是否有效
|
| 162 |
-
|
| 163 |
-
### 问题3:文生图功能不工作
|
| 164 |
-
**原因**: API 密钥未配置
|
| 165 |
-
**解决方案**:
|
| 166 |
-
- 按 `Ctrl+Shift+I` 配置 API 密钥
|
| 167 |
-
- 游戏会使用备用图片正常运行
|
| 168 |
-
|
| 169 |
-
### 问题4:性能问题
|
| 170 |
-
**原因**: 粒子数量过多
|
| 171 |
-
**解决方案**:
|
| 172 |
-
- 检查性能监控显示
|
| 173 |
-
- 刷新页面重置游戏状态
|
| 174 |
-
- 粒子系统已自动优化
|
| 175 |
-
|
| 176 |
-
## 📊 监控和分析
|
| 177 |
-
|
| 178 |
-
### Hugging Face Spaces 提供的功能
|
| 179 |
-
- **访问统计**: 查看 Space 的访问量
|
| 180 |
-
- **使用分析**: 了解用户行为
|
| 181 |
-
- **性能监控**: Space 运行状态
|
| 182 |
-
|
| 183 |
-
### 游戏内置监控
|
| 184 |
-
- **实时 FPS**: 游戏性能指标
|
| 185 |
-
- **粒子计数**: 当前粒子数量
|
| 186 |
-
- **动物计数**: 当前动物数量
|
| 187 |
-
- **内存使用**: 资源占用情况
|
| 188 |
-
|
| 189 |
-
## 🔄 更新和维护
|
| 190 |
-
|
| 191 |
-
### 更新游戏
|
| 192 |
-
1. 在本地修改代码
|
| 193 |
-
2. 提交到 Git 仓库
|
| 194 |
-
3. Hugging Face Spaces 自动更新
|
| 195 |
-
|
| 196 |
-
### 版本控制
|
| 197 |
-
```bash
|
| 198 |
-
git add .
|
| 199 |
-
git commit -m "Update: 描述更新内容"
|
| 200 |
-
git push
|
| 201 |
-
```
|
| 202 |
-
|
| 203 |
-
### 备份策略
|
| 204 |
-
- 定期备份游戏代码
|
| 205 |
-
- 保存重要的配置文件
|
| 206 |
-
- 记录 API 密钥等敏感信息
|
| 207 |
-
|
| 208 |
-
## 🚀 进阶配置
|
| 209 |
-
|
| 210 |
-
### 自定义域名
|
| 211 |
-
- Hugging Face Pro 用户可以配置自定义域名
|
| 212 |
-
- 联系 Hugging Face 支持获取帮助
|
| 213 |
-
|
| 214 |
-
### 分析集成
|
| 215 |
-
- 可以添加 Google Analytics
|
| 216 |
-
- 在 `index.html` 中添加跟踪代码
|
| 217 |
-
|
| 218 |
-
### SEO 优化
|
| 219 |
-
- 更新 meta 标签
|
| 220 |
-
- 添加结构化数据
|
| 221 |
-
- 优化页面描述
|
| 222 |
-
|
| 223 |
-
## 📞 获取帮助
|
| 224 |
-
|
| 225 |
-
### 官方资源
|
| 226 |
-
- [Hugging Face Spaces 文档](https://huggingface.co/docs/hub/spaces)
|
| 227 |
-
- [Hugging Face 社区论坛](https://discuss.huggingface.co/)
|
| 228 |
-
- [Discord 社区](https://discord.gg/huggingface)
|
| 229 |
-
|
| 230 |
-
### 项目支持
|
| 231 |
-
- 查看项目 README.md
|
| 232 |
-
- 提交 GitHub Issues
|
| 233 |
-
- 联系项目维护者
|
| 234 |
-
|
| 235 |
-
---
|
| 236 |
-
|
| 237 |
-
🎉 **恭喜!您的 MagicPot 魔法锅游戏已准备好在 Hugging Face Spaces 上部署!**
|
|
|
|
| 1 |
+
# MagicPot Hugging Face Spaces 部署指南
|
| 2 |
+
|
| 3 |
+
## 🚀 快速部署
|
| 4 |
+
|
| 5 |
+
### 1. 准备工作
|
| 6 |
+
确保您的项目根目录包含以下关键文件:
|
| 7 |
+
- `README.md` - 包含正确的frontmatter配置
|
| 8 |
+
- `index.html` - 主游戏页面
|
| 9 |
+
- 完整的项目文件结构
|
| 10 |
+
|
| 11 |
+
### 2. Hugging Face Spaces 配置
|
| 12 |
+
|
| 13 |
+
README.md 中的 frontmatter 配置已经正确设置:
|
| 14 |
+
|
| 15 |
+
```yaml
|
| 16 |
+
---
|
| 17 |
+
title: MagicPot - 魔法锅游戏
|
| 18 |
+
emoji: 🪄
|
| 19 |
+
colorFrom: purple
|
| 20 |
+
colorTo: pink
|
| 21 |
+
sdk: static
|
| 22 |
+
pinned: false
|
| 23 |
+
license: mit
|
| 24 |
+
---
|
| 25 |
+
```
|
| 26 |
+
|
| 27 |
+
### 3. 部署步骤
|
| 28 |
+
|
| 29 |
+
#### 方法一:通过 Hugging Face 网页界面
|
| 30 |
+
1. 访问 [Hugging Face Spaces](https://huggingface.co/spaces)
|
| 31 |
+
2. 点击 "Create new Space"
|
| 32 |
+
3. 填写以下信息:
|
| 33 |
+
- **Space name**: `magicpot-game`
|
| 34 |
+
- **License**: MIT
|
| 35 |
+
- **SDK**: Static
|
| 36 |
+
- **Visibility**: Public
|
| 37 |
+
4. 创建后,将项目文件上传到 Space
|
| 38 |
+
|
| 39 |
+
#### 方法二:通过 Git 命令行
|
| 40 |
+
```bash
|
| 41 |
+
# 1. 克隆您的 Hugging Face Space
|
| 42 |
+
git clone https://huggingface.co/spaces/YOUR_USERNAME/magicpot-game
|
| 43 |
+
cd magicpot-game
|
| 44 |
+
|
| 45 |
+
# 2. 复制项目文件
|
| 46 |
+
cp -r /path/to/MagicPot/* .
|
| 47 |
+
|
| 48 |
+
# 3. 提交和推送
|
| 49 |
+
git add .
|
| 50 |
+
git commit -m "Initial deployment of MagicPot game"
|
| 51 |
+
git push
|
| 52 |
+
```
|
| 53 |
+
|
| 54 |
+
#### 方法三:使用 Hugging Face CLI
|
| 55 |
+
```bash
|
| 56 |
+
# 安装 Hugging Face CLI
|
| 57 |
+
pip install huggingface_hub
|
| 58 |
+
|
| 59 |
+
# 登录
|
| 60 |
+
huggingface-cli login
|
| 61 |
+
|
| 62 |
+
# 上传项目
|
| 63 |
+
huggingface-cli upload YOUR_USERNAME/magicpot-game . --repo-type=space
|
| 64 |
+
```
|
| 65 |
+
|
| 66 |
+
## 📁 项目结构确认
|
| 67 |
+
|
| 68 |
+
确保项目根目录结构如下:
|
| 69 |
+
```
|
| 70 |
+
magicpot-game/
|
| 71 |
+
├── README.md # ✅ 包含正确的frontmatter
|
| 72 |
+
├── index.html # ✅ 主页面
|
| 73 |
+
├── css/
|
| 74 |
+
│ └── style.css # ✅ 样式文件
|
| 75 |
+
├── js/
|
| 76 |
+
│ ├── main.js # ✅ 主游戏逻辑
|
| 77 |
+
│ ├── voice.js # ✅ 语音识别
|
| 78 |
+
│ ├── pot.js # ✅ 魔法锅类
|
| 79 |
+
│ ├── particles.js # ✅ 粒子系统
|
| 80 |
+
│ ├── animals.js # ✅ 动物系统
|
| 81 |
+
│ ├── textToImage.js # ✅ 文生图API
|
| 82 |
+
│ ├── audio.js # ✅ 音频系统
|
| 83 |
+
│ └── keyboard.js # ✅ 键盘控制
|
| 84 |
+
├── assets/
|
| 85 |
+
│ ├── images/ # ✅ 图片资源
|
| 86 |
+
│ └── sounds/ # ✅ 音效文件
|
| 87 |
+
└── *.mp3 # ✅ 音频文件
|
| 88 |
+
```
|
| 89 |
+
|
| 90 |
+
## 🔧 Hugging Face Spaces 特殊注意事项
|
| 91 |
+
|
| 92 |
+
### HTTPS 要求
|
| 93 |
+
- Hugging Face Spaces 自动提供 HTTPS
|
| 94 |
+
- 语音识别功能需要 HTTPS 环境,在 Spaces 上会正常工作
|
| 95 |
+
|
| 96 |
+
### 跨域资源共享 (CORS)
|
| 97 |
+
- 静态文件自动配置正确的 CORS 头
|
| 98 |
+
- 音频和图片资源可以正常加载
|
| 99 |
+
|
| 100 |
+
### 文生图 API 配置
|
| 101 |
+
- 确保在游戏中配置有效的 API 密钥
|
| 102 |
+
- 用户可以通过 `Ctrl+Shift+I` 快捷键配置
|
| 103 |
+
|
| 104 |
+
### 性能优化
|
| 105 |
+
- Hugging Face Spaces 提供全球 CDN
|
| 106 |
+
- 静态资源会被自动缓存
|
| 107 |
+
- 建议文件大小保持合理(单个文件 < 10MB)
|
| 108 |
+
|
| 109 |
+
## 🌐 访问游戏
|
| 110 |
+
|
| 111 |
+
部署成功后,游戏将在以下地址可用:
|
| 112 |
+
```
|
| 113 |
+
https://huggingface.co/spaces/YOUR_USERNAME/magicpot-game
|
| 114 |
+
```
|
| 115 |
+
|
| 116 |
+
## 🎮 游戏功能验证
|
| 117 |
+
|
| 118 |
+
部署完成后,请验证以下功能:
|
| 119 |
+
|
| 120 |
+
### ✅ 基础功能
|
| 121 |
+
- [ ] 页面正常加载
|
| 122 |
+
- [ ] 魔法锅渲染正确
|
| 123 |
+
- [ ] CSS 样式正常应用
|
| 124 |
+
- [ ] 音效按钮可点击
|
| 125 |
+
|
| 126 |
+
### ✅ 语音功能
|
| 127 |
+
- [ ] 浏览器请求麦克风权限
|
| 128 |
+
- [ ] 语音状态指示器显示正常
|
| 129 |
+
- [ ] "cook cook cook pot" 命令有效
|
| 130 |
+
- [ ] 食物语音命令识别正常
|
| 131 |
+
- [ ] "stop stop stop pot" 命令有效
|
| 132 |
+
|
| 133 |
+
### ✅ 游戏机制
|
| 134 |
+
- [ ] 魔法锅激活动画
|
| 135 |
+
- [ ] 食物粒子涌出效果
|
| 136 |
+
- [ ] 动物出现和移动
|
| 137 |
+
- [ ] 彩蛋功能(草莓/西瓜)
|
| 138 |
+
- [ ] 性能监控显示
|
| 139 |
+
|
| 140 |
+
### ✅ 音效系统
|
| 141 |
+
- [ ] 魔法激活音效
|
| 142 |
+
- [ ] 烹饪冒泡音效
|
| 143 |
+
- [ ] 食物弹出��效
|
| 144 |
+
- [ ] 动物出现音效
|
| 145 |
+
- [ ] 庆祝音效
|
| 146 |
+
|
| 147 |
+
## 🐛 常见问题解决
|
| 148 |
+
|
| 149 |
+
### 问题1:语音识别不工作
|
| 150 |
+
**原因**: 浏览器不支持或权限问题
|
| 151 |
+
**解决方案**:
|
| 152 |
+
- 确保使用支持的浏览器(Chrome、Edge、Firefox)
|
| 153 |
+
- 检查麦克风权限设置
|
| 154 |
+
- HTTPS 环境自动满足(Hugging Face Spaces 提供)
|
| 155 |
+
|
| 156 |
+
### 问题2:音频文件无法播放
|
| 157 |
+
**原因**: 文件路径或格式问题
|
| 158 |
+
**解决方案**:
|
| 159 |
+
- 确保 .mp3 文件在根目录
|
| 160 |
+
- 检查文件名是否正确
|
| 161 |
+
- 验证文件格式是否有效
|
| 162 |
+
|
| 163 |
+
### 问题3:文生图功能不工作
|
| 164 |
+
**原因**: API 密钥未配置
|
| 165 |
+
**解决方案**:
|
| 166 |
+
- 按 `Ctrl+Shift+I` 配置 API 密钥
|
| 167 |
+
- 游戏会使用备用图片正常运行
|
| 168 |
+
|
| 169 |
+
### 问题4:性能问题
|
| 170 |
+
**原因**: 粒子数量过多
|
| 171 |
+
**解决方案**:
|
| 172 |
+
- 检查性能监控显示
|
| 173 |
+
- 刷新页面重置游戏状态
|
| 174 |
+
- 粒子系统已自动优化
|
| 175 |
+
|
| 176 |
+
## 📊 监控和分析
|
| 177 |
+
|
| 178 |
+
### Hugging Face Spaces 提供的功能
|
| 179 |
+
- **访问统计**: 查看 Space 的访问量
|
| 180 |
+
- **使用分析**: 了解用户行为
|
| 181 |
+
- **性能监控**: Space 运行状态
|
| 182 |
+
|
| 183 |
+
### 游戏内置监控
|
| 184 |
+
- **实时 FPS**: 游戏性能指标
|
| 185 |
+
- **粒子计数**: 当前粒子数量
|
| 186 |
+
- **动物计数**: 当前动物数量
|
| 187 |
+
- **内存使用**: 资源占用情况
|
| 188 |
+
|
| 189 |
+
## 🔄 更新和维护
|
| 190 |
+
|
| 191 |
+
### 更新游戏
|
| 192 |
+
1. 在本地修改代码
|
| 193 |
+
2. 提交到 Git 仓库
|
| 194 |
+
3. Hugging Face Spaces 自动更新
|
| 195 |
+
|
| 196 |
+
### 版本控制
|
| 197 |
+
```bash
|
| 198 |
+
git add .
|
| 199 |
+
git commit -m "Update: 描述更新内容"
|
| 200 |
+
git push
|
| 201 |
+
```
|
| 202 |
+
|
| 203 |
+
### 备份策略
|
| 204 |
+
- 定期备份游戏代码
|
| 205 |
+
- 保存重要的配置文件
|
| 206 |
+
- 记录 API 密钥等敏感信息
|
| 207 |
+
|
| 208 |
+
## 🚀 进阶配置
|
| 209 |
+
|
| 210 |
+
### 自定义域名
|
| 211 |
+
- Hugging Face Pro 用户可以配置自定义域名
|
| 212 |
+
- 联系 Hugging Face 支持获取帮助
|
| 213 |
+
|
| 214 |
+
### 分析集成
|
| 215 |
+
- 可以添加 Google Analytics
|
| 216 |
+
- 在 `index.html` 中添加跟踪代码
|
| 217 |
+
|
| 218 |
+
### SEO 优化
|
| 219 |
+
- 更新 meta 标签
|
| 220 |
+
- 添加结构化数据
|
| 221 |
+
- 优化页面描述
|
| 222 |
+
|
| 223 |
+
## 📞 获取帮助
|
| 224 |
+
|
| 225 |
+
### 官方资源
|
| 226 |
+
- [Hugging Face Spaces 文档](https://huggingface.co/docs/hub/spaces)
|
| 227 |
+
- [Hugging Face 社区论坛](https://discuss.huggingface.co/)
|
| 228 |
+
- [Discord 社区](https://discord.gg/huggingface)
|
| 229 |
+
|
| 230 |
+
### 项目支持
|
| 231 |
+
- 查看项目 README.md
|
| 232 |
+
- 提交 GitHub Issues
|
| 233 |
+
- 联系项目维护者
|
| 234 |
+
|
| 235 |
+
---
|
| 236 |
+
|
| 237 |
+
🎉 **恭喜!您的 MagicPot 魔法锅游戏已准备好在 Hugging Face Spaces 上部署!**
|
README.md
CHANGED
|
@@ -1,274 +1,274 @@
|
|
| 1 |
-
---
|
| 2 |
-
title: MagicPot - 魔法锅游戏
|
| 3 |
-
emoji: 🪄
|
| 4 |
-
colorFrom: purple
|
| 5 |
-
colorTo: pink
|
| 6 |
-
sdk: static
|
| 7 |
-
pinned: false
|
| 8 |
-
license: mit
|
| 9 |
-
---
|
| 10 |
-
|
| 11 |
-
# MagicPot - 魔法锅游戏
|
| 12 |
-
|
| 13 |
-
一个卡通手绘风格的语音交互游戏,通过声音控制魔法锅烹饪各种食物!
|
| 14 |
-
|
| 15 |
-
## 游戏特色
|
| 16 |
-
|
| 17 |
-
- 🎨 **卡通手绘风格**:温馨可爱的视觉效果
|
| 18 |
-
- 🎤 **语音交互**:通过语音命令控制游戏
|
| 19 |
-
- 🍳 **魔法烹饪**:AI生成食物和小动物素材
|
| 20 |
-
- ✨ **粒子效果**:食物从锅中涌出的动态效果
|
| 21 |
-
- 🐾 **动物互动**:小动物会来吃对应的食物
|
| 22 |
-
- 🎁 **隐藏彩蛋**:草莓和西瓜的特殊效果
|
| 23 |
-
|
| 24 |
-
## 游戏玩法
|
| 25 |
-
|
| 26 |
-
1. **激活魔法锅**:说出 "cook cook cook pot" 来激活魔法锅
|
| 27 |
-
2. **选择食物**:说出任何食物的英文单词开始烹饪
|
| 28 |
-
3. **AI生成素材**:系统自动生成食物和相关小动物的图片
|
| 29 |
-
4. **食物涌出**:锅盖被顶开,食物如粒子般涌出
|
| 30 |
-
5. **停止烹饪**:说出 "stop stop stop pot" 停止食物产生
|
| 31 |
-
6. **动物出现**:当食物达到一定数量,小动物会从屏幕两侧跑来
|
| 32 |
-
7. **特殊彩蛋**:草莓或西瓜达到一定数量时,小女孩会从右侧出现
|
| 33 |
-
|
| 34 |
-
## 技术栈
|
| 35 |
-
|
| 36 |
-
- **前端框架**:HTML5 Canvas + JavaScript
|
| 37 |
-
- **语音识别**:Web Speech API
|
| 38 |
-
- **文生图API**:集成AI图像生成服务
|
| 39 |
-
- **动画引擎**:自定义粒子系统
|
| 40 |
-
- **音频处理**:Web Audio API
|
| 41 |
-
|
| 42 |
-
## 项目结构
|
| 43 |
-
|
| 44 |
-
```
|
| 45 |
-
MagicPot/
|
| 46 |
-
├── index.html # 主页面
|
| 47 |
-
├── css/
|
| 48 |
-
│ └── style.css # 样式文件
|
| 49 |
-
├── js/
|
| 50 |
-
│ ├── main.js # 主游戏逻辑
|
| 51 |
-
│ ├── voice.js # 语音识别模块
|
| 52 |
-
│ ├── pot.js # 魔法锅类
|
| 53 |
-
│ ├── particles.js # 粒子系统
|
| 54 |
-
│ ├── animals.js # 动物系统
|
| 55 |
-
│ └── textToImage.js # 文生图API接口
|
| 56 |
-
├── assets/
|
| 57 |
-
│ ├── images/ # 图片资源
|
| 58 |
-
│ ├── sounds/ # 音效文件
|
| 59 |
-
│
|
| 60 |
-
└── README.md
|
| 61 |
-
```
|
| 62 |
-
|
| 63 |
-
## 安装和运行
|
| 64 |
-
|
| 65 |
-
1. 克隆项目到本地
|
| 66 |
-
2. 使用本地服务器运行(推荐使用 Live Server 或 Python HTTP Server)
|
| 67 |
-
3. 在浏览器中打开,允许麦克风权限
|
| 68 |
-
4. 开始游戏!
|
| 69 |
-
|
| 70 |
-
## 开发计划
|
| 71 |
-
|
| 72 |
-
- [x] 项目结构搭建
|
| 73 |
-
- [x] 语音识别功能
|
| 74 |
-
- [x] 魔法锅UI设计
|
| 75 |
-
- [x] 文生图API集成
|
| 76 |
-
- [x] 粒子系统实现
|
| 77 |
-
- [x] 动物生成系统
|
| 78 |
-
- [x] 彩蛋功能
|
| 79 |
-
- [x] 游戏状态管理
|
| 80 |
-
|
| 81 |
-
## 快速开始
|
| 82 |
-
|
| 83 |
-
### 方法一:使用 Python HTTP 服务器
|
| 84 |
-
```bash
|
| 85 |
-
# 在项目根目录运行
|
| 86 |
-
python -m http.server 8000
|
| 87 |
-
# 然后在浏览器中访问 http://localhost:8000
|
| 88 |
-
```
|
| 89 |
-
|
| 90 |
-
### 方法二:使用 Node.js
|
| 91 |
-
```bash
|
| 92 |
-
# 安装依赖
|
| 93 |
-
npm install
|
| 94 |
-
|
| 95 |
-
# 启动开发服务器
|
| 96 |
-
npm run dev
|
| 97 |
-
```
|
| 98 |
-
|
| 99 |
-
### 方法三:直接打开文件
|
| 100 |
-
直接用浏览器打开 `index.html` 文件(某些功能可能受限)
|
| 101 |
-
|
| 102 |
-
## 游戏控制
|
| 103 |
-
|
| 104 |
-
### 语音命令
|
| 105 |
-
- **"cook cook cook pot"** - 激活魔法锅
|
| 106 |
-
- **说出食物名称** - 开始烹饪(如:apple, banana, pizza等)
|
| 107 |
-
- **"stop stop stop pot"** - 停止食物涌出
|
| 108 |
-
|
| 109 |
-
### 键盘快捷键
|
| 110 |
-
- **F12** - 切换调试信息显示
|
| 111 |
-
- **F11** - 测试所有音效
|
| 112 |
-
- **F10** - 切换音效开关
|
| 113 |
-
- **Ctrl+Shift+I** - 配置文生图API密钥
|
| 114 |
-
- **ESC** - 关闭帮助窗口
|
| 115 |
-
|
| 116 |
-
### 界面功能
|
| 117 |
-
- **🔊 音效按钮** - 点击切换音效开关
|
| 118 |
-
- **❓ 帮助按钮** - 点击查看详细的语音命令帮助
|
| 119 |
-
- **🎤 语音状态指示器** - 显示当前语音识别状态
|
| 120 |
-
- **💬 实时语音显示** - 实时显示用户的语音输入内容
|
| 121 |
-
- **📊 性能监控** - 实时显示粒子数、动物数和FPS(烹饪时自动显示)
|
| 122 |
-
|
| 123 |
-
## 支持的食物
|
| 124 |
-
|
| 125 |
-
### 水果类
|
| 126 |
-
- apple (苹果) 🍎
|
| 127 |
-
- banana (香蕉) 🍌
|
| 128 |
-
- orange (橙子) 🍊
|
| 129 |
-
- strawberry (草莓) 🍓 *彩蛋*
|
| 130 |
-
- watermelon (西瓜) 🍉 *彩蛋*
|
| 131 |
-
- grape (葡萄) 🍇
|
| 132 |
-
|
| 133 |
-
### 主食类
|
| 134 |
-
- pizza (披萨) 🍕
|
| 135 |
-
- burger (汉堡) 🍔
|
| 136 |
-
- bread (面包) 🍞
|
| 137 |
-
- rice (米饭) 🍚
|
| 138 |
-
- noodles (面条) 🍜
|
| 139 |
-
|
| 140 |
-
### 甜点类
|
| 141 |
-
- cake (蛋糕) 🍰 *特殊效果*
|
| 142 |
-
- cookie (饼干) 🍪
|
| 143 |
-
|
| 144 |
-
### 其他
|
| 145 |
-
- cheese (奶酪) 🧀
|
| 146 |
-
- fish (鱼) 🐟
|
| 147 |
-
- chicken (鸡肉) 🍗
|
| 148 |
-
|
| 149 |
-
## 特殊功能
|
| 150 |
-
|
| 151 |
-
### 彩蛋功能
|
| 152 |
-
- **草莓/西瓜彩蛋**:当草莓或西瓜数量达到30个时,小女孩会从右侧出现
|
| 153 |
-
- **生日蛋糕特效**:制作蛋糕时会有特殊的生日庆祝效果
|
| 154 |
-
- **百食庆祝**:制作100个食物时会有烟花庆祝效果
|
| 155 |
-
|
| 156 |
-
### 动物系统
|
| 157 |
-
不同的食物会吸引不同的小动物:
|
| 158 |
-
- 🍎 苹果 → 🐰 兔子
|
| 159 |
-
- 🍌 香蕉 → 🐵 猴子
|
| 160 |
-
- 🍊 橙子 → 🐦 小鸟
|
| 161 |
-
- 🍓 草莓 → 🐻 熊
|
| 162 |
-
- 🍉 西瓜 → 🐘 大象
|
| 163 |
-
- 🍕 披萨 → 🐱 猫咪
|
| 164 |
-
- 🍔 汉堡 → 🐶 小狗
|
| 165 |
-
|
| 166 |
-
## 技术特性
|
| 167 |
-
|
| 168 |
-
### 语音识别
|
| 169 |
-
- 使用 Web Speech API
|
| 170 |
-
- 支持英文语音识别
|
| 171 |
-
- 自动重启和错误处理
|
| 172 |
-
- 实时状态显示
|
| 173 |
-
|
| 174 |
-
### 粒子系统
|
| 175 |
-
- 食物涌出效果
|
| 176 |
-
- 魔法粒子特效
|
| 177 |
-
- 蒸汽动画
|
| 178 |
-
- 庆祝烟花效果
|
| 179 |
-
|
| 180 |
-
### AI图片生成
|
| 181 |
-
- 支持文生图API集成
|
| 182 |
-
- 本地缓存机制
|
| 183 |
-
- 备用表情符号显示
|
| 184 |
-
- 可配置API密钥
|
| 185 |
-
|
| 186 |
-
### 动画效果
|
| 187 |
-
- 卡通手绘风格
|
| 188 |
-
- 流畅的Canvas动画
|
| 189 |
-
- 粒子物理系统
|
| 190 |
-
- 动物AI行为
|
| 191 |
-
|
| 192 |
-
### 音效系统
|
| 193 |
-
- **程序化音效生成**:使用Web Audio API实时生成音效
|
| 194 |
-
- **丰富的音效类型**:
|
| 195 |
-
- 🪄 魔法激活音效(上升音调带颤音)
|
| 196 |
-
- 🫧 烹饪冒泡音效(随机频率变化)
|
| 197 |
-
- 💥 食物弹出音效(短促爆破声)
|
| 198 |
-
- 🐦 动物出现音效(鸟叫声)
|
| 199 |
-
- 🔔 小女孩出现音效(闪亮铃声)
|
| 200 |
-
- 🎺 庆祝音效(三和弦号角声)
|
| 201 |
-
- 💨 停止音效(风声效果)
|
| 202 |
-
- **智能音效控制**:可开关、音量控制、随机音调变化
|
| 203 |
-
- **性能优化**:预生成音效缓存,避免实时计算
|
| 204 |
-
|
| 205 |
-
### 性能优化
|
| 206 |
-
- **内存管理**:智能控制粒子和动物数量上限
|
| 207 |
-
- **自动清理**:定期清理过期和无效对象
|
| 208 |
-
- **性能监控**:实时显示FPS、粒子数、动物数
|
| 209 |
-
- **资源限制**:
|
| 210 |
-
- 最大粒子数:150个
|
| 211 |
-
- 最大动物数:8只
|
| 212 |
-
- 最大食物数:100个
|
| 213 |
-
- 地面粒子上限:80个
|
| 214 |
-
|
| 215 |
-
## 浏览器兼容性
|
| 216 |
-
|
| 217 |
-
### 推荐浏览器
|
| 218 |
-
- Chrome 80+
|
| 219 |
-
- Edge 80+
|
| 220 |
-
- Firefox 75+
|
| 221 |
-
- Safari 14+
|
| 222 |
-
|
| 223 |
-
### 必需功能
|
| 224 |
-
- Web Speech API(语音识别)
|
| 225 |
-
- Canvas 2D API(游戏渲染)
|
| 226 |
-
- Web Audio API(音效支持)
|
| 227 |
-
- ES6+ 支持
|
| 228 |
-
|
| 229 |
-
## 故障排除
|
| 230 |
-
|
| 231 |
-
### 语音识别不工作
|
| 232 |
-
1. 检查浏览器是否支持 Web Speech API
|
| 233 |
-
2. 确保已允许麦克风权限
|
| 234 |
-
3. 检查网络连接(某些浏览器需要HTTPS)
|
| 235 |
-
|
| 236 |
-
### 文生图功能不工作
|
| 237 |
-
1. 按 Ctrl+Shift+I 配置API密钥
|
| 238 |
-
2. 检查API密钥是否有效
|
| 239 |
-
3. 即使没有API,游戏也会使用备用图片正常运行
|
| 240 |
-
|
| 241 |
-
### 性能问题
|
| 242 |
-
1. 按F12查看调试信息
|
| 243 |
-
2. 检查粒子数量是否过多
|
| 244 |
-
3. 尝试刷新页面重置游戏
|
| 245 |
-
|
| 246 |
-
## 开发说明
|
| 247 |
-
|
| 248 |
-
### 项目结构
|
| 249 |
-
```
|
| 250 |
-
MagicPot/
|
| 251 |
-
├── index.html # 主页面
|
| 252 |
-
├── css/style.css # 样式文件
|
| 253 |
-
├── js/ # JavaScript模块
|
| 254 |
-
│ ├── main.js # 主游戏逻辑
|
| 255 |
-
│ ├── voice.js # 语音识别
|
| 256 |
-
│ ├── pot.js # 魔法锅类
|
| 257 |
-
│ ├── particles.js # 粒子系统
|
| 258 |
-
│ ├── animals.js # 动物系统
|
| 259 |
-
│ └── textToImage.js # 文生图API
|
| 260 |
-
├── assets/ # 资源文件
|
| 261 |
-
│ ├── images/ # 图片资源
|
| 262 |
-
│ └── sounds/ # 音效文件
|
| 263 |
-
└── package.json # 项目配置
|
| 264 |
-
```
|
| 265 |
-
|
| 266 |
-
### 扩展开发
|
| 267 |
-
- 添加新食物:在各个模块的映射表中添加新条目
|
| 268 |
-
- 添加新动物:扩展 `animals.js` 中的动物类型
|
| 269 |
-
- 添加新特效:在 `particles.js` 中创建新的粒子类型
|
| 270 |
-
- 添加音效:在相应的事件中调用音频播放函数
|
| 271 |
-
|
| 272 |
-
## 许可证
|
| 273 |
-
|
| 274 |
-
MIT License - 详见 LICENSE 文件
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: MagicPot - 魔法锅游戏
|
| 3 |
+
emoji: 🪄
|
| 4 |
+
colorFrom: purple
|
| 5 |
+
colorTo: pink
|
| 6 |
+
sdk: static
|
| 7 |
+
pinned: false
|
| 8 |
+
license: mit
|
| 9 |
+
---
|
| 10 |
+
|
| 11 |
+
# MagicPot - 魔法锅游戏
|
| 12 |
+
|
| 13 |
+
一个卡通手绘风格的语音交互游戏,通过声音控制魔法锅烹饪各种食物!
|
| 14 |
+
|
| 15 |
+
## 游戏特色
|
| 16 |
+
|
| 17 |
+
- 🎨 **卡通手绘风格**:温馨可爱的视觉效果
|
| 18 |
+
- 🎤 **语音交互**:通过语音命令控制游戏
|
| 19 |
+
- 🍳 **魔法烹饪**:AI生成食物和小动物素材
|
| 20 |
+
- ✨ **粒子效果**:食物从锅中涌出的动态效果
|
| 21 |
+
- 🐾 **动物互动**:小动物会来吃对应的食物
|
| 22 |
+
- 🎁 **隐藏彩蛋**:草莓和西瓜的特殊效果
|
| 23 |
+
|
| 24 |
+
## 游戏玩法
|
| 25 |
+
|
| 26 |
+
1. **激活魔法锅**:说出 "cook cook cook pot" 来激活魔法锅
|
| 27 |
+
2. **选择食物**:说出任何食物的英文单词开始烹饪
|
| 28 |
+
3. **AI生成素材**:系统自动生成食物和相关小动物的图片
|
| 29 |
+
4. **食物涌出**:锅盖被顶开,食物如粒子般涌出
|
| 30 |
+
5. **停止烹饪**:说出 "stop stop stop pot" 停止食物产生
|
| 31 |
+
6. **动物出现**:当食物达到一定数量,小动物会从屏幕两侧跑来
|
| 32 |
+
7. **特殊彩蛋**:草莓或西瓜达到一定数量时,小女孩会从右侧出现
|
| 33 |
+
|
| 34 |
+
## 技术栈
|
| 35 |
+
|
| 36 |
+
- **前端框架**:HTML5 Canvas + JavaScript
|
| 37 |
+
- **语音识别**:Web Speech API
|
| 38 |
+
- **文生图API**:集成AI图像生成服务
|
| 39 |
+
- **动画引擎**:自定义粒子系统
|
| 40 |
+
- **音频处理**:Web Audio API
|
| 41 |
+
|
| 42 |
+
## 项目结构
|
| 43 |
+
|
| 44 |
+
```
|
| 45 |
+
MagicPot/
|
| 46 |
+
├── index.html # 主页面
|
| 47 |
+
├── css/
|
| 48 |
+
│ └── style.css # 样式文件
|
| 49 |
+
├── js/
|
| 50 |
+
│ ├── main.js # 主游戏逻辑
|
| 51 |
+
│ ├── voice.js # 语音识别模块
|
| 52 |
+
│ ├── pot.js # 魔法锅类
|
| 53 |
+
│ ├── particles.js # 粒子系统
|
| 54 |
+
│ ├── animals.js # 动物系统
|
| 55 |
+
│ └── textToImage.js # 文生图API接口
|
| 56 |
+
├── assets/
|
| 57 |
+
│ ├── images/ # 图片资源
|
| 58 |
+
│ ├── sounds/ # 音效文件
|
| 59 |
+
│ ���── fonts/ # 字体文件
|
| 60 |
+
└── README.md
|
| 61 |
+
```
|
| 62 |
+
|
| 63 |
+
## 安装和运行
|
| 64 |
+
|
| 65 |
+
1. 克隆项目到本地
|
| 66 |
+
2. 使用本地服务器运行(推荐使用 Live Server 或 Python HTTP Server)
|
| 67 |
+
3. 在浏览器中打开,允许麦克风权限
|
| 68 |
+
4. 开始游戏!
|
| 69 |
+
|
| 70 |
+
## 开发计划
|
| 71 |
+
|
| 72 |
+
- [x] 项目结构搭建
|
| 73 |
+
- [x] 语音识别功能
|
| 74 |
+
- [x] 魔法锅UI设计
|
| 75 |
+
- [x] 文生图API集成
|
| 76 |
+
- [x] 粒子系统实现
|
| 77 |
+
- [x] 动物生成系统
|
| 78 |
+
- [x] 彩蛋功能
|
| 79 |
+
- [x] 游戏状态管理
|
| 80 |
+
|
| 81 |
+
## 快速开始
|
| 82 |
+
|
| 83 |
+
### 方法一:使用 Python HTTP 服务器
|
| 84 |
+
```bash
|
| 85 |
+
# 在项目根目录运行
|
| 86 |
+
python -m http.server 8000
|
| 87 |
+
# 然后在浏览器中访问 http://localhost:8000
|
| 88 |
+
```
|
| 89 |
+
|
| 90 |
+
### 方法二:使用 Node.js
|
| 91 |
+
```bash
|
| 92 |
+
# 安装依赖
|
| 93 |
+
npm install
|
| 94 |
+
|
| 95 |
+
# 启动开发服务器
|
| 96 |
+
npm run dev
|
| 97 |
+
```
|
| 98 |
+
|
| 99 |
+
### 方法三:直接打开文件
|
| 100 |
+
直接用浏览器打开 `index.html` 文件(某些功能可能受限)
|
| 101 |
+
|
| 102 |
+
## 游戏控制
|
| 103 |
+
|
| 104 |
+
### 语音命令
|
| 105 |
+
- **"cook cook cook pot"** - 激活魔法锅
|
| 106 |
+
- **说出食物名称** - 开始烹饪(如:apple, banana, pizza等)
|
| 107 |
+
- **"stop stop stop pot"** - 停止食物涌出
|
| 108 |
+
|
| 109 |
+
### 键盘快捷键
|
| 110 |
+
- **F12** - 切换调试信息显示
|
| 111 |
+
- **F11** - 测试所有音效
|
| 112 |
+
- **F10** - 切换音效开关
|
| 113 |
+
- **Ctrl+Shift+I** - 配置文生图API密钥
|
| 114 |
+
- **ESC** - 关闭帮助窗口
|
| 115 |
+
|
| 116 |
+
### 界面功能
|
| 117 |
+
- **🔊 音效按钮** - 点击切换音效开关
|
| 118 |
+
- **❓ 帮助按钮** - 点击查看详细的语音命令帮助
|
| 119 |
+
- **🎤 语音状态指示器** - 显示当前语音识别状态
|
| 120 |
+
- **💬 实时语音显示** - 实时显示用户的语音输入内容
|
| 121 |
+
- **📊 性能监控** - 实时显示粒子数、动物数和FPS(烹饪时自动显示)
|
| 122 |
+
|
| 123 |
+
## 支持的食物
|
| 124 |
+
|
| 125 |
+
### 水果类
|
| 126 |
+
- apple (苹果) 🍎
|
| 127 |
+
- banana (香蕉) 🍌
|
| 128 |
+
- orange (橙子) 🍊
|
| 129 |
+
- strawberry (草莓) 🍓 *彩蛋*
|
| 130 |
+
- watermelon (西瓜) 🍉 *彩蛋*
|
| 131 |
+
- grape (葡萄) 🍇
|
| 132 |
+
|
| 133 |
+
### 主食类
|
| 134 |
+
- pizza (披萨) 🍕
|
| 135 |
+
- burger (汉堡) 🍔
|
| 136 |
+
- bread (面包) 🍞
|
| 137 |
+
- rice (米饭) 🍚
|
| 138 |
+
- noodles (面条) 🍜
|
| 139 |
+
|
| 140 |
+
### 甜点类
|
| 141 |
+
- cake (蛋糕) 🍰 *特殊效果*
|
| 142 |
+
- cookie (饼干) 🍪
|
| 143 |
+
|
| 144 |
+
### 其他
|
| 145 |
+
- cheese (奶酪) 🧀
|
| 146 |
+
- fish (鱼) 🐟
|
| 147 |
+
- chicken (鸡肉) 🍗
|
| 148 |
+
|
| 149 |
+
## 特殊功能
|
| 150 |
+
|
| 151 |
+
### 彩蛋功能
|
| 152 |
+
- **草莓/西瓜彩蛋**:当草莓或西瓜数量达到30个时,小女孩会从右侧出现
|
| 153 |
+
- **生日蛋糕特效**:制作蛋糕时会有特殊的生日庆祝效果
|
| 154 |
+
- **百食庆祝**:制作100个食物时会有烟花庆祝效果
|
| 155 |
+
|
| 156 |
+
### 动物系统
|
| 157 |
+
不同的食物会吸引不同的小动物:
|
| 158 |
+
- 🍎 苹果 → 🐰 兔子
|
| 159 |
+
- 🍌 香蕉 → 🐵 猴子
|
| 160 |
+
- 🍊 橙子 → 🐦 小鸟
|
| 161 |
+
- 🍓 草莓 → 🐻 熊
|
| 162 |
+
- 🍉 西瓜 → 🐘 大象
|
| 163 |
+
- 🍕 披萨 → 🐱 猫咪
|
| 164 |
+
- 🍔 汉堡 → 🐶 小狗
|
| 165 |
+
|
| 166 |
+
## 技术特性
|
| 167 |
+
|
| 168 |
+
### 语音识别
|
| 169 |
+
- 使用 Web Speech API
|
| 170 |
+
- 支持英文语音识别
|
| 171 |
+
- 自动重启和错误处理
|
| 172 |
+
- 实时状态显示
|
| 173 |
+
|
| 174 |
+
### 粒子系统
|
| 175 |
+
- 食物涌出效果
|
| 176 |
+
- 魔法粒子特效
|
| 177 |
+
- 蒸汽动画
|
| 178 |
+
- 庆祝烟花效果
|
| 179 |
+
|
| 180 |
+
### AI图片生成
|
| 181 |
+
- 支持文生图API集成
|
| 182 |
+
- 本地缓存机制
|
| 183 |
+
- 备用表情符号显示
|
| 184 |
+
- 可配置API密钥
|
| 185 |
+
|
| 186 |
+
### 动画效果
|
| 187 |
+
- 卡通手绘风格
|
| 188 |
+
- 流畅的Canvas动画
|
| 189 |
+
- 粒子物理系统
|
| 190 |
+
- 动物AI行为
|
| 191 |
+
|
| 192 |
+
### 音效系统
|
| 193 |
+
- **程序化音效生成**:使用Web Audio API实时生成音效
|
| 194 |
+
- **丰富的音效类型**:
|
| 195 |
+
- 🪄 魔法激活音效(上升音调带颤音)
|
| 196 |
+
- 🫧 烹饪冒泡音效(随机频率变化)
|
| 197 |
+
- 💥 食物弹出音效(短促爆破声)
|
| 198 |
+
- 🐦 动物出现音效(鸟叫声)
|
| 199 |
+
- 🔔 小女孩出现音效(闪亮铃声)
|
| 200 |
+
- 🎺 庆祝音效(三和弦号角声)
|
| 201 |
+
- 💨 停止音效(风声效果)
|
| 202 |
+
- **智能音效控制**:可开关、音量控制、随机音调变化
|
| 203 |
+
- **性能优化**:预生成音效缓存,避免实时计算
|
| 204 |
+
|
| 205 |
+
### 性能优化
|
| 206 |
+
- **内存管理**:智能控制粒子和动物数量上限
|
| 207 |
+
- **自动清理**:定期清理过期和无效对象
|
| 208 |
+
- **性能监控**:实时显示FPS、粒子数、动物数
|
| 209 |
+
- **资源限制**:
|
| 210 |
+
- 最大粒子数:150个
|
| 211 |
+
- 最大动物数:8只
|
| 212 |
+
- 最大食物数:100个
|
| 213 |
+
- 地面粒子上限:80个
|
| 214 |
+
|
| 215 |
+
## 浏览器兼容性
|
| 216 |
+
|
| 217 |
+
### 推荐浏览器
|
| 218 |
+
- Chrome 80+
|
| 219 |
+
- Edge 80+
|
| 220 |
+
- Firefox 75+
|
| 221 |
+
- Safari 14+
|
| 222 |
+
|
| 223 |
+
### 必需功能
|
| 224 |
+
- Web Speech API(语音识别)
|
| 225 |
+
- Canvas 2D API(游戏渲染)
|
| 226 |
+
- Web Audio API(音效支持)
|
| 227 |
+
- ES6+ 支持
|
| 228 |
+
|
| 229 |
+
## 故障排除
|
| 230 |
+
|
| 231 |
+
### 语音识别不工作
|
| 232 |
+
1. 检查浏览器是否支持 Web Speech API
|
| 233 |
+
2. 确保已允许麦克风权限
|
| 234 |
+
3. 检查网络连接(某些浏览器需要HTTPS)
|
| 235 |
+
|
| 236 |
+
### 文生图功能不工作
|
| 237 |
+
1. 按 Ctrl+Shift+I 配置API密钥
|
| 238 |
+
2. 检查API密钥是否有效
|
| 239 |
+
3. 即使没有API,游戏也会使用备用图片正常运行
|
| 240 |
+
|
| 241 |
+
### 性能问题
|
| 242 |
+
1. 按F12查看调试信息
|
| 243 |
+
2. 检查粒子数量是否过多
|
| 244 |
+
3. 尝试刷新页面重置游戏
|
| 245 |
+
|
| 246 |
+
## 开发说明
|
| 247 |
+
|
| 248 |
+
### 项目结构
|
| 249 |
+
```
|
| 250 |
+
MagicPot/
|
| 251 |
+
├── index.html # 主页面
|
| 252 |
+
├── css/style.css # 样式文件
|
| 253 |
+
├── js/ # JavaScript模块
|
| 254 |
+
│ ├── main.js # 主游戏逻辑
|
| 255 |
+
│ ├── voice.js # 语音识别
|
| 256 |
+
│ ├── pot.js # 魔法锅类
|
| 257 |
+
│ ├── particles.js # 粒子系统
|
| 258 |
+
│ ├── animals.js # 动物系统
|
| 259 |
+
│ └── textToImage.js # 文生图API
|
| 260 |
+
├── assets/ # 资源文件
|
| 261 |
+
│ ├── images/ # 图片资源
|
| 262 |
+
│ └── sounds/ # 音效文件
|
| 263 |
+
└── package.json # 项目配置
|
| 264 |
+
```
|
| 265 |
+
|
| 266 |
+
### 扩展开发
|
| 267 |
+
- 添加新食物:在各个模块的映射表中添加新条目
|
| 268 |
+
- 添加新动物:扩展 `animals.js` 中的动物类型
|
| 269 |
+
- 添加新特效:在 `particles.js` 中创建新的粒子类型
|
| 270 |
+
- 添加音效:在相应的事件中调用音频播放函数
|
| 271 |
+
|
| 272 |
+
## 许可证
|
| 273 |
+
|
| 274 |
+
MIT License - 详见 LICENSE 文件
|
assets/images/ChatGPT Image 2025年9月22日 17_48_21.png
DELETED
Git LFS Details
|
assets/images/ChatGPT Image 2025年9月22日 17_51_40.png
DELETED
Git LFS Details
|
assets/images/ChatGPT Image 2025年9月22日 17_54_23.png
DELETED
Git LFS Details
|
assets/images/README.md
CHANGED
|
@@ -1,31 +1,31 @@
|
|
| 1 |
-
# 图片资源
|
| 2 |
-
|
| 3 |
-
这个文件夹用于存放游戏图片资源。
|
| 4 |
-
|
| 5 |
-
## 图片分类:
|
| 6 |
-
|
| 7 |
-
### 食物图片 (food/)
|
| 8 |
-
- 各种食物的卡通手绘图片
|
| 9 |
-
- 建议尺寸:64x64 或 128x128 像素
|
| 10 |
-
- 格式:PNG(支持透明背景)
|
| 11 |
-
|
| 12 |
-
### 动物图片 (animals/)
|
| 13 |
-
- 各种小动物的卡通手绘图片
|
| 14 |
-
- 建议尺寸:64x64 或 128x128 像素
|
| 15 |
-
- 格式:PNG(支持透明背景)
|
| 16 |
-
|
| 17 |
-
### UI图片 (ui/)
|
| 18 |
-
- 游戏界面元素图片
|
| 19 |
-
- 按钮、图标等
|
| 20 |
-
- 格式:PNG
|
| 21 |
-
|
| 22 |
-
### 背景图片 (backgrounds/)
|
| 23 |
-
- 游戏背景图片
|
| 24 |
-
- 建议尺寸:800x600 或更高
|
| 25 |
-
- 格式:JPG 或 PNG
|
| 26 |
-
|
| 27 |
-
## 图片命名规范:
|
| 28 |
-
|
| 29 |
-
- 使用英文小写字母
|
| 30 |
-
- 单词之间用下划线连接
|
| 31 |
-
- 例如:`magic_pot.png`, `cute_rabbit.png`
|
|
|
|
| 1 |
+
# 图片资源
|
| 2 |
+
|
| 3 |
+
这个文件夹用于存放游戏图片资源。
|
| 4 |
+
|
| 5 |
+
## 图片分类:
|
| 6 |
+
|
| 7 |
+
### 食物图片 (food/)
|
| 8 |
+
- 各种食物的卡通手绘图片
|
| 9 |
+
- 建议尺寸:64x64 或 128x128 像素
|
| 10 |
+
- 格式:PNG(支持透明背景)
|
| 11 |
+
|
| 12 |
+
### 动物图片 (animals/)
|
| 13 |
+
- 各种小动物的卡通手绘图片
|
| 14 |
+
- 建议尺寸:64x64 或 128x128 像素
|
| 15 |
+
- 格式:PNG(支持透明背景)
|
| 16 |
+
|
| 17 |
+
### UI图片 (ui/)
|
| 18 |
+
- 游戏界面元素图片
|
| 19 |
+
- 按钮、图标等
|
| 20 |
+
- 格式:PNG
|
| 21 |
+
|
| 22 |
+
### 背景图片 (backgrounds/)
|
| 23 |
+
- 游戏背景图片
|
| 24 |
+
- 建议尺寸:800x600 或更高
|
| 25 |
+
- 格式:JPG 或 PNG
|
| 26 |
+
|
| 27 |
+
## 图片命名规范:
|
| 28 |
+
|
| 29 |
+
- 使用英文小写字母
|
| 30 |
+
- 单词之间用下划线连接
|
| 31 |
+
- 例如:`magic_pot.png`, `cute_rabbit.png`
|
assets/images/magic_potx.png
DELETED
Git LFS Details
|
assets/sounds/README.md
CHANGED
|
@@ -1,18 +1,18 @@
|
|
| 1 |
-
# 音效文件
|
| 2 |
-
|
| 3 |
-
这个文件夹用于存放游戏音效文件。
|
| 4 |
-
|
| 5 |
-
## 建议的音效文件:
|
| 6 |
-
|
| 7 |
-
- `pot_activate.mp3` - 魔法锅激活音效
|
| 8 |
-
- `cooking.mp3` - 烹饪过程音效
|
| 9 |
-
- `food_pop.mp3` - 食物涌出音效
|
| 10 |
-
- `animal_appear.mp3` - 动物出现音效
|
| 11 |
-
- `girl_appear.mp3` - 小女孩出现音效
|
| 12 |
-
- `celebration.mp3` - 庆祝音效
|
| 13 |
-
|
| 14 |
-
## 音效格式要求:
|
| 15 |
-
|
| 16 |
-
- 格式:MP3 或 WAV
|
| 17 |
-
- 大小:建议小于 1MB
|
| 18 |
-
- 时长:建议 1-3 秒
|
|
|
|
| 1 |
+
# 音效文件
|
| 2 |
+
|
| 3 |
+
这个文件夹用于存放游戏音效文件。
|
| 4 |
+
|
| 5 |
+
## 建议的音效文件:
|
| 6 |
+
|
| 7 |
+
- `pot_activate.mp3` - 魔法锅激活音效
|
| 8 |
+
- `cooking.mp3` - 烹饪过程音效
|
| 9 |
+
- `food_pop.mp3` - 食物涌出音效
|
| 10 |
+
- `animal_appear.mp3` - 动物出现音效
|
| 11 |
+
- `girl_appear.mp3` - 小女孩出现音效
|
| 12 |
+
- `celebration.mp3` - 庆祝音效
|
| 13 |
+
|
| 14 |
+
## 音效格式要求:
|
| 15 |
+
|
| 16 |
+
- 格式:MP3 或 WAV
|
| 17 |
+
- 大小:建议小于 1MB
|
| 18 |
+
- 时长:建议 1-3 秒
|
assets/sounds/animal_appear.mp3
DELETED
|
@@ -1,3 +0,0 @@
|
|
| 1 |
-
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:e774477f7327909be32f919dee0933725d6b7846d91c85417dbbaf8d869d03ef
|
| 3 |
-
size 412425
|
|
|
|
|
|
|
|
|
|
|
|
assets/sounds/cookingmp3.mp3
DELETED
|
@@ -1,3 +0,0 @@
|
|
| 1 |
-
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:f0e103049a8e25f57624af9dafd50abaa7e9537c6a3c46801ac50b1cb192002e
|
| 3 |
-
size 960788
|
|
|
|
|
|
|
|
|
|
|
|
css/style.css
CHANGED
|
@@ -1,1125 +1,1125 @@
|
|
| 1 |
-
/* 全局样式 */
|
| 2 |
-
* {
|
| 3 |
-
margin: 0;
|
| 4 |
-
padding: 0;
|
| 5 |
-
box-sizing: border-box;
|
| 6 |
-
}
|
| 7 |
-
|
| 8 |
-
body {
|
| 9 |
-
font-family: 'Comic Neue', cursive;
|
| 10 |
-
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
| 11 |
-
min-height: 100vh;
|
| 12 |
-
overflow: hidden;
|
| 13 |
-
}
|
| 14 |
-
|
| 15 |
-
/* 游戏容器 */
|
| 16 |
-
.game-container {
|
| 17 |
-
width: 100vw;
|
| 18 |
-
height: 100vh;
|
| 19 |
-
display: flex;
|
| 20 |
-
flex-direction: column;
|
| 21 |
-
position: relative;
|
| 22 |
-
}
|
| 23 |
-
|
| 24 |
-
/* 游戏标题区域 */
|
| 25 |
-
.game-header {
|
| 26 |
-
background: rgba(255, 255, 255, 0.95);
|
| 27 |
-
padding: 15px 20px;
|
| 28 |
-
display: flex;
|
| 29 |
-
justify-content: space-between;
|
| 30 |
-
align-items: center;
|
| 31 |
-
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
|
| 32 |
-
border-bottom: 3px solid #ff6b6b;
|
| 33 |
-
}
|
| 34 |
-
|
| 35 |
-
.header-controls {
|
| 36 |
-
display: flex;
|
| 37 |
-
align-items: center;
|
| 38 |
-
gap: 15px;
|
| 39 |
-
}
|
| 40 |
-
|
| 41 |
-
.audio-button, .help-button {
|
| 42 |
-
background: #ff6b6b;
|
| 43 |
-
color: white;
|
| 44 |
-
border: none;
|
| 45 |
-
border-radius: 50%;
|
| 46 |
-
width: 40px;
|
| 47 |
-
height: 40px;
|
| 48 |
-
font-size: 18px;
|
| 49 |
-
cursor: pointer;
|
| 50 |
-
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
|
| 51 |
-
transition: all 0.3s ease;
|
| 52 |
-
font-family: 'Comic Neue', cursive;
|
| 53 |
-
font-weight: bold;
|
| 54 |
-
}
|
| 55 |
-
|
| 56 |
-
.audio-button:hover, .help-button:hover {
|
| 57 |
-
background: #e55555;
|
| 58 |
-
transform: scale(1.1);
|
| 59 |
-
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
|
| 60 |
-
}
|
| 61 |
-
|
| 62 |
-
.audio-button:active, .help-button:active {
|
| 63 |
-
transform: scale(0.95);
|
| 64 |
-
}
|
| 65 |
-
|
| 66 |
-
.audio-button.muted {
|
| 67 |
-
background: #95a5a6;
|
| 68 |
-
color: #bdc3c7;
|
| 69 |
-
}
|
| 70 |
-
|
| 71 |
-
.audio-button.muted:hover {
|
| 72 |
-
background: #7f8c8d;
|
| 73 |
-
}
|
| 74 |
-
|
| 75 |
-
.game-title {
|
| 76 |
-
font-family: 'Fredoka One', cursive;
|
| 77 |
-
font-size: 2.2em;
|
| 78 |
-
color: #ff6b6b;
|
| 79 |
-
text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.1);
|
| 80 |
-
margin: 0;
|
| 81 |
-
}
|
| 82 |
-
|
| 83 |
-
.voice-status {
|
| 84 |
-
display: flex;
|
| 85 |
-
align-items: center;
|
| 86 |
-
gap: 10px;
|
| 87 |
-
background: #4ecdc4;
|
| 88 |
-
padding: 8px 15px;
|
| 89 |
-
border-radius: 25px;
|
| 90 |
-
color: white;
|
| 91 |
-
font-weight: bold;
|
| 92 |
-
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
|
| 93 |
-
}
|
| 94 |
-
|
| 95 |
-
.mic-icon {
|
| 96 |
-
font-size: 1.2em;
|
| 97 |
-
animation: pulse 2s infinite;
|
| 98 |
-
}
|
| 99 |
-
|
| 100 |
-
@keyframes pulse {
|
| 101 |
-
0%, 100% { transform: scale(1); }
|
| 102 |
-
50% { transform: scale(1.1); }
|
| 103 |
-
}
|
| 104 |
-
|
| 105 |
-
/* 主游戏区域 */
|
| 106 |
-
.game-main {
|
| 107 |
-
flex: 1;
|
| 108 |
-
position: relative;
|
| 109 |
-
display: flex;
|
| 110 |
-
justify-content: center;
|
| 111 |
-
align-items: center;
|
| 112 |
-
}
|
| 113 |
-
|
| 114 |
-
#gameCanvas {
|
| 115 |
-
border: 4px solid #fff;
|
| 116 |
-
border-radius: 20px;
|
| 117 |
-
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
|
| 118 |
-
background: linear-gradient(45deg, #ffeaa7, #fab1a0);
|
| 119 |
-
}
|
| 120 |
-
|
| 121 |
-
/* 游戏UI覆盖层 */
|
| 122 |
-
.game-ui {
|
| 123 |
-
position: absolute;
|
| 124 |
-
top: 0;
|
| 125 |
-
left: 0;
|
| 126 |
-
width: 100%;
|
| 127 |
-
height: 100%;
|
| 128 |
-
pointer-events: none;
|
| 129 |
-
z-index: 10;
|
| 130 |
-
}
|
| 131 |
-
|
| 132 |
-
/* 键盘面板在game-ui内,需要特殊处理 */
|
| 133 |
-
.game-ui .keyboard-input-panel {
|
| 134 |
-
pointer-events: auto;
|
| 135 |
-
}
|
| 136 |
-
|
| 137 |
-
.game-ui .keyboard-input-panel.inactive {
|
| 138 |
-
pointer-events: none;
|
| 139 |
-
}
|
| 140 |
-
|
| 141 |
-
.game-ui .keyboard-input-panel.active {
|
| 142 |
-
pointer-events: auto !important;
|
| 143 |
-
}
|
| 144 |
-
|
| 145 |
-
/* 确保激活状态下所有子元素都可以交互 */
|
| 146 |
-
.keyboard-input-panel.active,
|
| 147 |
-
.keyboard-input-panel.active *,
|
| 148 |
-
.keyboard-input-panel.active .input-content,
|
| 149 |
-
.keyboard-input-panel.active .command-input,
|
| 150 |
-
.keyboard-input-panel.active .send-btn,
|
| 151 |
-
.keyboard-input-panel.active .quick-cmd,
|
| 152 |
-
.keyboard-input-panel.active .toggle-panel-btn,
|
| 153 |
-
.keyboard-input-panel.active .history-item {
|
| 154 |
-
pointer-events: auto !important;
|
| 155 |
-
}
|
| 156 |
-
|
| 157 |
-
/* 魔法锅状态 */
|
| 158 |
-
.pot-status {
|
| 159 |
-
position: absolute;
|
| 160 |
-
top: 20px;
|
| 161 |
-
left: 50%;
|
| 162 |
-
transform: translateX(-50%);
|
| 163 |
-
pointer-events: auto;
|
| 164 |
-
}
|
| 165 |
-
|
| 166 |
-
.status-indicator {
|
| 167 |
-
padding: 10px 20px;
|
| 168 |
-
border-radius: 25px;
|
| 169 |
-
font-weight: bold;
|
| 170 |
-
text-align: center;
|
| 171 |
-
box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
|
| 172 |
-
transition: all 0.3s ease;
|
| 173 |
-
}
|
| 174 |
-
|
| 175 |
-
.status-indicator.inactive {
|
| 176 |
-
background: #95a5a6;
|
| 177 |
-
color: white;
|
| 178 |
-
}
|
| 179 |
-
|
| 180 |
-
.status-indicator.active {
|
| 181 |
-
background: #e74c3c;
|
| 182 |
-
color: white;
|
| 183 |
-
animation: glow 2s infinite alternate;
|
| 184 |
-
}
|
| 185 |
-
|
| 186 |
-
.status-indicator.cooking {
|
| 187 |
-
background: #f39c12;
|
| 188 |
-
color: white;
|
| 189 |
-
animation: cooking-pulse 1s infinite;
|
| 190 |
-
}
|
| 191 |
-
|
| 192 |
-
.status-indicator.overflowing {
|
| 193 |
-
background: #27ae60;
|
| 194 |
-
color: white;
|
| 195 |
-
animation: overflow-shake 0.5s infinite;
|
| 196 |
-
}
|
| 197 |
-
|
| 198 |
-
@keyframes glow {
|
| 199 |
-
from { box-shadow: 0 4px 15px rgba(231, 76, 60, 0.3); }
|
| 200 |
-
to { box-shadow: 0 4px 25px rgba(231, 76, 60, 0.8); }
|
| 201 |
-
}
|
| 202 |
-
|
| 203 |
-
@keyframes cooking-pulse {
|
| 204 |
-
0%, 100% { transform: scale(1); }
|
| 205 |
-
50% { transform: scale(1.05); }
|
| 206 |
-
}
|
| 207 |
-
|
| 208 |
-
@keyframes overflow-shake {
|
| 209 |
-
0%, 100% { transform: translateX(0); }
|
| 210 |
-
25% { transform: translateX(-2px); }
|
| 211 |
-
75% { transform: translateX(2px); }
|
| 212 |
-
}
|
| 213 |
-
|
| 214 |
-
/* 烹饪信息 */
|
| 215 |
-
.cooking-info {
|
| 216 |
-
position: absolute;
|
| 217 |
-
top: 80px;
|
| 218 |
-
left: 50%;
|
| 219 |
-
transform: translateX(-50%);
|
| 220 |
-
background: rgba(255, 255, 255, 0.95);
|
| 221 |
-
padding: 15px 25px;
|
| 222 |
-
border-radius: 15px;
|
| 223 |
-
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
|
| 224 |
-
text-align: center;
|
| 225 |
-
min-width: 200px;
|
| 226 |
-
}
|
| 227 |
-
|
| 228 |
-
.cooking-food {
|
| 229 |
-
font-size: 1.2em;
|
| 230 |
-
font-weight: bold;
|
| 231 |
-
color: #2c3e50;
|
| 232 |
-
margin-bottom: 10px;
|
| 233 |
-
}
|
| 234 |
-
|
| 235 |
-
.progress-bar {
|
| 236 |
-
width: 100%;
|
| 237 |
-
height: 8px;
|
| 238 |
-
background: #ecf0f1;
|
| 239 |
-
border-radius: 4px;
|
| 240 |
-
overflow: hidden;
|
| 241 |
-
}
|
| 242 |
-
|
| 243 |
-
.progress-fill {
|
| 244 |
-
height: 100%;
|
| 245 |
-
background: linear-gradient(90deg, #ff6b6b, #4ecdc4);
|
| 246 |
-
border-radius: 4px;
|
| 247 |
-
transition: width 0.3s ease;
|
| 248 |
-
width: 0%;
|
| 249 |
-
}
|
| 250 |
-
|
| 251 |
-
/* 食物计数器 */
|
| 252 |
-
.food-counter {
|
| 253 |
-
position: absolute;
|
| 254 |
-
top: 20px;
|
| 255 |
-
right: 20px;
|
| 256 |
-
background: rgba(255, 255, 255, 0.95);
|
| 257 |
-
padding: 15px 20px;
|
| 258 |
-
border-radius: 15px;
|
| 259 |
-
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
|
| 260 |
-
display: flex;
|
| 261 |
-
align-items: center;
|
| 262 |
-
gap: 10px;
|
| 263 |
-
}
|
| 264 |
-
|
| 265 |
-
/* 性能监控 */
|
| 266 |
-
.performance-monitor {
|
| 267 |
-
position: absolute;
|
| 268 |
-
top: 20px;
|
| 269 |
-
left: 20px;
|
| 270 |
-
background: rgba(0, 0, 0, 0.8);
|
| 271 |
-
color: white;
|
| 272 |
-
padding: 10px 15px;
|
| 273 |
-
border-radius: 10px;
|
| 274 |
-
font-family: 'Courier New', monospace;
|
| 275 |
-
font-size: 0.9em;
|
| 276 |
-
box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
|
| 277 |
-
min-width: 120px;
|
| 278 |
-
}
|
| 279 |
-
|
| 280 |
-
.perf-item {
|
| 281 |
-
display: flex;
|
| 282 |
-
justify-content: space-between;
|
| 283 |
-
margin-bottom: 5px;
|
| 284 |
-
align-items: center;
|
| 285 |
-
}
|
| 286 |
-
|
| 287 |
-
.perf-item:last-child {
|
| 288 |
-
margin-bottom: 0;
|
| 289 |
-
}
|
| 290 |
-
|
| 291 |
-
.perf-label {
|
| 292 |
-
color: #4ecdc4;
|
| 293 |
-
font-weight: bold;
|
| 294 |
-
}
|
| 295 |
-
|
| 296 |
-
.perf-value {
|
| 297 |
-
color: #ffffff;
|
| 298 |
-
font-weight: bold;
|
| 299 |
-
text-align: right;
|
| 300 |
-
min-width: 30px;
|
| 301 |
-
}
|
| 302 |
-
|
| 303 |
-
.food-emoji {
|
| 304 |
-
font-size: 2em;
|
| 305 |
-
}
|
| 306 |
-
|
| 307 |
-
.count {
|
| 308 |
-
font-size: 1.5em;
|
| 309 |
-
font-weight: bold;
|
| 310 |
-
color: #2c3e50;
|
| 311 |
-
min-width: 30px;
|
| 312 |
-
text-align: center;
|
| 313 |
-
}
|
| 314 |
-
|
| 315 |
-
/* 语音提示 */
|
| 316 |
-
.voice-hints {
|
| 317 |
-
position: absolute;
|
| 318 |
-
bottom: 20px;
|
| 319 |
-
left: 50%;
|
| 320 |
-
transform: translateX(-50%);
|
| 321 |
-
display: flex;
|
| 322 |
-
flex-direction: column;
|
| 323 |
-
gap: 10px;
|
| 324 |
-
align-items: center;
|
| 325 |
-
}
|
| 326 |
-
|
| 327 |
-
.hint-item {
|
| 328 |
-
background: rgba(0, 0, 0, 0.8);
|
| 329 |
-
color: white;
|
| 330 |
-
padding: 8px 15px;
|
| 331 |
-
border-radius: 20px;
|
| 332 |
-
display: flex;
|
| 333 |
-
align-items: center;
|
| 334 |
-
gap: 10px;
|
| 335 |
-
font-size: 0.9em;
|
| 336 |
-
animation: hint-fade-in 0.5s ease;
|
| 337 |
-
}
|
| 338 |
-
|
| 339 |
-
.hint-command {
|
| 340 |
-
background: #ff6b6b;
|
| 341 |
-
padding: 4px 8px;
|
| 342 |
-
border-radius: 10px;
|
| 343 |
-
font-weight: bold;
|
| 344 |
-
font-size: 0.8em;
|
| 345 |
-
}
|
| 346 |
-
|
| 347 |
-
.hint-desc {
|
| 348 |
-
opacity: 0.9;
|
| 349 |
-
}
|
| 350 |
-
|
| 351 |
-
@keyframes hint-fade-in {
|
| 352 |
-
from { opacity: 0; transform: translateY(10px); }
|
| 353 |
-
to { opacity: 1; transform: translateY(0); }
|
| 354 |
-
}
|
| 355 |
-
|
| 356 |
-
/* 调试信息 */
|
| 357 |
-
.debug-info {
|
| 358 |
-
position: absolute;
|
| 359 |
-
top: 10px;
|
| 360 |
-
left: 10px;
|
| 361 |
-
background: rgba(0, 0, 0, 0.8);
|
| 362 |
-
color: white;
|
| 363 |
-
padding: 10px;
|
| 364 |
-
border-radius: 5px;
|
| 365 |
-
font-family: monospace;
|
| 366 |
-
font-size: 0.8em;
|
| 367 |
-
max-width: 300px;
|
| 368 |
-
max-height: 200px;
|
| 369 |
-
overflow-y: auto;
|
| 370 |
-
z-index: 1000;
|
| 371 |
-
}
|
| 372 |
-
|
| 373 |
-
/* 响应式设计 */
|
| 374 |
-
@media (max-width: 768px) {
|
| 375 |
-
.game-title {
|
| 376 |
-
font-size: 1.5em;
|
| 377 |
-
}
|
| 378 |
-
|
| 379 |
-
#gameCanvas {
|
| 380 |
-
width: 95vw;
|
| 381 |
-
height: 70vh;
|
| 382 |
-
}
|
| 383 |
-
|
| 384 |
-
.voice-hints {
|
| 385 |
-
bottom: 10px;
|
| 386 |
-
}
|
| 387 |
-
|
| 388 |
-
.hint-item {
|
| 389 |
-
font-size: 0.8em;
|
| 390 |
-
padding: 6px 12px;
|
| 391 |
-
}
|
| 392 |
-
}
|
| 393 |
-
|
| 394 |
-
/* 动画效果 */
|
| 395 |
-
.bounce-in {
|
| 396 |
-
animation: bounceIn 0.6s ease;
|
| 397 |
-
}
|
| 398 |
-
|
| 399 |
-
@keyframes bounceIn {
|
| 400 |
-
0% { transform: scale(0.3); opacity: 0; }
|
| 401 |
-
50% { transform: scale(1.05); }
|
| 402 |
-
70% { transform: scale(0.9); }
|
| 403 |
-
100% { transform: scale(1); opacity: 1; }
|
| 404 |
-
}
|
| 405 |
-
|
| 406 |
-
.fade-out {
|
| 407 |
-
animation: fadeOut 0.5s ease forwards;
|
| 408 |
-
}
|
| 409 |
-
|
| 410 |
-
@keyframes fadeOut {
|
| 411 |
-
from { opacity: 1; }
|
| 412 |
-
to { opacity: 0; }
|
| 413 |
-
}
|
| 414 |
-
|
| 415 |
-
/* 特殊效果 */
|
| 416 |
-
.sparkle {
|
| 417 |
-
position: absolute;
|
| 418 |
-
width: 4px;
|
| 419 |
-
height: 4px;
|
| 420 |
-
background: #ffd700;
|
| 421 |
-
border-radius: 50%;
|
| 422 |
-
animation: sparkle 1s ease-in-out infinite;
|
| 423 |
-
}
|
| 424 |
-
|
| 425 |
-
@keyframes sparkle {
|
| 426 |
-
0%, 100% { opacity: 0; transform: scale(0); }
|
| 427 |
-
50% { opacity: 1; transform: scale(1); }
|
| 428 |
-
}
|
| 429 |
-
|
| 430 |
-
/* 音频激活提示 */
|
| 431 |
-
.audio-activation-hint {
|
| 432 |
-
position: absolute;
|
| 433 |
-
top: 30%;
|
| 434 |
-
left: 50%;
|
| 435 |
-
transform: translate(-50%, -50%);
|
| 436 |
-
z-index: 200;
|
| 437 |
-
pointer-events: none;
|
| 438 |
-
animation: audioHintPulse 2s infinite;
|
| 439 |
-
}
|
| 440 |
-
|
| 441 |
-
.hint-bubble {
|
| 442 |
-
background: rgba(255, 107, 107, 0.95);
|
| 443 |
-
border: 3px solid #e74c3c;
|
| 444 |
-
border-radius: 20px;
|
| 445 |
-
padding: 15px 25px;
|
| 446 |
-
display: flex;
|
| 447 |
-
align-items: center;
|
| 448 |
-
gap: 10px;
|
| 449 |
-
box-shadow: 0 8px 32px rgba(231, 76, 60, 0.3);
|
| 450 |
-
color: white;
|
| 451 |
-
font-family: 'Comic Neue', cursive;
|
| 452 |
-
font-weight: bold;
|
| 453 |
-
}
|
| 454 |
-
|
| 455 |
-
.hint-icon {
|
| 456 |
-
font-size: 1.5em;
|
| 457 |
-
animation: audioIconBounce 1s infinite;
|
| 458 |
-
}
|
| 459 |
-
|
| 460 |
-
.hint-text {
|
| 461 |
-
font-size: 1.1em;
|
| 462 |
-
}
|
| 463 |
-
|
| 464 |
-
@keyframes audioHintPulse {
|
| 465 |
-
0%, 100% {
|
| 466 |
-
transform: translate(-50%, -50%) scale(1);
|
| 467 |
-
opacity: 0.9;
|
| 468 |
-
}
|
| 469 |
-
50% {
|
| 470 |
-
transform: translate(-50%, -50%) scale(1.05);
|
| 471 |
-
opacity: 1;
|
| 472 |
-
}
|
| 473 |
-
}
|
| 474 |
-
|
| 475 |
-
@keyframes audioIconBounce {
|
| 476 |
-
0%, 100% {
|
| 477 |
-
transform: translateY(0);
|
| 478 |
-
}
|
| 479 |
-
50% {
|
| 480 |
-
transform: translateY(-3px);
|
| 481 |
-
}
|
| 482 |
-
}
|
| 483 |
-
|
| 484 |
-
/* 语音输入显示 */
|
| 485 |
-
.voice-input-display {
|
| 486 |
-
position: absolute;
|
| 487 |
-
top: 50%;
|
| 488 |
-
left: 50%;
|
| 489 |
-
transform: translate(-50%, -50%);
|
| 490 |
-
z-index: 100;
|
| 491 |
-
pointer-events: none;
|
| 492 |
-
}
|
| 493 |
-
|
| 494 |
-
.speech-bubble {
|
| 495 |
-
background: rgba(255, 255, 255, 0.95);
|
| 496 |
-
border: 3px solid #ff6b6b;
|
| 497 |
-
border-radius: 25px;
|
| 498 |
-
padding: 20px 30px;
|
| 499 |
-
position: relative;
|
| 500 |
-
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
|
| 501 |
-
animation: speechBubble 0.3s ease-out;
|
| 502 |
-
max-width: 400px;
|
| 503 |
-
text-align: center;
|
| 504 |
-
}
|
| 505 |
-
|
| 506 |
-
.speech-bubble::before {
|
| 507 |
-
content: '';
|
| 508 |
-
position: absolute;
|
| 509 |
-
bottom: -15px;
|
| 510 |
-
left: 50%;
|
| 511 |
-
transform: translateX(-50%);
|
| 512 |
-
width: 0;
|
| 513 |
-
height: 0;
|
| 514 |
-
border-left: 15px solid transparent;
|
| 515 |
-
border-right: 15px solid transparent;
|
| 516 |
-
border-top: 15px solid #ff6b6b;
|
| 517 |
-
}
|
| 518 |
-
|
| 519 |
-
.speech-bubble::after {
|
| 520 |
-
content: '';
|
| 521 |
-
position: absolute;
|
| 522 |
-
bottom: -12px;
|
| 523 |
-
left: 50%;
|
| 524 |
-
transform: translateX(-50%);
|
| 525 |
-
width: 0;
|
| 526 |
-
height: 0;
|
| 527 |
-
border-left: 12px solid transparent;
|
| 528 |
-
border-right: 12px solid transparent;
|
| 529 |
-
border-top: 12px solid rgba(255, 255, 255, 0.95);
|
| 530 |
-
}
|
| 531 |
-
|
| 532 |
-
.speech-text {
|
| 533 |
-
font-size: 1.4em;
|
| 534 |
-
font-weight: bold;
|
| 535 |
-
color: #2c3e50;
|
| 536 |
-
margin-bottom: 8px;
|
| 537 |
-
font-family: 'Comic Neue', cursive;
|
| 538 |
-
line-height: 1.3;
|
| 539 |
-
}
|
| 540 |
-
|
| 541 |
-
.speech-confidence {
|
| 542 |
-
font-size: 0.9em;
|
| 543 |
-
color: #7f8c8d;
|
| 544 |
-
font-style: italic;
|
| 545 |
-
}
|
| 546 |
-
|
| 547 |
-
@keyframes speechBubble {
|
| 548 |
-
0% {
|
| 549 |
-
opacity: 0;
|
| 550 |
-
transform: scale(0.3) translateY(20px);
|
| 551 |
-
}
|
| 552 |
-
50% {
|
| 553 |
-
transform: scale(1.1) translateY(-5px);
|
| 554 |
-
}
|
| 555 |
-
100% {
|
| 556 |
-
opacity: 1;
|
| 557 |
-
transform: scale(1) translateY(0);
|
| 558 |
-
}
|
| 559 |
-
}
|
| 560 |
-
|
| 561 |
-
/* 语音识别状态动画 */
|
| 562 |
-
.speech-bubble.listening {
|
| 563 |
-
border-color: #e74c3c;
|
| 564 |
-
animation: listening-pulse 1.5s infinite;
|
| 565 |
-
}
|
| 566 |
-
|
| 567 |
-
.speech-bubble.processing {
|
| 568 |
-
border-color: #f39c12;
|
| 569 |
-
animation: processing-spin 2s infinite linear;
|
| 570 |
-
}
|
| 571 |
-
|
| 572 |
-
.speech-bubble.recognized {
|
| 573 |
-
border-color: #27ae60;
|
| 574 |
-
animation: recognized-bounce 0.6s ease-out;
|
| 575 |
-
}
|
| 576 |
-
|
| 577 |
-
@keyframes listening-pulse {
|
| 578 |
-
0%, 100% {
|
| 579 |
-
border-color: #e74c3c;
|
| 580 |
-
box-shadow: 0 8px 32px rgba(231, 76, 60, 0.2);
|
| 581 |
-
}
|
| 582 |
-
50% {
|
| 583 |
-
border-color: #c0392b;
|
| 584 |
-
box-shadow: 0 8px 32px rgba(231, 76, 60, 0.4);
|
| 585 |
-
}
|
| 586 |
-
}
|
| 587 |
-
|
| 588 |
-
@keyframes processing-spin {
|
| 589 |
-
0% {
|
| 590 |
-
border-color: #f39c12;
|
| 591 |
-
transform: rotate(0deg);
|
| 592 |
-
}
|
| 593 |
-
100% {
|
| 594 |
-
border-color: #e67e22;
|
| 595 |
-
transform: rotate(360deg);
|
| 596 |
-
}
|
| 597 |
-
}
|
| 598 |
-
|
| 599 |
-
@keyframes recognized-bounce {
|
| 600 |
-
0% { transform: scale(1); }
|
| 601 |
-
30% { transform: scale(1.1); }
|
| 602 |
-
60% { transform: scale(0.95); }
|
| 603 |
-
100% { transform: scale(1); }
|
| 604 |
-
}
|
| 605 |
-
|
| 606 |
-
/* 帮助模态框 */
|
| 607 |
-
.help-modal {
|
| 608 |
-
position: fixed;
|
| 609 |
-
top: 0;
|
| 610 |
-
left: 0;
|
| 611 |
-
width: 100%;
|
| 612 |
-
height: 100%;
|
| 613 |
-
z-index: 10000;
|
| 614 |
-
animation: modalFadeIn 0.3s ease-out;
|
| 615 |
-
}
|
| 616 |
-
|
| 617 |
-
.modal-overlay {
|
| 618 |
-
position: absolute;
|
| 619 |
-
top: 0;
|
| 620 |
-
left: 0;
|
| 621 |
-
width: 100%;
|
| 622 |
-
height: 100%;
|
| 623 |
-
background: rgba(0, 0, 0, 0.5);
|
| 624 |
-
backdrop-filter: blur(5px);
|
| 625 |
-
}
|
| 626 |
-
|
| 627 |
-
.modal-content {
|
| 628 |
-
position: absolute;
|
| 629 |
-
top: 50%;
|
| 630 |
-
left: 50%;
|
| 631 |
-
transform: translate(-50%, -50%);
|
| 632 |
-
background: white;
|
| 633 |
-
border-radius: 20px;
|
| 634 |
-
box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
|
| 635 |
-
max-width: 600px;
|
| 636 |
-
max-height: 80vh;
|
| 637 |
-
overflow: hidden;
|
| 638 |
-
font-family: 'Comic Neue', cursive;
|
| 639 |
-
}
|
| 640 |
-
|
| 641 |
-
.modal-header {
|
| 642 |
-
background: linear-gradient(45deg, #ff6b6b, #4ecdc4);
|
| 643 |
-
color: white;
|
| 644 |
-
padding: 20px 30px;
|
| 645 |
-
display: flex;
|
| 646 |
-
justify-content: space-between;
|
| 647 |
-
align-items: center;
|
| 648 |
-
}
|
| 649 |
-
|
| 650 |
-
.modal-header h2 {
|
| 651 |
-
margin: 0;
|
| 652 |
-
font-family: 'Fredoka One', cursive;
|
| 653 |
-
font-size: 1.5em;
|
| 654 |
-
}
|
| 655 |
-
|
| 656 |
-
.modal-close {
|
| 657 |
-
background: none;
|
| 658 |
-
border: none;
|
| 659 |
-
color: white;
|
| 660 |
-
font-size: 24px;
|
| 661 |
-
cursor: pointer;
|
| 662 |
-
padding: 5px;
|
| 663 |
-
border-radius: 50%;
|
| 664 |
-
width: 35px;
|
| 665 |
-
height: 35px;
|
| 666 |
-
display: flex;
|
| 667 |
-
align-items: center;
|
| 668 |
-
justify-content: center;
|
| 669 |
-
transition: background 0.3s ease;
|
| 670 |
-
}
|
| 671 |
-
|
| 672 |
-
.modal-close:hover {
|
| 673 |
-
background: rgba(255, 255, 255, 0.2);
|
| 674 |
-
}
|
| 675 |
-
|
| 676 |
-
.modal-body {
|
| 677 |
-
padding: 30px;
|
| 678 |
-
overflow-y: auto;
|
| 679 |
-
max-height: calc(80vh - 100px);
|
| 680 |
-
}
|
| 681 |
-
|
| 682 |
-
.help-section {
|
| 683 |
-
margin-bottom: 25px;
|
| 684 |
-
padding-bottom: 20px;
|
| 685 |
-
border-bottom: 2px solid #f0f0f0;
|
| 686 |
-
}
|
| 687 |
-
|
| 688 |
-
.help-section:last-child {
|
| 689 |
-
border-bottom: none;
|
| 690 |
-
margin-bottom: 0;
|
| 691 |
-
}
|
| 692 |
-
|
| 693 |
-
.help-section h4 {
|
| 694 |
-
color: #ff6b6b;
|
| 695 |
-
margin-bottom: 10px;
|
| 696 |
-
font-size: 1.2em;
|
| 697 |
-
}
|
| 698 |
-
|
| 699 |
-
.help-section p {
|
| 700 |
-
margin-bottom: 10px;
|
| 701 |
-
line-height: 1.5;
|
| 702 |
-
color: #2c3e50;
|
| 703 |
-
}
|
| 704 |
-
|
| 705 |
-
.help-section ul {
|
| 706 |
-
margin: 10px 0;
|
| 707 |
-
padding-left: 20px;
|
| 708 |
-
}
|
| 709 |
-
|
| 710 |
-
.help-section li {
|
| 711 |
-
margin-bottom: 5px;
|
| 712 |
-
color: #34495e;
|
| 713 |
-
line-height: 1.4;
|
| 714 |
-
}
|
| 715 |
-
|
| 716 |
-
.help-section strong {
|
| 717 |
-
color: #e74c3c;
|
| 718 |
-
}
|
| 719 |
-
|
| 720 |
-
@keyframes modalFadeIn {
|
| 721 |
-
0% {
|
| 722 |
-
opacity: 0;
|
| 723 |
-
transform: scale(0.9);
|
| 724 |
-
}
|
| 725 |
-
100% {
|
| 726 |
-
opacity: 1;
|
| 727 |
-
transform: scale(1);
|
| 728 |
-
}
|
| 729 |
-
}
|
| 730 |
-
|
| 731 |
-
@keyframes modalFadeOut {
|
| 732 |
-
0% {
|
| 733 |
-
opacity: 1;
|
| 734 |
-
transform: scale(1);
|
| 735 |
-
}
|
| 736 |
-
100% {
|
| 737 |
-
opacity: 0;
|
| 738 |
-
transform: scale(0.9);
|
| 739 |
-
}
|
| 740 |
-
}
|
| 741 |
-
|
| 742 |
-
/* 特殊消息动画 */
|
| 743 |
-
@keyframes specialMessage {
|
| 744 |
-
0% {
|
| 745 |
-
opacity: 0;
|
| 746 |
-
transform: translate(-50%, -50%) scale(0.3);
|
| 747 |
-
}
|
| 748 |
-
20% {
|
| 749 |
-
opacity: 1;
|
| 750 |
-
transform: translate(-50%, -50%) scale(1.1);
|
| 751 |
-
}
|
| 752 |
-
30% {
|
| 753 |
-
transform: translate(-50%, -50%) scale(1);
|
| 754 |
-
}
|
| 755 |
-
70% {
|
| 756 |
-
opacity: 1;
|
| 757 |
-
transform: translate(-50%, -50%) scale(1);
|
| 758 |
-
}
|
| 759 |
-
100% {
|
| 760 |
-
opacity: 0;
|
| 761 |
-
transform: translate(-50%, -50%) scale(0.8);
|
| 762 |
-
}
|
| 763 |
-
}
|
| 764 |
-
|
| 765 |
-
/* 键盘输入调试面板 */
|
| 766 |
-
.keyboard-input-panel {
|
| 767 |
-
position: fixed;
|
| 768 |
-
bottom: 20px;
|
| 769 |
-
right: 20px;
|
| 770 |
-
background: rgba(44, 62, 80, 0.95);
|
| 771 |
-
border: 2px solid #4ecdc4;
|
| 772 |
-
border-radius: 15px;
|
| 773 |
-
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
|
| 774 |
-
backdrop-filter: blur(10px);
|
| 775 |
-
color: white;
|
| 776 |
-
font-family: 'Comic Neue', cursive;
|
| 777 |
-
min-width: 300px;
|
| 778 |
-
max-width: 400px;
|
| 779 |
-
transition: all 0.4s ease;
|
| 780 |
-
z-index: 50;
|
| 781 |
-
pointer-events: auto;
|
| 782 |
-
cursor: move;
|
| 783 |
-
user-select: none;
|
| 784 |
-
}
|
| 785 |
-
|
| 786 |
-
/* 面板激活状态 */
|
| 787 |
-
.keyboard-input-panel.active {
|
| 788 |
-
z-index: 10000 !important;
|
| 789 |
-
transform: scale(1.02);
|
| 790 |
-
box-shadow: 0 12px 40px rgba(78, 205, 196, 0.4);
|
| 791 |
-
border-color: #ff6b6b;
|
| 792 |
-
background: rgba(44, 62, 80, 0.98);
|
| 793 |
-
pointer-events: auto !important;
|
| 794 |
-
}
|
| 795 |
-
|
| 796 |
-
/* 拖拽状态 */
|
| 797 |
-
.keyboard-input-panel.dragging {
|
| 798 |
-
transition: none !important;
|
| 799 |
-
transform: scale(1.05) rotate(2deg);
|
| 800 |
-
box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
|
| 801 |
-
z-index: 15000 !important;
|
| 802 |
-
}
|
| 803 |
-
|
| 804 |
-
.keyboard-input-panel.dragging .input-content {
|
| 805 |
-
pointer-events: none;
|
| 806 |
-
}
|
| 807 |
-
|
| 808 |
-
.keyboard-input-panel.dragging .input-header {
|
| 809 |
-
background: linear-gradient(45deg, #ff6b6b, #e74c3c);
|
| 810 |
-
}
|
| 811 |
-
|
| 812 |
-
/* 面板非激活状态(灰色透明) */
|
| 813 |
-
.keyboard-input-panel.inactive {
|
| 814 |
-
opacity: 0.4;
|
| 815 |
-
background: rgba(108, 117, 125, 0.7);
|
| 816 |
-
border-color: #6c757d;
|
| 817 |
-
transform: scale(0.95);
|
| 818 |
-
pointer-events: none;
|
| 819 |
-
}
|
| 820 |
-
|
| 821 |
-
.keyboard-input-panel.inactive .input-header {
|
| 822 |
-
background: linear-gradient(45deg, #6c757d, #495057);
|
| 823 |
-
}
|
| 824 |
-
|
| 825 |
-
.keyboard-input-panel.inactive .command-input {
|
| 826 |
-
border-color: #6c757d;
|
| 827 |
-
background: rgba(108, 117, 125, 0.3);
|
| 828 |
-
color: rgba(255, 255, 255, 0.6);
|
| 829 |
-
}
|
| 830 |
-
|
| 831 |
-
.keyboard-input-panel.inactive .send-btn {
|
| 832 |
-
background: linear-gradient(45deg, #6c757d, #495057);
|
| 833 |
-
opacity: 0.6;
|
| 834 |
-
}
|
| 835 |
-
|
| 836 |
-
.keyboard-input-panel.inactive .quick-cmd {
|
| 837 |
-
border-color: #6c757d;
|
| 838 |
-
background: rgba(108, 117, 125, 0.2);
|
| 839 |
-
color: rgba(255, 255, 255, 0.6);
|
| 840 |
-
}
|
| 841 |
-
|
| 842 |
-
.keyboard-input-panel:hover:not(.inactive) {
|
| 843 |
-
transform: translateY(-5px);
|
| 844 |
-
box-shadow: 0 12px 40px rgba(0, 0, 0, 0.4);
|
| 845 |
-
}
|
| 846 |
-
|
| 847 |
-
.keyboard-input-panel.active:hover {
|
| 848 |
-
transform: scale(1.02) translateY(-5px);
|
| 849 |
-
box-shadow: 0 16px 50px rgba(78, 205, 196, 0.5);
|
| 850 |
-
}
|
| 851 |
-
|
| 852 |
-
.input-header {
|
| 853 |
-
background: linear-gradient(45deg, #4ecdc4, #44a08d);
|
| 854 |
-
padding: 15px 20px;
|
| 855 |
-
border-radius: 13px 13px 0 0;
|
| 856 |
-
display: flex;
|
| 857 |
-
justify-content: space-between;
|
| 858 |
-
align-items: center;
|
| 859 |
-
border-bottom: 2px solid rgba(255, 255, 255, 0.1);
|
| 860 |
-
cursor: move;
|
| 861 |
-
user-select: none;
|
| 862 |
-
}
|
| 863 |
-
|
| 864 |
-
.input-header h4 {
|
| 865 |
-
margin: 0;
|
| 866 |
-
font-size: 1.1em;
|
| 867 |
-
font-weight: bold;
|
| 868 |
-
color: white;
|
| 869 |
-
text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.3);
|
| 870 |
-
}
|
| 871 |
-
|
| 872 |
-
.toggle-panel-btn {
|
| 873 |
-
background: rgba(255, 255, 255, 0.2);
|
| 874 |
-
border: none;
|
| 875 |
-
border-radius: 50%;
|
| 876 |
-
width: 35px;
|
| 877 |
-
height: 35px;
|
| 878 |
-
color: white;
|
| 879 |
-
font-size: 16px;
|
| 880 |
-
cursor: pointer;
|
| 881 |
-
transition: all 0.3s ease;
|
| 882 |
-
display: flex;
|
| 883 |
-
align-items: center;
|
| 884 |
-
justify-content: center;
|
| 885 |
-
}
|
| 886 |
-
|
| 887 |
-
.toggle-panel-btn:hover {
|
| 888 |
-
background: rgba(255, 255, 255, 0.3);
|
| 889 |
-
transform: scale(1.1);
|
| 890 |
-
}
|
| 891 |
-
|
| 892 |
-
.toggle-panel-btn:active {
|
| 893 |
-
transform: scale(0.95);
|
| 894 |
-
}
|
| 895 |
-
|
| 896 |
-
.input-content {
|
| 897 |
-
padding: 20px;
|
| 898 |
-
transition: all 0.3s ease;
|
| 899 |
-
}
|
| 900 |
-
|
| 901 |
-
.input-content.collapsed {
|
| 902 |
-
display: none;
|
| 903 |
-
}
|
| 904 |
-
|
| 905 |
-
.input-group {
|
| 906 |
-
display: flex;
|
| 907 |
-
gap: 10px;
|
| 908 |
-
margin-bottom: 20px;
|
| 909 |
-
}
|
| 910 |
-
|
| 911 |
-
.command-input {
|
| 912 |
-
flex: 1;
|
| 913 |
-
padding: 12px 15px;
|
| 914 |
-
border: 2px solid #4ecdc4;
|
| 915 |
-
border-radius: 25px;
|
| 916 |
-
background: rgba(255, 255, 255, 0.1);
|
| 917 |
-
color: white;
|
| 918 |
-
font-family: 'Comic Neue', cursive;
|
| 919 |
-
font-size: 14px;
|
| 920 |
-
outline: none;
|
| 921 |
-
transition: all 0.3s ease;
|
| 922 |
-
}
|
| 923 |
-
|
| 924 |
-
.command-input::placeholder {
|
| 925 |
-
color: rgba(255, 255, 255, 0.7);
|
| 926 |
-
}
|
| 927 |
-
|
| 928 |
-
.command-input:focus {
|
| 929 |
-
border-color: #ff6b6b;
|
| 930 |
-
background: rgba(255, 255, 255, 0.2);
|
| 931 |
-
box-shadow: 0 0 15px rgba(255, 107, 107, 0.3);
|
| 932 |
-
}
|
| 933 |
-
|
| 934 |
-
.send-btn {
|
| 935 |
-
background: linear-gradient(45deg, #ff6b6b, #e55555);
|
| 936 |
-
border: none;
|
| 937 |
-
border-radius: 25px;
|
| 938 |
-
padding: 12px 20px;
|
| 939 |
-
color: white;
|
| 940 |
-
font-family: 'Comic Neue', cursive;
|
| 941 |
-
font-weight: bold;
|
| 942 |
-
font-size: 14px;
|
| 943 |
-
cursor: pointer;
|
| 944 |
-
transition: all 0.3s ease;
|
| 945 |
-
box-shadow: 0 4px 15px rgba(255, 107, 107, 0.3);
|
| 946 |
-
}
|
| 947 |
-
|
| 948 |
-
.send-btn:hover {
|
| 949 |
-
background: linear-gradient(45deg, #e55555, #d63447);
|
| 950 |
-
transform: translateY(-2px);
|
| 951 |
-
box-shadow: 0 6px 20px rgba(255, 107, 107, 0.4);
|
| 952 |
-
}
|
| 953 |
-
|
| 954 |
-
.send-btn:active {
|
| 955 |
-
transform: translateY(0);
|
| 956 |
-
}
|
| 957 |
-
|
| 958 |
-
.quick-commands {
|
| 959 |
-
margin-bottom: 20px;
|
| 960 |
-
}
|
| 961 |
-
|
| 962 |
-
.quick-commands h5 {
|
| 963 |
-
margin: 0 0 10px 0;
|
| 964 |
-
color: #4ecdc4;
|
| 965 |
-
font-size: 0.9em;
|
| 966 |
-
font-weight: bold;
|
| 967 |
-
text-transform: uppercase;
|
| 968 |
-
letter-spacing: 1px;
|
| 969 |
-
}
|
| 970 |
-
|
| 971 |
-
.command-buttons {
|
| 972 |
-
display: grid;
|
| 973 |
-
grid-template-columns: 1fr 1fr;
|
| 974 |
-
gap: 8px;
|
| 975 |
-
}
|
| 976 |
-
|
| 977 |
-
.quick-cmd {
|
| 978 |
-
background: rgba(78, 205, 196, 0.2);
|
| 979 |
-
border: 1px solid #4ecdc4;
|
| 980 |
-
border-radius: 20px;
|
| 981 |
-
padding: 8px 12px;
|
| 982 |
-
color: white;
|
| 983 |
-
font-family: 'Comic Neue', cursive;
|
| 984 |
-
font-size: 0.8em;
|
| 985 |
-
cursor: pointer;
|
| 986 |
-
transition: all 0.3s ease;
|
| 987 |
-
text-align: center;
|
| 988 |
-
}
|
| 989 |
-
|
| 990 |
-
.quick-cmd:hover {
|
| 991 |
-
background: rgba(78, 205, 196, 0.4);
|
| 992 |
-
border-color: #44a08d;
|
| 993 |
-
transform: scale(1.05);
|
| 994 |
-
}
|
| 995 |
-
|
| 996 |
-
.quick-cmd:active {
|
| 997 |
-
transform: scale(0.95);
|
| 998 |
-
}
|
| 999 |
-
|
| 1000 |
-
.command-history {
|
| 1001 |
-
border-top: 1px solid rgba(255, 255, 255, 0.1);
|
| 1002 |
-
padding-top: 15px;
|
| 1003 |
-
}
|
| 1004 |
-
|
| 1005 |
-
.command-history h5 {
|
| 1006 |
-
margin: 0 0 10px 0;
|
| 1007 |
-
color: #4ecdc4;
|
| 1008 |
-
font-size: 0.9em;
|
| 1009 |
-
font-weight: bold;
|
| 1010 |
-
text-transform: uppercase;
|
| 1011 |
-
letter-spacing: 1px;
|
| 1012 |
-
}
|
| 1013 |
-
|
| 1014 |
-
.history-list {
|
| 1015 |
-
max-height: 120px;
|
| 1016 |
-
overflow-y: auto;
|
| 1017 |
-
border-radius: 8px;
|
| 1018 |
-
background: rgba(0, 0, 0, 0.2);
|
| 1019 |
-
padding: 8px;
|
| 1020 |
-
}
|
| 1021 |
-
|
| 1022 |
-
.history-item {
|
| 1023 |
-
background: rgba(255, 255, 255, 0.1);
|
| 1024 |
-
border-radius: 15px;
|
| 1025 |
-
padding: 6px 12px;
|
| 1026 |
-
margin-bottom: 5px;
|
| 1027 |
-
font-size: 0.8em;
|
| 1028 |
-
color: rgba(255, 255, 255, 0.9);
|
| 1029 |
-
display: flex;
|
| 1030 |
-
justify-content: space-between;
|
| 1031 |
-
align-items: center;
|
| 1032 |
-
cursor: pointer;
|
| 1033 |
-
transition: all 0.3s ease;
|
| 1034 |
-
}
|
| 1035 |
-
|
| 1036 |
-
.history-item:hover {
|
| 1037 |
-
background: rgba(255, 255, 255, 0.2);
|
| 1038 |
-
transform: translateX(5px);
|
| 1039 |
-
}
|
| 1040 |
-
|
| 1041 |
-
.history-item:last-child {
|
| 1042 |
-
margin-bottom: 0;
|
| 1043 |
-
}
|
| 1044 |
-
|
| 1045 |
-
.history-command {
|
| 1046 |
-
flex: 1;
|
| 1047 |
-
white-space: nowrap;
|
| 1048 |
-
overflow: hidden;
|
| 1049 |
-
text-overflow: ellipsis;
|
| 1050 |
-
}
|
| 1051 |
-
|
| 1052 |
-
.history-time {
|
| 1053 |
-
color: rgba(255, 255, 255, 0.6);
|
| 1054 |
-
font-size: 0.7em;
|
| 1055 |
-
margin-left: 10px;
|
| 1056 |
-
}
|
| 1057 |
-
|
| 1058 |
-
/* 滚动条样式 */
|
| 1059 |
-
.history-list::-webkit-scrollbar {
|
| 1060 |
-
width: 4px;
|
| 1061 |
-
}
|
| 1062 |
-
|
| 1063 |
-
.history-list::-webkit-scrollbar-track {
|
| 1064 |
-
background: rgba(255, 255, 255, 0.1);
|
| 1065 |
-
border-radius: 2px;
|
| 1066 |
-
}
|
| 1067 |
-
|
| 1068 |
-
.history-list::-webkit-scrollbar-thumb {
|
| 1069 |
-
background: #4ecdc4;
|
| 1070 |
-
border-radius: 2px;
|
| 1071 |
-
}
|
| 1072 |
-
|
| 1073 |
-
.history-list::-webkit-scrollbar-thumb:hover {
|
| 1074 |
-
background: #44a08d;
|
| 1075 |
-
}
|
| 1076 |
-
|
| 1077 |
-
/* 面板折叠状态 */
|
| 1078 |
-
.keyboard-input-panel.collapsed {
|
| 1079 |
-
min-width: auto;
|
| 1080 |
-
width: auto;
|
| 1081 |
-
}
|
| 1082 |
-
|
| 1083 |
-
.keyboard-input-panel.collapsed .input-content {
|
| 1084 |
-
display: none;
|
| 1085 |
-
}
|
| 1086 |
-
|
| 1087 |
-
/* 面板动画 */
|
| 1088 |
-
@keyframes panelSlideIn {
|
| 1089 |
-
from {
|
| 1090 |
-
transform: translateX(100%);
|
| 1091 |
-
opacity: 0;
|
| 1092 |
-
}
|
| 1093 |
-
to {
|
| 1094 |
-
transform: translateX(0);
|
| 1095 |
-
opacity: 1;
|
| 1096 |
-
}
|
| 1097 |
-
}
|
| 1098 |
-
|
| 1099 |
-
.keyboard-input-panel {
|
| 1100 |
-
animation: panelSlideIn 0.5s ease-out;
|
| 1101 |
-
}
|
| 1102 |
-
|
| 1103 |
-
/* 响应式设计 */
|
| 1104 |
-
@media (max-width: 768px) {
|
| 1105 |
-
.keyboard-input-panel {
|
| 1106 |
-
bottom: 10px;
|
| 1107 |
-
right: 10px;
|
| 1108 |
-
left: 10px;
|
| 1109 |
-
min-width: auto;
|
| 1110 |
-
max-width: none;
|
| 1111 |
-
}
|
| 1112 |
-
|
| 1113 |
-
.command-buttons {
|
| 1114 |
-
grid-template-columns: 1fr;
|
| 1115 |
-
}
|
| 1116 |
-
|
| 1117 |
-
.input-group {
|
| 1118 |
-
flex-direction: column;
|
| 1119 |
-
}
|
| 1120 |
-
|
| 1121 |
-
.send-btn {
|
| 1122 |
-
align-self: flex-end;
|
| 1123 |
-
min-width: 100px;
|
| 1124 |
-
}
|
| 1125 |
}
|
|
|
|
| 1 |
+
/* 全局样式 */
|
| 2 |
+
* {
|
| 3 |
+
margin: 0;
|
| 4 |
+
padding: 0;
|
| 5 |
+
box-sizing: border-box;
|
| 6 |
+
}
|
| 7 |
+
|
| 8 |
+
body {
|
| 9 |
+
font-family: 'Comic Neue', cursive;
|
| 10 |
+
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
| 11 |
+
min-height: 100vh;
|
| 12 |
+
overflow: hidden;
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
/* 游戏容器 */
|
| 16 |
+
.game-container {
|
| 17 |
+
width: 100vw;
|
| 18 |
+
height: 100vh;
|
| 19 |
+
display: flex;
|
| 20 |
+
flex-direction: column;
|
| 21 |
+
position: relative;
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
/* 游戏标题区域 */
|
| 25 |
+
.game-header {
|
| 26 |
+
background: rgba(255, 255, 255, 0.95);
|
| 27 |
+
padding: 15px 20px;
|
| 28 |
+
display: flex;
|
| 29 |
+
justify-content: space-between;
|
| 30 |
+
align-items: center;
|
| 31 |
+
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
|
| 32 |
+
border-bottom: 3px solid #ff6b6b;
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
.header-controls {
|
| 36 |
+
display: flex;
|
| 37 |
+
align-items: center;
|
| 38 |
+
gap: 15px;
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
.audio-button, .help-button {
|
| 42 |
+
background: #ff6b6b;
|
| 43 |
+
color: white;
|
| 44 |
+
border: none;
|
| 45 |
+
border-radius: 50%;
|
| 46 |
+
width: 40px;
|
| 47 |
+
height: 40px;
|
| 48 |
+
font-size: 18px;
|
| 49 |
+
cursor: pointer;
|
| 50 |
+
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
|
| 51 |
+
transition: all 0.3s ease;
|
| 52 |
+
font-family: 'Comic Neue', cursive;
|
| 53 |
+
font-weight: bold;
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
.audio-button:hover, .help-button:hover {
|
| 57 |
+
background: #e55555;
|
| 58 |
+
transform: scale(1.1);
|
| 59 |
+
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
.audio-button:active, .help-button:active {
|
| 63 |
+
transform: scale(0.95);
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
.audio-button.muted {
|
| 67 |
+
background: #95a5a6;
|
| 68 |
+
color: #bdc3c7;
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
.audio-button.muted:hover {
|
| 72 |
+
background: #7f8c8d;
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
.game-title {
|
| 76 |
+
font-family: 'Fredoka One', cursive;
|
| 77 |
+
font-size: 2.2em;
|
| 78 |
+
color: #ff6b6b;
|
| 79 |
+
text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.1);
|
| 80 |
+
margin: 0;
|
| 81 |
+
}
|
| 82 |
+
|
| 83 |
+
.voice-status {
|
| 84 |
+
display: flex;
|
| 85 |
+
align-items: center;
|
| 86 |
+
gap: 10px;
|
| 87 |
+
background: #4ecdc4;
|
| 88 |
+
padding: 8px 15px;
|
| 89 |
+
border-radius: 25px;
|
| 90 |
+
color: white;
|
| 91 |
+
font-weight: bold;
|
| 92 |
+
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
|
| 93 |
+
}
|
| 94 |
+
|
| 95 |
+
.mic-icon {
|
| 96 |
+
font-size: 1.2em;
|
| 97 |
+
animation: pulse 2s infinite;
|
| 98 |
+
}
|
| 99 |
+
|
| 100 |
+
@keyframes pulse {
|
| 101 |
+
0%, 100% { transform: scale(1); }
|
| 102 |
+
50% { transform: scale(1.1); }
|
| 103 |
+
}
|
| 104 |
+
|
| 105 |
+
/* 主游戏区域 */
|
| 106 |
+
.game-main {
|
| 107 |
+
flex: 1;
|
| 108 |
+
position: relative;
|
| 109 |
+
display: flex;
|
| 110 |
+
justify-content: center;
|
| 111 |
+
align-items: center;
|
| 112 |
+
}
|
| 113 |
+
|
| 114 |
+
#gameCanvas {
|
| 115 |
+
border: 4px solid #fff;
|
| 116 |
+
border-radius: 20px;
|
| 117 |
+
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
|
| 118 |
+
background: linear-gradient(45deg, #ffeaa7, #fab1a0);
|
| 119 |
+
}
|
| 120 |
+
|
| 121 |
+
/* 游戏UI覆盖层 */
|
| 122 |
+
.game-ui {
|
| 123 |
+
position: absolute;
|
| 124 |
+
top: 0;
|
| 125 |
+
left: 0;
|
| 126 |
+
width: 100%;
|
| 127 |
+
height: 100%;
|
| 128 |
+
pointer-events: none;
|
| 129 |
+
z-index: 10;
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
+
/* 键盘面板在game-ui内,需要特殊处理 */
|
| 133 |
+
.game-ui .keyboard-input-panel {
|
| 134 |
+
pointer-events: auto;
|
| 135 |
+
}
|
| 136 |
+
|
| 137 |
+
.game-ui .keyboard-input-panel.inactive {
|
| 138 |
+
pointer-events: none;
|
| 139 |
+
}
|
| 140 |
+
|
| 141 |
+
.game-ui .keyboard-input-panel.active {
|
| 142 |
+
pointer-events: auto !important;
|
| 143 |
+
}
|
| 144 |
+
|
| 145 |
+
/* 确保激活状态下所有子元素都可以交互 */
|
| 146 |
+
.keyboard-input-panel.active,
|
| 147 |
+
.keyboard-input-panel.active *,
|
| 148 |
+
.keyboard-input-panel.active .input-content,
|
| 149 |
+
.keyboard-input-panel.active .command-input,
|
| 150 |
+
.keyboard-input-panel.active .send-btn,
|
| 151 |
+
.keyboard-input-panel.active .quick-cmd,
|
| 152 |
+
.keyboard-input-panel.active .toggle-panel-btn,
|
| 153 |
+
.keyboard-input-panel.active .history-item {
|
| 154 |
+
pointer-events: auto !important;
|
| 155 |
+
}
|
| 156 |
+
|
| 157 |
+
/* 魔法锅状态 */
|
| 158 |
+
.pot-status {
|
| 159 |
+
position: absolute;
|
| 160 |
+
top: 20px;
|
| 161 |
+
left: 50%;
|
| 162 |
+
transform: translateX(-50%);
|
| 163 |
+
pointer-events: auto;
|
| 164 |
+
}
|
| 165 |
+
|
| 166 |
+
.status-indicator {
|
| 167 |
+
padding: 10px 20px;
|
| 168 |
+
border-radius: 25px;
|
| 169 |
+
font-weight: bold;
|
| 170 |
+
text-align: center;
|
| 171 |
+
box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
|
| 172 |
+
transition: all 0.3s ease;
|
| 173 |
+
}
|
| 174 |
+
|
| 175 |
+
.status-indicator.inactive {
|
| 176 |
+
background: #95a5a6;
|
| 177 |
+
color: white;
|
| 178 |
+
}
|
| 179 |
+
|
| 180 |
+
.status-indicator.active {
|
| 181 |
+
background: #e74c3c;
|
| 182 |
+
color: white;
|
| 183 |
+
animation: glow 2s infinite alternate;
|
| 184 |
+
}
|
| 185 |
+
|
| 186 |
+
.status-indicator.cooking {
|
| 187 |
+
background: #f39c12;
|
| 188 |
+
color: white;
|
| 189 |
+
animation: cooking-pulse 1s infinite;
|
| 190 |
+
}
|
| 191 |
+
|
| 192 |
+
.status-indicator.overflowing {
|
| 193 |
+
background: #27ae60;
|
| 194 |
+
color: white;
|
| 195 |
+
animation: overflow-shake 0.5s infinite;
|
| 196 |
+
}
|
| 197 |
+
|
| 198 |
+
@keyframes glow {
|
| 199 |
+
from { box-shadow: 0 4px 15px rgba(231, 76, 60, 0.3); }
|
| 200 |
+
to { box-shadow: 0 4px 25px rgba(231, 76, 60, 0.8); }
|
| 201 |
+
}
|
| 202 |
+
|
| 203 |
+
@keyframes cooking-pulse {
|
| 204 |
+
0%, 100% { transform: scale(1); }
|
| 205 |
+
50% { transform: scale(1.05); }
|
| 206 |
+
}
|
| 207 |
+
|
| 208 |
+
@keyframes overflow-shake {
|
| 209 |
+
0%, 100% { transform: translateX(0); }
|
| 210 |
+
25% { transform: translateX(-2px); }
|
| 211 |
+
75% { transform: translateX(2px); }
|
| 212 |
+
}
|
| 213 |
+
|
| 214 |
+
/* 烹饪信息 */
|
| 215 |
+
.cooking-info {
|
| 216 |
+
position: absolute;
|
| 217 |
+
top: 80px;
|
| 218 |
+
left: 50%;
|
| 219 |
+
transform: translateX(-50%);
|
| 220 |
+
background: rgba(255, 255, 255, 0.95);
|
| 221 |
+
padding: 15px 25px;
|
| 222 |
+
border-radius: 15px;
|
| 223 |
+
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
|
| 224 |
+
text-align: center;
|
| 225 |
+
min-width: 200px;
|
| 226 |
+
}
|
| 227 |
+
|
| 228 |
+
.cooking-food {
|
| 229 |
+
font-size: 1.2em;
|
| 230 |
+
font-weight: bold;
|
| 231 |
+
color: #2c3e50;
|
| 232 |
+
margin-bottom: 10px;
|
| 233 |
+
}
|
| 234 |
+
|
| 235 |
+
.progress-bar {
|
| 236 |
+
width: 100%;
|
| 237 |
+
height: 8px;
|
| 238 |
+
background: #ecf0f1;
|
| 239 |
+
border-radius: 4px;
|
| 240 |
+
overflow: hidden;
|
| 241 |
+
}
|
| 242 |
+
|
| 243 |
+
.progress-fill {
|
| 244 |
+
height: 100%;
|
| 245 |
+
background: linear-gradient(90deg, #ff6b6b, #4ecdc4);
|
| 246 |
+
border-radius: 4px;
|
| 247 |
+
transition: width 0.3s ease;
|
| 248 |
+
width: 0%;
|
| 249 |
+
}
|
| 250 |
+
|
| 251 |
+
/* 食物计数器 */
|
| 252 |
+
.food-counter {
|
| 253 |
+
position: absolute;
|
| 254 |
+
top: 20px;
|
| 255 |
+
right: 20px;
|
| 256 |
+
background: rgba(255, 255, 255, 0.95);
|
| 257 |
+
padding: 15px 20px;
|
| 258 |
+
border-radius: 15px;
|
| 259 |
+
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
|
| 260 |
+
display: flex;
|
| 261 |
+
align-items: center;
|
| 262 |
+
gap: 10px;
|
| 263 |
+
}
|
| 264 |
+
|
| 265 |
+
/* 性能监控 */
|
| 266 |
+
.performance-monitor {
|
| 267 |
+
position: absolute;
|
| 268 |
+
top: 20px;
|
| 269 |
+
left: 20px;
|
| 270 |
+
background: rgba(0, 0, 0, 0.8);
|
| 271 |
+
color: white;
|
| 272 |
+
padding: 10px 15px;
|
| 273 |
+
border-radius: 10px;
|
| 274 |
+
font-family: 'Courier New', monospace;
|
| 275 |
+
font-size: 0.9em;
|
| 276 |
+
box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
|
| 277 |
+
min-width: 120px;
|
| 278 |
+
}
|
| 279 |
+
|
| 280 |
+
.perf-item {
|
| 281 |
+
display: flex;
|
| 282 |
+
justify-content: space-between;
|
| 283 |
+
margin-bottom: 5px;
|
| 284 |
+
align-items: center;
|
| 285 |
+
}
|
| 286 |
+
|
| 287 |
+
.perf-item:last-child {
|
| 288 |
+
margin-bottom: 0;
|
| 289 |
+
}
|
| 290 |
+
|
| 291 |
+
.perf-label {
|
| 292 |
+
color: #4ecdc4;
|
| 293 |
+
font-weight: bold;
|
| 294 |
+
}
|
| 295 |
+
|
| 296 |
+
.perf-value {
|
| 297 |
+
color: #ffffff;
|
| 298 |
+
font-weight: bold;
|
| 299 |
+
text-align: right;
|
| 300 |
+
min-width: 30px;
|
| 301 |
+
}
|
| 302 |
+
|
| 303 |
+
.food-emoji {
|
| 304 |
+
font-size: 2em;
|
| 305 |
+
}
|
| 306 |
+
|
| 307 |
+
.count {
|
| 308 |
+
font-size: 1.5em;
|
| 309 |
+
font-weight: bold;
|
| 310 |
+
color: #2c3e50;
|
| 311 |
+
min-width: 30px;
|
| 312 |
+
text-align: center;
|
| 313 |
+
}
|
| 314 |
+
|
| 315 |
+
/* 语音提示 */
|
| 316 |
+
.voice-hints {
|
| 317 |
+
position: absolute;
|
| 318 |
+
bottom: 20px;
|
| 319 |
+
left: 50%;
|
| 320 |
+
transform: translateX(-50%);
|
| 321 |
+
display: flex;
|
| 322 |
+
flex-direction: column;
|
| 323 |
+
gap: 10px;
|
| 324 |
+
align-items: center;
|
| 325 |
+
}
|
| 326 |
+
|
| 327 |
+
.hint-item {
|
| 328 |
+
background: rgba(0, 0, 0, 0.8);
|
| 329 |
+
color: white;
|
| 330 |
+
padding: 8px 15px;
|
| 331 |
+
border-radius: 20px;
|
| 332 |
+
display: flex;
|
| 333 |
+
align-items: center;
|
| 334 |
+
gap: 10px;
|
| 335 |
+
font-size: 0.9em;
|
| 336 |
+
animation: hint-fade-in 0.5s ease;
|
| 337 |
+
}
|
| 338 |
+
|
| 339 |
+
.hint-command {
|
| 340 |
+
background: #ff6b6b;
|
| 341 |
+
padding: 4px 8px;
|
| 342 |
+
border-radius: 10px;
|
| 343 |
+
font-weight: bold;
|
| 344 |
+
font-size: 0.8em;
|
| 345 |
+
}
|
| 346 |
+
|
| 347 |
+
.hint-desc {
|
| 348 |
+
opacity: 0.9;
|
| 349 |
+
}
|
| 350 |
+
|
| 351 |
+
@keyframes hint-fade-in {
|
| 352 |
+
from { opacity: 0; transform: translateY(10px); }
|
| 353 |
+
to { opacity: 1; transform: translateY(0); }
|
| 354 |
+
}
|
| 355 |
+
|
| 356 |
+
/* 调试信息 */
|
| 357 |
+
.debug-info {
|
| 358 |
+
position: absolute;
|
| 359 |
+
top: 10px;
|
| 360 |
+
left: 10px;
|
| 361 |
+
background: rgba(0, 0, 0, 0.8);
|
| 362 |
+
color: white;
|
| 363 |
+
padding: 10px;
|
| 364 |
+
border-radius: 5px;
|
| 365 |
+
font-family: monospace;
|
| 366 |
+
font-size: 0.8em;
|
| 367 |
+
max-width: 300px;
|
| 368 |
+
max-height: 200px;
|
| 369 |
+
overflow-y: auto;
|
| 370 |
+
z-index: 1000;
|
| 371 |
+
}
|
| 372 |
+
|
| 373 |
+
/* 响应式设计 */
|
| 374 |
+
@media (max-width: 768px) {
|
| 375 |
+
.game-title {
|
| 376 |
+
font-size: 1.5em;
|
| 377 |
+
}
|
| 378 |
+
|
| 379 |
+
#gameCanvas {
|
| 380 |
+
width: 95vw;
|
| 381 |
+
height: 70vh;
|
| 382 |
+
}
|
| 383 |
+
|
| 384 |
+
.voice-hints {
|
| 385 |
+
bottom: 10px;
|
| 386 |
+
}
|
| 387 |
+
|
| 388 |
+
.hint-item {
|
| 389 |
+
font-size: 0.8em;
|
| 390 |
+
padding: 6px 12px;
|
| 391 |
+
}
|
| 392 |
+
}
|
| 393 |
+
|
| 394 |
+
/* 动画效果 */
|
| 395 |
+
.bounce-in {
|
| 396 |
+
animation: bounceIn 0.6s ease;
|
| 397 |
+
}
|
| 398 |
+
|
| 399 |
+
@keyframes bounceIn {
|
| 400 |
+
0% { transform: scale(0.3); opacity: 0; }
|
| 401 |
+
50% { transform: scale(1.05); }
|
| 402 |
+
70% { transform: scale(0.9); }
|
| 403 |
+
100% { transform: scale(1); opacity: 1; }
|
| 404 |
+
}
|
| 405 |
+
|
| 406 |
+
.fade-out {
|
| 407 |
+
animation: fadeOut 0.5s ease forwards;
|
| 408 |
+
}
|
| 409 |
+
|
| 410 |
+
@keyframes fadeOut {
|
| 411 |
+
from { opacity: 1; }
|
| 412 |
+
to { opacity: 0; }
|
| 413 |
+
}
|
| 414 |
+
|
| 415 |
+
/* 特殊效果 */
|
| 416 |
+
.sparkle {
|
| 417 |
+
position: absolute;
|
| 418 |
+
width: 4px;
|
| 419 |
+
height: 4px;
|
| 420 |
+
background: #ffd700;
|
| 421 |
+
border-radius: 50%;
|
| 422 |
+
animation: sparkle 1s ease-in-out infinite;
|
| 423 |
+
}
|
| 424 |
+
|
| 425 |
+
@keyframes sparkle {
|
| 426 |
+
0%, 100% { opacity: 0; transform: scale(0); }
|
| 427 |
+
50% { opacity: 1; transform: scale(1); }
|
| 428 |
+
}
|
| 429 |
+
|
| 430 |
+
/* 音频激活提示 */
|
| 431 |
+
.audio-activation-hint {
|
| 432 |
+
position: absolute;
|
| 433 |
+
top: 30%;
|
| 434 |
+
left: 50%;
|
| 435 |
+
transform: translate(-50%, -50%);
|
| 436 |
+
z-index: 200;
|
| 437 |
+
pointer-events: none;
|
| 438 |
+
animation: audioHintPulse 2s infinite;
|
| 439 |
+
}
|
| 440 |
+
|
| 441 |
+
.hint-bubble {
|
| 442 |
+
background: rgba(255, 107, 107, 0.95);
|
| 443 |
+
border: 3px solid #e74c3c;
|
| 444 |
+
border-radius: 20px;
|
| 445 |
+
padding: 15px 25px;
|
| 446 |
+
display: flex;
|
| 447 |
+
align-items: center;
|
| 448 |
+
gap: 10px;
|
| 449 |
+
box-shadow: 0 8px 32px rgba(231, 76, 60, 0.3);
|
| 450 |
+
color: white;
|
| 451 |
+
font-family: 'Comic Neue', cursive;
|
| 452 |
+
font-weight: bold;
|
| 453 |
+
}
|
| 454 |
+
|
| 455 |
+
.hint-icon {
|
| 456 |
+
font-size: 1.5em;
|
| 457 |
+
animation: audioIconBounce 1s infinite;
|
| 458 |
+
}
|
| 459 |
+
|
| 460 |
+
.hint-text {
|
| 461 |
+
font-size: 1.1em;
|
| 462 |
+
}
|
| 463 |
+
|
| 464 |
+
@keyframes audioHintPulse {
|
| 465 |
+
0%, 100% {
|
| 466 |
+
transform: translate(-50%, -50%) scale(1);
|
| 467 |
+
opacity: 0.9;
|
| 468 |
+
}
|
| 469 |
+
50% {
|
| 470 |
+
transform: translate(-50%, -50%) scale(1.05);
|
| 471 |
+
opacity: 1;
|
| 472 |
+
}
|
| 473 |
+
}
|
| 474 |
+
|
| 475 |
+
@keyframes audioIconBounce {
|
| 476 |
+
0%, 100% {
|
| 477 |
+
transform: translateY(0);
|
| 478 |
+
}
|
| 479 |
+
50% {
|
| 480 |
+
transform: translateY(-3px);
|
| 481 |
+
}
|
| 482 |
+
}
|
| 483 |
+
|
| 484 |
+
/* 语音输入显示 */
|
| 485 |
+
.voice-input-display {
|
| 486 |
+
position: absolute;
|
| 487 |
+
top: 50%;
|
| 488 |
+
left: 50%;
|
| 489 |
+
transform: translate(-50%, -50%);
|
| 490 |
+
z-index: 100;
|
| 491 |
+
pointer-events: none;
|
| 492 |
+
}
|
| 493 |
+
|
| 494 |
+
.speech-bubble {
|
| 495 |
+
background: rgba(255, 255, 255, 0.95);
|
| 496 |
+
border: 3px solid #ff6b6b;
|
| 497 |
+
border-radius: 25px;
|
| 498 |
+
padding: 20px 30px;
|
| 499 |
+
position: relative;
|
| 500 |
+
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
|
| 501 |
+
animation: speechBubble 0.3s ease-out;
|
| 502 |
+
max-width: 400px;
|
| 503 |
+
text-align: center;
|
| 504 |
+
}
|
| 505 |
+
|
| 506 |
+
.speech-bubble::before {
|
| 507 |
+
content: '';
|
| 508 |
+
position: absolute;
|
| 509 |
+
bottom: -15px;
|
| 510 |
+
left: 50%;
|
| 511 |
+
transform: translateX(-50%);
|
| 512 |
+
width: 0;
|
| 513 |
+
height: 0;
|
| 514 |
+
border-left: 15px solid transparent;
|
| 515 |
+
border-right: 15px solid transparent;
|
| 516 |
+
border-top: 15px solid #ff6b6b;
|
| 517 |
+
}
|
| 518 |
+
|
| 519 |
+
.speech-bubble::after {
|
| 520 |
+
content: '';
|
| 521 |
+
position: absolute;
|
| 522 |
+
bottom: -12px;
|
| 523 |
+
left: 50%;
|
| 524 |
+
transform: translateX(-50%);
|
| 525 |
+
width: 0;
|
| 526 |
+
height: 0;
|
| 527 |
+
border-left: 12px solid transparent;
|
| 528 |
+
border-right: 12px solid transparent;
|
| 529 |
+
border-top: 12px solid rgba(255, 255, 255, 0.95);
|
| 530 |
+
}
|
| 531 |
+
|
| 532 |
+
.speech-text {
|
| 533 |
+
font-size: 1.4em;
|
| 534 |
+
font-weight: bold;
|
| 535 |
+
color: #2c3e50;
|
| 536 |
+
margin-bottom: 8px;
|
| 537 |
+
font-family: 'Comic Neue', cursive;
|
| 538 |
+
line-height: 1.3;
|
| 539 |
+
}
|
| 540 |
+
|
| 541 |
+
.speech-confidence {
|
| 542 |
+
font-size: 0.9em;
|
| 543 |
+
color: #7f8c8d;
|
| 544 |
+
font-style: italic;
|
| 545 |
+
}
|
| 546 |
+
|
| 547 |
+
@keyframes speechBubble {
|
| 548 |
+
0% {
|
| 549 |
+
opacity: 0;
|
| 550 |
+
transform: scale(0.3) translateY(20px);
|
| 551 |
+
}
|
| 552 |
+
50% {
|
| 553 |
+
transform: scale(1.1) translateY(-5px);
|
| 554 |
+
}
|
| 555 |
+
100% {
|
| 556 |
+
opacity: 1;
|
| 557 |
+
transform: scale(1) translateY(0);
|
| 558 |
+
}
|
| 559 |
+
}
|
| 560 |
+
|
| 561 |
+
/* 语音识别状态动画 */
|
| 562 |
+
.speech-bubble.listening {
|
| 563 |
+
border-color: #e74c3c;
|
| 564 |
+
animation: listening-pulse 1.5s infinite;
|
| 565 |
+
}
|
| 566 |
+
|
| 567 |
+
.speech-bubble.processing {
|
| 568 |
+
border-color: #f39c12;
|
| 569 |
+
animation: processing-spin 2s infinite linear;
|
| 570 |
+
}
|
| 571 |
+
|
| 572 |
+
.speech-bubble.recognized {
|
| 573 |
+
border-color: #27ae60;
|
| 574 |
+
animation: recognized-bounce 0.6s ease-out;
|
| 575 |
+
}
|
| 576 |
+
|
| 577 |
+
@keyframes listening-pulse {
|
| 578 |
+
0%, 100% {
|
| 579 |
+
border-color: #e74c3c;
|
| 580 |
+
box-shadow: 0 8px 32px rgba(231, 76, 60, 0.2);
|
| 581 |
+
}
|
| 582 |
+
50% {
|
| 583 |
+
border-color: #c0392b;
|
| 584 |
+
box-shadow: 0 8px 32px rgba(231, 76, 60, 0.4);
|
| 585 |
+
}
|
| 586 |
+
}
|
| 587 |
+
|
| 588 |
+
@keyframes processing-spin {
|
| 589 |
+
0% {
|
| 590 |
+
border-color: #f39c12;
|
| 591 |
+
transform: rotate(0deg);
|
| 592 |
+
}
|
| 593 |
+
100% {
|
| 594 |
+
border-color: #e67e22;
|
| 595 |
+
transform: rotate(360deg);
|
| 596 |
+
}
|
| 597 |
+
}
|
| 598 |
+
|
| 599 |
+
@keyframes recognized-bounce {
|
| 600 |
+
0% { transform: scale(1); }
|
| 601 |
+
30% { transform: scale(1.1); }
|
| 602 |
+
60% { transform: scale(0.95); }
|
| 603 |
+
100% { transform: scale(1); }
|
| 604 |
+
}
|
| 605 |
+
|
| 606 |
+
/* 帮助模态框 */
|
| 607 |
+
.help-modal {
|
| 608 |
+
position: fixed;
|
| 609 |
+
top: 0;
|
| 610 |
+
left: 0;
|
| 611 |
+
width: 100%;
|
| 612 |
+
height: 100%;
|
| 613 |
+
z-index: 10000;
|
| 614 |
+
animation: modalFadeIn 0.3s ease-out;
|
| 615 |
+
}
|
| 616 |
+
|
| 617 |
+
.modal-overlay {
|
| 618 |
+
position: absolute;
|
| 619 |
+
top: 0;
|
| 620 |
+
left: 0;
|
| 621 |
+
width: 100%;
|
| 622 |
+
height: 100%;
|
| 623 |
+
background: rgba(0, 0, 0, 0.5);
|
| 624 |
+
backdrop-filter: blur(5px);
|
| 625 |
+
}
|
| 626 |
+
|
| 627 |
+
.modal-content {
|
| 628 |
+
position: absolute;
|
| 629 |
+
top: 50%;
|
| 630 |
+
left: 50%;
|
| 631 |
+
transform: translate(-50%, -50%);
|
| 632 |
+
background: white;
|
| 633 |
+
border-radius: 20px;
|
| 634 |
+
box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
|
| 635 |
+
max-width: 600px;
|
| 636 |
+
max-height: 80vh;
|
| 637 |
+
overflow: hidden;
|
| 638 |
+
font-family: 'Comic Neue', cursive;
|
| 639 |
+
}
|
| 640 |
+
|
| 641 |
+
.modal-header {
|
| 642 |
+
background: linear-gradient(45deg, #ff6b6b, #4ecdc4);
|
| 643 |
+
color: white;
|
| 644 |
+
padding: 20px 30px;
|
| 645 |
+
display: flex;
|
| 646 |
+
justify-content: space-between;
|
| 647 |
+
align-items: center;
|
| 648 |
+
}
|
| 649 |
+
|
| 650 |
+
.modal-header h2 {
|
| 651 |
+
margin: 0;
|
| 652 |
+
font-family: 'Fredoka One', cursive;
|
| 653 |
+
font-size: 1.5em;
|
| 654 |
+
}
|
| 655 |
+
|
| 656 |
+
.modal-close {
|
| 657 |
+
background: none;
|
| 658 |
+
border: none;
|
| 659 |
+
color: white;
|
| 660 |
+
font-size: 24px;
|
| 661 |
+
cursor: pointer;
|
| 662 |
+
padding: 5px;
|
| 663 |
+
border-radius: 50%;
|
| 664 |
+
width: 35px;
|
| 665 |
+
height: 35px;
|
| 666 |
+
display: flex;
|
| 667 |
+
align-items: center;
|
| 668 |
+
justify-content: center;
|
| 669 |
+
transition: background 0.3s ease;
|
| 670 |
+
}
|
| 671 |
+
|
| 672 |
+
.modal-close:hover {
|
| 673 |
+
background: rgba(255, 255, 255, 0.2);
|
| 674 |
+
}
|
| 675 |
+
|
| 676 |
+
.modal-body {
|
| 677 |
+
padding: 30px;
|
| 678 |
+
overflow-y: auto;
|
| 679 |
+
max-height: calc(80vh - 100px);
|
| 680 |
+
}
|
| 681 |
+
|
| 682 |
+
.help-section {
|
| 683 |
+
margin-bottom: 25px;
|
| 684 |
+
padding-bottom: 20px;
|
| 685 |
+
border-bottom: 2px solid #f0f0f0;
|
| 686 |
+
}
|
| 687 |
+
|
| 688 |
+
.help-section:last-child {
|
| 689 |
+
border-bottom: none;
|
| 690 |
+
margin-bottom: 0;
|
| 691 |
+
}
|
| 692 |
+
|
| 693 |
+
.help-section h4 {
|
| 694 |
+
color: #ff6b6b;
|
| 695 |
+
margin-bottom: 10px;
|
| 696 |
+
font-size: 1.2em;
|
| 697 |
+
}
|
| 698 |
+
|
| 699 |
+
.help-section p {
|
| 700 |
+
margin-bottom: 10px;
|
| 701 |
+
line-height: 1.5;
|
| 702 |
+
color: #2c3e50;
|
| 703 |
+
}
|
| 704 |
+
|
| 705 |
+
.help-section ul {
|
| 706 |
+
margin: 10px 0;
|
| 707 |
+
padding-left: 20px;
|
| 708 |
+
}
|
| 709 |
+
|
| 710 |
+
.help-section li {
|
| 711 |
+
margin-bottom: 5px;
|
| 712 |
+
color: #34495e;
|
| 713 |
+
line-height: 1.4;
|
| 714 |
+
}
|
| 715 |
+
|
| 716 |
+
.help-section strong {
|
| 717 |
+
color: #e74c3c;
|
| 718 |
+
}
|
| 719 |
+
|
| 720 |
+
@keyframes modalFadeIn {
|
| 721 |
+
0% {
|
| 722 |
+
opacity: 0;
|
| 723 |
+
transform: scale(0.9);
|
| 724 |
+
}
|
| 725 |
+
100% {
|
| 726 |
+
opacity: 1;
|
| 727 |
+
transform: scale(1);
|
| 728 |
+
}
|
| 729 |
+
}
|
| 730 |
+
|
| 731 |
+
@keyframes modalFadeOut {
|
| 732 |
+
0% {
|
| 733 |
+
opacity: 1;
|
| 734 |
+
transform: scale(1);
|
| 735 |
+
}
|
| 736 |
+
100% {
|
| 737 |
+
opacity: 0;
|
| 738 |
+
transform: scale(0.9);
|
| 739 |
+
}
|
| 740 |
+
}
|
| 741 |
+
|
| 742 |
+
/* 特殊消息动画 */
|
| 743 |
+
@keyframes specialMessage {
|
| 744 |
+
0% {
|
| 745 |
+
opacity: 0;
|
| 746 |
+
transform: translate(-50%, -50%) scale(0.3);
|
| 747 |
+
}
|
| 748 |
+
20% {
|
| 749 |
+
opacity: 1;
|
| 750 |
+
transform: translate(-50%, -50%) scale(1.1);
|
| 751 |
+
}
|
| 752 |
+
30% {
|
| 753 |
+
transform: translate(-50%, -50%) scale(1);
|
| 754 |
+
}
|
| 755 |
+
70% {
|
| 756 |
+
opacity: 1;
|
| 757 |
+
transform: translate(-50%, -50%) scale(1);
|
| 758 |
+
}
|
| 759 |
+
100% {
|
| 760 |
+
opacity: 0;
|
| 761 |
+
transform: translate(-50%, -50%) scale(0.8);
|
| 762 |
+
}
|
| 763 |
+
}
|
| 764 |
+
|
| 765 |
+
/* 键盘输入调试面板 */
|
| 766 |
+
.keyboard-input-panel {
|
| 767 |
+
position: fixed;
|
| 768 |
+
bottom: 20px;
|
| 769 |
+
right: 20px;
|
| 770 |
+
background: rgba(44, 62, 80, 0.95);
|
| 771 |
+
border: 2px solid #4ecdc4;
|
| 772 |
+
border-radius: 15px;
|
| 773 |
+
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
|
| 774 |
+
backdrop-filter: blur(10px);
|
| 775 |
+
color: white;
|
| 776 |
+
font-family: 'Comic Neue', cursive;
|
| 777 |
+
min-width: 300px;
|
| 778 |
+
max-width: 400px;
|
| 779 |
+
transition: all 0.4s ease;
|
| 780 |
+
z-index: 50;
|
| 781 |
+
pointer-events: auto;
|
| 782 |
+
cursor: move;
|
| 783 |
+
user-select: none;
|
| 784 |
+
}
|
| 785 |
+
|
| 786 |
+
/* 面板激活状态 */
|
| 787 |
+
.keyboard-input-panel.active {
|
| 788 |
+
z-index: 10000 !important;
|
| 789 |
+
transform: scale(1.02);
|
| 790 |
+
box-shadow: 0 12px 40px rgba(78, 205, 196, 0.4);
|
| 791 |
+
border-color: #ff6b6b;
|
| 792 |
+
background: rgba(44, 62, 80, 0.98);
|
| 793 |
+
pointer-events: auto !important;
|
| 794 |
+
}
|
| 795 |
+
|
| 796 |
+
/* 拖拽状态 */
|
| 797 |
+
.keyboard-input-panel.dragging {
|
| 798 |
+
transition: none !important;
|
| 799 |
+
transform: scale(1.05) rotate(2deg);
|
| 800 |
+
box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
|
| 801 |
+
z-index: 15000 !important;
|
| 802 |
+
}
|
| 803 |
+
|
| 804 |
+
.keyboard-input-panel.dragging .input-content {
|
| 805 |
+
pointer-events: none;
|
| 806 |
+
}
|
| 807 |
+
|
| 808 |
+
.keyboard-input-panel.dragging .input-header {
|
| 809 |
+
background: linear-gradient(45deg, #ff6b6b, #e74c3c);
|
| 810 |
+
}
|
| 811 |
+
|
| 812 |
+
/* 面板非激活状态(灰色透明) */
|
| 813 |
+
.keyboard-input-panel.inactive {
|
| 814 |
+
opacity: 0.4;
|
| 815 |
+
background: rgba(108, 117, 125, 0.7);
|
| 816 |
+
border-color: #6c757d;
|
| 817 |
+
transform: scale(0.95);
|
| 818 |
+
pointer-events: none;
|
| 819 |
+
}
|
| 820 |
+
|
| 821 |
+
.keyboard-input-panel.inactive .input-header {
|
| 822 |
+
background: linear-gradient(45deg, #6c757d, #495057);
|
| 823 |
+
}
|
| 824 |
+
|
| 825 |
+
.keyboard-input-panel.inactive .command-input {
|
| 826 |
+
border-color: #6c757d;
|
| 827 |
+
background: rgba(108, 117, 125, 0.3);
|
| 828 |
+
color: rgba(255, 255, 255, 0.6);
|
| 829 |
+
}
|
| 830 |
+
|
| 831 |
+
.keyboard-input-panel.inactive .send-btn {
|
| 832 |
+
background: linear-gradient(45deg, #6c757d, #495057);
|
| 833 |
+
opacity: 0.6;
|
| 834 |
+
}
|
| 835 |
+
|
| 836 |
+
.keyboard-input-panel.inactive .quick-cmd {
|
| 837 |
+
border-color: #6c757d;
|
| 838 |
+
background: rgba(108, 117, 125, 0.2);
|
| 839 |
+
color: rgba(255, 255, 255, 0.6);
|
| 840 |
+
}
|
| 841 |
+
|
| 842 |
+
.keyboard-input-panel:hover:not(.inactive) {
|
| 843 |
+
transform: translateY(-5px);
|
| 844 |
+
box-shadow: 0 12px 40px rgba(0, 0, 0, 0.4);
|
| 845 |
+
}
|
| 846 |
+
|
| 847 |
+
.keyboard-input-panel.active:hover {
|
| 848 |
+
transform: scale(1.02) translateY(-5px);
|
| 849 |
+
box-shadow: 0 16px 50px rgba(78, 205, 196, 0.5);
|
| 850 |
+
}
|
| 851 |
+
|
| 852 |
+
.input-header {
|
| 853 |
+
background: linear-gradient(45deg, #4ecdc4, #44a08d);
|
| 854 |
+
padding: 15px 20px;
|
| 855 |
+
border-radius: 13px 13px 0 0;
|
| 856 |
+
display: flex;
|
| 857 |
+
justify-content: space-between;
|
| 858 |
+
align-items: center;
|
| 859 |
+
border-bottom: 2px solid rgba(255, 255, 255, 0.1);
|
| 860 |
+
cursor: move;
|
| 861 |
+
user-select: none;
|
| 862 |
+
}
|
| 863 |
+
|
| 864 |
+
.input-header h4 {
|
| 865 |
+
margin: 0;
|
| 866 |
+
font-size: 1.1em;
|
| 867 |
+
font-weight: bold;
|
| 868 |
+
color: white;
|
| 869 |
+
text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.3);
|
| 870 |
+
}
|
| 871 |
+
|
| 872 |
+
.toggle-panel-btn {
|
| 873 |
+
background: rgba(255, 255, 255, 0.2);
|
| 874 |
+
border: none;
|
| 875 |
+
border-radius: 50%;
|
| 876 |
+
width: 35px;
|
| 877 |
+
height: 35px;
|
| 878 |
+
color: white;
|
| 879 |
+
font-size: 16px;
|
| 880 |
+
cursor: pointer;
|
| 881 |
+
transition: all 0.3s ease;
|
| 882 |
+
display: flex;
|
| 883 |
+
align-items: center;
|
| 884 |
+
justify-content: center;
|
| 885 |
+
}
|
| 886 |
+
|
| 887 |
+
.toggle-panel-btn:hover {
|
| 888 |
+
background: rgba(255, 255, 255, 0.3);
|
| 889 |
+
transform: scale(1.1);
|
| 890 |
+
}
|
| 891 |
+
|
| 892 |
+
.toggle-panel-btn:active {
|
| 893 |
+
transform: scale(0.95);
|
| 894 |
+
}
|
| 895 |
+
|
| 896 |
+
.input-content {
|
| 897 |
+
padding: 20px;
|
| 898 |
+
transition: all 0.3s ease;
|
| 899 |
+
}
|
| 900 |
+
|
| 901 |
+
.input-content.collapsed {
|
| 902 |
+
display: none;
|
| 903 |
+
}
|
| 904 |
+
|
| 905 |
+
.input-group {
|
| 906 |
+
display: flex;
|
| 907 |
+
gap: 10px;
|
| 908 |
+
margin-bottom: 20px;
|
| 909 |
+
}
|
| 910 |
+
|
| 911 |
+
.command-input {
|
| 912 |
+
flex: 1;
|
| 913 |
+
padding: 12px 15px;
|
| 914 |
+
border: 2px solid #4ecdc4;
|
| 915 |
+
border-radius: 25px;
|
| 916 |
+
background: rgba(255, 255, 255, 0.1);
|
| 917 |
+
color: white;
|
| 918 |
+
font-family: 'Comic Neue', cursive;
|
| 919 |
+
font-size: 14px;
|
| 920 |
+
outline: none;
|
| 921 |
+
transition: all 0.3s ease;
|
| 922 |
+
}
|
| 923 |
+
|
| 924 |
+
.command-input::placeholder {
|
| 925 |
+
color: rgba(255, 255, 255, 0.7);
|
| 926 |
+
}
|
| 927 |
+
|
| 928 |
+
.command-input:focus {
|
| 929 |
+
border-color: #ff6b6b;
|
| 930 |
+
background: rgba(255, 255, 255, 0.2);
|
| 931 |
+
box-shadow: 0 0 15px rgba(255, 107, 107, 0.3);
|
| 932 |
+
}
|
| 933 |
+
|
| 934 |
+
.send-btn {
|
| 935 |
+
background: linear-gradient(45deg, #ff6b6b, #e55555);
|
| 936 |
+
border: none;
|
| 937 |
+
border-radius: 25px;
|
| 938 |
+
padding: 12px 20px;
|
| 939 |
+
color: white;
|
| 940 |
+
font-family: 'Comic Neue', cursive;
|
| 941 |
+
font-weight: bold;
|
| 942 |
+
font-size: 14px;
|
| 943 |
+
cursor: pointer;
|
| 944 |
+
transition: all 0.3s ease;
|
| 945 |
+
box-shadow: 0 4px 15px rgba(255, 107, 107, 0.3);
|
| 946 |
+
}
|
| 947 |
+
|
| 948 |
+
.send-btn:hover {
|
| 949 |
+
background: linear-gradient(45deg, #e55555, #d63447);
|
| 950 |
+
transform: translateY(-2px);
|
| 951 |
+
box-shadow: 0 6px 20px rgba(255, 107, 107, 0.4);
|
| 952 |
+
}
|
| 953 |
+
|
| 954 |
+
.send-btn:active {
|
| 955 |
+
transform: translateY(0);
|
| 956 |
+
}
|
| 957 |
+
|
| 958 |
+
.quick-commands {
|
| 959 |
+
margin-bottom: 20px;
|
| 960 |
+
}
|
| 961 |
+
|
| 962 |
+
.quick-commands h5 {
|
| 963 |
+
margin: 0 0 10px 0;
|
| 964 |
+
color: #4ecdc4;
|
| 965 |
+
font-size: 0.9em;
|
| 966 |
+
font-weight: bold;
|
| 967 |
+
text-transform: uppercase;
|
| 968 |
+
letter-spacing: 1px;
|
| 969 |
+
}
|
| 970 |
+
|
| 971 |
+
.command-buttons {
|
| 972 |
+
display: grid;
|
| 973 |
+
grid-template-columns: 1fr 1fr;
|
| 974 |
+
gap: 8px;
|
| 975 |
+
}
|
| 976 |
+
|
| 977 |
+
.quick-cmd {
|
| 978 |
+
background: rgba(78, 205, 196, 0.2);
|
| 979 |
+
border: 1px solid #4ecdc4;
|
| 980 |
+
border-radius: 20px;
|
| 981 |
+
padding: 8px 12px;
|
| 982 |
+
color: white;
|
| 983 |
+
font-family: 'Comic Neue', cursive;
|
| 984 |
+
font-size: 0.8em;
|
| 985 |
+
cursor: pointer;
|
| 986 |
+
transition: all 0.3s ease;
|
| 987 |
+
text-align: center;
|
| 988 |
+
}
|
| 989 |
+
|
| 990 |
+
.quick-cmd:hover {
|
| 991 |
+
background: rgba(78, 205, 196, 0.4);
|
| 992 |
+
border-color: #44a08d;
|
| 993 |
+
transform: scale(1.05);
|
| 994 |
+
}
|
| 995 |
+
|
| 996 |
+
.quick-cmd:active {
|
| 997 |
+
transform: scale(0.95);
|
| 998 |
+
}
|
| 999 |
+
|
| 1000 |
+
.command-history {
|
| 1001 |
+
border-top: 1px solid rgba(255, 255, 255, 0.1);
|
| 1002 |
+
padding-top: 15px;
|
| 1003 |
+
}
|
| 1004 |
+
|
| 1005 |
+
.command-history h5 {
|
| 1006 |
+
margin: 0 0 10px 0;
|
| 1007 |
+
color: #4ecdc4;
|
| 1008 |
+
font-size: 0.9em;
|
| 1009 |
+
font-weight: bold;
|
| 1010 |
+
text-transform: uppercase;
|
| 1011 |
+
letter-spacing: 1px;
|
| 1012 |
+
}
|
| 1013 |
+
|
| 1014 |
+
.history-list {
|
| 1015 |
+
max-height: 120px;
|
| 1016 |
+
overflow-y: auto;
|
| 1017 |
+
border-radius: 8px;
|
| 1018 |
+
background: rgba(0, 0, 0, 0.2);
|
| 1019 |
+
padding: 8px;
|
| 1020 |
+
}
|
| 1021 |
+
|
| 1022 |
+
.history-item {
|
| 1023 |
+
background: rgba(255, 255, 255, 0.1);
|
| 1024 |
+
border-radius: 15px;
|
| 1025 |
+
padding: 6px 12px;
|
| 1026 |
+
margin-bottom: 5px;
|
| 1027 |
+
font-size: 0.8em;
|
| 1028 |
+
color: rgba(255, 255, 255, 0.9);
|
| 1029 |
+
display: flex;
|
| 1030 |
+
justify-content: space-between;
|
| 1031 |
+
align-items: center;
|
| 1032 |
+
cursor: pointer;
|
| 1033 |
+
transition: all 0.3s ease;
|
| 1034 |
+
}
|
| 1035 |
+
|
| 1036 |
+
.history-item:hover {
|
| 1037 |
+
background: rgba(255, 255, 255, 0.2);
|
| 1038 |
+
transform: translateX(5px);
|
| 1039 |
+
}
|
| 1040 |
+
|
| 1041 |
+
.history-item:last-child {
|
| 1042 |
+
margin-bottom: 0;
|
| 1043 |
+
}
|
| 1044 |
+
|
| 1045 |
+
.history-command {
|
| 1046 |
+
flex: 1;
|
| 1047 |
+
white-space: nowrap;
|
| 1048 |
+
overflow: hidden;
|
| 1049 |
+
text-overflow: ellipsis;
|
| 1050 |
+
}
|
| 1051 |
+
|
| 1052 |
+
.history-time {
|
| 1053 |
+
color: rgba(255, 255, 255, 0.6);
|
| 1054 |
+
font-size: 0.7em;
|
| 1055 |
+
margin-left: 10px;
|
| 1056 |
+
}
|
| 1057 |
+
|
| 1058 |
+
/* 滚动条样式 */
|
| 1059 |
+
.history-list::-webkit-scrollbar {
|
| 1060 |
+
width: 4px;
|
| 1061 |
+
}
|
| 1062 |
+
|
| 1063 |
+
.history-list::-webkit-scrollbar-track {
|
| 1064 |
+
background: rgba(255, 255, 255, 0.1);
|
| 1065 |
+
border-radius: 2px;
|
| 1066 |
+
}
|
| 1067 |
+
|
| 1068 |
+
.history-list::-webkit-scrollbar-thumb {
|
| 1069 |
+
background: #4ecdc4;
|
| 1070 |
+
border-radius: 2px;
|
| 1071 |
+
}
|
| 1072 |
+
|
| 1073 |
+
.history-list::-webkit-scrollbar-thumb:hover {
|
| 1074 |
+
background: #44a08d;
|
| 1075 |
+
}
|
| 1076 |
+
|
| 1077 |
+
/* 面板折叠状态 */
|
| 1078 |
+
.keyboard-input-panel.collapsed {
|
| 1079 |
+
min-width: auto;
|
| 1080 |
+
width: auto;
|
| 1081 |
+
}
|
| 1082 |
+
|
| 1083 |
+
.keyboard-input-panel.collapsed .input-content {
|
| 1084 |
+
display: none;
|
| 1085 |
+
}
|
| 1086 |
+
|
| 1087 |
+
/* 面板动画 */
|
| 1088 |
+
@keyframes panelSlideIn {
|
| 1089 |
+
from {
|
| 1090 |
+
transform: translateX(100%);
|
| 1091 |
+
opacity: 0;
|
| 1092 |
+
}
|
| 1093 |
+
to {
|
| 1094 |
+
transform: translateX(0);
|
| 1095 |
+
opacity: 1;
|
| 1096 |
+
}
|
| 1097 |
+
}
|
| 1098 |
+
|
| 1099 |
+
.keyboard-input-panel {
|
| 1100 |
+
animation: panelSlideIn 0.5s ease-out;
|
| 1101 |
+
}
|
| 1102 |
+
|
| 1103 |
+
/* 响应式设计 */
|
| 1104 |
+
@media (max-width: 768px) {
|
| 1105 |
+
.keyboard-input-panel {
|
| 1106 |
+
bottom: 10px;
|
| 1107 |
+
right: 10px;
|
| 1108 |
+
left: 10px;
|
| 1109 |
+
min-width: auto;
|
| 1110 |
+
max-width: none;
|
| 1111 |
+
}
|
| 1112 |
+
|
| 1113 |
+
.command-buttons {
|
| 1114 |
+
grid-template-columns: 1fr;
|
| 1115 |
+
}
|
| 1116 |
+
|
| 1117 |
+
.input-group {
|
| 1118 |
+
flex-direction: column;
|
| 1119 |
+
}
|
| 1120 |
+
|
| 1121 |
+
.send-btn {
|
| 1122 |
+
align-self: flex-end;
|
| 1123 |
+
min-width: 100px;
|
| 1124 |
+
}
|
| 1125 |
}
|
docker-README.md
CHANGED
|
@@ -1,179 +1,179 @@
|
|
| 1 |
-
# MagicPot Docker 部署指南
|
| 2 |
-
|
| 3 |
-
## 项目简介
|
| 4 |
-
MagicPot是一个卡通手绘风格的语音交互魔法锅游戏,已经Docker化便于部署。
|
| 5 |
-
|
| 6 |
-
## 快速开始
|
| 7 |
-
|
| 8 |
-
### 1. 构建Docker镜像
|
| 9 |
-
```bash
|
| 10 |
-
docker build -t magicpot-game .
|
| 11 |
-
```
|
| 12 |
-
|
| 13 |
-
### 2. 运行容器
|
| 14 |
-
```bash
|
| 15 |
-
docker run -d -p 8080:80 --name magicpot magicpot-game
|
| 16 |
-
```
|
| 17 |
-
|
| 18 |
-
### 3. 访问游戏
|
| 19 |
-
打开浏览器访问:http://localhost:8080
|
| 20 |
-
|
| 21 |
-
## Docker命令详解
|
| 22 |
-
|
| 23 |
-
### 构建镜像
|
| 24 |
-
```bash
|
| 25 |
-
# 基础构建
|
| 26 |
-
docker build -t magicpot-game .
|
| 27 |
-
|
| 28 |
-
# 指定标签版本
|
| 29 |
-
docker build -t magicpot-game:v1.0 .
|
| 30 |
-
|
| 31 |
-
# 查看镜像
|
| 32 |
-
docker images | grep magicpot
|
| 33 |
-
```
|
| 34 |
-
|
| 35 |
-
### 运行容器
|
| 36 |
-
```bash
|
| 37 |
-
# 后台运行(推荐)
|
| 38 |
-
docker run -d -p 8080:80 --name magicpot magicpot-game
|
| 39 |
-
|
| 40 |
-
# 前台运行(调试用)
|
| 41 |
-
docker run -p 8080:80 --name magicpot magicpot-game
|
| 42 |
-
|
| 43 |
-
# 自定义端口
|
| 44 |
-
docker run -d -p 3000:80 --name magicpot magicpot-game
|
| 45 |
-
|
| 46 |
-
# 运行后访问:http://localhost:3000
|
| 47 |
-
```
|
| 48 |
-
|
| 49 |
-
### 容器管理
|
| 50 |
-
```bash
|
| 51 |
-
# 查看运行中的容器
|
| 52 |
-
docker ps
|
| 53 |
-
|
| 54 |
-
# 查看所有容器
|
| 55 |
-
docker ps -a
|
| 56 |
-
|
| 57 |
-
# 停止容器
|
| 58 |
-
docker stop magicpot
|
| 59 |
-
|
| 60 |
-
# 启动容器
|
| 61 |
-
docker start magicpot
|
| 62 |
-
|
| 63 |
-
# 重启容器
|
| 64 |
-
docker restart magicpot
|
| 65 |
-
|
| 66 |
-
# 删除容器
|
| 67 |
-
docker rm magicpot
|
| 68 |
-
|
| 69 |
-
# 查看容器日志
|
| 70 |
-
docker logs magicpot
|
| 71 |
-
|
| 72 |
-
# 进入容器(调试用)
|
| 73 |
-
docker exec -it magicpot sh
|
| 74 |
-
```
|
| 75 |
-
|
| 76 |
-
## Docker Compose(可选)
|
| 77 |
-
|
| 78 |
-
创建 `docker-compose.yml` 文件:
|
| 79 |
-
|
| 80 |
-
```yaml
|
| 81 |
-
version: '3.8'
|
| 82 |
-
|
| 83 |
-
services:
|
| 84 |
-
magicpot:
|
| 85 |
-
build: .
|
| 86 |
-
ports:
|
| 87 |
-
- "8080:80"
|
| 88 |
-
restart: unless-stopped
|
| 89 |
-
container_name: magicpot-game
|
| 90 |
-
```
|
| 91 |
-
|
| 92 |
-
使用Docker Compose运行:
|
| 93 |
-
```bash
|
| 94 |
-
# 构建并启动
|
| 95 |
-
docker-compose up -d
|
| 96 |
-
|
| 97 |
-
# 停止
|
| 98 |
-
docker-compose down
|
| 99 |
-
|
| 100 |
-
# 查看日志
|
| 101 |
-
docker-compose logs
|
| 102 |
-
```
|
| 103 |
-
|
| 104 |
-
## 技术栈
|
| 105 |
-
- **Base Image**: nginx:alpine
|
| 106 |
-
- **Web Server**: Nginx
|
| 107 |
-
- **Frontend**: HTML5 + CSS3 + JavaScript
|
| 108 |
-
- **Features**: 语音识别、Canvas动画、粒子系统
|
| 109 |
-
|
| 110 |
-
## 配置说明
|
| 111 |
-
|
| 112 |
-
### Nginx配置
|
| 113 |
-
- 静态文件缓存:1年
|
| 114 |
-
- HTML文件缓存:1小时
|
| 115 |
-
- 启用Gzip压缩
|
| 116 |
-
- 安全头设置
|
| 117 |
-
- 支持音频文件(.mp3)
|
| 118 |
-
|
| 119 |
-
### 端口配置
|
| 120 |
-
- 容器内部端口:80
|
| 121 |
-
- 建议外部端口:8080(可自定义)
|
| 122 |
-
|
| 123 |
-
## 故障排除
|
| 124 |
-
|
| 125 |
-
### 常见问题
|
| 126 |
-
|
| 127 |
-
1. **端口被占用**
|
| 128 |
-
```bash
|
| 129 |
-
# 检查端口使用情况
|
| 130 |
-
netstat -an | grep :8080
|
| 131 |
-
# 或使用其他端口
|
| 132 |
-
docker run -d -p 3000:80 --name magicpot magicpot-game
|
| 133 |
-
```
|
| 134 |
-
|
| 135 |
-
2. **容器启动失败**
|
| 136 |
-
```bash
|
| 137 |
-
# 查看详细错误信息
|
| 138 |
-
docker logs magicpot
|
| 139 |
-
|
| 140 |
-
# 检查容器状态
|
| 141 |
-
docker ps -a
|
| 142 |
-
```
|
| 143 |
-
|
| 144 |
-
3. **游戏无法正常运行**
|
| 145 |
-
- 确保浏览器支持Web Speech API
|
| 146 |
-
- 检查麦克风权限设置
|
| 147 |
-
- 尝试使用HTTPS(语音识别需要)
|
| 148 |
-
|
| 149 |
-
### 性能优化
|
| 150 |
-
|
| 151 |
-
1. **镜像大小优化**
|
| 152 |
-
- 使用alpine版本nginx(已实现)
|
| 153 |
-
- 清理不必要的文件(.dockerignore已配置)
|
| 154 |
-
|
| 155 |
-
2. **运行时优化**
|
| 156 |
-
```bash
|
| 157 |
-
# 限制内存使用
|
| 158 |
-
docker run -d -p 8080:80 -m 512m --name magicpot magicpot-game
|
| 159 |
-
|
| 160 |
-
# 设置CPU限制
|
| 161 |
-
docker run -d -p 8080:80 --cpus="1.0" --name magicpot magicpot-game
|
| 162 |
-
```
|
| 163 |
-
|
| 164 |
-
## 开发环境
|
| 165 |
-
|
| 166 |
-
如果需要在开发环境中运行:
|
| 167 |
-
```bash
|
| 168 |
-
# 本地开发(不使用Docker)
|
| 169 |
-
npm install
|
| 170 |
-
npm run dev
|
| 171 |
-
|
| 172 |
-
# 或使用Python
|
| 173 |
-
python -m http.server 8000
|
| 174 |
-
```
|
| 175 |
-
|
| 176 |
-
## 版本信息
|
| 177 |
-
- Docker Image: magicpot-game:latest
|
| 178 |
-
- Nginx Version: alpine
|
| 179 |
-
- Node.js Version: >=14.0.0(仅开发环境需要)
|
|
|
|
| 1 |
+
# MagicPot Docker 部署指南
|
| 2 |
+
|
| 3 |
+
## 项目简介
|
| 4 |
+
MagicPot是一个卡通手绘风格的语音交互魔法锅游戏,已经Docker化便于部署。
|
| 5 |
+
|
| 6 |
+
## 快速开始
|
| 7 |
+
|
| 8 |
+
### 1. 构建Docker镜像
|
| 9 |
+
```bash
|
| 10 |
+
docker build -t magicpot-game .
|
| 11 |
+
```
|
| 12 |
+
|
| 13 |
+
### 2. 运行容器
|
| 14 |
+
```bash
|
| 15 |
+
docker run -d -p 8080:80 --name magicpot magicpot-game
|
| 16 |
+
```
|
| 17 |
+
|
| 18 |
+
### 3. 访问游戏
|
| 19 |
+
打开浏览器访问:http://localhost:8080
|
| 20 |
+
|
| 21 |
+
## Docker命令详解
|
| 22 |
+
|
| 23 |
+
### 构建镜像
|
| 24 |
+
```bash
|
| 25 |
+
# 基础构建
|
| 26 |
+
docker build -t magicpot-game .
|
| 27 |
+
|
| 28 |
+
# 指定标签版本
|
| 29 |
+
docker build -t magicpot-game:v1.0 .
|
| 30 |
+
|
| 31 |
+
# 查看镜像
|
| 32 |
+
docker images | grep magicpot
|
| 33 |
+
```
|
| 34 |
+
|
| 35 |
+
### 运行容器
|
| 36 |
+
```bash
|
| 37 |
+
# 后台运行(推荐)
|
| 38 |
+
docker run -d -p 8080:80 --name magicpot magicpot-game
|
| 39 |
+
|
| 40 |
+
# 前台运行(调试用)
|
| 41 |
+
docker run -p 8080:80 --name magicpot magicpot-game
|
| 42 |
+
|
| 43 |
+
# 自定义端口
|
| 44 |
+
docker run -d -p 3000:80 --name magicpot magicpot-game
|
| 45 |
+
|
| 46 |
+
# 运行后访问:http://localhost:3000
|
| 47 |
+
```
|
| 48 |
+
|
| 49 |
+
### 容器管理
|
| 50 |
+
```bash
|
| 51 |
+
# 查看运行中的容器
|
| 52 |
+
docker ps
|
| 53 |
+
|
| 54 |
+
# 查看所有容器
|
| 55 |
+
docker ps -a
|
| 56 |
+
|
| 57 |
+
# 停止容器
|
| 58 |
+
docker stop magicpot
|
| 59 |
+
|
| 60 |
+
# 启动容器
|
| 61 |
+
docker start magicpot
|
| 62 |
+
|
| 63 |
+
# 重启容器
|
| 64 |
+
docker restart magicpot
|
| 65 |
+
|
| 66 |
+
# 删除容器
|
| 67 |
+
docker rm magicpot
|
| 68 |
+
|
| 69 |
+
# 查看容器日志
|
| 70 |
+
docker logs magicpot
|
| 71 |
+
|
| 72 |
+
# 进入容器(调试用)
|
| 73 |
+
docker exec -it magicpot sh
|
| 74 |
+
```
|
| 75 |
+
|
| 76 |
+
## Docker Compose(可选)
|
| 77 |
+
|
| 78 |
+
创建 `docker-compose.yml` 文件:
|
| 79 |
+
|
| 80 |
+
```yaml
|
| 81 |
+
version: '3.8'
|
| 82 |
+
|
| 83 |
+
services:
|
| 84 |
+
magicpot:
|
| 85 |
+
build: .
|
| 86 |
+
ports:
|
| 87 |
+
- "8080:80"
|
| 88 |
+
restart: unless-stopped
|
| 89 |
+
container_name: magicpot-game
|
| 90 |
+
```
|
| 91 |
+
|
| 92 |
+
使用Docker Compose运行:
|
| 93 |
+
```bash
|
| 94 |
+
# 构建并启动
|
| 95 |
+
docker-compose up -d
|
| 96 |
+
|
| 97 |
+
# 停止
|
| 98 |
+
docker-compose down
|
| 99 |
+
|
| 100 |
+
# 查看日志
|
| 101 |
+
docker-compose logs
|
| 102 |
+
```
|
| 103 |
+
|
| 104 |
+
## 技术栈
|
| 105 |
+
- **Base Image**: nginx:alpine
|
| 106 |
+
- **Web Server**: Nginx
|
| 107 |
+
- **Frontend**: HTML5 + CSS3 + JavaScript
|
| 108 |
+
- **Features**: 语音识别、Canvas动画、粒子系统
|
| 109 |
+
|
| 110 |
+
## 配置说明
|
| 111 |
+
|
| 112 |
+
### Nginx配置
|
| 113 |
+
- 静态文件缓存:1年
|
| 114 |
+
- HTML文件缓存:1小时
|
| 115 |
+
- 启用Gzip压缩
|
| 116 |
+
- 安全头设置
|
| 117 |
+
- 支持音频文件(.mp3)
|
| 118 |
+
|
| 119 |
+
### 端口配置
|
| 120 |
+
- 容器内部端口:80
|
| 121 |
+
- 建议外部端口:8080(可自定义)
|
| 122 |
+
|
| 123 |
+
## 故障排除
|
| 124 |
+
|
| 125 |
+
### 常见问题
|
| 126 |
+
|
| 127 |
+
1. **端口被占用**
|
| 128 |
+
```bash
|
| 129 |
+
# 检查端口使用情况
|
| 130 |
+
netstat -an | grep :8080
|
| 131 |
+
# 或使用其他端口
|
| 132 |
+
docker run -d -p 3000:80 --name magicpot magicpot-game
|
| 133 |
+
```
|
| 134 |
+
|
| 135 |
+
2. **容器启动失败**
|
| 136 |
+
```bash
|
| 137 |
+
# 查看详细错误信息
|
| 138 |
+
docker logs magicpot
|
| 139 |
+
|
| 140 |
+
# 检查容器状态
|
| 141 |
+
docker ps -a
|
| 142 |
+
```
|
| 143 |
+
|
| 144 |
+
3. **游戏无法正常运行**
|
| 145 |
+
- 确保浏览器支持Web Speech API
|
| 146 |
+
- 检查麦克风权限设置
|
| 147 |
+
- 尝试使用HTTPS(语音识别需要)
|
| 148 |
+
|
| 149 |
+
### 性能优化
|
| 150 |
+
|
| 151 |
+
1. **镜像大小优化**
|
| 152 |
+
- 使用alpine版本nginx(已实现)
|
| 153 |
+
- 清理不必要的文件(.dockerignore已配置)
|
| 154 |
+
|
| 155 |
+
2. **运行时优化**
|
| 156 |
+
```bash
|
| 157 |
+
# 限制内存使用
|
| 158 |
+
docker run -d -p 8080:80 -m 512m --name magicpot magicpot-game
|
| 159 |
+
|
| 160 |
+
# 设置CPU限制
|
| 161 |
+
docker run -d -p 8080:80 --cpus="1.0" --name magicpot magicpot-game
|
| 162 |
+
```
|
| 163 |
+
|
| 164 |
+
## 开发环境
|
| 165 |
+
|
| 166 |
+
如果需要在开发环境中运行:
|
| 167 |
+
```bash
|
| 168 |
+
# 本地开发(不使用Docker)
|
| 169 |
+
npm install
|
| 170 |
+
npm run dev
|
| 171 |
+
|
| 172 |
+
# 或使用Python
|
| 173 |
+
python -m http.server 8000
|
| 174 |
+
```
|
| 175 |
+
|
| 176 |
+
## 版本信息
|
| 177 |
+
- Docker Image: magicpot-game:latest
|
| 178 |
+
- Nginx Version: alpine
|
| 179 |
+
- Node.js Version: >=14.0.0(仅开发环境需要)
|
index.html
CHANGED
|
@@ -1,164 +1,164 @@
|
|
| 1 |
-
<!DOCTYPE html>
|
| 2 |
-
<html lang="zh-CN">
|
| 3 |
-
<head>
|
| 4 |
-
<meta charset="UTF-8">
|
| 5 |
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
-
<title>MagicPot - 魔法锅游戏</title>
|
| 7 |
-
<link rel="stylesheet" href="css/style.css">
|
| 8 |
-
<link href="https://fonts.googleapis.com/css2?family=Fredoka+One:wght@400&family=Comic+Neue:wght@400;700&display=swap" rel="stylesheet">
|
| 9 |
-
</head>
|
| 10 |
-
<body>
|
| 11 |
-
<div class="game-container">
|
| 12 |
-
<!-- 游戏标题 -->
|
| 13 |
-
<header class="game-header">
|
| 14 |
-
<h1 class="game-title">🪄 MagicPot 魔法锅 ✨</h1>
|
| 15 |
-
<div class="header-controls">
|
| 16 |
-
<button class="audio-button" id="audioButton" title="音效开关">🔊</button>
|
| 17 |
-
<button class="help-button" id="helpButton" title="语音命令帮助">❓</button>
|
| 18 |
-
<div class="voice-status" id="voiceStatus">
|
| 19 |
-
<span class="status-text">准备中...</span>
|
| 20 |
-
<div class="mic-icon">🎤</div>
|
| 21 |
-
</div>
|
| 22 |
-
</div>
|
| 23 |
-
</header>
|
| 24 |
-
|
| 25 |
-
<!-- 主游戏区域 -->
|
| 26 |
-
<main class="game-main">
|
| 27 |
-
<canvas id="gameCanvas" width="800" height="600"></canvas>
|
| 28 |
-
|
| 29 |
-
<!-- 游戏UI覆盖层 -->
|
| 30 |
-
<div class="game-ui">
|
| 31 |
-
<!-- 魔法锅状态显示 -->
|
| 32 |
-
<div class="pot-status" id="potStatus">
|
| 33 |
-
<div class="status-indicator inactive">魔法锅休眠中</div>
|
| 34 |
-
</div>
|
| 35 |
-
|
| 36 |
-
<!-- 当前烹饪的食物 -->
|
| 37 |
-
<div class="cooking-info" id="cookingInfo" style="display: none;">
|
| 38 |
-
<div class="cooking-food">
|
| 39 |
-
<span>正在烹饪:</span>
|
| 40 |
-
<span id="currentFood">-</span>
|
| 41 |
-
</div>
|
| 42 |
-
<div class="cooking-progress">
|
| 43 |
-
<div class="progress-bar">
|
| 44 |
-
<div class="progress-fill" id="progressFill"></div>
|
| 45 |
-
</div>
|
| 46 |
-
</div>
|
| 47 |
-
</div>
|
| 48 |
-
|
| 49 |
-
<!-- 食物计数器 -->
|
| 50 |
-
<div class="food-counter" id="foodCounter" style="display: none;">
|
| 51 |
-
<div class="counter-item">
|
| 52 |
-
<span class="food-emoji" id="foodEmoji">🍎</span>
|
| 53 |
-
<span class="count" id="foodCount">0</span>
|
| 54 |
-
</div>
|
| 55 |
-
</div>
|
| 56 |
-
|
| 57 |
-
<!-- 性能监控 -->
|
| 58 |
-
<div class="performance-monitor" id="performanceMonitor" style="display: none;">
|
| 59 |
-
<div class="perf-item">
|
| 60 |
-
<span class="perf-label">粒子:</span>
|
| 61 |
-
<span class="perf-value" id="particleCount">0</span>
|
| 62 |
-
</div>
|
| 63 |
-
<div class="perf-item">
|
| 64 |
-
<span class="perf-label">动物:</span>
|
| 65 |
-
<span class="perf-value" id="animalCount">0</span>
|
| 66 |
-
</div>
|
| 67 |
-
<div class="perf-item">
|
| 68 |
-
<span class="perf-label">FPS:</span>
|
| 69 |
-
<span class="perf-value" id="fpsCount">60</span>
|
| 70 |
-
</div>
|
| 71 |
-
</div>
|
| 72 |
-
|
| 73 |
-
<!-- 音频激活提示 -->
|
| 74 |
-
<div class="audio-activation-hint" id="audioActivationHint" style="display: none;">
|
| 75 |
-
<div class="hint-bubble">
|
| 76 |
-
<div class="hint-icon">🔊</div>
|
| 77 |
-
<div class="hint-text">点击任意位置启动音效</div>
|
| 78 |
-
</div>
|
| 79 |
-
</div>
|
| 80 |
-
|
| 81 |
-
<!-- 语音输入显示 -->
|
| 82 |
-
<div class="voice-input-display" id="voiceInputDisplay" style="display: none;">
|
| 83 |
-
<div class="speech-bubble">
|
| 84 |
-
<div class="speech-text" id="speechText">正在听取...</div>
|
| 85 |
-
<div class="speech-confidence" id="speechConfidence"></div>
|
| 86 |
-
</div>
|
| 87 |
-
</div>
|
| 88 |
-
|
| 89 |
-
<!-- 语音提示 -->
|
| 90 |
-
<div class="voice-hints" id="voiceHints">
|
| 91 |
-
<div class="hint-item">
|
| 92 |
-
<span class="hint-command">"cook cook cook pot"</span>
|
| 93 |
-
<span class="hint-desc">激活魔法锅</span>
|
| 94 |
-
</div>
|
| 95 |
-
<div class="hint-item" style="display: none;" id="foodHint">
|
| 96 |
-
<span class="hint-command">说出食物名称</span>
|
| 97 |
-
<span class="hint-desc">开始烹饪</span>
|
| 98 |
-
</div>
|
| 99 |
-
<div class="hint-item" style="display: none;" id="stopHint">
|
| 100 |
-
<span class="hint-command">"stop stop stop pot"</span>
|
| 101 |
-
<span class="hint-desc">停止烹饪</span>
|
| 102 |
-
</div>
|
| 103 |
-
</div>
|
| 104 |
-
|
| 105 |
-
<!-- 键盘输入调试面
|
| 106 |
-
<div class="keyboard-input-panel" id="keyboardInputPanel">
|
| 107 |
-
<div class="input-header">
|
| 108 |
-
<h4>🎮 键盘调试输入</h4>
|
| 109 |
-
<button class="toggle-panel-btn" id="toggleKeyboardPanel" title="切换键盘输入面板">⌨️</button>
|
| 110 |
-
</div>
|
| 111 |
-
<div class="input-content" id="keyboardInputContent">
|
| 112 |
-
<div class="input-group">
|
| 113 |
-
<input type="text"
|
| 114 |
-
id="commandInput"
|
| 115 |
-
class="command-input"
|
| 116 |
-
placeholder="输入指令,如:cook cook cook pot"
|
| 117 |
-
autocomplete="off">
|
| 118 |
-
<button class="send-btn" id="sendCommandBtn">发送</button>
|
| 119 |
-
</div>
|
| 120 |
-
|
| 121 |
-
<div class="quick-commands">
|
| 122 |
-
<h5>快捷指令:</h5>
|
| 123 |
-
<div class="command-buttons">
|
| 124 |
-
<button class="quick-cmd" data-command="cook cook cook pot">激活魔法锅</button>
|
| 125 |
-
<button class="quick-cmd" data-command="stop stop stop pot">停止烹饪</button>
|
| 126 |
-
<button class="quick-cmd" data-command="apple">苹果</button>
|
| 127 |
-
<button class="quick-cmd" data-command="banana">香蕉</button>
|
| 128 |
-
<button class="quick-cmd" data-command="pizza">披萨</button>
|
| 129 |
-
<button class="quick-cmd" data-command="cake">蛋糕</button>
|
| 130 |
-
</div>
|
| 131 |
-
</div>
|
| 132 |
-
|
| 133 |
-
<div class="command-history">
|
| 134 |
-
<h5>命令历史:</h5>
|
| 135 |
-
<div class="history-list" id="commandHistory"></div>
|
| 136 |
-
</div>
|
| 137 |
-
|
| 138 |
-
<!-- 快捷键提示 -->
|
| 139 |
-
<div class="keyboard-shortcuts-hint">
|
| 140 |
-
快捷键: F9(激活显示) | F8(显示/隐藏) | 1-6(快速命令) | 可拖拽标题栏
|
| 141 |
-
</div>
|
| 142 |
-
</div>
|
| 143 |
-
</div>
|
| 144 |
-
</div>
|
| 145 |
-
</main>
|
| 146 |
-
|
| 147 |
-
<!-- 调试信息 -->
|
| 148 |
-
<div class="debug-info" id="debugInfo" style="display: none;">
|
| 149 |
-
<h3>调试信息</h3>
|
| 150 |
-
<div id="debugLog"></div>
|
| 151 |
-
</div>
|
| 152 |
-
</div>
|
| 153 |
-
|
| 154 |
-
<!-- 加载脚本 -->
|
| 155 |
-
<script src="js/audio.js"></script>
|
| 156 |
-
<script src="js/voice.js"></script>
|
| 157 |
-
<script src="js/keyboard.js"></script>
|
| 158 |
-
<script src="js/particles.js"></script>
|
| 159 |
-
<script src="js/animals.js"></script>
|
| 160 |
-
<script src="js/pot.js"></script>
|
| 161 |
-
<script src="js/textToImage.js"></script>
|
| 162 |
-
<script src="js/main.js"></script>
|
| 163 |
-
</body>
|
| 164 |
-
</html>
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="zh-CN">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>MagicPot - 魔法锅游戏</title>
|
| 7 |
+
<link rel="stylesheet" href="css/style.css">
|
| 8 |
+
<link href="https://fonts.googleapis.com/css2?family=Fredoka+One:wght@400&family=Comic+Neue:wght@400;700&display=swap" rel="stylesheet">
|
| 9 |
+
</head>
|
| 10 |
+
<body>
|
| 11 |
+
<div class="game-container">
|
| 12 |
+
<!-- 游戏标题 -->
|
| 13 |
+
<header class="game-header">
|
| 14 |
+
<h1 class="game-title">🪄 MagicPot 魔法锅 ✨</h1>
|
| 15 |
+
<div class="header-controls">
|
| 16 |
+
<button class="audio-button" id="audioButton" title="音效开关">🔊</button>
|
| 17 |
+
<button class="help-button" id="helpButton" title="语音命令帮助">❓</button>
|
| 18 |
+
<div class="voice-status" id="voiceStatus">
|
| 19 |
+
<span class="status-text">准备中...</span>
|
| 20 |
+
<div class="mic-icon">🎤</div>
|
| 21 |
+
</div>
|
| 22 |
+
</div>
|
| 23 |
+
</header>
|
| 24 |
+
|
| 25 |
+
<!-- 主游戏区域 -->
|
| 26 |
+
<main class="game-main">
|
| 27 |
+
<canvas id="gameCanvas" width="800" height="600"></canvas>
|
| 28 |
+
|
| 29 |
+
<!-- 游戏UI覆盖层 -->
|
| 30 |
+
<div class="game-ui">
|
| 31 |
+
<!-- 魔法锅状态显示 -->
|
| 32 |
+
<div class="pot-status" id="potStatus">
|
| 33 |
+
<div class="status-indicator inactive">魔法锅休眠中</div>
|
| 34 |
+
</div>
|
| 35 |
+
|
| 36 |
+
<!-- 当前烹饪的食物 -->
|
| 37 |
+
<div class="cooking-info" id="cookingInfo" style="display: none;">
|
| 38 |
+
<div class="cooking-food">
|
| 39 |
+
<span>正在烹饪:</span>
|
| 40 |
+
<span id="currentFood">-</span>
|
| 41 |
+
</div>
|
| 42 |
+
<div class="cooking-progress">
|
| 43 |
+
<div class="progress-bar">
|
| 44 |
+
<div class="progress-fill" id="progressFill"></div>
|
| 45 |
+
</div>
|
| 46 |
+
</div>
|
| 47 |
+
</div>
|
| 48 |
+
|
| 49 |
+
<!-- 食物计数器 -->
|
| 50 |
+
<div class="food-counter" id="foodCounter" style="display: none;">
|
| 51 |
+
<div class="counter-item">
|
| 52 |
+
<span class="food-emoji" id="foodEmoji">🍎</span>
|
| 53 |
+
<span class="count" id="foodCount">0</span>
|
| 54 |
+
</div>
|
| 55 |
+
</div>
|
| 56 |
+
|
| 57 |
+
<!-- 性能监控 -->
|
| 58 |
+
<div class="performance-monitor" id="performanceMonitor" style="display: none;">
|
| 59 |
+
<div class="perf-item">
|
| 60 |
+
<span class="perf-label">粒子:</span>
|
| 61 |
+
<span class="perf-value" id="particleCount">0</span>
|
| 62 |
+
</div>
|
| 63 |
+
<div class="perf-item">
|
| 64 |
+
<span class="perf-label">动物:</span>
|
| 65 |
+
<span class="perf-value" id="animalCount">0</span>
|
| 66 |
+
</div>
|
| 67 |
+
<div class="perf-item">
|
| 68 |
+
<span class="perf-label">FPS:</span>
|
| 69 |
+
<span class="perf-value" id="fpsCount">60</span>
|
| 70 |
+
</div>
|
| 71 |
+
</div>
|
| 72 |
+
|
| 73 |
+
<!-- 音频激活提示 -->
|
| 74 |
+
<div class="audio-activation-hint" id="audioActivationHint" style="display: none;">
|
| 75 |
+
<div class="hint-bubble">
|
| 76 |
+
<div class="hint-icon">🔊</div>
|
| 77 |
+
<div class="hint-text">点击任意位置启动音效</div>
|
| 78 |
+
</div>
|
| 79 |
+
</div>
|
| 80 |
+
|
| 81 |
+
<!-- 语音输入显示 -->
|
| 82 |
+
<div class="voice-input-display" id="voiceInputDisplay" style="display: none;">
|
| 83 |
+
<div class="speech-bubble">
|
| 84 |
+
<div class="speech-text" id="speechText">正在听取...</div>
|
| 85 |
+
<div class="speech-confidence" id="speechConfidence"></div>
|
| 86 |
+
</div>
|
| 87 |
+
</div>
|
| 88 |
+
|
| 89 |
+
<!-- 语音提示 -->
|
| 90 |
+
<div class="voice-hints" id="voiceHints">
|
| 91 |
+
<div class="hint-item">
|
| 92 |
+
<span class="hint-command">"cook cook cook pot"</span>
|
| 93 |
+
<span class="hint-desc">激活魔法锅</span>
|
| 94 |
+
</div>
|
| 95 |
+
<div class="hint-item" style="display: none;" id="foodHint">
|
| 96 |
+
<span class="hint-command">说出食物名称</span>
|
| 97 |
+
<span class="hint-desc">开始烹饪</span>
|
| 98 |
+
</div>
|
| 99 |
+
<div class="hint-item" style="display: none;" id="stopHint">
|
| 100 |
+
<span class="hint-command">"stop stop stop pot"</span>
|
| 101 |
+
<span class="hint-desc">停止烹饪</span>
|
| 102 |
+
</div>
|
| 103 |
+
</div>
|
| 104 |
+
|
| 105 |
+
<!-- 键盘输入调试面板 -->
|
| 106 |
+
<div class="keyboard-input-panel" id="keyboardInputPanel">
|
| 107 |
+
<div class="input-header">
|
| 108 |
+
<h4>🎮 键盘调试输入</h4>
|
| 109 |
+
<button class="toggle-panel-btn" id="toggleKeyboardPanel" title="切换键盘输入面板">⌨️</button>
|
| 110 |
+
</div>
|
| 111 |
+
<div class="input-content" id="keyboardInputContent">
|
| 112 |
+
<div class="input-group">
|
| 113 |
+
<input type="text"
|
| 114 |
+
id="commandInput"
|
| 115 |
+
class="command-input"
|
| 116 |
+
placeholder="输入指令,如:cook cook cook pot"
|
| 117 |
+
autocomplete="off">
|
| 118 |
+
<button class="send-btn" id="sendCommandBtn">发送</button>
|
| 119 |
+
</div>
|
| 120 |
+
|
| 121 |
+
<div class="quick-commands">
|
| 122 |
+
<h5>快捷指令:</h5>
|
| 123 |
+
<div class="command-buttons">
|
| 124 |
+
<button class="quick-cmd" data-command="cook cook cook pot">激活魔法锅</button>
|
| 125 |
+
<button class="quick-cmd" data-command="stop stop stop pot">停止烹饪</button>
|
| 126 |
+
<button class="quick-cmd" data-command="apple">苹果</button>
|
| 127 |
+
<button class="quick-cmd" data-command="banana">香蕉</button>
|
| 128 |
+
<button class="quick-cmd" data-command="pizza">披萨</button>
|
| 129 |
+
<button class="quick-cmd" data-command="cake">蛋糕</button>
|
| 130 |
+
</div>
|
| 131 |
+
</div>
|
| 132 |
+
|
| 133 |
+
<div class="command-history">
|
| 134 |
+
<h5>命令历史:</h5>
|
| 135 |
+
<div class="history-list" id="commandHistory"></div>
|
| 136 |
+
</div>
|
| 137 |
+
|
| 138 |
+
<!-- 快捷键提示 -->
|
| 139 |
+
<div class="keyboard-shortcuts-hint">
|
| 140 |
+
快捷键: F9(激活显示) | F8(显示/隐藏) | 1-6(快速命令) | 可拖拽标题栏
|
| 141 |
+
</div>
|
| 142 |
+
</div>
|
| 143 |
+
</div>
|
| 144 |
+
</div>
|
| 145 |
+
</main>
|
| 146 |
+
|
| 147 |
+
<!-- 调试信息 -->
|
| 148 |
+
<div class="debug-info" id="debugInfo" style="display: none;">
|
| 149 |
+
<h3>调试信息</h3>
|
| 150 |
+
<div id="debugLog"></div>
|
| 151 |
+
</div>
|
| 152 |
+
</div>
|
| 153 |
+
|
| 154 |
+
<!-- 加载脚本 -->
|
| 155 |
+
<script src="js/audio.js"></script>
|
| 156 |
+
<script src="js/voice.js"></script>
|
| 157 |
+
<script src="js/keyboard.js"></script>
|
| 158 |
+
<script src="js/particles.js"></script>
|
| 159 |
+
<script src="js/animals.js"></script>
|
| 160 |
+
<script src="js/pot.js"></script>
|
| 161 |
+
<script src="js/textToImage.js"></script>
|
| 162 |
+
<script src="js/main.js"></script>
|
| 163 |
+
</body>
|
| 164 |
+
</html>
|
js/audio.js
CHANGED
|
@@ -1,474 +1,474 @@
|
|
| 1 |
-
// 音频管理系统
|
| 2 |
-
class AudioManager {
|
| 3 |
-
constructor() {
|
| 4 |
-
this.audioContext = null;
|
| 5 |
-
this.sounds = new Map();
|
| 6 |
-
this.isEnabled = true;
|
| 7 |
-
this.volume = 0.7;
|
| 8 |
-
this.isInitialized = false;
|
| 9 |
-
this.hasShownInteractionHint = false;
|
| 10 |
-
|
| 11 |
-
// 音效配置
|
| 12 |
-
this.soundConfig = {
|
| 13 |
-
potActivate: { frequency: 440, duration: 0.5, type: 'magic' },
|
| 14 |
-
cooking: { frequency: 220, duration: 0.3, type: 'bubble' },
|
| 15 |
-
foodPop: { frequency: 660, duration: 0.2, type: 'pop' },
|
| 16 |
-
animalAppear: { frequency: 880, duration: 0.4, type: 'chirp' },
|
| 17 |
-
girlAppear: { frequency: 1320, duration: 0.6, type: 'sparkle' },
|
| 18 |
-
celebration: { frequency: 1760, duration: 1.0, type: 'fanfare' },
|
| 19 |
-
stopCooking: { frequency: 330, duration: 0.4, type: 'whoosh' }
|
| 20 |
-
};
|
| 21 |
-
|
| 22 |
-
this.init();
|
| 23 |
-
}
|
| 24 |
-
|
| 25 |
-
async init() {
|
| 26 |
-
try {
|
| 27 |
-
// 创建音频上下文(暂停状态)
|
| 28 |
-
this.audioContext = new (window.AudioContext || window.webkitAudioContext)();
|
| 29 |
-
|
| 30 |
-
// 注册用户交互事件来启动音频上下文
|
| 31 |
-
this.setupUserInteractionHandlers();
|
| 32 |
-
|
| 33 |
-
console.log('音频系统已准备,等待用户交互启动');
|
| 34 |
-
} catch (error) {
|
| 35 |
-
console.warn('音频系统初始化失败:', error);
|
| 36 |
-
this.isEnabled = false;
|
| 37 |
-
}
|
| 38 |
-
}
|
| 39 |
-
|
| 40 |
-
setupUserInteractionHandlers() {
|
| 41 |
-
const startAudio = async () => {
|
| 42 |
-
if (this.audioContext && this.audioContext.state === 'suspended') {
|
| 43 |
-
try {
|
| 44 |
-
await this.audioContext.resume();
|
| 45 |
-
|
| 46 |
-
// 音频上下文启动后,预生成音效
|
| 47 |
-
if (!this.isInitialized) {
|
| 48 |
-
this.preGenerateSounds();
|
| 49 |
-
this.isInitialized = true;
|
| 50 |
-
console.log('音频系统初始化完成');
|
| 51 |
-
}
|
| 52 |
-
|
| 53 |
-
// 隐藏音频激活提示
|
| 54 |
-
this.hideAudioActivationHint();
|
| 55 |
-
|
| 56 |
-
} catch (error) {
|
| 57 |
-
console.warn('启动音频上下文失败:', error);
|
| 58 |
-
}
|
| 59 |
-
}
|
| 60 |
-
};
|
| 61 |
-
|
| 62 |
-
// 监听各种用户交互事件
|
| 63 |
-
const events = ['click', 'touchstart', 'keydown'];
|
| 64 |
-
const handler = () => {
|
| 65 |
-
startAudio();
|
| 66 |
-
// 移除事件监听器,只需要启动一次
|
| 67 |
-
events.forEach(event => {
|
| 68 |
-
document.removeEventListener(event, handler);
|
| 69 |
-
});
|
| 70 |
-
};
|
| 71 |
-
|
| 72 |
-
events.forEach(event => {
|
| 73 |
-
document.addEventListener(event, handler, { once: true });
|
| 74 |
-
});
|
| 75 |
-
}
|
| 76 |
-
|
| 77 |
-
showAudioActivationHint() {
|
| 78 |
-
const hint = document.getElementById('audioActivationHint');
|
| 79 |
-
if (hint) {
|
| 80 |
-
hint.style.display = 'block';
|
| 81 |
-
console.log('显示音频激活提示');
|
| 82 |
-
}
|
| 83 |
-
}
|
| 84 |
-
|
| 85 |
-
hideAudioActivationHint() {
|
| 86 |
-
const hint = document.getElementById('audioActivationHint');
|
| 87 |
-
if (hint) {
|
| 88 |
-
hint.style.display = 'none';
|
| 89 |
-
console.log('隐藏音频激活提示');
|
| 90 |
-
}
|
| 91 |
-
}
|
| 92 |
-
|
| 93 |
-
async ensureAudioContext() {
|
| 94 |
-
if (!this.audioContext) return false;
|
| 95 |
-
|
| 96 |
-
if (this.audioContext.state === 'suspended') {
|
| 97 |
-
try {
|
| 98 |
-
await this.audioContext.resume();
|
| 99 |
-
|
| 100 |
-
// 如果音频上下文刚刚启动,且还未初始化,则初始化音效
|
| 101 |
-
if (!this.isInitialized) {
|
| 102 |
-
this.preGenerateSounds();
|
| 103 |
-
this.isInitialized = true;
|
| 104 |
-
console.log('音频系统延迟初始化完成');
|
| 105 |
-
}
|
| 106 |
-
|
| 107 |
-
// 隐藏音频激活提示
|
| 108 |
-
this.hideAudioActivationHint();
|
| 109 |
-
} catch (error) {
|
| 110 |
-
console.warn('无法恢复音频上下文:', error);
|
| 111 |
-
return false;
|
| 112 |
-
}
|
| 113 |
-
}
|
| 114 |
-
|
| 115 |
-
return this.audioContext.state === 'running';
|
| 116 |
-
}
|
| 117 |
-
|
| 118 |
-
preGenerateSounds() {
|
| 119 |
-
// 预生成所有音效的音频数据
|
| 120 |
-
Object.keys(this.soundConfig).forEach(soundName => {
|
| 121 |
-
this.generateSound(soundName);
|
| 122 |
-
});
|
| 123 |
-
}
|
| 124 |
-
|
| 125 |
-
generateSound(soundName) {
|
| 126 |
-
const config = this.soundConfig[soundName];
|
| 127 |
-
if (!config) return null;
|
| 128 |
-
|
| 129 |
-
const sampleRate = this.audioContext.sampleRate;
|
| 130 |
-
const duration = config.duration;
|
| 131 |
-
const length = sampleRate * duration;
|
| 132 |
-
const buffer = this.audioContext.createBuffer(1, length, sampleRate);
|
| 133 |
-
const data = buffer.getChannelData(0);
|
| 134 |
-
|
| 135 |
-
// 根据音效类型生成不同的波形
|
| 136 |
-
switch (config.type) {
|
| 137 |
-
case 'magic':
|
| 138 |
-
this.generateMagicSound(data, config, sampleRate);
|
| 139 |
-
break;
|
| 140 |
-
case 'bubble':
|
| 141 |
-
this.generateBubbleSound(data, config, sampleRate);
|
| 142 |
-
break;
|
| 143 |
-
case 'pop':
|
| 144 |
-
this.generatePopSound(data, config, sampleRate);
|
| 145 |
-
break;
|
| 146 |
-
case 'chirp':
|
| 147 |
-
this.generateChirpSound(data, config, sampleRate);
|
| 148 |
-
break;
|
| 149 |
-
case 'sparkle':
|
| 150 |
-
this.generateSparkleSound(data, config, sampleRate);
|
| 151 |
-
break;
|
| 152 |
-
case 'fanfare':
|
| 153 |
-
this.generateFanfareSound(data, config, sampleRate);
|
| 154 |
-
break;
|
| 155 |
-
case 'whoosh':
|
| 156 |
-
this.generateWhooshSound(data, config, sampleRate);
|
| 157 |
-
break;
|
| 158 |
-
default:
|
| 159 |
-
this.generateSimpleBeep(data, config, sampleRate);
|
| 160 |
-
}
|
| 161 |
-
|
| 162 |
-
this.sounds.set(soundName, buffer);
|
| 163 |
-
return buffer;
|
| 164 |
-
}
|
| 165 |
-
|
| 166 |
-
generateMagicSound(data, config, sampleRate) {
|
| 167 |
-
// 魔法激活音效 - 上升的音调带有颤音
|
| 168 |
-
const baseFreq = config.frequency;
|
| 169 |
-
const length = data.length;
|
| 170 |
-
|
| 171 |
-
for (let i = 0; i < length; i++) {
|
| 172 |
-
const t = i / sampleRate;
|
| 173 |
-
const progress = i / length;
|
| 174 |
-
|
| 175 |
-
// 上升的频率
|
| 176 |
-
const freq = baseFreq * (1 + progress * 0.5);
|
| 177 |
-
|
| 178 |
-
// 颤音效果
|
| 179 |
-
const vibrato = 1 + 0.1 * Math.sin(2 * Math.PI * 6 * t);
|
| 180 |
-
|
| 181 |
-
// 主音调
|
| 182 |
-
const wave = Math.sin(2 * Math.PI * freq * vibrato * t);
|
| 183 |
-
|
| 184 |
-
// 包络(淡入淡出)
|
| 185 |
-
const envelope = Math.sin(Math.PI * progress) * Math.exp(-progress * 2);
|
| 186 |
-
|
| 187 |
-
data[i] = wave * envelope * 0.3;
|
| 188 |
-
}
|
| 189 |
-
}
|
| 190 |
-
|
| 191 |
-
generateBubbleSound(data, config, sampleRate) {
|
| 192 |
-
// 烹饪冒泡音效
|
| 193 |
-
const baseFreq = config.frequency;
|
| 194 |
-
const length = data.length;
|
| 195 |
-
|
| 196 |
-
for (let i = 0; i < length; i++) {
|
| 197 |
-
const t = i / sampleRate;
|
| 198 |
-
const progress = i / length;
|
| 199 |
-
|
| 200 |
-
// 随机频率变化模拟冒泡
|
| 201 |
-
const randomFactor = 1 + 0.3 * (Math.random() - 0.5);
|
| 202 |
-
const freq = baseFreq * randomFactor;
|
| 203 |
-
|
| 204 |
-
// 多个正弦波叠加
|
| 205 |
-
const wave1 = Math.sin(2 * Math.PI * freq * t);
|
| 206 |
-
const wave2 = Math.sin(2 * Math.PI * freq * 1.5 * t) * 0.5;
|
| 207 |
-
const wave3 = Math.sin(2 * Math.PI * freq * 2 * t) * 0.25;
|
| 208 |
-
|
| 209 |
-
const wave = wave1 + wave2 + wave3;
|
| 210 |
-
|
| 211 |
-
// 快速衰减
|
| 212 |
-
const envelope = Math.exp(-progress * 8);
|
| 213 |
-
|
| 214 |
-
data[i] = wave * envelope * 0.2;
|
| 215 |
-
}
|
| 216 |
-
}
|
| 217 |
-
|
| 218 |
-
generatePopSound(data, config, sampleRate) {
|
| 219 |
-
// 食物弹出音效 - 短促的爆破声
|
| 220 |
-
const baseFreq = config.frequency;
|
| 221 |
-
const length = data.length;
|
| 222 |
-
|
| 223 |
-
for (let i = 0; i < length; i++) {
|
| 224 |
-
const t = i / sampleRate;
|
| 225 |
-
const progress = i / length;
|
| 226 |
-
|
| 227 |
-
// 快速下降的频率
|
| 228 |
-
const freq = baseFreq * (1 - progress * 0.8);
|
| 229 |
-
|
| 230 |
-
// 噪音成分
|
| 231 |
-
const noise = (Math.random() - 0.5) * 0.3;
|
| 232 |
-
|
| 233 |
-
// 主音调
|
| 234 |
-
const wave = Math.sin(2 * Math.PI * freq * t) + noise;
|
| 235 |
-
|
| 236 |
-
// 非常快的衰减
|
| 237 |
-
const envelope = Math.exp(-progress * 15);
|
| 238 |
-
|
| 239 |
-
data[i] = wave * envelope * 0.4;
|
| 240 |
-
}
|
| 241 |
-
}
|
| 242 |
-
|
| 243 |
-
generateChirpSound(data, config, sampleRate) {
|
| 244 |
-
// 动物出现音效 - 鸟叫声
|
| 245 |
-
const baseFreq = config.frequency;
|
| 246 |
-
const length = data.length;
|
| 247 |
-
|
| 248 |
-
for (let i = 0; i < length; i++) {
|
| 249 |
-
const t = i / sampleRate;
|
| 250 |
-
const progress = i / length;
|
| 251 |
-
|
| 252 |
-
// 频率变化模拟鸟叫
|
| 253 |
-
const freqMod = Math.sin(2 * Math.PI * 8 * t) * 0.2;
|
| 254 |
-
const freq = baseFreq * (1 + freqMod);
|
| 255 |
-
|
| 256 |
-
const wave = Math.sin(2 * Math.PI * freq * t);
|
| 257 |
-
|
| 258 |
-
// 自然的包络
|
| 259 |
-
const envelope = Math.sin(Math.PI * progress) * Math.exp(-progress * 3);
|
| 260 |
-
|
| 261 |
-
data[i] = wave * envelope * 0.25;
|
| 262 |
-
}
|
| 263 |
-
}
|
| 264 |
-
|
| 265 |
-
generateSparkleSound(data, config, sampleRate) {
|
| 266 |
-
// 小女孩出现音效 - 闪亮的铃声
|
| 267 |
-
const baseFreq = config.frequency;
|
| 268 |
-
const length = data.length;
|
| 269 |
-
|
| 270 |
-
for (let i = 0; i < length; i++) {
|
| 271 |
-
const t = i / sampleRate;
|
| 272 |
-
const progress = i / length;
|
| 273 |
-
|
| 274 |
-
// 多个谐波创造铃声效果
|
| 275 |
-
const wave1 = Math.sin(2 * Math.PI * baseFreq * t);
|
| 276 |
-
const wave2 = Math.sin(2 * Math.PI * baseFreq * 2 * t) * 0.5;
|
| 277 |
-
const wave3 = Math.sin(2 * Math.PI * baseFreq * 3 * t) * 0.25;
|
| 278 |
-
const wave4 = Math.sin(2 * Math.PI * baseFreq * 4 * t) * 0.125;
|
| 279 |
-
|
| 280 |
-
const wave = wave1 + wave2 + wave3 + wave4;
|
| 281 |
-
|
| 282 |
-
// 缓慢衰减
|
| 283 |
-
const envelope = Math.exp(-progress * 1.5);
|
| 284 |
-
|
| 285 |
-
data[i] = wave * envelope * 0.2;
|
| 286 |
-
}
|
| 287 |
-
}
|
| 288 |
-
|
| 289 |
-
generateFanfareSound(data, config, sampleRate) {
|
| 290 |
-
// 庆祝音效 - 号角声
|
| 291 |
-
const baseFreq = config.frequency;
|
| 292 |
-
const length = data.length;
|
| 293 |
-
|
| 294 |
-
for (let i = 0; i < length; i++) {
|
| 295 |
-
const t = i / sampleRate;
|
| 296 |
-
const progress = i / length;
|
| 297 |
-
|
| 298 |
-
// 三和弦
|
| 299 |
-
const freq1 = baseFreq;
|
| 300 |
-
const freq2 = baseFreq * 1.25; // 大三度
|
| 301 |
-
const freq3 = baseFreq * 1.5; // 完全五度
|
| 302 |
-
|
| 303 |
-
const wave1 = Math.sin(2 * Math.PI * freq1 * t);
|
| 304 |
-
const wave2 = Math.sin(2 * Math.PI * freq2 * t) * 0.8;
|
| 305 |
-
const wave3 = Math.sin(2 * Math.PI * freq3 * t) * 0.6;
|
| 306 |
-
|
| 307 |
-
const wave = wave1 + wave2 + wave3;
|
| 308 |
-
|
| 309 |
-
// 持续的包络
|
| 310 |
-
const envelope = Math.sin(Math.PI * progress) * 0.8;
|
| 311 |
-
|
| 312 |
-
data[i] = wave * envelope * 0.15;
|
| 313 |
-
}
|
| 314 |
-
}
|
| 315 |
-
|
| 316 |
-
generateWhooshSound(data, config, sampleRate) {
|
| 317 |
-
// 停止音效 - 风声
|
| 318 |
-
const length = data.length;
|
| 319 |
-
|
| 320 |
-
for (let i = 0; i < length; i++) {
|
| 321 |
-
const progress = i / length;
|
| 322 |
-
|
| 323 |
-
// 白噪音
|
| 324 |
-
const noise = (Math.random() - 0.5) * 2;
|
| 325 |
-
|
| 326 |
-
// 低通滤波效果(简化)
|
| 327 |
-
const cutoff = 1000 * (1 - progress);
|
| 328 |
-
const filtered = noise * Math.exp(-progress * 3);
|
| 329 |
-
|
| 330 |
-
// 快速衰减
|
| 331 |
-
const envelope = Math.exp(-progress * 5);
|
| 332 |
-
|
| 333 |
-
data[i] = filtered * envelope * 0.3;
|
| 334 |
-
}
|
| 335 |
-
}
|
| 336 |
-
|
| 337 |
-
generateSimpleBeep(data, config, sampleRate) {
|
| 338 |
-
// 简单的蜂鸣声
|
| 339 |
-
const freq = config.frequency;
|
| 340 |
-
const length = data.length;
|
| 341 |
-
|
| 342 |
-
for (let i = 0; i < length; i++) {
|
| 343 |
-
const t = i / sampleRate;
|
| 344 |
-
const progress = i / length;
|
| 345 |
-
|
| 346 |
-
const wave = Math.sin(2 * Math.PI * freq * t);
|
| 347 |
-
const envelope = Math.exp(-progress * 3);
|
| 348 |
-
|
| 349 |
-
data[i] = wave * envelope * 0.3;
|
| 350 |
-
}
|
| 351 |
-
}
|
| 352 |
-
|
| 353 |
-
async playSound(soundName, volume = 1.0) {
|
| 354 |
-
if (!this.isEnabled) return;
|
| 355 |
-
|
| 356 |
-
const canPlay = await this.ensureAudioContext();
|
| 357 |
-
if (!canPlay) {
|
| 358 |
-
// 如果是第一次尝试播放,显示视觉提示
|
| 359 |
-
if (!this.hasShownInteractionHint) {
|
| 360 |
-
this.showAudioActivationHint();
|
| 361 |
-
this.hasShownInteractionHint = true;
|
| 362 |
-
}
|
| 363 |
-
return;
|
| 364 |
-
}
|
| 365 |
-
|
| 366 |
-
if (!this.isInitialized) {
|
| 367 |
-
console.warn('音频系统尚未初始化');
|
| 368 |
-
return;
|
| 369 |
-
}
|
| 370 |
-
|
| 371 |
-
const buffer = this.sounds.get(soundName);
|
| 372 |
-
if (!buffer) {
|
| 373 |
-
console.warn(`音效 ${soundName} 不存在`);
|
| 374 |
-
return;
|
| 375 |
-
}
|
| 376 |
-
|
| 377 |
-
try {
|
| 378 |
-
const source = this.audioContext.createBufferSource();
|
| 379 |
-
const gainNode = this.audioContext.createGain();
|
| 380 |
-
|
| 381 |
-
source.buffer = buffer;
|
| 382 |
-
source.connect(gainNode);
|
| 383 |
-
gainNode.connect(this.audioContext.destination);
|
| 384 |
-
|
| 385 |
-
// 设置音量
|
| 386 |
-
gainNode.gain.value = this.volume * volume;
|
| 387 |
-
|
| 388 |
-
source.start();
|
| 389 |
-
|
| 390 |
-
// 清理资源
|
| 391 |
-
source.onended = () => {
|
| 392 |
-
source.disconnect();
|
| 393 |
-
gainNode.disconnect();
|
| 394 |
-
};
|
| 395 |
-
|
| 396 |
-
} catch (error) {
|
| 397 |
-
console.warn(`播放音效 ${soundName} 失败:`, error);
|
| 398 |
-
}
|
| 399 |
-
}
|
| 400 |
-
|
| 401 |
-
// 播放特定音效的便捷方法
|
| 402 |
-
playPotActivate() {
|
| 403 |
-
this.playSound('potActivate');
|
| 404 |
-
}
|
| 405 |
-
|
| 406 |
-
playCooking() {
|
| 407 |
-
this.playSound('cooking', 0.5);
|
| 408 |
-
}
|
| 409 |
-
|
| 410 |
-
playFoodPop() {
|
| 411 |
-
this.playSound('foodPop', 0.8);
|
| 412 |
-
}
|
| 413 |
-
|
| 414 |
-
playAnimalAppear() {
|
| 415 |
-
this.playSound('animalAppear', 0.6);
|
| 416 |
-
}
|
| 417 |
-
|
| 418 |
-
playGirlAppear() {
|
| 419 |
-
this.playSound('girlAppear', 0.7);
|
| 420 |
-
}
|
| 421 |
-
|
| 422 |
-
playCelebration() {
|
| 423 |
-
this.playSound('celebration', 0.9);
|
| 424 |
-
}
|
| 425 |
-
|
| 426 |
-
playStopCooking() {
|
| 427 |
-
this.playSound('stopCooking', 0.6);
|
| 428 |
-
}
|
| 429 |
-
|
| 430 |
-
// 播放随机音调的食物弹出声
|
| 431 |
-
playRandomFoodPop() {
|
| 432 |
-
const randomPitch = 0.8 + Math.random() * 0.4; // 0.8 到 1.2
|
| 433 |
-
this.playSound('foodPop', randomPitch);
|
| 434 |
-
}
|
| 435 |
-
|
| 436 |
-
// 设置音
|
| 437 |
-
setVolume(volume) {
|
| 438 |
-
this.volume = Math.max(0, Math.min(1, volume));
|
| 439 |
-
}
|
| 440 |
-
|
| 441 |
-
// 启用/禁用音效
|
| 442 |
-
setEnabled(enabled) {
|
| 443 |
-
this.isEnabled = enabled;
|
| 444 |
-
localStorage.setItem('magicPotAudioEnabled', enabled.toString());
|
| 445 |
-
}
|
| 446 |
-
|
| 447 |
-
// 获取音效状态
|
| 448 |
-
getStatus() {
|
| 449 |
-
return {
|
| 450 |
-
enabled: this.isEnabled,
|
| 451 |
-
initialized: this.isInitialized,
|
| 452 |
-
volume: this.volume,
|
| 453 |
-
soundCount: this.sounds.size,
|
| 454 |
-
contextState: this.audioContext ? this.audioContext.state : 'none'
|
| 455 |
-
};
|
| 456 |
-
}
|
| 457 |
-
|
| 458 |
-
// 测试所有音效
|
| 459 |
-
async testAllSounds() {
|
| 460 |
-
const soundNames = Object.keys(this.soundConfig);
|
| 461 |
-
|
| 462 |
-
for (let i = 0; i < soundNames.length; i++) {
|
| 463 |
-
const soundName = soundNames[i];
|
| 464 |
-
console.log(`测试音效: ${soundName}`);
|
| 465 |
-
await this.playSound(soundName);
|
| 466 |
-
|
| 467 |
-
// 等待一段时间再播放下一个
|
| 468 |
-
await new Promise(resolve => setTimeout(resolve, 800));
|
| 469 |
-
}
|
| 470 |
-
}
|
| 471 |
-
}
|
| 472 |
-
|
| 473 |
-
// 创建全局音频管理器实例
|
| 474 |
-
window.audioManager = new AudioManager();
|
|
|
|
| 1 |
+
// 音频管理系统
|
| 2 |
+
class AudioManager {
|
| 3 |
+
constructor() {
|
| 4 |
+
this.audioContext = null;
|
| 5 |
+
this.sounds = new Map();
|
| 6 |
+
this.isEnabled = true;
|
| 7 |
+
this.volume = 0.7;
|
| 8 |
+
this.isInitialized = false;
|
| 9 |
+
this.hasShownInteractionHint = false;
|
| 10 |
+
|
| 11 |
+
// 音效配置
|
| 12 |
+
this.soundConfig = {
|
| 13 |
+
potActivate: { frequency: 440, duration: 0.5, type: 'magic' },
|
| 14 |
+
cooking: { frequency: 220, duration: 0.3, type: 'bubble' },
|
| 15 |
+
foodPop: { frequency: 660, duration: 0.2, type: 'pop' },
|
| 16 |
+
animalAppear: { frequency: 880, duration: 0.4, type: 'chirp' },
|
| 17 |
+
girlAppear: { frequency: 1320, duration: 0.6, type: 'sparkle' },
|
| 18 |
+
celebration: { frequency: 1760, duration: 1.0, type: 'fanfare' },
|
| 19 |
+
stopCooking: { frequency: 330, duration: 0.4, type: 'whoosh' }
|
| 20 |
+
};
|
| 21 |
+
|
| 22 |
+
this.init();
|
| 23 |
+
}
|
| 24 |
+
|
| 25 |
+
async init() {
|
| 26 |
+
try {
|
| 27 |
+
// 创建音频上下文(暂停状态)
|
| 28 |
+
this.audioContext = new (window.AudioContext || window.webkitAudioContext)();
|
| 29 |
+
|
| 30 |
+
// 注册用户交互事件来启动音频上下文
|
| 31 |
+
this.setupUserInteractionHandlers();
|
| 32 |
+
|
| 33 |
+
console.log('音频系统已准备,等待用户交互启动');
|
| 34 |
+
} catch (error) {
|
| 35 |
+
console.warn('音频系统初始化失败:', error);
|
| 36 |
+
this.isEnabled = false;
|
| 37 |
+
}
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
setupUserInteractionHandlers() {
|
| 41 |
+
const startAudio = async () => {
|
| 42 |
+
if (this.audioContext && this.audioContext.state === 'suspended') {
|
| 43 |
+
try {
|
| 44 |
+
await this.audioContext.resume();
|
| 45 |
+
|
| 46 |
+
// 音频上下文启动后,预生成音效
|
| 47 |
+
if (!this.isInitialized) {
|
| 48 |
+
this.preGenerateSounds();
|
| 49 |
+
this.isInitialized = true;
|
| 50 |
+
console.log('音频系统初始化完成');
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
// 隐藏音频激活提示
|
| 54 |
+
this.hideAudioActivationHint();
|
| 55 |
+
|
| 56 |
+
} catch (error) {
|
| 57 |
+
console.warn('启动音频上下文失败:', error);
|
| 58 |
+
}
|
| 59 |
+
}
|
| 60 |
+
};
|
| 61 |
+
|
| 62 |
+
// 监听各种用户交互事件
|
| 63 |
+
const events = ['click', 'touchstart', 'keydown'];
|
| 64 |
+
const handler = () => {
|
| 65 |
+
startAudio();
|
| 66 |
+
// 移除事件监听器,只需要启动一次
|
| 67 |
+
events.forEach(event => {
|
| 68 |
+
document.removeEventListener(event, handler);
|
| 69 |
+
});
|
| 70 |
+
};
|
| 71 |
+
|
| 72 |
+
events.forEach(event => {
|
| 73 |
+
document.addEventListener(event, handler, { once: true });
|
| 74 |
+
});
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
showAudioActivationHint() {
|
| 78 |
+
const hint = document.getElementById('audioActivationHint');
|
| 79 |
+
if (hint) {
|
| 80 |
+
hint.style.display = 'block';
|
| 81 |
+
console.log('显示音频激活提示');
|
| 82 |
+
}
|
| 83 |
+
}
|
| 84 |
+
|
| 85 |
+
hideAudioActivationHint() {
|
| 86 |
+
const hint = document.getElementById('audioActivationHint');
|
| 87 |
+
if (hint) {
|
| 88 |
+
hint.style.display = 'none';
|
| 89 |
+
console.log('隐藏音频激活提示');
|
| 90 |
+
}
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
async ensureAudioContext() {
|
| 94 |
+
if (!this.audioContext) return false;
|
| 95 |
+
|
| 96 |
+
if (this.audioContext.state === 'suspended') {
|
| 97 |
+
try {
|
| 98 |
+
await this.audioContext.resume();
|
| 99 |
+
|
| 100 |
+
// 如果音频上下文刚刚启动,且还未初始化,则初始化音效
|
| 101 |
+
if (!this.isInitialized) {
|
| 102 |
+
this.preGenerateSounds();
|
| 103 |
+
this.isInitialized = true;
|
| 104 |
+
console.log('音频系统延迟初始化完成');
|
| 105 |
+
}
|
| 106 |
+
|
| 107 |
+
// 隐藏音频激活提示
|
| 108 |
+
this.hideAudioActivationHint();
|
| 109 |
+
} catch (error) {
|
| 110 |
+
console.warn('无法恢复音频上下文:', error);
|
| 111 |
+
return false;
|
| 112 |
+
}
|
| 113 |
+
}
|
| 114 |
+
|
| 115 |
+
return this.audioContext.state === 'running';
|
| 116 |
+
}
|
| 117 |
+
|
| 118 |
+
preGenerateSounds() {
|
| 119 |
+
// 预生成所有音效的音频数据
|
| 120 |
+
Object.keys(this.soundConfig).forEach(soundName => {
|
| 121 |
+
this.generateSound(soundName);
|
| 122 |
+
});
|
| 123 |
+
}
|
| 124 |
+
|
| 125 |
+
generateSound(soundName) {
|
| 126 |
+
const config = this.soundConfig[soundName];
|
| 127 |
+
if (!config) return null;
|
| 128 |
+
|
| 129 |
+
const sampleRate = this.audioContext.sampleRate;
|
| 130 |
+
const duration = config.duration;
|
| 131 |
+
const length = sampleRate * duration;
|
| 132 |
+
const buffer = this.audioContext.createBuffer(1, length, sampleRate);
|
| 133 |
+
const data = buffer.getChannelData(0);
|
| 134 |
+
|
| 135 |
+
// 根据音效类型生成不同的波形
|
| 136 |
+
switch (config.type) {
|
| 137 |
+
case 'magic':
|
| 138 |
+
this.generateMagicSound(data, config, sampleRate);
|
| 139 |
+
break;
|
| 140 |
+
case 'bubble':
|
| 141 |
+
this.generateBubbleSound(data, config, sampleRate);
|
| 142 |
+
break;
|
| 143 |
+
case 'pop':
|
| 144 |
+
this.generatePopSound(data, config, sampleRate);
|
| 145 |
+
break;
|
| 146 |
+
case 'chirp':
|
| 147 |
+
this.generateChirpSound(data, config, sampleRate);
|
| 148 |
+
break;
|
| 149 |
+
case 'sparkle':
|
| 150 |
+
this.generateSparkleSound(data, config, sampleRate);
|
| 151 |
+
break;
|
| 152 |
+
case 'fanfare':
|
| 153 |
+
this.generateFanfareSound(data, config, sampleRate);
|
| 154 |
+
break;
|
| 155 |
+
case 'whoosh':
|
| 156 |
+
this.generateWhooshSound(data, config, sampleRate);
|
| 157 |
+
break;
|
| 158 |
+
default:
|
| 159 |
+
this.generateSimpleBeep(data, config, sampleRate);
|
| 160 |
+
}
|
| 161 |
+
|
| 162 |
+
this.sounds.set(soundName, buffer);
|
| 163 |
+
return buffer;
|
| 164 |
+
}
|
| 165 |
+
|
| 166 |
+
generateMagicSound(data, config, sampleRate) {
|
| 167 |
+
// 魔法激活音效 - 上升的音调带有颤音
|
| 168 |
+
const baseFreq = config.frequency;
|
| 169 |
+
const length = data.length;
|
| 170 |
+
|
| 171 |
+
for (let i = 0; i < length; i++) {
|
| 172 |
+
const t = i / sampleRate;
|
| 173 |
+
const progress = i / length;
|
| 174 |
+
|
| 175 |
+
// 上升的频率
|
| 176 |
+
const freq = baseFreq * (1 + progress * 0.5);
|
| 177 |
+
|
| 178 |
+
// 颤音效果
|
| 179 |
+
const vibrato = 1 + 0.1 * Math.sin(2 * Math.PI * 6 * t);
|
| 180 |
+
|
| 181 |
+
// 主音调
|
| 182 |
+
const wave = Math.sin(2 * Math.PI * freq * vibrato * t);
|
| 183 |
+
|
| 184 |
+
// 包络(淡入淡出)
|
| 185 |
+
const envelope = Math.sin(Math.PI * progress) * Math.exp(-progress * 2);
|
| 186 |
+
|
| 187 |
+
data[i] = wave * envelope * 0.3;
|
| 188 |
+
}
|
| 189 |
+
}
|
| 190 |
+
|
| 191 |
+
generateBubbleSound(data, config, sampleRate) {
|
| 192 |
+
// 烹饪冒泡音效
|
| 193 |
+
const baseFreq = config.frequency;
|
| 194 |
+
const length = data.length;
|
| 195 |
+
|
| 196 |
+
for (let i = 0; i < length; i++) {
|
| 197 |
+
const t = i / sampleRate;
|
| 198 |
+
const progress = i / length;
|
| 199 |
+
|
| 200 |
+
// 随机频率变化模拟冒泡
|
| 201 |
+
const randomFactor = 1 + 0.3 * (Math.random() - 0.5);
|
| 202 |
+
const freq = baseFreq * randomFactor;
|
| 203 |
+
|
| 204 |
+
// 多个正弦波叠加
|
| 205 |
+
const wave1 = Math.sin(2 * Math.PI * freq * t);
|
| 206 |
+
const wave2 = Math.sin(2 * Math.PI * freq * 1.5 * t) * 0.5;
|
| 207 |
+
const wave3 = Math.sin(2 * Math.PI * freq * 2 * t) * 0.25;
|
| 208 |
+
|
| 209 |
+
const wave = wave1 + wave2 + wave3;
|
| 210 |
+
|
| 211 |
+
// 快速衰减
|
| 212 |
+
const envelope = Math.exp(-progress * 8);
|
| 213 |
+
|
| 214 |
+
data[i] = wave * envelope * 0.2;
|
| 215 |
+
}
|
| 216 |
+
}
|
| 217 |
+
|
| 218 |
+
generatePopSound(data, config, sampleRate) {
|
| 219 |
+
// 食物弹出音效 - 短促的爆破声
|
| 220 |
+
const baseFreq = config.frequency;
|
| 221 |
+
const length = data.length;
|
| 222 |
+
|
| 223 |
+
for (let i = 0; i < length; i++) {
|
| 224 |
+
const t = i / sampleRate;
|
| 225 |
+
const progress = i / length;
|
| 226 |
+
|
| 227 |
+
// 快速下降的频率
|
| 228 |
+
const freq = baseFreq * (1 - progress * 0.8);
|
| 229 |
+
|
| 230 |
+
// 噪音成分
|
| 231 |
+
const noise = (Math.random() - 0.5) * 0.3;
|
| 232 |
+
|
| 233 |
+
// 主音调
|
| 234 |
+
const wave = Math.sin(2 * Math.PI * freq * t) + noise;
|
| 235 |
+
|
| 236 |
+
// 非常快的衰减
|
| 237 |
+
const envelope = Math.exp(-progress * 15);
|
| 238 |
+
|
| 239 |
+
data[i] = wave * envelope * 0.4;
|
| 240 |
+
}
|
| 241 |
+
}
|
| 242 |
+
|
| 243 |
+
generateChirpSound(data, config, sampleRate) {
|
| 244 |
+
// 动物出现音效 - 鸟叫声
|
| 245 |
+
const baseFreq = config.frequency;
|
| 246 |
+
const length = data.length;
|
| 247 |
+
|
| 248 |
+
for (let i = 0; i < length; i++) {
|
| 249 |
+
const t = i / sampleRate;
|
| 250 |
+
const progress = i / length;
|
| 251 |
+
|
| 252 |
+
// 频率变化模拟鸟叫
|
| 253 |
+
const freqMod = Math.sin(2 * Math.PI * 8 * t) * 0.2;
|
| 254 |
+
const freq = baseFreq * (1 + freqMod);
|
| 255 |
+
|
| 256 |
+
const wave = Math.sin(2 * Math.PI * freq * t);
|
| 257 |
+
|
| 258 |
+
// 自然的包络
|
| 259 |
+
const envelope = Math.sin(Math.PI * progress) * Math.exp(-progress * 3);
|
| 260 |
+
|
| 261 |
+
data[i] = wave * envelope * 0.25;
|
| 262 |
+
}
|
| 263 |
+
}
|
| 264 |
+
|
| 265 |
+
generateSparkleSound(data, config, sampleRate) {
|
| 266 |
+
// 小女孩出现音效 - 闪亮的铃声
|
| 267 |
+
const baseFreq = config.frequency;
|
| 268 |
+
const length = data.length;
|
| 269 |
+
|
| 270 |
+
for (let i = 0; i < length; i++) {
|
| 271 |
+
const t = i / sampleRate;
|
| 272 |
+
const progress = i / length;
|
| 273 |
+
|
| 274 |
+
// 多个谐波创造铃声效果
|
| 275 |
+
const wave1 = Math.sin(2 * Math.PI * baseFreq * t);
|
| 276 |
+
const wave2 = Math.sin(2 * Math.PI * baseFreq * 2 * t) * 0.5;
|
| 277 |
+
const wave3 = Math.sin(2 * Math.PI * baseFreq * 3 * t) * 0.25;
|
| 278 |
+
const wave4 = Math.sin(2 * Math.PI * baseFreq * 4 * t) * 0.125;
|
| 279 |
+
|
| 280 |
+
const wave = wave1 + wave2 + wave3 + wave4;
|
| 281 |
+
|
| 282 |
+
// 缓慢衰减
|
| 283 |
+
const envelope = Math.exp(-progress * 1.5);
|
| 284 |
+
|
| 285 |
+
data[i] = wave * envelope * 0.2;
|
| 286 |
+
}
|
| 287 |
+
}
|
| 288 |
+
|
| 289 |
+
generateFanfareSound(data, config, sampleRate) {
|
| 290 |
+
// 庆祝音效 - 号角声
|
| 291 |
+
const baseFreq = config.frequency;
|
| 292 |
+
const length = data.length;
|
| 293 |
+
|
| 294 |
+
for (let i = 0; i < length; i++) {
|
| 295 |
+
const t = i / sampleRate;
|
| 296 |
+
const progress = i / length;
|
| 297 |
+
|
| 298 |
+
// 三和弦
|
| 299 |
+
const freq1 = baseFreq;
|
| 300 |
+
const freq2 = baseFreq * 1.25; // 大三度
|
| 301 |
+
const freq3 = baseFreq * 1.5; // 完全五度
|
| 302 |
+
|
| 303 |
+
const wave1 = Math.sin(2 * Math.PI * freq1 * t);
|
| 304 |
+
const wave2 = Math.sin(2 * Math.PI * freq2 * t) * 0.8;
|
| 305 |
+
const wave3 = Math.sin(2 * Math.PI * freq3 * t) * 0.6;
|
| 306 |
+
|
| 307 |
+
const wave = wave1 + wave2 + wave3;
|
| 308 |
+
|
| 309 |
+
// 持续的包络
|
| 310 |
+
const envelope = Math.sin(Math.PI * progress) * 0.8;
|
| 311 |
+
|
| 312 |
+
data[i] = wave * envelope * 0.15;
|
| 313 |
+
}
|
| 314 |
+
}
|
| 315 |
+
|
| 316 |
+
generateWhooshSound(data, config, sampleRate) {
|
| 317 |
+
// 停止音效 - 风声
|
| 318 |
+
const length = data.length;
|
| 319 |
+
|
| 320 |
+
for (let i = 0; i < length; i++) {
|
| 321 |
+
const progress = i / length;
|
| 322 |
+
|
| 323 |
+
// 白噪音
|
| 324 |
+
const noise = (Math.random() - 0.5) * 2;
|
| 325 |
+
|
| 326 |
+
// 低通滤波效果(简化)
|
| 327 |
+
const cutoff = 1000 * (1 - progress);
|
| 328 |
+
const filtered = noise * Math.exp(-progress * 3);
|
| 329 |
+
|
| 330 |
+
// 快速衰减
|
| 331 |
+
const envelope = Math.exp(-progress * 5);
|
| 332 |
+
|
| 333 |
+
data[i] = filtered * envelope * 0.3;
|
| 334 |
+
}
|
| 335 |
+
}
|
| 336 |
+
|
| 337 |
+
generateSimpleBeep(data, config, sampleRate) {
|
| 338 |
+
// 简单的蜂鸣声
|
| 339 |
+
const freq = config.frequency;
|
| 340 |
+
const length = data.length;
|
| 341 |
+
|
| 342 |
+
for (let i = 0; i < length; i++) {
|
| 343 |
+
const t = i / sampleRate;
|
| 344 |
+
const progress = i / length;
|
| 345 |
+
|
| 346 |
+
const wave = Math.sin(2 * Math.PI * freq * t);
|
| 347 |
+
const envelope = Math.exp(-progress * 3);
|
| 348 |
+
|
| 349 |
+
data[i] = wave * envelope * 0.3;
|
| 350 |
+
}
|
| 351 |
+
}
|
| 352 |
+
|
| 353 |
+
async playSound(soundName, volume = 1.0) {
|
| 354 |
+
if (!this.isEnabled) return;
|
| 355 |
+
|
| 356 |
+
const canPlay = await this.ensureAudioContext();
|
| 357 |
+
if (!canPlay) {
|
| 358 |
+
// 如果是第一次尝试播放,显示视觉提示
|
| 359 |
+
if (!this.hasShownInteractionHint) {
|
| 360 |
+
this.showAudioActivationHint();
|
| 361 |
+
this.hasShownInteractionHint = true;
|
| 362 |
+
}
|
| 363 |
+
return;
|
| 364 |
+
}
|
| 365 |
+
|
| 366 |
+
if (!this.isInitialized) {
|
| 367 |
+
console.warn('音频系统尚未初始化');
|
| 368 |
+
return;
|
| 369 |
+
}
|
| 370 |
+
|
| 371 |
+
const buffer = this.sounds.get(soundName);
|
| 372 |
+
if (!buffer) {
|
| 373 |
+
console.warn(`音效 ${soundName} 不存在`);
|
| 374 |
+
return;
|
| 375 |
+
}
|
| 376 |
+
|
| 377 |
+
try {
|
| 378 |
+
const source = this.audioContext.createBufferSource();
|
| 379 |
+
const gainNode = this.audioContext.createGain();
|
| 380 |
+
|
| 381 |
+
source.buffer = buffer;
|
| 382 |
+
source.connect(gainNode);
|
| 383 |
+
gainNode.connect(this.audioContext.destination);
|
| 384 |
+
|
| 385 |
+
// 设置音量
|
| 386 |
+
gainNode.gain.value = this.volume * volume;
|
| 387 |
+
|
| 388 |
+
source.start();
|
| 389 |
+
|
| 390 |
+
// 清理资源
|
| 391 |
+
source.onended = () => {
|
| 392 |
+
source.disconnect();
|
| 393 |
+
gainNode.disconnect();
|
| 394 |
+
};
|
| 395 |
+
|
| 396 |
+
} catch (error) {
|
| 397 |
+
console.warn(`播放音效 ${soundName} 失败:`, error);
|
| 398 |
+
}
|
| 399 |
+
}
|
| 400 |
+
|
| 401 |
+
// 播放特定音效的便捷方法
|
| 402 |
+
playPotActivate() {
|
| 403 |
+
this.playSound('potActivate');
|
| 404 |
+
}
|
| 405 |
+
|
| 406 |
+
playCooking() {
|
| 407 |
+
this.playSound('cooking', 0.5);
|
| 408 |
+
}
|
| 409 |
+
|
| 410 |
+
playFoodPop() {
|
| 411 |
+
this.playSound('foodPop', 0.8);
|
| 412 |
+
}
|
| 413 |
+
|
| 414 |
+
playAnimalAppear() {
|
| 415 |
+
this.playSound('animalAppear', 0.6);
|
| 416 |
+
}
|
| 417 |
+
|
| 418 |
+
playGirlAppear() {
|
| 419 |
+
this.playSound('girlAppear', 0.7);
|
| 420 |
+
}
|
| 421 |
+
|
| 422 |
+
playCelebration() {
|
| 423 |
+
this.playSound('celebration', 0.9);
|
| 424 |
+
}
|
| 425 |
+
|
| 426 |
+
playStopCooking() {
|
| 427 |
+
this.playSound('stopCooking', 0.6);
|
| 428 |
+
}
|
| 429 |
+
|
| 430 |
+
// 播放随机音调的食物弹出声
|
| 431 |
+
playRandomFoodPop() {
|
| 432 |
+
const randomPitch = 0.8 + Math.random() * 0.4; // 0.8 到 1.2
|
| 433 |
+
this.playSound('foodPop', randomPitch);
|
| 434 |
+
}
|
| 435 |
+
|
| 436 |
+
// 设置音量
|
| 437 |
+
setVolume(volume) {
|
| 438 |
+
this.volume = Math.max(0, Math.min(1, volume));
|
| 439 |
+
}
|
| 440 |
+
|
| 441 |
+
// 启用/禁用音效
|
| 442 |
+
setEnabled(enabled) {
|
| 443 |
+
this.isEnabled = enabled;
|
| 444 |
+
localStorage.setItem('magicPotAudioEnabled', enabled.toString());
|
| 445 |
+
}
|
| 446 |
+
|
| 447 |
+
// 获取音效状态
|
| 448 |
+
getStatus() {
|
| 449 |
+
return {
|
| 450 |
+
enabled: this.isEnabled,
|
| 451 |
+
initialized: this.isInitialized,
|
| 452 |
+
volume: this.volume,
|
| 453 |
+
soundCount: this.sounds.size,
|
| 454 |
+
contextState: this.audioContext ? this.audioContext.state : 'none'
|
| 455 |
+
};
|
| 456 |
+
}
|
| 457 |
+
|
| 458 |
+
// 测试所有音效
|
| 459 |
+
async testAllSounds() {
|
| 460 |
+
const soundNames = Object.keys(this.soundConfig);
|
| 461 |
+
|
| 462 |
+
for (let i = 0; i < soundNames.length; i++) {
|
| 463 |
+
const soundName = soundNames[i];
|
| 464 |
+
console.log(`测试音效: ${soundName}`);
|
| 465 |
+
await this.playSound(soundName);
|
| 466 |
+
|
| 467 |
+
// 等待一段时间再播放下一个
|
| 468 |
+
await new Promise(resolve => setTimeout(resolve, 800));
|
| 469 |
+
}
|
| 470 |
+
}
|
| 471 |
+
}
|
| 472 |
+
|
| 473 |
+
// 创建全局音频管理器实例
|
| 474 |
+
window.audioManager = new AudioManager();
|
js/keyboard.js
CHANGED
|
@@ -1,684 +1,684 @@
|
|
| 1 |
-
// 键盘输入处理类
|
| 2 |
-
class KeyboardInputHandler {
|
| 3 |
-
constructor() {
|
| 4 |
-
this.onCommand = null; // 命令回调函数
|
| 5 |
-
this.commandHistory = [];
|
| 6 |
-
this.maxHistorySize = 20;
|
| 7 |
-
this.isPanelCollapsed = false;
|
| 8 |
-
this.isActive = false; // 面板激活状态
|
| 9 |
-
|
| 10 |
-
// 拖拽相关属性
|
| 11 |
-
this.isDragging = false;
|
| 12 |
-
this.dragOffset = { x: 0, y: 0 };
|
| 13 |
-
this.currentPosition = { x: null, y: null };
|
| 14 |
-
|
| 15 |
-
this.init();
|
| 16 |
-
}
|
| 17 |
-
|
| 18 |
-
init() {
|
| 19 |
-
this.setupEventListeners();
|
| 20 |
-
this.updatePanel();
|
| 21 |
-
this.setActiveState(false); // 初始为非激活状态
|
| 22 |
-
this.setPanelCollapsed(true); // 默认折叠面板
|
| 23 |
-
console.log('键盘输入处理器已初始化');
|
| 24 |
-
}
|
| 25 |
-
|
| 26 |
-
setupEventListeners() {
|
| 27 |
-
// 输入框事件
|
| 28 |
-
const commandInput = document.getElementById('commandInput');
|
| 29 |
-
const sendBtn = document.getElementById('sendCommandBtn');
|
| 30 |
-
const toggleBtn = document.getElementById('toggleKeyboardPanel');
|
| 31 |
-
|
| 32 |
-
if (commandInput) {
|
| 33 |
-
// 回车发送命令
|
| 34 |
-
commandInput.addEventListener('keydown', (e) => {
|
| 35 |
-
if (e.key === 'Enter') {
|
| 36 |
-
e.preventDefault();
|
| 37 |
-
this.sendCommand();
|
| 38 |
-
}
|
| 39 |
-
});
|
| 40 |
-
|
| 41 |
-
// 历史记录导航(上下键)
|
| 42 |
-
commandInput.addEventListener('keydown', (e) => {
|
| 43 |
-
if (e.key === 'ArrowUp') {
|
| 44 |
-
e.preventDefault();
|
| 45 |
-
this.navigateHistory(-1);
|
| 46 |
-
} else if (e.key === 'ArrowDown') {
|
| 47 |
-
e.preventDefault();
|
| 48 |
-
this.navigateHistory(1);
|
| 49 |
-
}
|
| 50 |
-
});
|
| 51 |
-
}
|
| 52 |
-
|
| 53 |
-
// 发送按钮
|
| 54 |
-
if (sendBtn) {
|
| 55 |
-
sendBtn.addEventListener('click', () => {
|
| 56 |
-
this.sendCommand();
|
| 57 |
-
});
|
| 58 |
-
}
|
| 59 |
-
|
| 60 |
-
// 面板折叠按钮
|
| 61 |
-
if (toggleBtn) {
|
| 62 |
-
toggleBtn.addEventListener('click', () => {
|
| 63 |
-
this.togglePanel();
|
| 64 |
-
});
|
| 65 |
-
}
|
| 66 |
-
|
| 67 |
-
// 快捷指令按钮
|
| 68 |
-
const quickCmdBtns = document.querySelectorAll('.quick-cmd');
|
| 69 |
-
quickCmdBtns.forEach(btn => {
|
| 70 |
-
btn.addEventListener('click', () => {
|
| 71 |
-
const command = btn.getAttribute('data-command');
|
| 72 |
-
if (command) {
|
| 73 |
-
this.executeCommand(command);
|
| 74 |
-
}
|
| 75 |
-
});
|
| 76 |
-
});
|
| 77 |
-
|
| 78 |
-
// 全局键盘快捷键
|
| 79 |
-
document.addEventListener('keydown', (e) => {
|
| 80 |
-
this.handleGlobalShortcuts(e);
|
| 81 |
-
});
|
| 82 |
-
|
| 83 |
-
// 历史记录点击事件
|
| 84 |
-
this.setupHistoryListener();
|
| 85 |
-
|
| 86 |
-
// 拖拽功能
|
| 87 |
-
this.setupDragFunctionality();
|
| 88 |
-
}
|
| 89 |
-
|
| 90 |
-
setupHistoryListener() {
|
| 91 |
-
const historyList = document.getElementById('commandHistory');
|
| 92 |
-
if (historyList) {
|
| 93 |
-
historyList.addEventListener('click', (e) => {
|
| 94 |
-
if (e.target.classList.contains('history-item') ||
|
| 95 |
-
e.target.parentElement.classList.contains('history-item')) {
|
| 96 |
-
|
| 97 |
-
const historyItem = e.target.classList.contains('history-item')
|
| 98 |
-
? e.target
|
| 99 |
-
: e.target.parentElement;
|
| 100 |
-
|
| 101 |
-
const command = historyItem.querySelector('.history-command').textContent;
|
| 102 |
-
if (command) {
|
| 103 |
-
this.fillInputWithCommand(command);
|
| 104 |
-
}
|
| 105 |
-
}
|
| 106 |
-
});
|
| 107 |
-
}
|
| 108 |
-
}
|
| 109 |
-
|
| 110 |
-
handleGlobalShortcuts(e) {
|
| 111 |
-
// F9 由 main.js 处理,这里不再处理
|
| 112 |
-
// if (e.key === 'F9') {
|
| 113 |
-
// e.preventDefault();
|
| 114 |
-
// this.toggleActiveState();
|
| 115 |
-
// return;
|
| 116 |
-
// }
|
| 117 |
-
|
| 118 |
-
// 只在面板激活且没有焦点在输入框时处理全局快捷键
|
| 119 |
-
if (!this.isActive || document.activeElement.tagName === 'INPUT') {
|
| 120 |
-
return;
|
| 121 |
-
}
|
| 122 |
-
|
| 123 |
-
// Ctrl/Cmd + K 聚焦到输入框
|
| 124 |
-
if ((e.ctrlKey || e.metaKey) && e.key === 'k') {
|
| 125 |
-
e.preventDefault();
|
| 126 |
-
this.focusInput();
|
| 127 |
-
}
|
| 128 |
-
|
| 129 |
-
// Ctrl/Cmd + ` 切换面板
|
| 130 |
-
if ((e.ctrlKey || e.metaKey) && e.key === '`') {
|
| 131 |
-
e.preventDefault();
|
| 132 |
-
this.togglePanel();
|
| 133 |
-
}
|
| 134 |
-
|
| 135 |
-
// ESC 清空输入框、取消激活或折叠面板
|
| 136 |
-
if (e.key === 'Escape') {
|
| 137 |
-
const input = document.getElementById('commandInput');
|
| 138 |
-
if (input && input.value) {
|
| 139 |
-
input.value = '';
|
| 140 |
-
input.blur();
|
| 141 |
-
} else if (this.isActive) {
|
| 142 |
-
this.setActiveState(false);
|
| 143 |
-
} else {
|
| 144 |
-
this.togglePanel();
|
| 145 |
-
}
|
| 146 |
-
}
|
| 147 |
-
|
| 148 |
-
// 数字键快速命令(1-6) - 仅在激活状态下工作
|
| 149 |
-
if (this.isActive && e.key >= '1' && e.key <= '6') {
|
| 150 |
-
const quickCommands = [
|
| 151 |
-
'cook cook cook pot', // 1
|
| 152 |
-
'stop stop stop pot', // 2
|
| 153 |
-
'apple', // 3
|
| 154 |
-
'banana', // 4
|
| 155 |
-
'pizza', // 5
|
| 156 |
-
'cake' // 6
|
| 157 |
-
];
|
| 158 |
-
|
| 159 |
-
const commandIndex = parseInt(e.key) - 1;
|
| 160 |
-
if (commandIndex < quickCommands.length) {
|
| 161 |
-
e.preventDefault();
|
| 162 |
-
this.executeCommand(quickCommands[commandIndex]);
|
| 163 |
-
}
|
| 164 |
-
}
|
| 165 |
-
}
|
| 166 |
-
|
| 167 |
-
sendCommand() {
|
| 168 |
-
const input = document.getElementById('commandInput');
|
| 169 |
-
if (!input || !this.isActive) return;
|
| 170 |
-
|
| 171 |
-
const command = input.value.trim();
|
| 172 |
-
if (!command) return;
|
| 173 |
-
|
| 174 |
-
this.executeCommand(command);
|
| 175 |
-
input.value = '';
|
| 176 |
-
}
|
| 177 |
-
|
| 178 |
-
executeCommand(command) {
|
| 179 |
-
// 添加到历史记录
|
| 180 |
-
this.addToHistory(command);
|
| 181 |
-
|
| 182 |
-
// 显示调试信息
|
| 183 |
-
console.log(`[键盘输入] 执行命令: "${command}"`);
|
| 184 |
-
|
| 185 |
-
// 触发命令回调
|
| 186 |
-
if (this.onCommand) {
|
| 187 |
-
this.onCommand(command);
|
| 188 |
-
}
|
| 189 |
-
|
| 190 |
-
// 更新界面
|
| 191 |
-
this.updatePanel();
|
| 192 |
-
this.showCommandFeedback(command);
|
| 193 |
-
}
|
| 194 |
-
|
| 195 |
-
addToHistory(command) {
|
| 196 |
-
// 避免重复的连续命令
|
| 197 |
-
if (this.commandHistory.length > 0 &&
|
| 198 |
-
this.commandHistory[this.commandHistory.length - 1].command === command) {
|
| 199 |
-
return;
|
| 200 |
-
}
|
| 201 |
-
|
| 202 |
-
const historyItem = {
|
| 203 |
-
command: command,
|
| 204 |
-
timestamp: new Date().toLocaleTimeString(),
|
| 205 |
-
fullTimestamp: Date.now()
|
| 206 |
-
};
|
| 207 |
-
|
| 208 |
-
this.commandHistory.push(historyItem);
|
| 209 |
-
|
| 210 |
-
// 限制历史记录大小
|
| 211 |
-
if (this.commandHistory.length > this.maxHistorySize) {
|
| 212 |
-
this.commandHistory.shift();
|
| 213 |
-
}
|
| 214 |
-
|
| 215 |
-
this.updateHistoryDisplay();
|
| 216 |
-
}
|
| 217 |
-
|
| 218 |
-
navigateHistory(direction) {
|
| 219 |
-
// 实现历史记录导航功能
|
| 220 |
-
const input = document.getElementById('commandInput');
|
| 221 |
-
if (!input || this.commandHistory.length === 0) return;
|
| 222 |
-
|
| 223 |
-
if (!this.historyIndex) {
|
| 224 |
-
this.historyIndex = this.commandHistory.length;
|
| 225 |
-
}
|
| 226 |
-
|
| 227 |
-
this.historyIndex += direction;
|
| 228 |
-
|
| 229 |
-
if (this.historyIndex < 0) {
|
| 230 |
-
this.historyIndex = 0;
|
| 231 |
-
} else if (this.historyIndex >= this.commandHistory.length) {
|
| 232 |
-
this.historyIndex = this.commandHistory.length;
|
| 233 |
-
input.value = '';
|
| 234 |
-
return;
|
| 235 |
-
}
|
| 236 |
-
|
| 237 |
-
input.value = this.commandHistory[this.historyIndex].command;
|
| 238 |
-
}
|
| 239 |
-
|
| 240 |
-
fillInputWithCommand(command) {
|
| 241 |
-
const input = document.getElementById('commandInput');
|
| 242 |
-
if (input) {
|
| 243 |
-
input.value = command;
|
| 244 |
-
input.focus();
|
| 245 |
-
}
|
| 246 |
-
}
|
| 247 |
-
|
| 248 |
-
updateHistoryDisplay() {
|
| 249 |
-
const historyList = document.getElementById('commandHistory');
|
| 250 |
-
if (!historyList) return;
|
| 251 |
-
|
| 252 |
-
if (this.commandHistory.length === 0) {
|
| 253 |
-
historyList.innerHTML = '<div style="color: rgba(255,255,255,0.5); font-style: italic; text-align: center; padding: 10px;">暂无命令历史</div>';
|
| 254 |
-
return;
|
| 255 |
-
}
|
| 256 |
-
|
| 257 |
-
const historyHTML = this.commandHistory
|
| 258 |
-
.slice(-10) // 只显示最近10条
|
| 259 |
-
.reverse()
|
| 260 |
-
.map(item => `
|
| 261 |
-
<div class="history-item" title="点击重新使用此命令">
|
| 262 |
-
<span class="history-command">${this.escapeHtml(item.command)}</span>
|
| 263 |
-
<span class="history-time">${item.timestamp}</span>
|
| 264 |
-
</div>
|
| 265 |
-
`).join('');
|
| 266 |
-
|
| 267 |
-
historyList.innerHTML = historyHTML;
|
| 268 |
-
}
|
| 269 |
-
|
| 270 |
-
showCommandFeedback(command) {
|
| 271 |
-
// 创建命令反馈动画
|
| 272 |
-
const panel = document.getElementById('keyboardInputPanel');
|
| 273 |
-
if (!panel) return;
|
| 274 |
-
|
| 275 |
-
// 添加闪烁效果
|
| 276 |
-
panel.style.borderColor = '#ff6b6b';
|
| 277 |
-
setTimeout(() => {
|
| 278 |
-
panel.style.borderColor = '#4ecdc4';
|
| 279 |
-
}, 200);
|
| 280 |
-
|
| 281 |
-
// 在面板标题旁显示最后执行的命令
|
| 282 |
-
const header = panel.querySelector('.input-header h4');
|
| 283 |
-
if (header) {
|
| 284 |
-
const originalText = header.textContent;
|
| 285 |
-
header.textContent = `🎮 执行: ${command}`;
|
| 286 |
-
header.style.color = '#ff6b6b';
|
| 287 |
-
|
| 288 |
-
setTimeout(() => {
|
| 289 |
-
header.textContent = originalText;
|
| 290 |
-
header.style.color = 'white';
|
| 291 |
-
}, 1500);
|
| 292 |
-
}
|
| 293 |
-
}
|
| 294 |
-
|
| 295 |
-
togglePanel() {
|
| 296 |
-
this.setPanelCollapsed(!this.isPanelCollapsed);
|
| 297 |
-
}
|
| 298 |
-
|
| 299 |
-
setPanelCollapsed(collapsed) {
|
| 300 |
-
const panel = document.getElementById('keyboardInputPanel');
|
| 301 |
-
const content = document.getElementById('keyboardInputContent');
|
| 302 |
-
const toggleBtn = document.getElementById('toggleKeyboardPanel');
|
| 303 |
-
|
| 304 |
-
if (!panel || !content || !toggleBtn) return;
|
| 305 |
-
|
| 306 |
-
this.isPanelCollapsed = collapsed;
|
| 307 |
-
|
| 308 |
-
if (this.isPanelCollapsed) {
|
| 309 |
-
// 完全隐藏面板
|
| 310 |
-
panel.style.display = 'none';
|
| 311 |
-
panel.classList.add('collapsed');
|
| 312 |
-
} else {
|
| 313 |
-
// 显示面板
|
| 314 |
-
panel.style.display = 'block';
|
| 315 |
-
panel.classList.remove('collapsed');
|
| 316 |
-
content.style.display = 'block';
|
| 317 |
-
toggleBtn.textContent = '⌨️';
|
| 318 |
-
toggleBtn.title = '折叠键盘输入面板';
|
| 319 |
-
}
|
| 320 |
-
|
| 321 |
-
console.log(`键盘输入面板${this.isPanelCollapsed ? '已隐藏' : '已显示'}`);
|
| 322 |
-
}
|
| 323 |
-
|
| 324 |
-
focusInput() {
|
| 325 |
-
const input = document.getElementById('commandInput');
|
| 326 |
-
if (input) {
|
| 327 |
-
// 如果面板未激活,先激活
|
| 328 |
-
if (!this.isActive) {
|
| 329 |
-
this.setActiveState(true);
|
| 330 |
-
}
|
| 331 |
-
|
| 332 |
-
// 如果面板是折叠的,先展开
|
| 333 |
-
if (this.isPanelCollapsed) {
|
| 334 |
-
this.setPanelCollapsed(false);
|
| 335 |
-
}
|
| 336 |
-
|
| 337 |
-
setTimeout(() => {
|
| 338 |
-
input.focus();
|
| 339 |
-
}, 100);
|
| 340 |
-
}
|
| 341 |
-
}
|
| 342 |
-
|
| 343 |
-
updatePanel() {
|
| 344 |
-
this.updateHistoryDisplay();
|
| 345 |
-
|
| 346 |
-
// 更新快捷指令状态
|
| 347 |
-
const quickCmdBtns = document.querySelectorAll('.quick-cmd');
|
| 348 |
-
quickCmdBtns.forEach(btn => {
|
| 349 |
-
btn.addEventListener('mouseenter', () => {
|
| 350 |
-
const command = btn.getAttribute('data-command');
|
| 351 |
-
btn.title = `点击执行: ${command}`;
|
| 352 |
-
});
|
| 353 |
-
});
|
| 354 |
-
}
|
| 355 |
-
|
| 356 |
-
// 工具方法
|
| 357 |
-
escapeHtml(text) {
|
| 358 |
-
const div = document.createElement('div');
|
| 359 |
-
div.textContent = text;
|
| 360 |
-
return div.innerHTML;
|
| 361 |
-
}
|
| 362 |
-
|
| 363 |
-
// 设置面板
|
| 364 |
-
setActiveState(active) {
|
| 365 |
-
console.log(`setActiveState called with: ${active}`);
|
| 366 |
-
this.isActive = active;
|
| 367 |
-
const panel = document.getElementById('keyboardInputPanel');
|
| 368 |
-
if (!panel) {
|
| 369 |
-
console.log('keyboardInputPanel not found!');
|
| 370 |
-
return;
|
| 371 |
-
}
|
| 372 |
-
|
| 373 |
-
panel.classList.remove('active', 'inactive');
|
| 374 |
-
|
| 375 |
-
if (active) {
|
| 376 |
-
panel.classList.add('active');
|
| 377 |
-
console.log('Panel activated - adding active class');
|
| 378 |
-
this.showActivationIndicator('面板已激活 - 可以输入命令');
|
| 379 |
-
} else {
|
| 380 |
-
panel.classList.add('inactive');
|
| 381 |
-
console.log('Panel deactivated - adding inactive class');
|
| 382 |
-
this.showActivationIndicator('面板未激活 - 按F9激活');
|
| 383 |
-
}
|
| 384 |
-
|
| 385 |
-
console.log(`键盘输入面板${active ? '已激活' : '已取消激活'}`);
|
| 386 |
-
console.log('Panel classes:', panel.className);
|
| 387 |
-
}
|
| 388 |
-
|
| 389 |
-
// 切换面板激活状态
|
| 390 |
-
toggleActiveState() {
|
| 391 |
-
console.log('toggleActiveState called, current state:', this.isActive);
|
| 392 |
-
this.setActiveState(!this.isActive);
|
| 393 |
-
console.log('toggleActiveState completed, new state:', this.isActive);
|
| 394 |
-
}
|
| 395 |
-
|
| 396 |
-
// 显示激活状态指示器
|
| 397 |
-
showActivationIndicator(message) {
|
| 398 |
-
// 移除之前的指示器
|
| 399 |
-
const existingIndicator = document.querySelector('.activation-indicator');
|
| 400 |
-
if (existingIndicator) {
|
| 401 |
-
existingIndicator.remove();
|
| 402 |
-
}
|
| 403 |
-
|
| 404 |
-
// 创建新的指示器
|
| 405 |
-
const indicator = document.createElement('div');
|
| 406 |
-
indicator.className = 'activation-indicator';
|
| 407 |
-
indicator.textContent = message;
|
| 408 |
-
indicator.style.cssText = `
|
| 409 |
-
position: fixed;
|
| 410 |
-
top: 50%;
|
| 411 |
-
left: 50%;
|
| 412 |
-
transform: translate(-50%, -50%);
|
| 413 |
-
background: ${this.isActive ? '#4ecdc4' : '#6c757d'};
|
| 414 |
-
color: white;
|
| 415 |
-
padding: 15px 25px;
|
| 416 |
-
border-radius: 25px;
|
| 417 |
-
font-family: 'Comic Neue', cursive;
|
| 418 |
-
font-weight: bold;
|
| 419 |
-
font-size: 16px;
|
| 420 |
-
z-index: 15000;
|
| 421 |
-
box-shadow: 0 8px 32px rgba(0,0,0,0.3);
|
| 422 |
-
animation: activationPulse 0.5s ease-out;
|
| 423 |
-
`;
|
| 424 |
-
|
| 425 |
-
document.body.appendChild(indicator);
|
| 426 |
-
|
| 427 |
-
// 自动移除
|
| 428 |
-
setTimeout(() => {
|
| 429 |
-
if (indicator.parentNode) {
|
| 430 |
-
indicator.style.animation = 'activationFadeOut 0.3s ease-out forwards';
|
| 431 |
-
setTimeout(() => {
|
| 432 |
-
if (indicator.parentNode) {
|
| 433 |
-
indicator.parentNode.removeChild(indicator);
|
| 434 |
-
}
|
| 435 |
-
}, 300);
|
| 436 |
-
}
|
| 437 |
-
}, 2000);
|
| 438 |
-
}
|
| 439 |
-
|
| 440 |
-
// 获取统计信息
|
| 441 |
-
getStats() {
|
| 442 |
-
return {
|
| 443 |
-
totalCommands: this.commandHistory.length,
|
| 444 |
-
isCollapsed: this.isPanelCollapsed,
|
| 445 |
-
isActive: this.isActive,
|
| 446 |
-
lastCommand: this.commandHistory.length > 0
|
| 447 |
-
? this.commandHistory[this.commandHistory.length - 1].command
|
| 448 |
-
: null
|
| 449 |
-
};
|
| 450 |
-
}
|
| 451 |
-
|
| 452 |
-
// 清空历史记录
|
| 453 |
-
clearHistory() {
|
| 454 |
-
this.commandHistory = [];
|
| 455 |
-
this.updateHistoryDisplay();
|
| 456 |
-
console.log('命令历史已清空');
|
| 457 |
-
}
|
| 458 |
-
|
| 459 |
-
// 导出历史记录
|
| 460 |
-
exportHistory() {
|
| 461 |
-
const data = {
|
| 462 |
-
exported: new Date().toISOString(),
|
| 463 |
-
commands: this.commandHistory
|
| 464 |
-
};
|
| 465 |
-
|
| 466 |
-
const blob = new Blob([JSON.stringify(data, null, 2)],
|
| 467 |
-
{ type: 'application/json' });
|
| 468 |
-
const url = URL.createObjectURL(blob);
|
| 469 |
-
|
| 470 |
-
const a = document.createElement('a');
|
| 471 |
-
a.href = url;
|
| 472 |
-
a.download = `magicpot-commands-${Date.now()}.json`;
|
| 473 |
-
document.body.appendChild(a);
|
| 474 |
-
a.click();
|
| 475 |
-
document.body.removeChild(a);
|
| 476 |
-
URL.revokeObjectURL(url);
|
| 477 |
-
|
| 478 |
-
console.log('命令历史已导出');
|
| 479 |
-
}
|
| 480 |
-
|
| 481 |
-
// 获取命令提示
|
| 482 |
-
getCommandSuggestions(input) {
|
| 483 |
-
const suggestions = [
|
| 484 |
-
'cook cook cook pot',
|
| 485 |
-
'stop stop stop pot',
|
| 486 |
-
'apple', 'banana', 'orange', 'strawberry', 'watermelon', 'grape',
|
| 487 |
-
'pizza', 'burger', 'bread', 'rice', 'noodles', 'cake', 'cookie',
|
| 488 |
-
'cheese', 'fish', 'chicken', 'carrot', 'tomato', 'corn', 'broccoli'
|
| 489 |
-
];
|
| 490 |
-
|
| 491 |
-
if (!input) return suggestions.slice(0, 5);
|
| 492 |
-
|
| 493 |
-
const filtered = suggestions.filter(cmd =>
|
| 494 |
-
cmd.toLowerCase().includes(input.toLowerCase())
|
| 495 |
-
);
|
| 496 |
-
|
| 497 |
-
return filtered.slice(0, 8);
|
| 498 |
-
}
|
| 499 |
-
|
| 500 |
-
// 设置拖拽功能
|
| 501 |
-
setupDragFunctionality() {
|
| 502 |
-
const panel = document.getElementById('keyboardInputPanel');
|
| 503 |
-
const header = panel?.querySelector('.input-header');
|
| 504 |
-
|
| 505 |
-
if (!panel || !header) return;
|
| 506 |
-
|
| 507 |
-
// 鼠标按下开始拖拽
|
| 508 |
-
header.addEventListener('mousedown', (e) => {
|
| 509 |
-
if (!this.isActive) return; // 只有激活状态下才能拖拽
|
| 510 |
-
|
| 511 |
-
this.isDragging = true;
|
| 512 |
-
panel.classList.add('dragging');
|
| 513 |
-
|
| 514 |
-
const rect = panel.getBoundingClientRect();
|
| 515 |
-
this.dragOffset.x = e.clientX - rect.left;
|
| 516 |
-
this.dragOffset.y = e.clientY - rect.top;
|
| 517 |
-
|
| 518 |
-
// 记录当前位置
|
| 519 |
-
this.currentPosition.x = rect.left;
|
| 520 |
-
this.currentPosition.y = rect.top;
|
| 521 |
-
|
| 522 |
-
e.preventDefault();
|
| 523 |
-
});
|
| 524 |
-
|
| 525 |
-
// 全局鼠标移动事件
|
| 526 |
-
document.addEventListener('mousemove', (e) => {
|
| 527 |
-
if (!this.isDragging) return;
|
| 528 |
-
|
| 529 |
-
e.preventDefault();
|
| 530 |
-
|
| 531 |
-
// 计算新位置
|
| 532 |
-
let newX = e.clientX - this.dragOffset.x;
|
| 533 |
-
let newY = e.clientY - this.dragOffset.y;
|
| 534 |
-
|
| 535 |
-
// 边界检查
|
| 536 |
-
const rect = panel.getBoundingClientRect();
|
| 537 |
-
const maxX = window.innerWidth - rect.width;
|
| 538 |
-
const maxY = window.innerHeight - rect.height;
|
| 539 |
-
|
| 540 |
-
newX = Math.max(0, Math.min(newX, maxX));
|
| 541 |
-
newY = Math.max(0, Math.min(newY, maxY));
|
| 542 |
-
|
| 543 |
-
// 应用新位置
|
| 544 |
-
panel.style.left = newX + 'px';
|
| 545 |
-
panel.style.top = newY + 'px';
|
| 546 |
-
panel.style.right = 'auto';
|
| 547 |
-
panel.style.bottom = 'auto';
|
| 548 |
-
|
| 549 |
-
this.currentPosition.x = newX;
|
| 550 |
-
this.currentPosition.y = newY;
|
| 551 |
-
});
|
| 552 |
-
|
| 553 |
-
// 全局鼠标松开事件
|
| 554 |
-
document.addEventListener('mouseup', (e) => {
|
| 555 |
-
if (!this.isDragging) return;
|
| 556 |
-
|
| 557 |
-
this.isDragging = false;
|
| 558 |
-
panel.classList.remove('dragging');
|
| 559 |
-
|
| 560 |
-
// 保存位置到localStorage
|
| 561 |
-
this.savePosition();
|
| 562 |
-
});
|
| 563 |
-
|
| 564 |
-
// 加载保存的位置
|
| 565 |
-
this.loadPosition();
|
| 566 |
-
}
|
| 567 |
-
|
| 568 |
-
// 保存面板位置
|
| 569 |
-
savePosition() {
|
| 570 |
-
if (this.currentPosition.x !== null && this.currentPosition.y !== null) {
|
| 571 |
-
const position = {
|
| 572 |
-
x: this.currentPosition.x,
|
| 573 |
-
y: this.currentPosition.y
|
| 574 |
-
};
|
| 575 |
-
localStorage.setItem('keyboardPanelPosition', JSON.stringify(position));
|
| 576 |
-
}
|
| 577 |
-
}
|
| 578 |
-
|
| 579 |
-
// 加载保存的位置
|
| 580 |
-
loadPosition() {
|
| 581 |
-
const panel = document.getElementById('keyboardInputPanel');
|
| 582 |
-
if (!panel) return;
|
| 583 |
-
|
| 584 |
-
try {
|
| 585 |
-
const savedPosition = localStorage.getItem('keyboardPanelPosition');
|
| 586 |
-
if (savedPosition) {
|
| 587 |
-
const position = JSON.parse(savedPosition);
|
| 588 |
-
|
| 589 |
-
// 检查位置是否在屏幕范围内
|
| 590 |
-
const rect = panel.getBoundingClientRect();
|
| 591 |
-
const maxX = window.innerWidth - rect.width;
|
| 592 |
-
const maxY = window.innerHeight - rect.height;
|
| 593 |
-
|
| 594 |
-
if (position.x >= 0 && position.x <= maxX &&
|
| 595 |
-
position.y >= 0 && position.y <= maxY) {
|
| 596 |
-
|
| 597 |
-
panel.style.left = position.x + 'px';
|
| 598 |
-
panel.style.top = position.y + 'px';
|
| 599 |
-
panel.style.right = 'auto';
|
| 600 |
-
panel.style.bottom = 'auto';
|
| 601 |
-
|
| 602 |
-
this.currentPosition.x = position.x;
|
| 603 |
-
this.currentPosition.y = position.y;
|
| 604 |
-
}
|
| 605 |
-
}
|
| 606 |
-
} catch (error) {
|
| 607 |
-
console.warn('加载面板位置失败:', error);
|
| 608 |
-
}
|
| 609 |
-
}
|
| 610 |
-
|
| 611 |
-
// 重置面板位置到右下角
|
| 612 |
-
resetPosition() {
|
| 613 |
-
const panel = document.getElementById('keyboardInputPanel');
|
| 614 |
-
if (!panel) return;
|
| 615 |
-
|
| 616 |
-
panel.style.left = 'auto';
|
| 617 |
-
panel.style.top = 'auto';
|
| 618 |
-
panel.style.right = '20px';
|
| 619 |
-
panel.style.bottom = '20px';
|
| 620 |
-
|
| 621 |
-
this.currentPosition.x = null;
|
| 622 |
-
this.currentPosition.y = null;
|
| 623 |
-
|
| 624 |
-
// 清除保存的位置
|
| 625 |
-
localStorage.removeItem('keyboardPanelPosition');
|
| 626 |
-
|
| 627 |
-
console.log('面板位置已重置到右下角');
|
| 628 |
-
}
|
| 629 |
-
}
|
| 630 |
-
|
| 631 |
-
// 添加快捷键提示样式
|
| 632 |
-
const keyboardStyle = document.createElement('style');
|
| 633 |
-
keyboardStyle.textContent = `
|
| 634 |
-
.keyboard-shortcuts-hint {
|
| 635 |
-
position: absolute;
|
| 636 |
-
bottom: 5px;
|
| 637 |
-
left: 50%;
|
| 638 |
-
transform: translateX(-50%);
|
| 639 |
-
background: rgba(0, 0, 0, 0.8);
|
| 640 |
-
color: white;
|
| 641 |
-
padding: 5px 10px;
|
| 642 |
-
border-radius: 10px;
|
| 643 |
-
font-size: 0.7em;
|
| 644 |
-
white-space: nowrap;
|
| 645 |
-
opacity: 0;
|
| 646 |
-
transition: opacity 0.3s ease;
|
| 647 |
-
pointer-events: none;
|
| 648 |
-
font-family: 'Comic Neue', cursive;
|
| 649 |
-
}
|
| 650 |
-
|
| 651 |
-
.keyboard-input-panel:hover .keyboard-shortcuts-hint {
|
| 652 |
-
opacity: 1;
|
| 653 |
-
}
|
| 654 |
-
|
| 655 |
-
.command-input:focus + .keyboard-shortcuts-hint {
|
| 656 |
-
opacity: 1;
|
| 657 |
-
}
|
| 658 |
-
|
| 659 |
-
@keyframes activationPulse {
|
| 660 |
-
0% {
|
| 661 |
-
opacity: 0;
|
| 662 |
-
transform: translate(-50%, -50%) scale(0.8);
|
| 663 |
-
}
|
| 664 |
-
50% {
|
| 665 |
-
transform: translate(-50%, -50%) scale(1.1);
|
| 666 |
-
}
|
| 667 |
-
100% {
|
| 668 |
-
opacity: 1;
|
| 669 |
-
transform: translate(-50%, -50%) scale(1);
|
| 670 |
-
}
|
| 671 |
-
}
|
| 672 |
-
|
| 673 |
-
@keyframes activationFadeOut {
|
| 674 |
-
from {
|
| 675 |
-
opacity: 1;
|
| 676 |
-
transform: translate(-50%, -50%) scale(1);
|
| 677 |
-
}
|
| 678 |
-
to {
|
| 679 |
-
opacity: 0;
|
| 680 |
-
transform: translate(-50%, -50%) scale(0.9);
|
| 681 |
-
}
|
| 682 |
-
}
|
| 683 |
-
`;
|
| 684 |
-
document.head.appendChild(keyboardStyle);
|
|
|
|
| 1 |
+
// 键盘输入处理类
|
| 2 |
+
class KeyboardInputHandler {
|
| 3 |
+
constructor() {
|
| 4 |
+
this.onCommand = null; // 命令回调函数
|
| 5 |
+
this.commandHistory = [];
|
| 6 |
+
this.maxHistorySize = 20;
|
| 7 |
+
this.isPanelCollapsed = false;
|
| 8 |
+
this.isActive = false; // 面板激活状态
|
| 9 |
+
|
| 10 |
+
// 拖拽相关属性
|
| 11 |
+
this.isDragging = false;
|
| 12 |
+
this.dragOffset = { x: 0, y: 0 };
|
| 13 |
+
this.currentPosition = { x: null, y: null };
|
| 14 |
+
|
| 15 |
+
this.init();
|
| 16 |
+
}
|
| 17 |
+
|
| 18 |
+
init() {
|
| 19 |
+
this.setupEventListeners();
|
| 20 |
+
this.updatePanel();
|
| 21 |
+
this.setActiveState(false); // 初始为非激活状态
|
| 22 |
+
this.setPanelCollapsed(true); // 默认折叠面板
|
| 23 |
+
console.log('键盘输入处理器已初始化');
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
setupEventListeners() {
|
| 27 |
+
// 输入框事件
|
| 28 |
+
const commandInput = document.getElementById('commandInput');
|
| 29 |
+
const sendBtn = document.getElementById('sendCommandBtn');
|
| 30 |
+
const toggleBtn = document.getElementById('toggleKeyboardPanel');
|
| 31 |
+
|
| 32 |
+
if (commandInput) {
|
| 33 |
+
// 回车发送命令
|
| 34 |
+
commandInput.addEventListener('keydown', (e) => {
|
| 35 |
+
if (e.key === 'Enter') {
|
| 36 |
+
e.preventDefault();
|
| 37 |
+
this.sendCommand();
|
| 38 |
+
}
|
| 39 |
+
});
|
| 40 |
+
|
| 41 |
+
// 历史记录导航(上下键)
|
| 42 |
+
commandInput.addEventListener('keydown', (e) => {
|
| 43 |
+
if (e.key === 'ArrowUp') {
|
| 44 |
+
e.preventDefault();
|
| 45 |
+
this.navigateHistory(-1);
|
| 46 |
+
} else if (e.key === 'ArrowDown') {
|
| 47 |
+
e.preventDefault();
|
| 48 |
+
this.navigateHistory(1);
|
| 49 |
+
}
|
| 50 |
+
});
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
// 发送按钮
|
| 54 |
+
if (sendBtn) {
|
| 55 |
+
sendBtn.addEventListener('click', () => {
|
| 56 |
+
this.sendCommand();
|
| 57 |
+
});
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
// 面板折叠按钮
|
| 61 |
+
if (toggleBtn) {
|
| 62 |
+
toggleBtn.addEventListener('click', () => {
|
| 63 |
+
this.togglePanel();
|
| 64 |
+
});
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
// 快捷指令按钮
|
| 68 |
+
const quickCmdBtns = document.querySelectorAll('.quick-cmd');
|
| 69 |
+
quickCmdBtns.forEach(btn => {
|
| 70 |
+
btn.addEventListener('click', () => {
|
| 71 |
+
const command = btn.getAttribute('data-command');
|
| 72 |
+
if (command) {
|
| 73 |
+
this.executeCommand(command);
|
| 74 |
+
}
|
| 75 |
+
});
|
| 76 |
+
});
|
| 77 |
+
|
| 78 |
+
// 全局键盘快捷键
|
| 79 |
+
document.addEventListener('keydown', (e) => {
|
| 80 |
+
this.handleGlobalShortcuts(e);
|
| 81 |
+
});
|
| 82 |
+
|
| 83 |
+
// 历史记录点击事件
|
| 84 |
+
this.setupHistoryListener();
|
| 85 |
+
|
| 86 |
+
// 拖拽功能
|
| 87 |
+
this.setupDragFunctionality();
|
| 88 |
+
}
|
| 89 |
+
|
| 90 |
+
setupHistoryListener() {
|
| 91 |
+
const historyList = document.getElementById('commandHistory');
|
| 92 |
+
if (historyList) {
|
| 93 |
+
historyList.addEventListener('click', (e) => {
|
| 94 |
+
if (e.target.classList.contains('history-item') ||
|
| 95 |
+
e.target.parentElement.classList.contains('history-item')) {
|
| 96 |
+
|
| 97 |
+
const historyItem = e.target.classList.contains('history-item')
|
| 98 |
+
? e.target
|
| 99 |
+
: e.target.parentElement;
|
| 100 |
+
|
| 101 |
+
const command = historyItem.querySelector('.history-command').textContent;
|
| 102 |
+
if (command) {
|
| 103 |
+
this.fillInputWithCommand(command);
|
| 104 |
+
}
|
| 105 |
+
}
|
| 106 |
+
});
|
| 107 |
+
}
|
| 108 |
+
}
|
| 109 |
+
|
| 110 |
+
handleGlobalShortcuts(e) {
|
| 111 |
+
// F9 由 main.js 处理,这里不再处理
|
| 112 |
+
// if (e.key === 'F9') {
|
| 113 |
+
// e.preventDefault();
|
| 114 |
+
// this.toggleActiveState();
|
| 115 |
+
// return;
|
| 116 |
+
// }
|
| 117 |
+
|
| 118 |
+
// 只在面板激活且没有焦点在输入框时处理全局快捷键
|
| 119 |
+
if (!this.isActive || document.activeElement.tagName === 'INPUT') {
|
| 120 |
+
return;
|
| 121 |
+
}
|
| 122 |
+
|
| 123 |
+
// Ctrl/Cmd + K 聚焦到输入框
|
| 124 |
+
if ((e.ctrlKey || e.metaKey) && e.key === 'k') {
|
| 125 |
+
e.preventDefault();
|
| 126 |
+
this.focusInput();
|
| 127 |
+
}
|
| 128 |
+
|
| 129 |
+
// Ctrl/Cmd + ` 切换面板
|
| 130 |
+
if ((e.ctrlKey || e.metaKey) && e.key === '`') {
|
| 131 |
+
e.preventDefault();
|
| 132 |
+
this.togglePanel();
|
| 133 |
+
}
|
| 134 |
+
|
| 135 |
+
// ESC 清空输入框、取消激活或折叠面板
|
| 136 |
+
if (e.key === 'Escape') {
|
| 137 |
+
const input = document.getElementById('commandInput');
|
| 138 |
+
if (input && input.value) {
|
| 139 |
+
input.value = '';
|
| 140 |
+
input.blur();
|
| 141 |
+
} else if (this.isActive) {
|
| 142 |
+
this.setActiveState(false);
|
| 143 |
+
} else {
|
| 144 |
+
this.togglePanel();
|
| 145 |
+
}
|
| 146 |
+
}
|
| 147 |
+
|
| 148 |
+
// 数字键快速命令(1-6) - 仅在激活状态下工作
|
| 149 |
+
if (this.isActive && e.key >= '1' && e.key <= '6') {
|
| 150 |
+
const quickCommands = [
|
| 151 |
+
'cook cook cook pot', // 1
|
| 152 |
+
'stop stop stop pot', // 2
|
| 153 |
+
'apple', // 3
|
| 154 |
+
'banana', // 4
|
| 155 |
+
'pizza', // 5
|
| 156 |
+
'cake' // 6
|
| 157 |
+
];
|
| 158 |
+
|
| 159 |
+
const commandIndex = parseInt(e.key) - 1;
|
| 160 |
+
if (commandIndex < quickCommands.length) {
|
| 161 |
+
e.preventDefault();
|
| 162 |
+
this.executeCommand(quickCommands[commandIndex]);
|
| 163 |
+
}
|
| 164 |
+
}
|
| 165 |
+
}
|
| 166 |
+
|
| 167 |
+
sendCommand() {
|
| 168 |
+
const input = document.getElementById('commandInput');
|
| 169 |
+
if (!input || !this.isActive) return;
|
| 170 |
+
|
| 171 |
+
const command = input.value.trim();
|
| 172 |
+
if (!command) return;
|
| 173 |
+
|
| 174 |
+
this.executeCommand(command);
|
| 175 |
+
input.value = '';
|
| 176 |
+
}
|
| 177 |
+
|
| 178 |
+
executeCommand(command) {
|
| 179 |
+
// 添加到历史记录
|
| 180 |
+
this.addToHistory(command);
|
| 181 |
+
|
| 182 |
+
// 显示调试信息
|
| 183 |
+
console.log(`[键盘输入] 执行命令: "${command}"`);
|
| 184 |
+
|
| 185 |
+
// 触发命令回调
|
| 186 |
+
if (this.onCommand) {
|
| 187 |
+
this.onCommand(command);
|
| 188 |
+
}
|
| 189 |
+
|
| 190 |
+
// 更新界面
|
| 191 |
+
this.updatePanel();
|
| 192 |
+
this.showCommandFeedback(command);
|
| 193 |
+
}
|
| 194 |
+
|
| 195 |
+
addToHistory(command) {
|
| 196 |
+
// 避免重复的连续命令
|
| 197 |
+
if (this.commandHistory.length > 0 &&
|
| 198 |
+
this.commandHistory[this.commandHistory.length - 1].command === command) {
|
| 199 |
+
return;
|
| 200 |
+
}
|
| 201 |
+
|
| 202 |
+
const historyItem = {
|
| 203 |
+
command: command,
|
| 204 |
+
timestamp: new Date().toLocaleTimeString(),
|
| 205 |
+
fullTimestamp: Date.now()
|
| 206 |
+
};
|
| 207 |
+
|
| 208 |
+
this.commandHistory.push(historyItem);
|
| 209 |
+
|
| 210 |
+
// 限制历史记录大小
|
| 211 |
+
if (this.commandHistory.length > this.maxHistorySize) {
|
| 212 |
+
this.commandHistory.shift();
|
| 213 |
+
}
|
| 214 |
+
|
| 215 |
+
this.updateHistoryDisplay();
|
| 216 |
+
}
|
| 217 |
+
|
| 218 |
+
navigateHistory(direction) {
|
| 219 |
+
// 实现历史记录导航功能
|
| 220 |
+
const input = document.getElementById('commandInput');
|
| 221 |
+
if (!input || this.commandHistory.length === 0) return;
|
| 222 |
+
|
| 223 |
+
if (!this.historyIndex) {
|
| 224 |
+
this.historyIndex = this.commandHistory.length;
|
| 225 |
+
}
|
| 226 |
+
|
| 227 |
+
this.historyIndex += direction;
|
| 228 |
+
|
| 229 |
+
if (this.historyIndex < 0) {
|
| 230 |
+
this.historyIndex = 0;
|
| 231 |
+
} else if (this.historyIndex >= this.commandHistory.length) {
|
| 232 |
+
this.historyIndex = this.commandHistory.length;
|
| 233 |
+
input.value = '';
|
| 234 |
+
return;
|
| 235 |
+
}
|
| 236 |
+
|
| 237 |
+
input.value = this.commandHistory[this.historyIndex].command;
|
| 238 |
+
}
|
| 239 |
+
|
| 240 |
+
fillInputWithCommand(command) {
|
| 241 |
+
const input = document.getElementById('commandInput');
|
| 242 |
+
if (input) {
|
| 243 |
+
input.value = command;
|
| 244 |
+
input.focus();
|
| 245 |
+
}
|
| 246 |
+
}
|
| 247 |
+
|
| 248 |
+
updateHistoryDisplay() {
|
| 249 |
+
const historyList = document.getElementById('commandHistory');
|
| 250 |
+
if (!historyList) return;
|
| 251 |
+
|
| 252 |
+
if (this.commandHistory.length === 0) {
|
| 253 |
+
historyList.innerHTML = '<div style="color: rgba(255,255,255,0.5); font-style: italic; text-align: center; padding: 10px;">暂无命令历史</div>';
|
| 254 |
+
return;
|
| 255 |
+
}
|
| 256 |
+
|
| 257 |
+
const historyHTML = this.commandHistory
|
| 258 |
+
.slice(-10) // 只显示最近10条
|
| 259 |
+
.reverse()
|
| 260 |
+
.map(item => `
|
| 261 |
+
<div class="history-item" title="点击重新使用此命令">
|
| 262 |
+
<span class="history-command">${this.escapeHtml(item.command)}</span>
|
| 263 |
+
<span class="history-time">${item.timestamp}</span>
|
| 264 |
+
</div>
|
| 265 |
+
`).join('');
|
| 266 |
+
|
| 267 |
+
historyList.innerHTML = historyHTML;
|
| 268 |
+
}
|
| 269 |
+
|
| 270 |
+
showCommandFeedback(command) {
|
| 271 |
+
// 创建命令反馈动画
|
| 272 |
+
const panel = document.getElementById('keyboardInputPanel');
|
| 273 |
+
if (!panel) return;
|
| 274 |
+
|
| 275 |
+
// 添加闪烁效果
|
| 276 |
+
panel.style.borderColor = '#ff6b6b';
|
| 277 |
+
setTimeout(() => {
|
| 278 |
+
panel.style.borderColor = '#4ecdc4';
|
| 279 |
+
}, 200);
|
| 280 |
+
|
| 281 |
+
// 在面板标题旁显示最后执行的命令
|
| 282 |
+
const header = panel.querySelector('.input-header h4');
|
| 283 |
+
if (header) {
|
| 284 |
+
const originalText = header.textContent;
|
| 285 |
+
header.textContent = `🎮 执行: ${command}`;
|
| 286 |
+
header.style.color = '#ff6b6b';
|
| 287 |
+
|
| 288 |
+
setTimeout(() => {
|
| 289 |
+
header.textContent = originalText;
|
| 290 |
+
header.style.color = 'white';
|
| 291 |
+
}, 1500);
|
| 292 |
+
}
|
| 293 |
+
}
|
| 294 |
+
|
| 295 |
+
togglePanel() {
|
| 296 |
+
this.setPanelCollapsed(!this.isPanelCollapsed);
|
| 297 |
+
}
|
| 298 |
+
|
| 299 |
+
setPanelCollapsed(collapsed) {
|
| 300 |
+
const panel = document.getElementById('keyboardInputPanel');
|
| 301 |
+
const content = document.getElementById('keyboardInputContent');
|
| 302 |
+
const toggleBtn = document.getElementById('toggleKeyboardPanel');
|
| 303 |
+
|
| 304 |
+
if (!panel || !content || !toggleBtn) return;
|
| 305 |
+
|
| 306 |
+
this.isPanelCollapsed = collapsed;
|
| 307 |
+
|
| 308 |
+
if (this.isPanelCollapsed) {
|
| 309 |
+
// 完全隐藏面板
|
| 310 |
+
panel.style.display = 'none';
|
| 311 |
+
panel.classList.add('collapsed');
|
| 312 |
+
} else {
|
| 313 |
+
// 显示面板
|
| 314 |
+
panel.style.display = 'block';
|
| 315 |
+
panel.classList.remove('collapsed');
|
| 316 |
+
content.style.display = 'block';
|
| 317 |
+
toggleBtn.textContent = '⌨️';
|
| 318 |
+
toggleBtn.title = '折叠键盘输入面板';
|
| 319 |
+
}
|
| 320 |
+
|
| 321 |
+
console.log(`键盘输入面板${this.isPanelCollapsed ? '已隐藏' : '已显示'}`);
|
| 322 |
+
}
|
| 323 |
+
|
| 324 |
+
focusInput() {
|
| 325 |
+
const input = document.getElementById('commandInput');
|
| 326 |
+
if (input) {
|
| 327 |
+
// 如果面板未激活,先激活
|
| 328 |
+
if (!this.isActive) {
|
| 329 |
+
this.setActiveState(true);
|
| 330 |
+
}
|
| 331 |
+
|
| 332 |
+
// 如果面板是折叠的,先展开
|
| 333 |
+
if (this.isPanelCollapsed) {
|
| 334 |
+
this.setPanelCollapsed(false);
|
| 335 |
+
}
|
| 336 |
+
|
| 337 |
+
setTimeout(() => {
|
| 338 |
+
input.focus();
|
| 339 |
+
}, 100);
|
| 340 |
+
}
|
| 341 |
+
}
|
| 342 |
+
|
| 343 |
+
updatePanel() {
|
| 344 |
+
this.updateHistoryDisplay();
|
| 345 |
+
|
| 346 |
+
// 更新快捷指令状态
|
| 347 |
+
const quickCmdBtns = document.querySelectorAll('.quick-cmd');
|
| 348 |
+
quickCmdBtns.forEach(btn => {
|
| 349 |
+
btn.addEventListener('mouseenter', () => {
|
| 350 |
+
const command = btn.getAttribute('data-command');
|
| 351 |
+
btn.title = `点击执行: ${command}`;
|
| 352 |
+
});
|
| 353 |
+
});
|
| 354 |
+
}
|
| 355 |
+
|
| 356 |
+
// 工具方法
|
| 357 |
+
escapeHtml(text) {
|
| 358 |
+
const div = document.createElement('div');
|
| 359 |
+
div.textContent = text;
|
| 360 |
+
return div.innerHTML;
|
| 361 |
+
}
|
| 362 |
+
|
| 363 |
+
// 设置面板��活状态
|
| 364 |
+
setActiveState(active) {
|
| 365 |
+
console.log(`setActiveState called with: ${active}`);
|
| 366 |
+
this.isActive = active;
|
| 367 |
+
const panel = document.getElementById('keyboardInputPanel');
|
| 368 |
+
if (!panel) {
|
| 369 |
+
console.log('keyboardInputPanel not found!');
|
| 370 |
+
return;
|
| 371 |
+
}
|
| 372 |
+
|
| 373 |
+
panel.classList.remove('active', 'inactive');
|
| 374 |
+
|
| 375 |
+
if (active) {
|
| 376 |
+
panel.classList.add('active');
|
| 377 |
+
console.log('Panel activated - adding active class');
|
| 378 |
+
this.showActivationIndicator('面板已激活 - 可以输入命令');
|
| 379 |
+
} else {
|
| 380 |
+
panel.classList.add('inactive');
|
| 381 |
+
console.log('Panel deactivated - adding inactive class');
|
| 382 |
+
this.showActivationIndicator('面板未激活 - 按F9激活');
|
| 383 |
+
}
|
| 384 |
+
|
| 385 |
+
console.log(`键盘输入面板${active ? '已激活' : '已取消激活'}`);
|
| 386 |
+
console.log('Panel classes:', panel.className);
|
| 387 |
+
}
|
| 388 |
+
|
| 389 |
+
// 切换面板激活状态
|
| 390 |
+
toggleActiveState() {
|
| 391 |
+
console.log('toggleActiveState called, current state:', this.isActive);
|
| 392 |
+
this.setActiveState(!this.isActive);
|
| 393 |
+
console.log('toggleActiveState completed, new state:', this.isActive);
|
| 394 |
+
}
|
| 395 |
+
|
| 396 |
+
// 显示激活状态指示器
|
| 397 |
+
showActivationIndicator(message) {
|
| 398 |
+
// 移除之前的指示器
|
| 399 |
+
const existingIndicator = document.querySelector('.activation-indicator');
|
| 400 |
+
if (existingIndicator) {
|
| 401 |
+
existingIndicator.remove();
|
| 402 |
+
}
|
| 403 |
+
|
| 404 |
+
// 创建新的指示器
|
| 405 |
+
const indicator = document.createElement('div');
|
| 406 |
+
indicator.className = 'activation-indicator';
|
| 407 |
+
indicator.textContent = message;
|
| 408 |
+
indicator.style.cssText = `
|
| 409 |
+
position: fixed;
|
| 410 |
+
top: 50%;
|
| 411 |
+
left: 50%;
|
| 412 |
+
transform: translate(-50%, -50%);
|
| 413 |
+
background: ${this.isActive ? '#4ecdc4' : '#6c757d'};
|
| 414 |
+
color: white;
|
| 415 |
+
padding: 15px 25px;
|
| 416 |
+
border-radius: 25px;
|
| 417 |
+
font-family: 'Comic Neue', cursive;
|
| 418 |
+
font-weight: bold;
|
| 419 |
+
font-size: 16px;
|
| 420 |
+
z-index: 15000;
|
| 421 |
+
box-shadow: 0 8px 32px rgba(0,0,0,0.3);
|
| 422 |
+
animation: activationPulse 0.5s ease-out;
|
| 423 |
+
`;
|
| 424 |
+
|
| 425 |
+
document.body.appendChild(indicator);
|
| 426 |
+
|
| 427 |
+
// 自动移除
|
| 428 |
+
setTimeout(() => {
|
| 429 |
+
if (indicator.parentNode) {
|
| 430 |
+
indicator.style.animation = 'activationFadeOut 0.3s ease-out forwards';
|
| 431 |
+
setTimeout(() => {
|
| 432 |
+
if (indicator.parentNode) {
|
| 433 |
+
indicator.parentNode.removeChild(indicator);
|
| 434 |
+
}
|
| 435 |
+
}, 300);
|
| 436 |
+
}
|
| 437 |
+
}, 2000);
|
| 438 |
+
}
|
| 439 |
+
|
| 440 |
+
// 获取统计信息
|
| 441 |
+
getStats() {
|
| 442 |
+
return {
|
| 443 |
+
totalCommands: this.commandHistory.length,
|
| 444 |
+
isCollapsed: this.isPanelCollapsed,
|
| 445 |
+
isActive: this.isActive,
|
| 446 |
+
lastCommand: this.commandHistory.length > 0
|
| 447 |
+
? this.commandHistory[this.commandHistory.length - 1].command
|
| 448 |
+
: null
|
| 449 |
+
};
|
| 450 |
+
}
|
| 451 |
+
|
| 452 |
+
// 清空历史记录
|
| 453 |
+
clearHistory() {
|
| 454 |
+
this.commandHistory = [];
|
| 455 |
+
this.updateHistoryDisplay();
|
| 456 |
+
console.log('命令历史已清空');
|
| 457 |
+
}
|
| 458 |
+
|
| 459 |
+
// 导出历史记录
|
| 460 |
+
exportHistory() {
|
| 461 |
+
const data = {
|
| 462 |
+
exported: new Date().toISOString(),
|
| 463 |
+
commands: this.commandHistory
|
| 464 |
+
};
|
| 465 |
+
|
| 466 |
+
const blob = new Blob([JSON.stringify(data, null, 2)],
|
| 467 |
+
{ type: 'application/json' });
|
| 468 |
+
const url = URL.createObjectURL(blob);
|
| 469 |
+
|
| 470 |
+
const a = document.createElement('a');
|
| 471 |
+
a.href = url;
|
| 472 |
+
a.download = `magicpot-commands-${Date.now()}.json`;
|
| 473 |
+
document.body.appendChild(a);
|
| 474 |
+
a.click();
|
| 475 |
+
document.body.removeChild(a);
|
| 476 |
+
URL.revokeObjectURL(url);
|
| 477 |
+
|
| 478 |
+
console.log('命令历史已导出');
|
| 479 |
+
}
|
| 480 |
+
|
| 481 |
+
// 获取命令提示
|
| 482 |
+
getCommandSuggestions(input) {
|
| 483 |
+
const suggestions = [
|
| 484 |
+
'cook cook cook pot',
|
| 485 |
+
'stop stop stop pot',
|
| 486 |
+
'apple', 'banana', 'orange', 'strawberry', 'watermelon', 'grape',
|
| 487 |
+
'pizza', 'burger', 'bread', 'rice', 'noodles', 'cake', 'cookie',
|
| 488 |
+
'cheese', 'fish', 'chicken', 'carrot', 'tomato', 'corn', 'broccoli'
|
| 489 |
+
];
|
| 490 |
+
|
| 491 |
+
if (!input) return suggestions.slice(0, 5);
|
| 492 |
+
|
| 493 |
+
const filtered = suggestions.filter(cmd =>
|
| 494 |
+
cmd.toLowerCase().includes(input.toLowerCase())
|
| 495 |
+
);
|
| 496 |
+
|
| 497 |
+
return filtered.slice(0, 8);
|
| 498 |
+
}
|
| 499 |
+
|
| 500 |
+
// 设置拖拽功能
|
| 501 |
+
setupDragFunctionality() {
|
| 502 |
+
const panel = document.getElementById('keyboardInputPanel');
|
| 503 |
+
const header = panel?.querySelector('.input-header');
|
| 504 |
+
|
| 505 |
+
if (!panel || !header) return;
|
| 506 |
+
|
| 507 |
+
// 鼠标按下开始拖拽
|
| 508 |
+
header.addEventListener('mousedown', (e) => {
|
| 509 |
+
if (!this.isActive) return; // 只有激活状态下才能拖拽
|
| 510 |
+
|
| 511 |
+
this.isDragging = true;
|
| 512 |
+
panel.classList.add('dragging');
|
| 513 |
+
|
| 514 |
+
const rect = panel.getBoundingClientRect();
|
| 515 |
+
this.dragOffset.x = e.clientX - rect.left;
|
| 516 |
+
this.dragOffset.y = e.clientY - rect.top;
|
| 517 |
+
|
| 518 |
+
// 记录当前位置
|
| 519 |
+
this.currentPosition.x = rect.left;
|
| 520 |
+
this.currentPosition.y = rect.top;
|
| 521 |
+
|
| 522 |
+
e.preventDefault();
|
| 523 |
+
});
|
| 524 |
+
|
| 525 |
+
// 全局鼠标移动事件
|
| 526 |
+
document.addEventListener('mousemove', (e) => {
|
| 527 |
+
if (!this.isDragging) return;
|
| 528 |
+
|
| 529 |
+
e.preventDefault();
|
| 530 |
+
|
| 531 |
+
// 计算新位置
|
| 532 |
+
let newX = e.clientX - this.dragOffset.x;
|
| 533 |
+
let newY = e.clientY - this.dragOffset.y;
|
| 534 |
+
|
| 535 |
+
// 边界检查
|
| 536 |
+
const rect = panel.getBoundingClientRect();
|
| 537 |
+
const maxX = window.innerWidth - rect.width;
|
| 538 |
+
const maxY = window.innerHeight - rect.height;
|
| 539 |
+
|
| 540 |
+
newX = Math.max(0, Math.min(newX, maxX));
|
| 541 |
+
newY = Math.max(0, Math.min(newY, maxY));
|
| 542 |
+
|
| 543 |
+
// 应用新位置
|
| 544 |
+
panel.style.left = newX + 'px';
|
| 545 |
+
panel.style.top = newY + 'px';
|
| 546 |
+
panel.style.right = 'auto';
|
| 547 |
+
panel.style.bottom = 'auto';
|
| 548 |
+
|
| 549 |
+
this.currentPosition.x = newX;
|
| 550 |
+
this.currentPosition.y = newY;
|
| 551 |
+
});
|
| 552 |
+
|
| 553 |
+
// 全局鼠标松开事件
|
| 554 |
+
document.addEventListener('mouseup', (e) => {
|
| 555 |
+
if (!this.isDragging) return;
|
| 556 |
+
|
| 557 |
+
this.isDragging = false;
|
| 558 |
+
panel.classList.remove('dragging');
|
| 559 |
+
|
| 560 |
+
// 保存位置到localStorage
|
| 561 |
+
this.savePosition();
|
| 562 |
+
});
|
| 563 |
+
|
| 564 |
+
// 加载保存的位置
|
| 565 |
+
this.loadPosition();
|
| 566 |
+
}
|
| 567 |
+
|
| 568 |
+
// 保存面板位置
|
| 569 |
+
savePosition() {
|
| 570 |
+
if (this.currentPosition.x !== null && this.currentPosition.y !== null) {
|
| 571 |
+
const position = {
|
| 572 |
+
x: this.currentPosition.x,
|
| 573 |
+
y: this.currentPosition.y
|
| 574 |
+
};
|
| 575 |
+
localStorage.setItem('keyboardPanelPosition', JSON.stringify(position));
|
| 576 |
+
}
|
| 577 |
+
}
|
| 578 |
+
|
| 579 |
+
// 加载保存的位置
|
| 580 |
+
loadPosition() {
|
| 581 |
+
const panel = document.getElementById('keyboardInputPanel');
|
| 582 |
+
if (!panel) return;
|
| 583 |
+
|
| 584 |
+
try {
|
| 585 |
+
const savedPosition = localStorage.getItem('keyboardPanelPosition');
|
| 586 |
+
if (savedPosition) {
|
| 587 |
+
const position = JSON.parse(savedPosition);
|
| 588 |
+
|
| 589 |
+
// 检查位置是否在屏幕范围内
|
| 590 |
+
const rect = panel.getBoundingClientRect();
|
| 591 |
+
const maxX = window.innerWidth - rect.width;
|
| 592 |
+
const maxY = window.innerHeight - rect.height;
|
| 593 |
+
|
| 594 |
+
if (position.x >= 0 && position.x <= maxX &&
|
| 595 |
+
position.y >= 0 && position.y <= maxY) {
|
| 596 |
+
|
| 597 |
+
panel.style.left = position.x + 'px';
|
| 598 |
+
panel.style.top = position.y + 'px';
|
| 599 |
+
panel.style.right = 'auto';
|
| 600 |
+
panel.style.bottom = 'auto';
|
| 601 |
+
|
| 602 |
+
this.currentPosition.x = position.x;
|
| 603 |
+
this.currentPosition.y = position.y;
|
| 604 |
+
}
|
| 605 |
+
}
|
| 606 |
+
} catch (error) {
|
| 607 |
+
console.warn('加载面板位置失败:', error);
|
| 608 |
+
}
|
| 609 |
+
}
|
| 610 |
+
|
| 611 |
+
// 重置面板位置到右下角
|
| 612 |
+
resetPosition() {
|
| 613 |
+
const panel = document.getElementById('keyboardInputPanel');
|
| 614 |
+
if (!panel) return;
|
| 615 |
+
|
| 616 |
+
panel.style.left = 'auto';
|
| 617 |
+
panel.style.top = 'auto';
|
| 618 |
+
panel.style.right = '20px';
|
| 619 |
+
panel.style.bottom = '20px';
|
| 620 |
+
|
| 621 |
+
this.currentPosition.x = null;
|
| 622 |
+
this.currentPosition.y = null;
|
| 623 |
+
|
| 624 |
+
// 清除保存的位置
|
| 625 |
+
localStorage.removeItem('keyboardPanelPosition');
|
| 626 |
+
|
| 627 |
+
console.log('面板位置已重置到右下角');
|
| 628 |
+
}
|
| 629 |
+
}
|
| 630 |
+
|
| 631 |
+
// 添加快捷键提示样式
|
| 632 |
+
const keyboardStyle = document.createElement('style');
|
| 633 |
+
keyboardStyle.textContent = `
|
| 634 |
+
.keyboard-shortcuts-hint {
|
| 635 |
+
position: absolute;
|
| 636 |
+
bottom: 5px;
|
| 637 |
+
left: 50%;
|
| 638 |
+
transform: translateX(-50%);
|
| 639 |
+
background: rgba(0, 0, 0, 0.8);
|
| 640 |
+
color: white;
|
| 641 |
+
padding: 5px 10px;
|
| 642 |
+
border-radius: 10px;
|
| 643 |
+
font-size: 0.7em;
|
| 644 |
+
white-space: nowrap;
|
| 645 |
+
opacity: 0;
|
| 646 |
+
transition: opacity 0.3s ease;
|
| 647 |
+
pointer-events: none;
|
| 648 |
+
font-family: 'Comic Neue', cursive;
|
| 649 |
+
}
|
| 650 |
+
|
| 651 |
+
.keyboard-input-panel:hover .keyboard-shortcuts-hint {
|
| 652 |
+
opacity: 1;
|
| 653 |
+
}
|
| 654 |
+
|
| 655 |
+
.command-input:focus + .keyboard-shortcuts-hint {
|
| 656 |
+
opacity: 1;
|
| 657 |
+
}
|
| 658 |
+
|
| 659 |
+
@keyframes activationPulse {
|
| 660 |
+
0% {
|
| 661 |
+
opacity: 0;
|
| 662 |
+
transform: translate(-50%, -50%) scale(0.8);
|
| 663 |
+
}
|
| 664 |
+
50% {
|
| 665 |
+
transform: translate(-50%, -50%) scale(1.1);
|
| 666 |
+
}
|
| 667 |
+
100% {
|
| 668 |
+
opacity: 1;
|
| 669 |
+
transform: translate(-50%, -50%) scale(1);
|
| 670 |
+
}
|
| 671 |
+
}
|
| 672 |
+
|
| 673 |
+
@keyframes activationFadeOut {
|
| 674 |
+
from {
|
| 675 |
+
opacity: 1;
|
| 676 |
+
transform: translate(-50%, -50%) scale(1);
|
| 677 |
+
}
|
| 678 |
+
to {
|
| 679 |
+
opacity: 0;
|
| 680 |
+
transform: translate(-50%, -50%) scale(0.9);
|
| 681 |
+
}
|
| 682 |
+
}
|
| 683 |
+
`;
|
| 684 |
+
document.head.appendChild(keyboardStyle);
|
js/particles.js
CHANGED
|
@@ -1,528 +1,528 @@
|
|
| 1 |
-
// 粒子系统类
|
| 2 |
-
class ParticleSystem {
|
| 3 |
-
constructor() {
|
| 4 |
-
this.particles = [];
|
| 5 |
-
this.maxParticles = 150; // 降低最大粒子数
|
| 6 |
-
this.gravity = 0.5;
|
| 7 |
-
this.bounce = 0.6;
|
| 8 |
-
this.friction = 0.98;
|
| 9 |
-
this.lastCleanupTime = 0;
|
| 10 |
-
}
|
| 11 |
-
|
| 12 |
-
update(deltaTime) {
|
| 13 |
-
const dt = deltaTime * 0.001; // 转换为秒
|
| 14 |
-
|
| 15 |
-
for (let i = this.particles.length - 1; i >= 0; i--) {
|
| 16 |
-
const particle = this.particles[i];
|
| 17 |
-
this.updateParticle(particle, dt);
|
| 18 |
-
|
| 19 |
-
// 移除生命周期结束的粒子
|
| 20 |
-
if (particle.life <= 0) {
|
| 21 |
-
this.particles.splice(i, 1);
|
| 22 |
-
}
|
| 23 |
-
}
|
| 24 |
-
}
|
| 25 |
-
|
| 26 |
-
updateParticle(particle, dt) {
|
| 27 |
-
// 更新位置
|
| 28 |
-
particle.x += particle.vx * dt;
|
| 29 |
-
particle.y += particle.vy * dt;
|
| 30 |
-
|
| 31 |
-
// 应用重力
|
| 32 |
-
particle.vy += this.gravity * dt * 60; // 60fps基准
|
| 33 |
-
|
| 34 |
-
// 应用摩擦力
|
| 35 |
-
particle.vx *= this.friction;
|
| 36 |
-
|
| 37 |
-
// 边界碰撞检测
|
| 38 |
-
this.handleBoundaryCollision(particle);
|
| 39 |
-
|
| 40 |
-
// 更新生命周期
|
| 41 |
-
particle.life -= dt / particle.maxLife;
|
| 42 |
-
particle.opacity = Math.max(0, particle.life);
|
| 43 |
-
|
| 44 |
-
// 更新大小(某些粒子会变化)
|
| 45 |
-
if (particle.sizeChange) {
|
| 46 |
-
particle.size += particle.sizeChange * dt;
|
| 47 |
-
particle.size = Math.max(1, particle.size);
|
| 48 |
-
}
|
| 49 |
-
|
| 50 |
-
// 更新旋转
|
| 51 |
-
if (particle.rotation !== undefined) {
|
| 52 |
-
particle.rotation += particle.rotationSpeed * dt;
|
| 53 |
-
}
|
| 54 |
-
}
|
| 55 |
-
|
| 56 |
-
handleBoundaryCollision(particle) {
|
| 57 |
-
const canvas = document.getElementById('gameCanvas');
|
| 58 |
-
const canvasWidth = canvas.width;
|
| 59 |
-
const canvasHeight = canvas.height;
|
| 60 |
-
|
| 61 |
-
// 底部碰撞
|
| 62 |
-
if (particle.y + particle.size > canvasHeight) {
|
| 63 |
-
particle.y = canvasHeight - particle.size;
|
| 64 |
-
particle.vy *= -this.bounce;
|
| 65 |
-
|
| 66 |
-
// 减少水平速度
|
| 67 |
-
particle.vx *= 0.8;
|
| 68 |
-
|
| 69 |
-
// 如果速度太小,停止弹跳
|
| 70 |
-
if (Math.abs(particle.vy) < 10) {
|
| 71 |
-
particle.vy = 0;
|
| 72 |
-
particle.isGrounded = true;
|
| 73 |
-
}
|
| 74 |
-
}
|
| 75 |
-
|
| 76 |
-
// 左右边界碰撞
|
| 77 |
-
if (particle.x - particle.size < 0) {
|
| 78 |
-
particle.x = particle.size;
|
| 79 |
-
particle.vx *= -this.bounce;
|
| 80 |
-
} else if (particle.x + particle.size > canvasWidth) {
|
| 81 |
-
particle.x = canvasWidth - particle.size;
|
| 82 |
-
particle.vx *= -this.bounce;
|
| 83 |
-
}
|
| 84 |
-
|
| 85 |
-
// 顶部边界(防止粒子飞出屏幕)
|
| 86 |
-
if (particle.y - particle.size < 0) {
|
| 87 |
-
particle.y = particle.size;
|
| 88 |
-
particle.vy *= -this.bounce;
|
| 89 |
-
}
|
| 90 |
-
}
|
| 91 |
-
|
| 92 |
-
createFoodParticle(x, y, foodType) {
|
| 93 |
-
if (this.particles.length >= this.maxParticles) {
|
| 94 |
-
// 移除最老的粒子
|
| 95 |
-
this.particles.shift();
|
| 96 |
-
}
|
| 97 |
-
|
| 98 |
-
const particle = {
|
| 99 |
-
x: x + (Math.random() - 0.5) * 20,
|
| 100 |
-
y: y + (Math.random() - 0.5) * 10,
|
| 101 |
-
vx: (Math.random() - 0.5) * 200,
|
| 102 |
-
vy: -Math.random() * 150 - 50,
|
| 103 |
-
size: Math.random() * 15 + 8,
|
| 104 |
-
color: this.getFoodColor(foodType),
|
| 105 |
-
emoji: this.getFoodEmoji(foodType),
|
| 106 |
-
life: 1,
|
| 107 |
-
maxLife: Math.random() * 3 + 2,
|
| 108 |
-
opacity: 1,
|
| 109 |
-
rotation: Math.random() * Math.PI * 2,
|
| 110 |
-
rotationSpeed: (Math.random() - 0.5) * 5,
|
| 111 |
-
type: 'food',
|
| 112 |
-
foodType: foodType,
|
| 113 |
-
isGrounded: false,
|
| 114 |
-
bounceCount: 0,
|
| 115 |
-
maxBounces: Math.floor(Math.random() * 3) + 2
|
| 116 |
-
};
|
| 117 |
-
|
| 118 |
-
this.particles.push(particle);
|
| 119 |
-
return particle;
|
| 120 |
-
}
|
| 121 |
-
|
| 122 |
-
createExplosionParticles(x, y, count = 10, color = '#FFD700') {
|
| 123 |
-
for (let i = 0; i < count; i++) {
|
| 124 |
-
const angle = (i / count) * Math.PI * 2;
|
| 125 |
-
const speed = Math.random() * 100 + 50;
|
| 126 |
-
|
| 127 |
-
const particle = {
|
| 128 |
-
x: x,
|
| 129 |
-
y: y,
|
| 130 |
-
vx: Math.cos(angle) * speed,
|
| 131 |
-
vy: Math.sin(angle) * speed,
|
| 132 |
-
size: Math.random() * 8 + 4,
|
| 133 |
-
color: color,
|
| 134 |
-
life: 1,
|
| 135 |
-
maxLife: Math.random() * 1 + 0.5,
|
| 136 |
-
opacity: 1,
|
| 137 |
-
type: 'explosion',
|
| 138 |
-
sizeChange: -5 // 粒子逐渐变小
|
| 139 |
-
};
|
| 140 |
-
|
| 141 |
-
this.particles.push(particle);
|
| 142 |
-
}
|
| 143 |
-
}
|
| 144 |
-
|
| 145 |
-
createSparkleParticles(x, y, count = 5) {
|
| 146 |
-
for (let i = 0; i < count; i++) {
|
| 147 |
-
const particle = {
|
| 148 |
-
x: x + (Math.random() - 0.5) * 50,
|
| 149 |
-
y: y + (Math.random() - 0.5) * 50,
|
| 150 |
-
vx: (Math.random() - 0.5) * 30,
|
| 151 |
-
vy: -Math.random() * 30 - 10,
|
| 152 |
-
size: Math.random() * 4 + 2,
|
| 153 |
-
color: Math.random() < 0.5 ? '#FFD700' : '#FF69B4',
|
| 154 |
-
life: 1,
|
| 155 |
-
maxLife: Math.random() * 1.5 + 0.5,
|
| 156 |
-
opacity: 1,
|
| 157 |
-
type: 'sparkle',
|
| 158 |
-
twinkle: true
|
| 159 |
-
};
|
| 160 |
-
|
| 161 |
-
this.particles.push(particle);
|
| 162 |
-
}
|
| 163 |
-
}
|
| 164 |
-
|
| 165 |
-
render(ctx) {
|
| 166 |
-
this.particles.forEach(particle => {
|
| 167 |
-
this.renderParticle(ctx, particle);
|
| 168 |
-
});
|
| 169 |
-
}
|
| 170 |
-
|
| 171 |
-
renderParticle(ctx, particle) {
|
| 172 |
-
ctx.save();
|
| 173 |
-
ctx.globalAlpha = particle.opacity;
|
| 174 |
-
|
| 175 |
-
// 移动到粒子位置
|
| 176 |
-
ctx.translate(particle.x, particle.y);
|
| 177 |
-
|
| 178 |
-
// 应用旋转
|
| 179 |
-
if (particle.rotation !== undefined) {
|
| 180 |
-
ctx.rotate(particle.rotation);
|
| 181 |
-
}
|
| 182 |
-
|
| 183 |
-
switch (particle.type) {
|
| 184 |
-
case 'food':
|
| 185 |
-
this.renderFoodParticle(ctx, particle);
|
| 186 |
-
break;
|
| 187 |
-
case 'explosion':
|
| 188 |
-
this.renderExplosionParticle(ctx, particle);
|
| 189 |
-
break;
|
| 190 |
-
case 'sparkle':
|
| 191 |
-
this.renderSparkleParticle(ctx, particle);
|
| 192 |
-
break;
|
| 193 |
-
default:
|
| 194 |
-
this.renderDefaultParticle(ctx, particle);
|
| 195 |
-
break;
|
| 196 |
-
}
|
| 197 |
-
|
| 198 |
-
ctx.restore();
|
| 199 |
-
}
|
| 200 |
-
|
| 201 |
-
renderFoodParticle(ctx, particle) {
|
| 202 |
-
// 绘制食物表情符号
|
| 203 |
-
if (particle.emoji) {
|
| 204 |
-
ctx.font = `${particle.size}px Arial`;
|
| 205 |
-
ctx.textAlign = 'center';
|
| 206 |
-
ctx.textBaseline = 'middle';
|
| 207 |
-
ctx.fillText(particle.emoji, 0, 0);
|
| 208 |
-
} else {
|
| 209 |
-
// 备用:绘制彩色圆形
|
| 210 |
-
ctx.fillStyle = particle.color;
|
| 211 |
-
ctx.beginPath();
|
| 212 |
-
ctx.arc(0, 0, particle.size / 2, 0, Math.PI * 2);
|
| 213 |
-
ctx.fill();
|
| 214 |
-
|
| 215 |
-
// 添加高光
|
| 216 |
-
ctx.fillStyle = 'rgba(255, 255, 255, 0.3)';
|
| 217 |
-
ctx.beginPath();
|
| 218 |
-
ctx.arc(-particle.size / 6, -particle.size / 6, particle.size / 4, 0, Math.PI * 2);
|
| 219 |
-
ctx.fill();
|
| 220 |
-
}
|
| 221 |
-
}
|
| 222 |
-
|
| 223 |
-
renderExplosionParticle(ctx, particle) {
|
| 224 |
-
ctx.fillStyle = particle.color;
|
| 225 |
-
ctx.shadowBlur = 10;
|
| 226 |
-
ctx.shadowColor = particle.color;
|
| 227 |
-
|
| 228 |
-
ctx.beginPath();
|
| 229 |
-
ctx.arc(0, 0, particle.size, 0, Math.PI * 2);
|
| 230 |
-
ctx.fill();
|
| 231 |
-
}
|
| 232 |
-
|
| 233 |
-
renderSparkleParticle(ctx, particle) {
|
| 234 |
-
ctx.fillStyle = particle.color;
|
| 235 |
-
ctx.shadowBlur = 8;
|
| 236 |
-
ctx.shadowColor = particle.color;
|
| 237 |
-
|
| 238 |
-
// 绘制星形
|
| 239 |
-
const spikes = 4;
|
| 240 |
-
const outerRadius = particle.size;
|
| 241 |
-
const innerRadius = particle.size * 0.4;
|
| 242 |
-
|
| 243 |
-
ctx.beginPath();
|
| 244 |
-
for (let i = 0; i < spikes * 2; i++) {
|
| 245 |
-
const angle = (i / (spikes * 2)) * Math.PI * 2;
|
| 246 |
-
const radius = i % 2 === 0 ? outerRadius : innerRadius;
|
| 247 |
-
const x = Math.cos(angle) * radius;
|
| 248 |
-
const y = Math.sin(angle) * radius;
|
| 249 |
-
|
| 250 |
-
if (i === 0) {
|
| 251 |
-
ctx.moveTo(x, y);
|
| 252 |
-
} else {
|
| 253 |
-
ctx.lineTo(x, y);
|
| 254 |
-
}
|
| 255 |
-
}
|
| 256 |
-
ctx.closePath();
|
| 257 |
-
ctx.fill();
|
| 258 |
-
|
| 259 |
-
// 闪烁效果
|
| 260 |
-
if (particle.twinkle) {
|
| 261 |
-
const twinkleAlpha = Math.sin(Date.now() * 0.01) * 0.5 + 0.5;
|
| 262 |
-
ctx.globalAlpha *= twinkleAlpha;
|
| 263 |
-
}
|
| 264 |
-
}
|
| 265 |
-
|
| 266 |
-
renderDefaultParticle(ctx, particle) {
|
| 267 |
-
ctx.fillStyle = particle.color || '#FFD700';
|
| 268 |
-
ctx.beginPath();
|
| 269 |
-
ctx.arc(0, 0, particle.size, 0, Math.PI * 2);
|
| 270 |
-
ctx.fill();
|
| 271 |
-
}
|
| 272 |
-
|
| 273 |
-
getFoodColor(foodType) {
|
| 274 |
-
const colorMap = {
|
| 275 |
-
'apple': '#FF6B6B',
|
| 276 |
-
'banana': '#FFE66D',
|
| 277 |
-
'orange': '#FF8E53',
|
| 278 |
-
'strawberry': '#FF6B9D',
|
| 279 |
-
'watermelon': '#C44569',
|
| 280 |
-
'grape': '#9B59B6',
|
| 281 |
-
'pizza': '#F39C12',
|
| 282 |
-
'burger': '#D35400',
|
| 283 |
-
'cake': '#F8C471',
|
| 284 |
-
'cookie': '#D2691E',
|
| 285 |
-
'bread': '#DEB887',
|
| 286 |
-
'cheese': '#F1C40F',
|
| 287 |
-
'fish': '#3498DB',
|
| 288 |
-
'chicken': '#E67E22',
|
| 289 |
-
'rice': '#ECF0F1',
|
| 290 |
-
'noodles': '#F4D03F'
|
| 291 |
-
};
|
| 292 |
-
|
| 293 |
-
return colorMap[foodType] || '#FFD700';
|
| 294 |
-
}
|
| 295 |
-
|
| 296 |
-
getFoodEmoji(foodType) {
|
| 297 |
-
const emojiMap = {
|
| 298 |
-
'apple': '🍎',
|
| 299 |
-
'banana': '🍌',
|
| 300 |
-
'orange': '🍊',
|
| 301 |
-
'strawberry': '🍓',
|
| 302 |
-
'watermelon': '🍉',
|
| 303 |
-
'grape': '🍇',
|
| 304 |
-
'pizza': '🍕',
|
| 305 |
-
'burger': '🍔',
|
| 306 |
-
'cake': '🍰',
|
| 307 |
-
'cookie': '🍪',
|
| 308 |
-
'bread': '🍞',
|
| 309 |
-
'cheese': '🧀',
|
| 310 |
-
'fish': '🐟',
|
| 311 |
-
'chicken': '🍗',
|
| 312 |
-
'rice': '🍚',
|
| 313 |
-
'noodles': '🍜',
|
| 314 |
-
'carrot': '🥕',
|
| 315 |
-
'tomato': '🍅',
|
| 316 |
-
'corn': '🌽',
|
| 317 |
-
'broccoli': '🥦',
|
| 318 |
-
'potato': '🥔',
|
| 319 |
-
'onion': '🧅'
|
| 320 |
-
};
|
| 321 |
-
|
| 322 |
-
return emojiMap[foodType] || '🍽️';
|
| 323 |
-
}
|
| 324 |
-
|
| 325 |
-
// 清理所有粒子
|
| 326 |
-
clear() {
|
| 327 |
-
this.particles = [];
|
| 328 |
-
}
|
| 329 |
-
|
| 330 |
-
// 获取指定类型的粒子数量
|
| 331 |
-
getParticleCount(type = null) {
|
| 332 |
-
if (type) {
|
| 333 |
-
return this.particles.filter(p => p.type === type).length;
|
| 334 |
-
}
|
| 335 |
-
return this.particles.length;
|
| 336 |
-
}
|
| 337 |
-
|
| 338 |
-
// 移除指定类型的粒子
|
| 339 |
-
removeParticlesByType(type) {
|
| 340 |
-
this.particles = this.particles.filter(p => p.type !== type);
|
| 341 |
-
}
|
| 342 |
-
|
| 343 |
-
// 获取地面上的食物粒子数量
|
| 344 |
-
getGroundedFoodCount() {
|
| 345 |
-
return this.particles.filter(p => p.type === 'food' && p.isGrounded).length;
|
| 346 |
-
}
|
| 347 |
-
|
| 348 |
-
// 在指定区域内创建粒子爆炸效果
|
| 349 |
-
createAreaExplosion(x, y, radius, particleCount = 20) {
|
| 350 |
-
for (let i = 0; i < particleCount; i++) {
|
| 351 |
-
const angle = Math.random() * Math.PI * 2;
|
| 352 |
-
const distance = Math.random() * radius;
|
| 353 |
-
const particleX = x + Math.cos(angle) * distance;
|
| 354 |
-
const particleY = y + Math.sin(angle) * distance;
|
| 355 |
-
|
| 356 |
-
this.createExplosionParticles(particleX, particleY, 3);
|
| 357 |
-
}
|
| 358 |
-
}
|
| 359 |
-
|
| 360 |
-
// 清理无效粒子
|
| 361 |
-
cleanupInvalidParticles() {
|
| 362 |
-
const beforeCount = this.particles.length;
|
| 363 |
-
|
| 364 |
-
// 移除生命周期结束的粒子
|
| 365 |
-
this.particles = this.particles.filter(particle => particle.life > 0);
|
| 366 |
-
|
| 367 |
-
// 移除超出边界太远的粒子
|
| 368 |
-
const canvas = document.getElementById('gameCanvas');
|
| 369 |
-
if (canvas) {
|
| 370 |
-
const margin = 100; // 边界外100像素
|
| 371 |
-
this.particles = this.particles.filter(particle => {
|
| 372 |
-
return particle.x > -margin &&
|
| 373 |
-
particle.x < canvas.width + margin &&
|
| 374 |
-
particle.y > -margin &&
|
| 375 |
-
particle.y < canvas.height + margin;
|
| 376 |
-
});
|
| 377 |
-
}
|
| 378 |
-
|
| 379 |
-
const afterCount = this.particles.length;
|
| 380 |
-
return beforeCount - afterCount; // 返回清理的粒子数量
|
| 381 |
-
}
|
| 382 |
-
|
| 383 |
-
// 优化粒子更新
|
| 384 |
-
updateParticle(particle, dt) {
|
| 385 |
-
// 更新生命周期
|
| 386 |
-
particle.life -= dt / particle.maxLife;
|
| 387 |
-
if (particle.life <= 0) {
|
| 388 |
-
return; // 粒子死亡,将在下次清理时移除
|
| 389 |
-
}
|
| 390 |
-
|
| 391 |
-
// 更新位置
|
| 392 |
-
particle.x += particle.vx * dt;
|
| 393 |
-
particle.y += particle.vy * dt;
|
| 394 |
-
|
| 395 |
-
// 应用重力
|
| 396 |
-
particle.vy += this.gravity * dt * 60; // 60fps基准
|
| 397 |
-
|
| 398 |
-
// 应用摩擦力
|
| 399 |
-
particle.vx *= this.friction;
|
| 400 |
-
|
| 401 |
-
// 边界碰撞检测
|
| 402 |
-
this.handleBoundaryCollision(particle);
|
| 403 |
-
|
| 404 |
-
// 更新透明度
|
| 405 |
-
particle.opacity = Math.max(0, particle.life);
|
| 406 |
-
|
| 407 |
-
// 更新大小(某些粒子会变化)
|
| 408 |
-
if (particle.sizeChange) {
|
| 409 |
-
particle.size += particle.sizeChange * dt;
|
| 410 |
-
particle.size = Math.max(1, particle.size);
|
| 411 |
-
}
|
| 412 |
-
|
| 413 |
-
// 更新旋转
|
| 414 |
-
if (particle.rotation !== undefined) {
|
| 415 |
-
particle.rotation += particle.rotationSpeed * dt;
|
| 416 |
-
}
|
| 417 |
-
|
| 418 |
-
// 更新生命时间(用于清理)
|
| 419 |
-
particle.lifeTime = (particle.lifeTime || 0) + dt;
|
| 420 |
-
}
|
| 421 |
-
|
| 422 |
-
// 获取特定状态的粒子统计
|
| 423 |
-
getParticleStats() {
|
| 424 |
-
const stats = {
|
| 425 |
-
total: this.particles.length,
|
| 426 |
-
food: 0,
|
| 427 |
-
explosion: 0,
|
| 428 |
-
sparkle: 0,
|
| 429 |
-
grounded: 0,
|
| 430 |
-
moving: 0
|
| 431 |
-
};
|
| 432 |
-
|
| 433 |
-
this.particles.forEach(particle => {
|
| 434 |
-
if (particle.type === 'food') {
|
| 435 |
-
stats.food++;
|
| 436 |
-
if (particle.isGrounded) stats.grounded++;
|
| 437 |
-
else stats.moving++;
|
| 438 |
-
} else if (particle.type === 'explosion') {
|
| 439 |
-
stats.explosion++;
|
| 440 |
-
} else if (particle.type === 'sparkle') {
|
| 441 |
-
stats.sparkle++;
|
| 442 |
-
}
|
| 443 |
-
});
|
| 444 |
-
|
| 445 |
-
return stats;
|
| 446 |
-
}
|
| 447 |
-
|
| 448 |
-
// 强制清理最老的粒子
|
| 449 |
-
forceCleanupOldest(count) {
|
| 450 |
-
if (count <= 0) return 0;
|
| 451 |
-
|
| 452 |
-
// 按生命时间排序,移除最老的
|
| 453 |
-
const sortedParticles = this.particles
|
| 454 |
-
.map((particle, index) => ({ particle, index, lifeTime: particle.lifeTime || 0 }))
|
| 455 |
-
.sort((a, b) => b.lifeTime - a.lifeTime);
|
| 456 |
-
|
| 457 |
-
const toRemove = Math.min(count, sortedParticles.length);
|
| 458 |
-
const indicesToRemove = sortedParticles
|
| 459 |
-
.slice(0, toRemove)
|
| 460 |
-
.map(item => item.index)
|
| 461 |
-
.sort((a, b) => b - a); // 从后往前删除
|
| 462 |
-
|
| 463 |
-
indicesToRemove.forEach(index => {
|
| 464 |
-
this.particles.splice(index, 1);
|
| 465 |
-
});
|
| 466 |
-
|
| 467 |
-
return toRemove;
|
| 468 |
-
}
|
| 469 |
-
}
|
| 470 |
-
|
| 471 |
-
// 食物粒子特殊效果类
|
| 472 |
-
class FoodParticleEffects {
|
| 473 |
-
static createBurstEffect(particleSystem, x, y, foodType, count = 15) {
|
| 474 |
-
for (let i = 0; i < count; i++) {
|
| 475 |
-
const angle = (i / count) * Math.PI * 2;
|
| 476 |
-
const speed = Math.random() * 80 + 40;
|
| 477 |
-
|
| 478 |
-
const particle = {
|
| 479 |
-
x: x,
|
| 480 |
-
y: y,
|
| 481 |
-
vx: Math.cos(angle) * speed,
|
| 482 |
-
vy: Math.sin(angle) * speed - 30,
|
| 483 |
-
size: Math.random() * 12 + 6,
|
| 484 |
-
color: particleSystem.getFoodColor(foodType),
|
| 485 |
-
emoji: particleSystem.getFoodEmoji(foodType),
|
| 486 |
-
life: 1,
|
| 487 |
-
maxLife: Math.random() * 2 + 1,
|
| 488 |
-
opacity: 1,
|
| 489 |
-
rotation: Math.random() * Math.PI * 2,
|
| 490 |
-
rotationSpeed: (Math.random() - 0.5) * 8,
|
| 491 |
-
type: 'food',
|
| 492 |
-
foodType: foodType,
|
| 493 |
-
isGrounded: false
|
| 494 |
-
};
|
| 495 |
-
|
| 496 |
-
particleSystem.particles.push(particle);
|
| 497 |
-
}
|
| 498 |
-
}
|
| 499 |
-
|
| 500 |
-
static createFountainEffect(particleSystem, x, y, foodType) {
|
| 501 |
-
const particleCount = 8;
|
| 502 |
-
|
| 503 |
-
for (let i = 0; i < particleCount; i++) {
|
| 504 |
-
const angle = -Math.PI / 2 + (Math.random() - 0.5) * Math.PI / 3;
|
| 505 |
-
const speed = Math.random() * 120 + 80;
|
| 506 |
-
|
| 507 |
-
const particle = {
|
| 508 |
-
x: x + (Math.random() - 0.5) * 30,
|
| 509 |
-
y: y,
|
| 510 |
-
vx: Math.cos(angle) * speed,
|
| 511 |
-
vy: Math.sin(angle) * speed,
|
| 512 |
-
size: Math.random() * 18 + 10,
|
| 513 |
-
color: particleSystem.getFoodColor(foodType),
|
| 514 |
-
emoji: particleSystem.getFoodEmoji(foodType),
|
| 515 |
-
life: 1,
|
| 516 |
-
maxLife: Math.random() * 4 + 2,
|
| 517 |
-
opacity: 1,
|
| 518 |
-
rotation: Math.random() * Math.PI * 2,
|
| 519 |
-
rotationSpeed: (Math.random() - 0.5) * 6,
|
| 520 |
-
type: 'food',
|
| 521 |
-
foodType: foodType,
|
| 522 |
-
isGrounded: false
|
| 523 |
-
};
|
| 524 |
-
|
| 525 |
-
particleSystem.particles.push(particle);
|
| 526 |
-
}
|
| 527 |
-
}
|
| 528 |
-
}
|
|
|
|
| 1 |
+
// 粒子系统类
|
| 2 |
+
class ParticleSystem {
|
| 3 |
+
constructor() {
|
| 4 |
+
this.particles = [];
|
| 5 |
+
this.maxParticles = 150; // 降低最大粒子数
|
| 6 |
+
this.gravity = 0.5;
|
| 7 |
+
this.bounce = 0.6;
|
| 8 |
+
this.friction = 0.98;
|
| 9 |
+
this.lastCleanupTime = 0;
|
| 10 |
+
}
|
| 11 |
+
|
| 12 |
+
update(deltaTime) {
|
| 13 |
+
const dt = deltaTime * 0.001; // 转换为秒
|
| 14 |
+
|
| 15 |
+
for (let i = this.particles.length - 1; i >= 0; i--) {
|
| 16 |
+
const particle = this.particles[i];
|
| 17 |
+
this.updateParticle(particle, dt);
|
| 18 |
+
|
| 19 |
+
// 移除生命周期结束的粒子
|
| 20 |
+
if (particle.life <= 0) {
|
| 21 |
+
this.particles.splice(i, 1);
|
| 22 |
+
}
|
| 23 |
+
}
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
updateParticle(particle, dt) {
|
| 27 |
+
// 更新位置
|
| 28 |
+
particle.x += particle.vx * dt;
|
| 29 |
+
particle.y += particle.vy * dt;
|
| 30 |
+
|
| 31 |
+
// 应用重力
|
| 32 |
+
particle.vy += this.gravity * dt * 60; // 60fps基准
|
| 33 |
+
|
| 34 |
+
// 应用摩擦力
|
| 35 |
+
particle.vx *= this.friction;
|
| 36 |
+
|
| 37 |
+
// 边界碰撞检测
|
| 38 |
+
this.handleBoundaryCollision(particle);
|
| 39 |
+
|
| 40 |
+
// 更新生命周期
|
| 41 |
+
particle.life -= dt / particle.maxLife;
|
| 42 |
+
particle.opacity = Math.max(0, particle.life);
|
| 43 |
+
|
| 44 |
+
// 更新大小(某些粒子会变化)
|
| 45 |
+
if (particle.sizeChange) {
|
| 46 |
+
particle.size += particle.sizeChange * dt;
|
| 47 |
+
particle.size = Math.max(1, particle.size);
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
// 更新旋转
|
| 51 |
+
if (particle.rotation !== undefined) {
|
| 52 |
+
particle.rotation += particle.rotationSpeed * dt;
|
| 53 |
+
}
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
handleBoundaryCollision(particle) {
|
| 57 |
+
const canvas = document.getElementById('gameCanvas');
|
| 58 |
+
const canvasWidth = canvas.width;
|
| 59 |
+
const canvasHeight = canvas.height;
|
| 60 |
+
|
| 61 |
+
// 底部碰撞
|
| 62 |
+
if (particle.y + particle.size > canvasHeight) {
|
| 63 |
+
particle.y = canvasHeight - particle.size;
|
| 64 |
+
particle.vy *= -this.bounce;
|
| 65 |
+
|
| 66 |
+
// 减少水平速度
|
| 67 |
+
particle.vx *= 0.8;
|
| 68 |
+
|
| 69 |
+
// 如果速度太小,停止弹跳
|
| 70 |
+
if (Math.abs(particle.vy) < 10) {
|
| 71 |
+
particle.vy = 0;
|
| 72 |
+
particle.isGrounded = true;
|
| 73 |
+
}
|
| 74 |
+
}
|
| 75 |
+
|
| 76 |
+
// 左右边界碰撞
|
| 77 |
+
if (particle.x - particle.size < 0) {
|
| 78 |
+
particle.x = particle.size;
|
| 79 |
+
particle.vx *= -this.bounce;
|
| 80 |
+
} else if (particle.x + particle.size > canvasWidth) {
|
| 81 |
+
particle.x = canvasWidth - particle.size;
|
| 82 |
+
particle.vx *= -this.bounce;
|
| 83 |
+
}
|
| 84 |
+
|
| 85 |
+
// 顶部边界(防止粒子飞出屏幕)
|
| 86 |
+
if (particle.y - particle.size < 0) {
|
| 87 |
+
particle.y = particle.size;
|
| 88 |
+
particle.vy *= -this.bounce;
|
| 89 |
+
}
|
| 90 |
+
}
|
| 91 |
+
|
| 92 |
+
createFoodParticle(x, y, foodType) {
|
| 93 |
+
if (this.particles.length >= this.maxParticles) {
|
| 94 |
+
// 移除最老的粒子
|
| 95 |
+
this.particles.shift();
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
const particle = {
|
| 99 |
+
x: x + (Math.random() - 0.5) * 20,
|
| 100 |
+
y: y + (Math.random() - 0.5) * 10,
|
| 101 |
+
vx: (Math.random() - 0.5) * 200,
|
| 102 |
+
vy: -Math.random() * 150 - 50,
|
| 103 |
+
size: Math.random() * 15 + 8,
|
| 104 |
+
color: this.getFoodColor(foodType),
|
| 105 |
+
emoji: this.getFoodEmoji(foodType),
|
| 106 |
+
life: 1,
|
| 107 |
+
maxLife: Math.random() * 3 + 2,
|
| 108 |
+
opacity: 1,
|
| 109 |
+
rotation: Math.random() * Math.PI * 2,
|
| 110 |
+
rotationSpeed: (Math.random() - 0.5) * 5,
|
| 111 |
+
type: 'food',
|
| 112 |
+
foodType: foodType,
|
| 113 |
+
isGrounded: false,
|
| 114 |
+
bounceCount: 0,
|
| 115 |
+
maxBounces: Math.floor(Math.random() * 3) + 2
|
| 116 |
+
};
|
| 117 |
+
|
| 118 |
+
this.particles.push(particle);
|
| 119 |
+
return particle;
|
| 120 |
+
}
|
| 121 |
+
|
| 122 |
+
createExplosionParticles(x, y, count = 10, color = '#FFD700') {
|
| 123 |
+
for (let i = 0; i < count; i++) {
|
| 124 |
+
const angle = (i / count) * Math.PI * 2;
|
| 125 |
+
const speed = Math.random() * 100 + 50;
|
| 126 |
+
|
| 127 |
+
const particle = {
|
| 128 |
+
x: x,
|
| 129 |
+
y: y,
|
| 130 |
+
vx: Math.cos(angle) * speed,
|
| 131 |
+
vy: Math.sin(angle) * speed,
|
| 132 |
+
size: Math.random() * 8 + 4,
|
| 133 |
+
color: color,
|
| 134 |
+
life: 1,
|
| 135 |
+
maxLife: Math.random() * 1 + 0.5,
|
| 136 |
+
opacity: 1,
|
| 137 |
+
type: 'explosion',
|
| 138 |
+
sizeChange: -5 // 粒子逐渐变小
|
| 139 |
+
};
|
| 140 |
+
|
| 141 |
+
this.particles.push(particle);
|
| 142 |
+
}
|
| 143 |
+
}
|
| 144 |
+
|
| 145 |
+
createSparkleParticles(x, y, count = 5) {
|
| 146 |
+
for (let i = 0; i < count; i++) {
|
| 147 |
+
const particle = {
|
| 148 |
+
x: x + (Math.random() - 0.5) * 50,
|
| 149 |
+
y: y + (Math.random() - 0.5) * 50,
|
| 150 |
+
vx: (Math.random() - 0.5) * 30,
|
| 151 |
+
vy: -Math.random() * 30 - 10,
|
| 152 |
+
size: Math.random() * 4 + 2,
|
| 153 |
+
color: Math.random() < 0.5 ? '#FFD700' : '#FF69B4',
|
| 154 |
+
life: 1,
|
| 155 |
+
maxLife: Math.random() * 1.5 + 0.5,
|
| 156 |
+
opacity: 1,
|
| 157 |
+
type: 'sparkle',
|
| 158 |
+
twinkle: true
|
| 159 |
+
};
|
| 160 |
+
|
| 161 |
+
this.particles.push(particle);
|
| 162 |
+
}
|
| 163 |
+
}
|
| 164 |
+
|
| 165 |
+
render(ctx) {
|
| 166 |
+
this.particles.forEach(particle => {
|
| 167 |
+
this.renderParticle(ctx, particle);
|
| 168 |
+
});
|
| 169 |
+
}
|
| 170 |
+
|
| 171 |
+
renderParticle(ctx, particle) {
|
| 172 |
+
ctx.save();
|
| 173 |
+
ctx.globalAlpha = particle.opacity;
|
| 174 |
+
|
| 175 |
+
// 移动到粒子位置
|
| 176 |
+
ctx.translate(particle.x, particle.y);
|
| 177 |
+
|
| 178 |
+
// 应用旋转
|
| 179 |
+
if (particle.rotation !== undefined) {
|
| 180 |
+
ctx.rotate(particle.rotation);
|
| 181 |
+
}
|
| 182 |
+
|
| 183 |
+
switch (particle.type) {
|
| 184 |
+
case 'food':
|
| 185 |
+
this.renderFoodParticle(ctx, particle);
|
| 186 |
+
break;
|
| 187 |
+
case 'explosion':
|
| 188 |
+
this.renderExplosionParticle(ctx, particle);
|
| 189 |
+
break;
|
| 190 |
+
case 'sparkle':
|
| 191 |
+
this.renderSparkleParticle(ctx, particle);
|
| 192 |
+
break;
|
| 193 |
+
default:
|
| 194 |
+
this.renderDefaultParticle(ctx, particle);
|
| 195 |
+
break;
|
| 196 |
+
}
|
| 197 |
+
|
| 198 |
+
ctx.restore();
|
| 199 |
+
}
|
| 200 |
+
|
| 201 |
+
renderFoodParticle(ctx, particle) {
|
| 202 |
+
// 绘制食物表情符号
|
| 203 |
+
if (particle.emoji) {
|
| 204 |
+
ctx.font = `${particle.size}px Arial`;
|
| 205 |
+
ctx.textAlign = 'center';
|
| 206 |
+
ctx.textBaseline = 'middle';
|
| 207 |
+
ctx.fillText(particle.emoji, 0, 0);
|
| 208 |
+
} else {
|
| 209 |
+
// 备用:绘制彩色圆形
|
| 210 |
+
ctx.fillStyle = particle.color;
|
| 211 |
+
ctx.beginPath();
|
| 212 |
+
ctx.arc(0, 0, particle.size / 2, 0, Math.PI * 2);
|
| 213 |
+
ctx.fill();
|
| 214 |
+
|
| 215 |
+
// 添加高光
|
| 216 |
+
ctx.fillStyle = 'rgba(255, 255, 255, 0.3)';
|
| 217 |
+
ctx.beginPath();
|
| 218 |
+
ctx.arc(-particle.size / 6, -particle.size / 6, particle.size / 4, 0, Math.PI * 2);
|
| 219 |
+
ctx.fill();
|
| 220 |
+
}
|
| 221 |
+
}
|
| 222 |
+
|
| 223 |
+
renderExplosionParticle(ctx, particle) {
|
| 224 |
+
ctx.fillStyle = particle.color;
|
| 225 |
+
ctx.shadowBlur = 10;
|
| 226 |
+
ctx.shadowColor = particle.color;
|
| 227 |
+
|
| 228 |
+
ctx.beginPath();
|
| 229 |
+
ctx.arc(0, 0, particle.size, 0, Math.PI * 2);
|
| 230 |
+
ctx.fill();
|
| 231 |
+
}
|
| 232 |
+
|
| 233 |
+
renderSparkleParticle(ctx, particle) {
|
| 234 |
+
ctx.fillStyle = particle.color;
|
| 235 |
+
ctx.shadowBlur = 8;
|
| 236 |
+
ctx.shadowColor = particle.color;
|
| 237 |
+
|
| 238 |
+
// 绘制星形
|
| 239 |
+
const spikes = 4;
|
| 240 |
+
const outerRadius = particle.size;
|
| 241 |
+
const innerRadius = particle.size * 0.4;
|
| 242 |
+
|
| 243 |
+
ctx.beginPath();
|
| 244 |
+
for (let i = 0; i < spikes * 2; i++) {
|
| 245 |
+
const angle = (i / (spikes * 2)) * Math.PI * 2;
|
| 246 |
+
const radius = i % 2 === 0 ? outerRadius : innerRadius;
|
| 247 |
+
const x = Math.cos(angle) * radius;
|
| 248 |
+
const y = Math.sin(angle) * radius;
|
| 249 |
+
|
| 250 |
+
if (i === 0) {
|
| 251 |
+
ctx.moveTo(x, y);
|
| 252 |
+
} else {
|
| 253 |
+
ctx.lineTo(x, y);
|
| 254 |
+
}
|
| 255 |
+
}
|
| 256 |
+
ctx.closePath();
|
| 257 |
+
ctx.fill();
|
| 258 |
+
|
| 259 |
+
// 闪烁效果
|
| 260 |
+
if (particle.twinkle) {
|
| 261 |
+
const twinkleAlpha = Math.sin(Date.now() * 0.01) * 0.5 + 0.5;
|
| 262 |
+
ctx.globalAlpha *= twinkleAlpha;
|
| 263 |
+
}
|
| 264 |
+
}
|
| 265 |
+
|
| 266 |
+
renderDefaultParticle(ctx, particle) {
|
| 267 |
+
ctx.fillStyle = particle.color || '#FFD700';
|
| 268 |
+
ctx.beginPath();
|
| 269 |
+
ctx.arc(0, 0, particle.size, 0, Math.PI * 2);
|
| 270 |
+
ctx.fill();
|
| 271 |
+
}
|
| 272 |
+
|
| 273 |
+
getFoodColor(foodType) {
|
| 274 |
+
const colorMap = {
|
| 275 |
+
'apple': '#FF6B6B',
|
| 276 |
+
'banana': '#FFE66D',
|
| 277 |
+
'orange': '#FF8E53',
|
| 278 |
+
'strawberry': '#FF6B9D',
|
| 279 |
+
'watermelon': '#C44569',
|
| 280 |
+
'grape': '#9B59B6',
|
| 281 |
+
'pizza': '#F39C12',
|
| 282 |
+
'burger': '#D35400',
|
| 283 |
+
'cake': '#F8C471',
|
| 284 |
+
'cookie': '#D2691E',
|
| 285 |
+
'bread': '#DEB887',
|
| 286 |
+
'cheese': '#F1C40F',
|
| 287 |
+
'fish': '#3498DB',
|
| 288 |
+
'chicken': '#E67E22',
|
| 289 |
+
'rice': '#ECF0F1',
|
| 290 |
+
'noodles': '#F4D03F'
|
| 291 |
+
};
|
| 292 |
+
|
| 293 |
+
return colorMap[foodType] || '#FFD700';
|
| 294 |
+
}
|
| 295 |
+
|
| 296 |
+
getFoodEmoji(foodType) {
|
| 297 |
+
const emojiMap = {
|
| 298 |
+
'apple': '🍎',
|
| 299 |
+
'banana': '🍌',
|
| 300 |
+
'orange': '🍊',
|
| 301 |
+
'strawberry': '🍓',
|
| 302 |
+
'watermelon': '🍉',
|
| 303 |
+
'grape': '🍇',
|
| 304 |
+
'pizza': '🍕',
|
| 305 |
+
'burger': '🍔',
|
| 306 |
+
'cake': '🍰',
|
| 307 |
+
'cookie': '🍪',
|
| 308 |
+
'bread': '🍞',
|
| 309 |
+
'cheese': '🧀',
|
| 310 |
+
'fish': '🐟',
|
| 311 |
+
'chicken': '🍗',
|
| 312 |
+
'rice': '🍚',
|
| 313 |
+
'noodles': '🍜',
|
| 314 |
+
'carrot': '🥕',
|
| 315 |
+
'tomato': '🍅',
|
| 316 |
+
'corn': '🌽',
|
| 317 |
+
'broccoli': '🥦',
|
| 318 |
+
'potato': '🥔',
|
| 319 |
+
'onion': '🧅'
|
| 320 |
+
};
|
| 321 |
+
|
| 322 |
+
return emojiMap[foodType] || '🍽️';
|
| 323 |
+
}
|
| 324 |
+
|
| 325 |
+
// 清理所有粒子
|
| 326 |
+
clear() {
|
| 327 |
+
this.particles = [];
|
| 328 |
+
}
|
| 329 |
+
|
| 330 |
+
// 获取指定类型的粒子数量
|
| 331 |
+
getParticleCount(type = null) {
|
| 332 |
+
if (type) {
|
| 333 |
+
return this.particles.filter(p => p.type === type).length;
|
| 334 |
+
}
|
| 335 |
+
return this.particles.length;
|
| 336 |
+
}
|
| 337 |
+
|
| 338 |
+
// 移除指定类型的粒子
|
| 339 |
+
removeParticlesByType(type) {
|
| 340 |
+
this.particles = this.particles.filter(p => p.type !== type);
|
| 341 |
+
}
|
| 342 |
+
|
| 343 |
+
// 获取地面上的食物粒子数量
|
| 344 |
+
getGroundedFoodCount() {
|
| 345 |
+
return this.particles.filter(p => p.type === 'food' && p.isGrounded).length;
|
| 346 |
+
}
|
| 347 |
+
|
| 348 |
+
// 在指定区域内创建粒子爆炸效果
|
| 349 |
+
createAreaExplosion(x, y, radius, particleCount = 20) {
|
| 350 |
+
for (let i = 0; i < particleCount; i++) {
|
| 351 |
+
const angle = Math.random() * Math.PI * 2;
|
| 352 |
+
const distance = Math.random() * radius;
|
| 353 |
+
const particleX = x + Math.cos(angle) * distance;
|
| 354 |
+
const particleY = y + Math.sin(angle) * distance;
|
| 355 |
+
|
| 356 |
+
this.createExplosionParticles(particleX, particleY, 3);
|
| 357 |
+
}
|
| 358 |
+
}
|
| 359 |
+
|
| 360 |
+
// 清理无效粒子
|
| 361 |
+
cleanupInvalidParticles() {
|
| 362 |
+
const beforeCount = this.particles.length;
|
| 363 |
+
|
| 364 |
+
// 移除生命周期结束的粒子
|
| 365 |
+
this.particles = this.particles.filter(particle => particle.life > 0);
|
| 366 |
+
|
| 367 |
+
// 移除超出边界太远的粒子
|
| 368 |
+
const canvas = document.getElementById('gameCanvas');
|
| 369 |
+
if (canvas) {
|
| 370 |
+
const margin = 100; // 边界外100像素
|
| 371 |
+
this.particles = this.particles.filter(particle => {
|
| 372 |
+
return particle.x > -margin &&
|
| 373 |
+
particle.x < canvas.width + margin &&
|
| 374 |
+
particle.y > -margin &&
|
| 375 |
+
particle.y < canvas.height + margin;
|
| 376 |
+
});
|
| 377 |
+
}
|
| 378 |
+
|
| 379 |
+
const afterCount = this.particles.length;
|
| 380 |
+
return beforeCount - afterCount; // 返回清理的粒子数量
|
| 381 |
+
}
|
| 382 |
+
|
| 383 |
+
// 优化粒子更新
|
| 384 |
+
updateParticle(particle, dt) {
|
| 385 |
+
// 更新生命周期
|
| 386 |
+
particle.life -= dt / particle.maxLife;
|
| 387 |
+
if (particle.life <= 0) {
|
| 388 |
+
return; // 粒子死亡,将在下次清理时移除
|
| 389 |
+
}
|
| 390 |
+
|
| 391 |
+
// 更新位置
|
| 392 |
+
particle.x += particle.vx * dt;
|
| 393 |
+
particle.y += particle.vy * dt;
|
| 394 |
+
|
| 395 |
+
// 应用重力
|
| 396 |
+
particle.vy += this.gravity * dt * 60; // 60fps基准
|
| 397 |
+
|
| 398 |
+
// 应用摩擦力
|
| 399 |
+
particle.vx *= this.friction;
|
| 400 |
+
|
| 401 |
+
// 边界碰撞检测
|
| 402 |
+
this.handleBoundaryCollision(particle);
|
| 403 |
+
|
| 404 |
+
// 更新透明度
|
| 405 |
+
particle.opacity = Math.max(0, particle.life);
|
| 406 |
+
|
| 407 |
+
// 更新大小(某些粒子会变化)
|
| 408 |
+
if (particle.sizeChange) {
|
| 409 |
+
particle.size += particle.sizeChange * dt;
|
| 410 |
+
particle.size = Math.max(1, particle.size);
|
| 411 |
+
}
|
| 412 |
+
|
| 413 |
+
// 更新旋转
|
| 414 |
+
if (particle.rotation !== undefined) {
|
| 415 |
+
particle.rotation += particle.rotationSpeed * dt;
|
| 416 |
+
}
|
| 417 |
+
|
| 418 |
+
// 更新生命时间(用于清理)
|
| 419 |
+
particle.lifeTime = (particle.lifeTime || 0) + dt;
|
| 420 |
+
}
|
| 421 |
+
|
| 422 |
+
// 获取特定状态的粒子统计
|
| 423 |
+
getParticleStats() {
|
| 424 |
+
const stats = {
|
| 425 |
+
total: this.particles.length,
|
| 426 |
+
food: 0,
|
| 427 |
+
explosion: 0,
|
| 428 |
+
sparkle: 0,
|
| 429 |
+
grounded: 0,
|
| 430 |
+
moving: 0
|
| 431 |
+
};
|
| 432 |
+
|
| 433 |
+
this.particles.forEach(particle => {
|
| 434 |
+
if (particle.type === 'food') {
|
| 435 |
+
stats.food++;
|
| 436 |
+
if (particle.isGrounded) stats.grounded++;
|
| 437 |
+
else stats.moving++;
|
| 438 |
+
} else if (particle.type === 'explosion') {
|
| 439 |
+
stats.explosion++;
|
| 440 |
+
} else if (particle.type === 'sparkle') {
|
| 441 |
+
stats.sparkle++;
|
| 442 |
+
}
|
| 443 |
+
});
|
| 444 |
+
|
| 445 |
+
return stats;
|
| 446 |
+
}
|
| 447 |
+
|
| 448 |
+
// 强制清理最老的粒子
|
| 449 |
+
forceCleanupOldest(count) {
|
| 450 |
+
if (count <= 0) return 0;
|
| 451 |
+
|
| 452 |
+
// 按生命时间排序,移除最老的
|
| 453 |
+
const sortedParticles = this.particles
|
| 454 |
+
.map((particle, index) => ({ particle, index, lifeTime: particle.lifeTime || 0 }))
|
| 455 |
+
.sort((a, b) => b.lifeTime - a.lifeTime);
|
| 456 |
+
|
| 457 |
+
const toRemove = Math.min(count, sortedParticles.length);
|
| 458 |
+
const indicesToRemove = sortedParticles
|
| 459 |
+
.slice(0, toRemove)
|
| 460 |
+
.map(item => item.index)
|
| 461 |
+
.sort((a, b) => b - a); // 从后往前删除
|
| 462 |
+
|
| 463 |
+
indicesToRemove.forEach(index => {
|
| 464 |
+
this.particles.splice(index, 1);
|
| 465 |
+
});
|
| 466 |
+
|
| 467 |
+
return toRemove;
|
| 468 |
+
}
|
| 469 |
+
}
|
| 470 |
+
|
| 471 |
+
// 食物粒子特殊效果类
|
| 472 |
+
class FoodParticleEffects {
|
| 473 |
+
static createBurstEffect(particleSystem, x, y, foodType, count = 15) {
|
| 474 |
+
for (let i = 0; i < count; i++) {
|
| 475 |
+
const angle = (i / count) * Math.PI * 2;
|
| 476 |
+
const speed = Math.random() * 80 + 40;
|
| 477 |
+
|
| 478 |
+
const particle = {
|
| 479 |
+
x: x,
|
| 480 |
+
y: y,
|
| 481 |
+
vx: Math.cos(angle) * speed,
|
| 482 |
+
vy: Math.sin(angle) * speed - 30,
|
| 483 |
+
size: Math.random() * 12 + 6,
|
| 484 |
+
color: particleSystem.getFoodColor(foodType),
|
| 485 |
+
emoji: particleSystem.getFoodEmoji(foodType),
|
| 486 |
+
life: 1,
|
| 487 |
+
maxLife: Math.random() * 2 + 1,
|
| 488 |
+
opacity: 1,
|
| 489 |
+
rotation: Math.random() * Math.PI * 2,
|
| 490 |
+
rotationSpeed: (Math.random() - 0.5) * 8,
|
| 491 |
+
type: 'food',
|
| 492 |
+
foodType: foodType,
|
| 493 |
+
isGrounded: false
|
| 494 |
+
};
|
| 495 |
+
|
| 496 |
+
particleSystem.particles.push(particle);
|
| 497 |
+
}
|
| 498 |
+
}
|
| 499 |
+
|
| 500 |
+
static createFountainEffect(particleSystem, x, y, foodType) {
|
| 501 |
+
const particleCount = 8;
|
| 502 |
+
|
| 503 |
+
for (let i = 0; i < particleCount; i++) {
|
| 504 |
+
const angle = -Math.PI / 2 + (Math.random() - 0.5) * Math.PI / 3;
|
| 505 |
+
const speed = Math.random() * 120 + 80;
|
| 506 |
+
|
| 507 |
+
const particle = {
|
| 508 |
+
x: x + (Math.random() - 0.5) * 30,
|
| 509 |
+
y: y,
|
| 510 |
+
vx: Math.cos(angle) * speed,
|
| 511 |
+
vy: Math.sin(angle) * speed,
|
| 512 |
+
size: Math.random() * 18 + 10,
|
| 513 |
+
color: particleSystem.getFoodColor(foodType),
|
| 514 |
+
emoji: particleSystem.getFoodEmoji(foodType),
|
| 515 |
+
life: 1,
|
| 516 |
+
maxLife: Math.random() * 4 + 2,
|
| 517 |
+
opacity: 1,
|
| 518 |
+
rotation: Math.random() * Math.PI * 2,
|
| 519 |
+
rotationSpeed: (Math.random() - 0.5) * 6,
|
| 520 |
+
type: 'food',
|
| 521 |
+
foodType: foodType,
|
| 522 |
+
isGrounded: false
|
| 523 |
+
};
|
| 524 |
+
|
| 525 |
+
particleSystem.particles.push(particle);
|
| 526 |
+
}
|
| 527 |
+
}
|
| 528 |
+
}
|
js/pot.js
CHANGED
|
@@ -1,471 +1,471 @@
|
|
| 1 |
-
// 魔法锅类
|
| 2 |
-
class MagicPot {
|
| 3 |
-
constructor(x, y) {
|
| 4 |
-
this.x = x;
|
| 5 |
-
this.y = y;
|
| 6 |
-
this.width = 120;
|
| 7 |
-
this.height = 100;
|
| 8 |
-
this.state = 'idle'; // idle, activated, cooking, overflowing
|
| 9 |
-
|
| 10 |
-
// 动画属性
|
| 11 |
-
this.animationTime = 0;
|
| 12 |
-
this.glowIntensity = 0;
|
| 13 |
-
this.shakeAmount = 0;
|
| 14 |
-
this.lidOffset = 0;
|
| 15 |
-
this.steamParticles = [];
|
| 16 |
-
|
| 17 |
-
// 颜色配置
|
| 18 |
-
this.colors = {
|
| 19 |
-
pot: '#8B4513',
|
| 20 |
-
potHighlight: '#CD853F',
|
| 21 |
-
potShadow: '#654321',
|
| 22 |
-
lid: '#A0522D',
|
| 23 |
-
lidHighlight: '#DEB887',
|
| 24 |
-
glow: '#FFD700',
|
| 25 |
-
steam: '#FFFFFF',
|
| 26 |
-
magic: '#FF69B4'
|
| 27 |
-
};
|
| 28 |
-
|
| 29 |
-
// 食物和动物素材
|
| 30 |
-
this.foodImage = null;
|
| 31 |
-
this.animalImage = null;
|
| 32 |
-
this.currentFood = null;
|
| 33 |
-
|
| 34 |
-
// 魔法锅图片
|
| 35 |
-
this.potImage = null;
|
| 36 |
-
this.imageLoaded = false;
|
| 37 |
-
this.loadPotImage();
|
| 38 |
-
}
|
| 39 |
-
|
| 40 |
-
update(deltaTime) {
|
| 41 |
-
this.animationTime += deltaTime * 0.001;
|
| 42 |
-
|
| 43 |
-
// 根据状态更新动画
|
| 44 |
-
switch (this.state) {
|
| 45 |
-
case 'idle':
|
| 46 |
-
this.updateIdleAnimation();
|
| 47 |
-
break;
|
| 48 |
-
case 'activated':
|
| 49 |
-
this.updateActivatedAnimation();
|
| 50 |
-
break;
|
| 51 |
-
case 'cooking':
|
| 52 |
-
this.updateCookingAnimation();
|
| 53 |
-
break;
|
| 54 |
-
case 'overflowing':
|
| 55 |
-
this.updateOverflowingAnimation();
|
| 56 |
-
break;
|
| 57 |
-
}
|
| 58 |
-
|
| 59 |
-
// 更新蒸汽粒子
|
| 60 |
-
this.updateSteamParticles(deltaTime);
|
| 61 |
-
}
|
| 62 |
-
|
| 63 |
-
updateIdleAnimation() {
|
| 64 |
-
// 轻微的呼吸效果
|
| 65 |
-
this.glowIntensity = Math.sin(this.animationTime * 0.5) * 0.1 + 0.1;
|
| 66 |
-
this.shakeAmount = 0;
|
| 67 |
-
this.lidOffset = 0;
|
| 68 |
-
}
|
| 69 |
-
|
| 70 |
-
updateActivatedAnimation() {
|
| 71 |
-
// 发光效果
|
| 72 |
-
this.glowIntensity = Math.sin(this.animationTime * 2) * 0.3 + 0.5;
|
| 73 |
-
this.shakeAmount = 0;
|
| 74 |
-
this.lidOffset = 0;
|
| 75 |
-
|
| 76 |
-
// 生成魔法粒子
|
| 77 |
-
if (Math.random() < 0.1) {
|
| 78 |
-
this.createMagicParticle();
|
| 79 |
-
}
|
| 80 |
-
}
|
| 81 |
-
|
| 82 |
-
updateCookingAnimation() {
|
| 83 |
-
// 强烈的发光和轻微震动
|
| 84 |
-
this.glowIntensity = Math.sin(this.animationTime * 3) * 0.4 + 0.6;
|
| 85 |
-
this.shakeAmount = Math.sin(this.animationTime * 8) * 2;
|
| 86 |
-
this.lidOffset = Math.sin(this.animationTime * 4) * 3;
|
| 87 |
-
|
| 88 |
-
// 生成蒸汽
|
| 89 |
-
if (Math.random() < 0.3) {
|
| 90 |
-
this.createSteamParticle();
|
| 91 |
-
}
|
| 92 |
-
|
| 93 |
-
// 生成魔法粒子
|
| 94 |
-
if (Math.random() < 0.2) {
|
| 95 |
-
this.createMagicParticle();
|
| 96 |
-
}
|
| 97 |
-
}
|
| 98 |
-
|
| 99 |
-
updateOverflowingAnimation() {
|
| 100 |
-
// 剧烈震动,锅盖被顶开
|
| 101 |
-
this.glowIntensity = 1;
|
| 102 |
-
this.shakeAmount = Math.sin(this.animationTime * 15) * 5;
|
| 103 |
-
this.lidOffset = -20 + Math.sin(this.animationTime * 10) * 5;
|
| 104 |
-
|
| 105 |
-
// 大量蒸汽
|
| 106 |
-
if (Math.random() < 0.8) {
|
| 107 |
-
this.createSteamParticle();
|
| 108 |
-
}
|
| 109 |
-
|
| 110 |
-
// 魔法粒子
|
| 111 |
-
if (Math.random() < 0.5) {
|
| 112 |
-
this.createMagicParticle();
|
| 113 |
-
}
|
| 114 |
-
}
|
| 115 |
-
|
| 116 |
-
createSteamParticle() {
|
| 117 |
-
const particle = {
|
| 118 |
-
x: this.x + (Math.random() - 0.5) * this.width * 0.8,
|
| 119 |
-
y: this.y - this.height * 0.3,
|
| 120 |
-
vx: (Math.random() - 0.5) * 20,
|
| 121 |
-
vy: -Math.random() * 50 - 30,
|
| 122 |
-
size: Math.random() * 8 + 4,
|
| 123 |
-
opacity: 0.8,
|
| 124 |
-
life: 1,
|
| 125 |
-
maxLife: Math.random() * 2 + 1
|
| 126 |
-
};
|
| 127 |
-
|
| 128 |
-
this.steamParticles.push(particle);
|
| 129 |
-
}
|
| 130 |
-
|
| 131 |
-
createMagicParticle() {
|
| 132 |
-
const angle = Math.random() * Math.PI * 2;
|
| 133 |
-
const radius = this.width * 0.6;
|
| 134 |
-
|
| 135 |
-
const particle = {
|
| 136 |
-
x: this.x + Math.cos(angle) * radius,
|
| 137 |
-
y: this.y + Math.sin(angle) * radius * 0.5,
|
| 138 |
-
vx: Math.cos(angle) * 30,
|
| 139 |
-
vy: Math.sin(angle) * 30 - 20,
|
| 140 |
-
size: Math.random() * 4 + 2,
|
| 141 |
-
opacity: 1,
|
| 142 |
-
life: 1,
|
| 143 |
-
maxLife: Math.random() * 1.5 + 0.5,
|
| 144 |
-
color: Math.random() < 0.5 ? '#FFD700' : '#FF69B4'
|
| 145 |
-
};
|
| 146 |
-
|
| 147 |
-
this.steamParticles.push(particle);
|
| 148 |
-
}
|
| 149 |
-
|
| 150 |
-
updateSteamParticles(deltaTime) {
|
| 151 |
-
for (let i = this.steamParticles.length - 1; i >= 0; i--) {
|
| 152 |
-
const particle = this.steamParticles[i];
|
| 153 |
-
|
| 154 |
-
// 更新位置
|
| 155 |
-
particle.x += particle.vx * deltaTime * 0.001;
|
| 156 |
-
particle.y += particle.vy * deltaTime * 0.001;
|
| 157 |
-
|
| 158 |
-
// 更新生命周期
|
| 159 |
-
particle.life -= deltaTime * 0.001 / particle.maxLife;
|
| 160 |
-
particle.opacity = particle.life;
|
| 161 |
-
|
| 162 |
-
// 蒸汽粒子逐渐变大
|
| 163 |
-
if (!particle.color) {
|
| 164 |
-
particle.size += deltaTime * 0.002;
|
| 165 |
-
}
|
| 166 |
-
|
| 167 |
-
// 移除死亡的粒子
|
| 168 |
-
if (particle.life <= 0) {
|
| 169 |
-
this.steamParticles.splice(i, 1);
|
| 170 |
-
}
|
| 171 |
-
}
|
| 172 |
-
}
|
| 173 |
-
|
| 174 |
-
render(ctx) {
|
| 175 |
-
const currentX = this.x + (Math.random() - 0.5) * this.shakeAmount;
|
| 176 |
-
const currentY = this.y + (Math.random() - 0.5) * this.shakeAmount;
|
| 177 |
-
|
| 178 |
-
// 绘制发光效果
|
| 179 |
-
if (this.glowIntensity > 0) {
|
| 180 |
-
this.renderGlow(ctx, currentX, currentY);
|
| 181 |
-
}
|
| 182 |
-
|
| 183 |
-
// 绘制魔法锅(图片或默认绘制)
|
| 184 |
-
if (this.imageLoaded && this.potImage) {
|
| 185 |
-
this.renderPotImage(ctx, currentX, currentY);
|
| 186 |
-
} else {
|
| 187 |
-
// 备用绘制方案
|
| 188 |
-
this.renderPotBody(ctx, currentX, currentY);
|
| 189 |
-
this.renderPotLid(ctx, currentX, currentY + this.lidOffset);
|
| 190 |
-
}
|
| 191 |
-
|
| 192 |
-
// 绘制蒸汽和魔法粒子
|
| 193 |
-
this.renderParticles(ctx);
|
| 194 |
-
|
| 195 |
-
// 绘制装饰
|
| 196 |
-
this.renderDecorations(ctx, currentX, currentY);
|
| 197 |
-
}
|
| 198 |
-
|
| 199 |
-
renderPotImage(ctx, x, y) {
|
| 200 |
-
ctx.save();
|
| 201 |
-
|
| 202 |
-
// 如果有发光效果,添加阴影
|
| 203 |
-
if (this.glowIntensity > 0) {
|
| 204 |
-
ctx.shadowBlur = this.glowIntensity * 30;
|
| 205 |
-
ctx.shadowColor = '#FFD700';
|
| 206 |
-
}
|
| 207 |
-
|
| 208 |
-
// 计算图片尺寸和位置
|
| 209 |
-
const imageWidth = this.width * 1.5; // 稍微放大一点
|
| 210 |
-
const imageHeight = this.height * 1.5;
|
| 211 |
-
const imageX = x - imageWidth / 2;
|
| 212 |
-
const imageY = y - imageHeight / 2 + this.lidOffset * 0.3; // 锅盖偏移效果
|
| 213 |
-
|
| 214 |
-
// 绘制魔法锅图片
|
| 215 |
-
ctx.drawImage(
|
| 216 |
-
this.potImage,
|
| 217 |
-
imageX,
|
| 218 |
-
imageY,
|
| 219 |
-
imageWidth,
|
| 220 |
-
imageHeight
|
| 221 |
-
);
|
| 222 |
-
|
| 223 |
-
ctx.restore();
|
| 224 |
-
}
|
| 225 |
-
|
| 226 |
-
renderGlow(ctx, x, y) {
|
| 227 |
-
const glowRadius = this.width * 0.8 * this.glowIntensity;
|
| 228 |
-
const gradient = ctx.createRadialGradient(x, y, 0, x, y, glowRadius);
|
| 229 |
-
|
| 230 |
-
gradient.addColorStop(0, `rgba(255, 215, 0, ${this.glowIntensity * 0.3})`);
|
| 231 |
-
gradient.addColorStop(0.5, `rgba(255, 105, 180, ${this.glowIntensity * 0.2})`);
|
| 232 |
-
gradient.addColorStop(1, 'rgba(255, 215, 0, 0)');
|
| 233 |
-
|
| 234 |
-
ctx.fillStyle = gradient;
|
| 235 |
-
ctx.beginPath();
|
| 236 |
-
ctx.arc(x, y, glowRadius, 0, Math.PI * 2);
|
| 237 |
-
ctx.fill();
|
| 238 |
-
}
|
| 239 |
-
|
| 240 |
-
renderPotBody(ctx, x, y) {
|
| 241 |
-
const potWidth = this.width;
|
| 242 |
-
const potHeight = this.height;
|
| 243 |
-
|
| 244 |
-
// 锅身主体
|
| 245 |
-
ctx.fillStyle = this.colors.pot;
|
| 246 |
-
ctx.beginPath();
|
| 247 |
-
ctx.ellipse(x, y + potHeight * 0.3, potWidth * 0.5, potHeight * 0.4, 0, 0, Math.PI * 2);
|
| 248 |
-
ctx.fill();
|
| 249 |
-
|
| 250 |
-
// 锅身侧面
|
| 251 |
-
ctx.fillStyle = this.colors.potShadow;
|
| 252 |
-
ctx.fillRect(x - potWidth * 0.5, y - potHeight * 0.2, potWidth, potHeight * 0.5);
|
| 253 |
-
|
| 254 |
-
// 锅身高光
|
| 255 |
-
ctx.fillStyle = this.colors.potHighlight;
|
| 256 |
-
ctx.beginPath();
|
| 257 |
-
ctx.ellipse(x - potWidth * 0.2, y - potHeight * 0.1, potWidth * 0.15, potHeight * 0.1, 0, 0, Math.PI * 2);
|
| 258 |
-
ctx.fill();
|
| 259 |
-
|
| 260 |
-
// 锅把手
|
| 261 |
-
this.renderHandles(ctx, x, y);
|
| 262 |
-
}
|
| 263 |
-
|
| 264 |
-
renderHandles(ctx, x, y) {
|
| 265 |
-
ctx.strokeStyle = this.colors.potShadow;
|
| 266 |
-
ctx.lineWidth = 8;
|
| 267 |
-
ctx.lineCap = 'round';
|
| 268 |
-
|
| 269 |
-
// 左把手
|
| 270 |
-
ctx.beginPath();
|
| 271 |
-
ctx.arc(x - this.width * 0.6, y, this.width * 0.15, -Math.PI * 0.3, Math.PI * 0.3);
|
| 272 |
-
ctx.stroke();
|
| 273 |
-
|
| 274 |
-
// 右把手
|
| 275 |
-
ctx.beginPath();
|
| 276 |
-
ctx.arc(x + this.width * 0.6, y, this.width * 0.15, Math.PI * 0.7, Math.PI * 1.3);
|
| 277 |
-
ctx.stroke();
|
| 278 |
-
}
|
| 279 |
-
|
| 280 |
-
renderPotLid(ctx, x, y) {
|
| 281 |
-
const lidWidth = this.width * 0.9;
|
| 282 |
-
const lidHeight = this.height * 0.2;
|
| 283 |
-
|
| 284 |
-
// 锅盖主体
|
| 285 |
-
ctx.fillStyle = this.colors.lid;
|
| 286 |
-
ctx.beginPath();
|
| 287 |
-
ctx.ellipse(x, y - this.height * 0.3, lidWidth * 0.5, lidHeight * 0.5, 0, 0, Math.PI * 2);
|
| 288 |
-
ctx.fill();
|
| 289 |
-
|
| 290 |
-
// 锅盖高光
|
| 291 |
-
ctx.fillStyle = this.colors.lidHighlight;
|
| 292 |
-
ctx.beginPath();
|
| 293 |
-
ctx.ellipse(x - lidWidth * 0.1, y - this.height * 0.35, lidWidth * 0.3, lidHeight * 0.3, 0, 0, Math.PI * 2);
|
| 294 |
-
ctx.fill();
|
| 295 |
-
|
| 296 |
-
// 锅盖把手
|
| 297 |
-
ctx.fillStyle = this.colors.potShadow;
|
| 298 |
-
ctx.beginPath();
|
| 299 |
-
ctx.ellipse(x, y - this.height * 0.45, 8, 12, 0, 0, Math.PI * 2);
|
| 300 |
-
ctx.fill();
|
| 301 |
-
|
| 302 |
-
ctx.fillStyle = this.colors.lidHighlight;
|
| 303 |
-
ctx.beginPath();
|
| 304 |
-
ctx.ellipse(x - 2, y - this.height * 0.48, 4, 6, 0, 0, Math.PI * 2);
|
| 305 |
-
ctx.fill();
|
| 306 |
-
}
|
| 307 |
-
|
| 308 |
-
renderParticles(ctx) {
|
| 309 |
-
this.steamParticles.forEach(particle => {
|
| 310 |
-
ctx.save();
|
| 311 |
-
ctx.globalAlpha = particle.opacity;
|
| 312 |
-
|
| 313 |
-
if (particle.color) {
|
| 314 |
-
// 魔法粒子
|
| 315 |
-
ctx.fillStyle = particle.color;
|
| 316 |
-
ctx.shadowBlur = 10;
|
| 317 |
-
ctx.shadowColor = particle.color;
|
| 318 |
-
} else {
|
| 319 |
-
// 蒸汽粒子
|
| 320 |
-
ctx.fillStyle = this.colors.steam;
|
| 321 |
-
}
|
| 322 |
-
|
| 323 |
-
ctx.beginPath();
|
| 324 |
-
ctx.arc(particle.x, particle.y, particle.size, 0, Math.PI * 2);
|
| 325 |
-
ctx.fill();
|
| 326 |
-
|
| 327 |
-
ctx.restore();
|
| 328 |
-
});
|
| 329 |
-
}
|
| 330 |
-
|
| 331 |
-
renderDecorations(ctx, x, y) {
|
| 332 |
-
// 绘制魔法符文(如果激活)
|
| 333 |
-
if (this.state !== 'idle') {
|
| 334 |
-
this.renderMagicRunes(ctx, x, y);
|
| 335 |
-
}
|
| 336 |
-
|
| 337 |
-
// 绘制食物图标(如果正在烹饪)
|
| 338 |
-
if (this.state === 'cooking' && this.currentFood) {
|
| 339 |
-
this.renderFoodIcon(ctx, x, y);
|
| 340 |
-
}
|
| 341 |
-
}
|
| 342 |
-
|
| 343 |
-
renderMagicRunes(ctx, x, y) {
|
| 344 |
-
const runeRadius = this.width * 0.8;
|
| 345 |
-
const runeCount = 6;
|
| 346 |
-
const time = this.animationTime * 2;
|
| 347 |
-
|
| 348 |
-
ctx.strokeStyle = this.colors.magic;
|
| 349 |
-
ctx.lineWidth = 2;
|
| 350 |
-
ctx.globalAlpha = this.glowIntensity * 0.5;
|
| 351 |
-
|
| 352 |
-
for (let i = 0; i < runeCount; i++) {
|
| 353 |
-
const angle = (i / runeCount) * Math.PI * 2 + time;
|
| 354 |
-
const runeX = x + Math.cos(angle) * runeRadius;
|
| 355 |
-
const runeY = y + Math.sin(angle) * runeRadius * 0.5;
|
| 356 |
-
|
| 357 |
-
// 绘制简单的符文形状
|
| 358 |
-
ctx.beginPath();
|
| 359 |
-
ctx.moveTo(runeX - 5, runeY - 5);
|
| 360 |
-
ctx.lineTo(runeX + 5, runeY + 5);
|
| 361 |
-
ctx.moveTo(runeX + 5, runeY - 5);
|
| 362 |
-
ctx.lineTo(runeX - 5, runeY + 5);
|
| 363 |
-
ctx.stroke();
|
| 364 |
-
}
|
| 365 |
-
|
| 366 |
-
ctx.globalAlpha = 1;
|
| 367 |
-
}
|
| 368 |
-
|
| 369 |
-
renderFoodIcon(ctx, x, y) {
|
| 370 |
-
// 在锅上方显示食物图标
|
| 371 |
-
const iconY = y - this.height * 0.8;
|
| 372 |
-
|
| 373 |
-
ctx.fillStyle = '#FFD700';
|
| 374 |
-
ctx.font = '24px Arial';
|
| 375 |
-
ctx.textAlign = 'center';
|
| 376 |
-
ctx.fillText(this.getFoodEmoji(this.currentFood), x, iconY);
|
| 377 |
-
}
|
| 378 |
-
|
| 379 |
-
getFoodEmoji(foodName) {
|
| 380 |
-
const emojiMap = {
|
| 381 |
-
'apple': '🍎',
|
| 382 |
-
'banana': '🍌',
|
| 383 |
-
'orange': '🍊',
|
| 384 |
-
'strawberry': '🍓',
|
| 385 |
-
'watermelon': '🍉',
|
| 386 |
-
'grape': '🍇',
|
| 387 |
-
'pizza': '🍕',
|
| 388 |
-
'burger': '🍔',
|
| 389 |
-
'cake': '🍰',
|
| 390 |
-
'cookie': '🍪',
|
| 391 |
-
'bread': '🍞',
|
| 392 |
-
'cheese': '🧀',
|
| 393 |
-
'fish': '🐟',
|
| 394 |
-
'chicken': '🍗',
|
| 395 |
-
'rice': '🍚',
|
| 396 |
-
'noodles': '🍜'
|
| 397 |
-
};
|
| 398 |
-
|
| 399 |
-
return emojiMap[foodName] || '🍽️';
|
| 400 |
-
}
|
| 401 |
-
|
| 402 |
-
// 状态控制方法
|
| 403 |
-
activate() {
|
| 404 |
-
this.state = 'activated';
|
| 405 |
-
this.animationTime = 0;
|
| 406 |
-
}
|
| 407 |
-
|
| 408 |
-
startCooking(foodName) {
|
| 409 |
-
this.state = 'cooking';
|
| 410 |
-
this.currentFood = foodName;
|
| 411 |
-
this.animationTime = 0;
|
| 412 |
-
}
|
| 413 |
-
|
| 414 |
-
startOverflowing() {
|
| 415 |
-
this.state = 'overflowing';
|
| 416 |
-
this.animationTime = 0;
|
| 417 |
-
}
|
| 418 |
-
|
| 419 |
-
stopOverflowing() {
|
| 420 |
-
this.state = 'activated';
|
| 421 |
-
this.lidOffset = 0;
|
| 422 |
-
this.shakeAmount = 0;
|
| 423 |
-
}
|
| 424 |
-
|
| 425 |
-
reset() {
|
| 426 |
-
this.state = 'idle';
|
| 427 |
-
this.currentFood = null;
|
| 428 |
-
this.animationTime = 0;
|
| 429 |
-
this.glowIntensity = 0;
|
| 430 |
-
this.shakeAmount = 0;
|
| 431 |
-
this.lidOffset = 0;
|
| 432 |
-
this.steamParticles = [];
|
| 433 |
-
}
|
| 434 |
-
|
| 435 |
-
setFoodAssets(foodImage, animalImage) {
|
| 436 |
-
this.foodImage = foodImage;
|
| 437 |
-
this.animalImage = animalImage;
|
| 438 |
-
}
|
| 439 |
-
|
| 440 |
-
// 碰撞检测
|
| 441 |
-
contains(x, y) {
|
| 442 |
-
const dx = x - this.x;
|
| 443 |
-
const dy = y - this.y;
|
| 444 |
-
const distance = Math.sqrt(dx * dx + dy * dy);
|
| 445 |
-
return distance < this.width * 0.5;
|
| 446 |
-
}
|
| 447 |
-
|
| 448 |
-
// 获取锅的边界
|
| 449 |
-
getBounds() {
|
| 450 |
-
return {
|
| 451 |
-
left: this.x - this.width * 0.5,
|
| 452 |
-
right: this.x + this.width * 0.5,
|
| 453 |
-
top: this.y - this.height * 0.5,
|
| 454 |
-
bottom: this.y + this.height * 0.5
|
| 455 |
-
};
|
| 456 |
-
}
|
| 457 |
-
|
| 458 |
-
// 加载魔法锅图片
|
| 459 |
-
loadPotImage() {
|
| 460 |
-
this.potImage = new Image();
|
| 461 |
-
this.potImage.onload = () => {
|
| 462 |
-
this.imageLoaded = true;
|
| 463 |
-
console.log('魔法锅图片加载成功');
|
| 464 |
-
};
|
| 465 |
-
this.potImage.onerror = () => {
|
| 466 |
-
console.warn('魔法锅图片加载失败,使用默认绘制');
|
| 467 |
-
this.imageLoaded = false;
|
| 468 |
-
};
|
| 469 |
-
this.potImage.src = 'assets/images/magic_pot.png';
|
| 470 |
-
}
|
| 471 |
-
}
|
|
|
|
| 1 |
+
// 魔法锅类
|
| 2 |
+
class MagicPot {
|
| 3 |
+
constructor(x, y) {
|
| 4 |
+
this.x = x;
|
| 5 |
+
this.y = y;
|
| 6 |
+
this.width = 120;
|
| 7 |
+
this.height = 100;
|
| 8 |
+
this.state = 'idle'; // idle, activated, cooking, overflowing
|
| 9 |
+
|
| 10 |
+
// 动画属性
|
| 11 |
+
this.animationTime = 0;
|
| 12 |
+
this.glowIntensity = 0;
|
| 13 |
+
this.shakeAmount = 0;
|
| 14 |
+
this.lidOffset = 0;
|
| 15 |
+
this.steamParticles = [];
|
| 16 |
+
|
| 17 |
+
// 颜色配置
|
| 18 |
+
this.colors = {
|
| 19 |
+
pot: '#8B4513',
|
| 20 |
+
potHighlight: '#CD853F',
|
| 21 |
+
potShadow: '#654321',
|
| 22 |
+
lid: '#A0522D',
|
| 23 |
+
lidHighlight: '#DEB887',
|
| 24 |
+
glow: '#FFD700',
|
| 25 |
+
steam: '#FFFFFF',
|
| 26 |
+
magic: '#FF69B4'
|
| 27 |
+
};
|
| 28 |
+
|
| 29 |
+
// 食物和动物素材
|
| 30 |
+
this.foodImage = null;
|
| 31 |
+
this.animalImage = null;
|
| 32 |
+
this.currentFood = null;
|
| 33 |
+
|
| 34 |
+
// 魔法锅图片
|
| 35 |
+
this.potImage = null;
|
| 36 |
+
this.imageLoaded = false;
|
| 37 |
+
this.loadPotImage();
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
update(deltaTime) {
|
| 41 |
+
this.animationTime += deltaTime * 0.001;
|
| 42 |
+
|
| 43 |
+
// 根据状态更新动画
|
| 44 |
+
switch (this.state) {
|
| 45 |
+
case 'idle':
|
| 46 |
+
this.updateIdleAnimation();
|
| 47 |
+
break;
|
| 48 |
+
case 'activated':
|
| 49 |
+
this.updateActivatedAnimation();
|
| 50 |
+
break;
|
| 51 |
+
case 'cooking':
|
| 52 |
+
this.updateCookingAnimation();
|
| 53 |
+
break;
|
| 54 |
+
case 'overflowing':
|
| 55 |
+
this.updateOverflowingAnimation();
|
| 56 |
+
break;
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
// 更新蒸汽粒子
|
| 60 |
+
this.updateSteamParticles(deltaTime);
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
updateIdleAnimation() {
|
| 64 |
+
// 轻微的呼吸效果
|
| 65 |
+
this.glowIntensity = Math.sin(this.animationTime * 0.5) * 0.1 + 0.1;
|
| 66 |
+
this.shakeAmount = 0;
|
| 67 |
+
this.lidOffset = 0;
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
updateActivatedAnimation() {
|
| 71 |
+
// 发光效果
|
| 72 |
+
this.glowIntensity = Math.sin(this.animationTime * 2) * 0.3 + 0.5;
|
| 73 |
+
this.shakeAmount = 0;
|
| 74 |
+
this.lidOffset = 0;
|
| 75 |
+
|
| 76 |
+
// 生成魔法粒子
|
| 77 |
+
if (Math.random() < 0.1) {
|
| 78 |
+
this.createMagicParticle();
|
| 79 |
+
}
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
updateCookingAnimation() {
|
| 83 |
+
// 强烈的发光和轻微震动
|
| 84 |
+
this.glowIntensity = Math.sin(this.animationTime * 3) * 0.4 + 0.6;
|
| 85 |
+
this.shakeAmount = Math.sin(this.animationTime * 8) * 2;
|
| 86 |
+
this.lidOffset = Math.sin(this.animationTime * 4) * 3;
|
| 87 |
+
|
| 88 |
+
// 生成蒸汽
|
| 89 |
+
if (Math.random() < 0.3) {
|
| 90 |
+
this.createSteamParticle();
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
// 生成魔法粒子
|
| 94 |
+
if (Math.random() < 0.2) {
|
| 95 |
+
this.createMagicParticle();
|
| 96 |
+
}
|
| 97 |
+
}
|
| 98 |
+
|
| 99 |
+
updateOverflowingAnimation() {
|
| 100 |
+
// 剧烈震动,锅盖被顶开
|
| 101 |
+
this.glowIntensity = 1;
|
| 102 |
+
this.shakeAmount = Math.sin(this.animationTime * 15) * 5;
|
| 103 |
+
this.lidOffset = -20 + Math.sin(this.animationTime * 10) * 5;
|
| 104 |
+
|
| 105 |
+
// 大量蒸汽
|
| 106 |
+
if (Math.random() < 0.8) {
|
| 107 |
+
this.createSteamParticle();
|
| 108 |
+
}
|
| 109 |
+
|
| 110 |
+
// 魔法粒子
|
| 111 |
+
if (Math.random() < 0.5) {
|
| 112 |
+
this.createMagicParticle();
|
| 113 |
+
}
|
| 114 |
+
}
|
| 115 |
+
|
| 116 |
+
createSteamParticle() {
|
| 117 |
+
const particle = {
|
| 118 |
+
x: this.x + (Math.random() - 0.5) * this.width * 0.8,
|
| 119 |
+
y: this.y - this.height * 0.3,
|
| 120 |
+
vx: (Math.random() - 0.5) * 20,
|
| 121 |
+
vy: -Math.random() * 50 - 30,
|
| 122 |
+
size: Math.random() * 8 + 4,
|
| 123 |
+
opacity: 0.8,
|
| 124 |
+
life: 1,
|
| 125 |
+
maxLife: Math.random() * 2 + 1
|
| 126 |
+
};
|
| 127 |
+
|
| 128 |
+
this.steamParticles.push(particle);
|
| 129 |
+
}
|
| 130 |
+
|
| 131 |
+
createMagicParticle() {
|
| 132 |
+
const angle = Math.random() * Math.PI * 2;
|
| 133 |
+
const radius = this.width * 0.6;
|
| 134 |
+
|
| 135 |
+
const particle = {
|
| 136 |
+
x: this.x + Math.cos(angle) * radius,
|
| 137 |
+
y: this.y + Math.sin(angle) * radius * 0.5,
|
| 138 |
+
vx: Math.cos(angle) * 30,
|
| 139 |
+
vy: Math.sin(angle) * 30 - 20,
|
| 140 |
+
size: Math.random() * 4 + 2,
|
| 141 |
+
opacity: 1,
|
| 142 |
+
life: 1,
|
| 143 |
+
maxLife: Math.random() * 1.5 + 0.5,
|
| 144 |
+
color: Math.random() < 0.5 ? '#FFD700' : '#FF69B4'
|
| 145 |
+
};
|
| 146 |
+
|
| 147 |
+
this.steamParticles.push(particle);
|
| 148 |
+
}
|
| 149 |
+
|
| 150 |
+
updateSteamParticles(deltaTime) {
|
| 151 |
+
for (let i = this.steamParticles.length - 1; i >= 0; i--) {
|
| 152 |
+
const particle = this.steamParticles[i];
|
| 153 |
+
|
| 154 |
+
// 更新位置
|
| 155 |
+
particle.x += particle.vx * deltaTime * 0.001;
|
| 156 |
+
particle.y += particle.vy * deltaTime * 0.001;
|
| 157 |
+
|
| 158 |
+
// 更新生命周期
|
| 159 |
+
particle.life -= deltaTime * 0.001 / particle.maxLife;
|
| 160 |
+
particle.opacity = particle.life;
|
| 161 |
+
|
| 162 |
+
// 蒸汽粒子逐渐变大
|
| 163 |
+
if (!particle.color) {
|
| 164 |
+
particle.size += deltaTime * 0.002;
|
| 165 |
+
}
|
| 166 |
+
|
| 167 |
+
// 移除死亡的粒子
|
| 168 |
+
if (particle.life <= 0) {
|
| 169 |
+
this.steamParticles.splice(i, 1);
|
| 170 |
+
}
|
| 171 |
+
}
|
| 172 |
+
}
|
| 173 |
+
|
| 174 |
+
render(ctx) {
|
| 175 |
+
const currentX = this.x + (Math.random() - 0.5) * this.shakeAmount;
|
| 176 |
+
const currentY = this.y + (Math.random() - 0.5) * this.shakeAmount;
|
| 177 |
+
|
| 178 |
+
// 绘制发光效果
|
| 179 |
+
if (this.glowIntensity > 0) {
|
| 180 |
+
this.renderGlow(ctx, currentX, currentY);
|
| 181 |
+
}
|
| 182 |
+
|
| 183 |
+
// 绘制魔法锅(图片或默认绘制)
|
| 184 |
+
if (this.imageLoaded && this.potImage) {
|
| 185 |
+
this.renderPotImage(ctx, currentX, currentY);
|
| 186 |
+
} else {
|
| 187 |
+
// 备用绘制方案
|
| 188 |
+
this.renderPotBody(ctx, currentX, currentY);
|
| 189 |
+
this.renderPotLid(ctx, currentX, currentY + this.lidOffset);
|
| 190 |
+
}
|
| 191 |
+
|
| 192 |
+
// 绘制蒸汽和魔法粒子
|
| 193 |
+
this.renderParticles(ctx);
|
| 194 |
+
|
| 195 |
+
// 绘制装饰
|
| 196 |
+
this.renderDecorations(ctx, currentX, currentY);
|
| 197 |
+
}
|
| 198 |
+
|
| 199 |
+
renderPotImage(ctx, x, y) {
|
| 200 |
+
ctx.save();
|
| 201 |
+
|
| 202 |
+
// 如果有发光效果,添加阴影
|
| 203 |
+
if (this.glowIntensity > 0) {
|
| 204 |
+
ctx.shadowBlur = this.glowIntensity * 30;
|
| 205 |
+
ctx.shadowColor = '#FFD700';
|
| 206 |
+
}
|
| 207 |
+
|
| 208 |
+
// 计算图片尺寸和位置
|
| 209 |
+
const imageWidth = this.width * 1.5; // 稍微放大一点
|
| 210 |
+
const imageHeight = this.height * 1.5;
|
| 211 |
+
const imageX = x - imageWidth / 2;
|
| 212 |
+
const imageY = y - imageHeight / 2 + this.lidOffset * 0.3; // 锅盖偏移效果
|
| 213 |
+
|
| 214 |
+
// 绘制魔法锅图片
|
| 215 |
+
ctx.drawImage(
|
| 216 |
+
this.potImage,
|
| 217 |
+
imageX,
|
| 218 |
+
imageY,
|
| 219 |
+
imageWidth,
|
| 220 |
+
imageHeight
|
| 221 |
+
);
|
| 222 |
+
|
| 223 |
+
ctx.restore();
|
| 224 |
+
}
|
| 225 |
+
|
| 226 |
+
renderGlow(ctx, x, y) {
|
| 227 |
+
const glowRadius = this.width * 0.8 * this.glowIntensity;
|
| 228 |
+
const gradient = ctx.createRadialGradient(x, y, 0, x, y, glowRadius);
|
| 229 |
+
|
| 230 |
+
gradient.addColorStop(0, `rgba(255, 215, 0, ${this.glowIntensity * 0.3})`);
|
| 231 |
+
gradient.addColorStop(0.5, `rgba(255, 105, 180, ${this.glowIntensity * 0.2})`);
|
| 232 |
+
gradient.addColorStop(1, 'rgba(255, 215, 0, 0)');
|
| 233 |
+
|
| 234 |
+
ctx.fillStyle = gradient;
|
| 235 |
+
ctx.beginPath();
|
| 236 |
+
ctx.arc(x, y, glowRadius, 0, Math.PI * 2);
|
| 237 |
+
ctx.fill();
|
| 238 |
+
}
|
| 239 |
+
|
| 240 |
+
renderPotBody(ctx, x, y) {
|
| 241 |
+
const potWidth = this.width;
|
| 242 |
+
const potHeight = this.height;
|
| 243 |
+
|
| 244 |
+
// 锅身主体
|
| 245 |
+
ctx.fillStyle = this.colors.pot;
|
| 246 |
+
ctx.beginPath();
|
| 247 |
+
ctx.ellipse(x, y + potHeight * 0.3, potWidth * 0.5, potHeight * 0.4, 0, 0, Math.PI * 2);
|
| 248 |
+
ctx.fill();
|
| 249 |
+
|
| 250 |
+
// 锅身侧面
|
| 251 |
+
ctx.fillStyle = this.colors.potShadow;
|
| 252 |
+
ctx.fillRect(x - potWidth * 0.5, y - potHeight * 0.2, potWidth, potHeight * 0.5);
|
| 253 |
+
|
| 254 |
+
// 锅身高光
|
| 255 |
+
ctx.fillStyle = this.colors.potHighlight;
|
| 256 |
+
ctx.beginPath();
|
| 257 |
+
ctx.ellipse(x - potWidth * 0.2, y - potHeight * 0.1, potWidth * 0.15, potHeight * 0.1, 0, 0, Math.PI * 2);
|
| 258 |
+
ctx.fill();
|
| 259 |
+
|
| 260 |
+
// 锅把手
|
| 261 |
+
this.renderHandles(ctx, x, y);
|
| 262 |
+
}
|
| 263 |
+
|
| 264 |
+
renderHandles(ctx, x, y) {
|
| 265 |
+
ctx.strokeStyle = this.colors.potShadow;
|
| 266 |
+
ctx.lineWidth = 8;
|
| 267 |
+
ctx.lineCap = 'round';
|
| 268 |
+
|
| 269 |
+
// 左把手
|
| 270 |
+
ctx.beginPath();
|
| 271 |
+
ctx.arc(x - this.width * 0.6, y, this.width * 0.15, -Math.PI * 0.3, Math.PI * 0.3);
|
| 272 |
+
ctx.stroke();
|
| 273 |
+
|
| 274 |
+
// 右把手
|
| 275 |
+
ctx.beginPath();
|
| 276 |
+
ctx.arc(x + this.width * 0.6, y, this.width * 0.15, Math.PI * 0.7, Math.PI * 1.3);
|
| 277 |
+
ctx.stroke();
|
| 278 |
+
}
|
| 279 |
+
|
| 280 |
+
renderPotLid(ctx, x, y) {
|
| 281 |
+
const lidWidth = this.width * 0.9;
|
| 282 |
+
const lidHeight = this.height * 0.2;
|
| 283 |
+
|
| 284 |
+
// 锅盖主体
|
| 285 |
+
ctx.fillStyle = this.colors.lid;
|
| 286 |
+
ctx.beginPath();
|
| 287 |
+
ctx.ellipse(x, y - this.height * 0.3, lidWidth * 0.5, lidHeight * 0.5, 0, 0, Math.PI * 2);
|
| 288 |
+
ctx.fill();
|
| 289 |
+
|
| 290 |
+
// 锅盖高光
|
| 291 |
+
ctx.fillStyle = this.colors.lidHighlight;
|
| 292 |
+
ctx.beginPath();
|
| 293 |
+
ctx.ellipse(x - lidWidth * 0.1, y - this.height * 0.35, lidWidth * 0.3, lidHeight * 0.3, 0, 0, Math.PI * 2);
|
| 294 |
+
ctx.fill();
|
| 295 |
+
|
| 296 |
+
// 锅盖把手
|
| 297 |
+
ctx.fillStyle = this.colors.potShadow;
|
| 298 |
+
ctx.beginPath();
|
| 299 |
+
ctx.ellipse(x, y - this.height * 0.45, 8, 12, 0, 0, Math.PI * 2);
|
| 300 |
+
ctx.fill();
|
| 301 |
+
|
| 302 |
+
ctx.fillStyle = this.colors.lidHighlight;
|
| 303 |
+
ctx.beginPath();
|
| 304 |
+
ctx.ellipse(x - 2, y - this.height * 0.48, 4, 6, 0, 0, Math.PI * 2);
|
| 305 |
+
ctx.fill();
|
| 306 |
+
}
|
| 307 |
+
|
| 308 |
+
renderParticles(ctx) {
|
| 309 |
+
this.steamParticles.forEach(particle => {
|
| 310 |
+
ctx.save();
|
| 311 |
+
ctx.globalAlpha = particle.opacity;
|
| 312 |
+
|
| 313 |
+
if (particle.color) {
|
| 314 |
+
// 魔法粒子
|
| 315 |
+
ctx.fillStyle = particle.color;
|
| 316 |
+
ctx.shadowBlur = 10;
|
| 317 |
+
ctx.shadowColor = particle.color;
|
| 318 |
+
} else {
|
| 319 |
+
// 蒸汽粒子
|
| 320 |
+
ctx.fillStyle = this.colors.steam;
|
| 321 |
+
}
|
| 322 |
+
|
| 323 |
+
ctx.beginPath();
|
| 324 |
+
ctx.arc(particle.x, particle.y, particle.size, 0, Math.PI * 2);
|
| 325 |
+
ctx.fill();
|
| 326 |
+
|
| 327 |
+
ctx.restore();
|
| 328 |
+
});
|
| 329 |
+
}
|
| 330 |
+
|
| 331 |
+
renderDecorations(ctx, x, y) {
|
| 332 |
+
// 绘制魔法符文(如果激活)
|
| 333 |
+
if (this.state !== 'idle') {
|
| 334 |
+
this.renderMagicRunes(ctx, x, y);
|
| 335 |
+
}
|
| 336 |
+
|
| 337 |
+
// 绘制食物图标(如果正在烹饪)
|
| 338 |
+
if (this.state === 'cooking' && this.currentFood) {
|
| 339 |
+
this.renderFoodIcon(ctx, x, y);
|
| 340 |
+
}
|
| 341 |
+
}
|
| 342 |
+
|
| 343 |
+
renderMagicRunes(ctx, x, y) {
|
| 344 |
+
const runeRadius = this.width * 0.8;
|
| 345 |
+
const runeCount = 6;
|
| 346 |
+
const time = this.animationTime * 2;
|
| 347 |
+
|
| 348 |
+
ctx.strokeStyle = this.colors.magic;
|
| 349 |
+
ctx.lineWidth = 2;
|
| 350 |
+
ctx.globalAlpha = this.glowIntensity * 0.5;
|
| 351 |
+
|
| 352 |
+
for (let i = 0; i < runeCount; i++) {
|
| 353 |
+
const angle = (i / runeCount) * Math.PI * 2 + time;
|
| 354 |
+
const runeX = x + Math.cos(angle) * runeRadius;
|
| 355 |
+
const runeY = y + Math.sin(angle) * runeRadius * 0.5;
|
| 356 |
+
|
| 357 |
+
// 绘制简单的符文形状
|
| 358 |
+
ctx.beginPath();
|
| 359 |
+
ctx.moveTo(runeX - 5, runeY - 5);
|
| 360 |
+
ctx.lineTo(runeX + 5, runeY + 5);
|
| 361 |
+
ctx.moveTo(runeX + 5, runeY - 5);
|
| 362 |
+
ctx.lineTo(runeX - 5, runeY + 5);
|
| 363 |
+
ctx.stroke();
|
| 364 |
+
}
|
| 365 |
+
|
| 366 |
+
ctx.globalAlpha = 1;
|
| 367 |
+
}
|
| 368 |
+
|
| 369 |
+
renderFoodIcon(ctx, x, y) {
|
| 370 |
+
// 在锅上方显示食物图标
|
| 371 |
+
const iconY = y - this.height * 0.8;
|
| 372 |
+
|
| 373 |
+
ctx.fillStyle = '#FFD700';
|
| 374 |
+
ctx.font = '24px Arial';
|
| 375 |
+
ctx.textAlign = 'center';
|
| 376 |
+
ctx.fillText(this.getFoodEmoji(this.currentFood), x, iconY);
|
| 377 |
+
}
|
| 378 |
+
|
| 379 |
+
getFoodEmoji(foodName) {
|
| 380 |
+
const emojiMap = {
|
| 381 |
+
'apple': '🍎',
|
| 382 |
+
'banana': '🍌',
|
| 383 |
+
'orange': '🍊',
|
| 384 |
+
'strawberry': '🍓',
|
| 385 |
+
'watermelon': '🍉',
|
| 386 |
+
'grape': '🍇',
|
| 387 |
+
'pizza': '🍕',
|
| 388 |
+
'burger': '🍔',
|
| 389 |
+
'cake': '🍰',
|
| 390 |
+
'cookie': '🍪',
|
| 391 |
+
'bread': '🍞',
|
| 392 |
+
'cheese': '🧀',
|
| 393 |
+
'fish': '🐟',
|
| 394 |
+
'chicken': '🍗',
|
| 395 |
+
'rice': '🍚',
|
| 396 |
+
'noodles': '🍜'
|
| 397 |
+
};
|
| 398 |
+
|
| 399 |
+
return emojiMap[foodName] || '🍽️';
|
| 400 |
+
}
|
| 401 |
+
|
| 402 |
+
// 状态控制方法
|
| 403 |
+
activate() {
|
| 404 |
+
this.state = 'activated';
|
| 405 |
+
this.animationTime = 0;
|
| 406 |
+
}
|
| 407 |
+
|
| 408 |
+
startCooking(foodName) {
|
| 409 |
+
this.state = 'cooking';
|
| 410 |
+
this.currentFood = foodName;
|
| 411 |
+
this.animationTime = 0;
|
| 412 |
+
}
|
| 413 |
+
|
| 414 |
+
startOverflowing() {
|
| 415 |
+
this.state = 'overflowing';
|
| 416 |
+
this.animationTime = 0;
|
| 417 |
+
}
|
| 418 |
+
|
| 419 |
+
stopOverflowing() {
|
| 420 |
+
this.state = 'activated';
|
| 421 |
+
this.lidOffset = 0;
|
| 422 |
+
this.shakeAmount = 0;
|
| 423 |
+
}
|
| 424 |
+
|
| 425 |
+
reset() {
|
| 426 |
+
this.state = 'idle';
|
| 427 |
+
this.currentFood = null;
|
| 428 |
+
this.animationTime = 0;
|
| 429 |
+
this.glowIntensity = 0;
|
| 430 |
+
this.shakeAmount = 0;
|
| 431 |
+
this.lidOffset = 0;
|
| 432 |
+
this.steamParticles = [];
|
| 433 |
+
}
|
| 434 |
+
|
| 435 |
+
setFoodAssets(foodImage, animalImage) {
|
| 436 |
+
this.foodImage = foodImage;
|
| 437 |
+
this.animalImage = animalImage;
|
| 438 |
+
}
|
| 439 |
+
|
| 440 |
+
// 碰撞检测
|
| 441 |
+
contains(x, y) {
|
| 442 |
+
const dx = x - this.x;
|
| 443 |
+
const dy = y - this.y;
|
| 444 |
+
const distance = Math.sqrt(dx * dx + dy * dy);
|
| 445 |
+
return distance < this.width * 0.5;
|
| 446 |
+
}
|
| 447 |
+
|
| 448 |
+
// 获取锅的边界
|
| 449 |
+
getBounds() {
|
| 450 |
+
return {
|
| 451 |
+
left: this.x - this.width * 0.5,
|
| 452 |
+
right: this.x + this.width * 0.5,
|
| 453 |
+
top: this.y - this.height * 0.5,
|
| 454 |
+
bottom: this.y + this.height * 0.5
|
| 455 |
+
};
|
| 456 |
+
}
|
| 457 |
+
|
| 458 |
+
// 加载魔法锅图片
|
| 459 |
+
loadPotImage() {
|
| 460 |
+
this.potImage = new Image();
|
| 461 |
+
this.potImage.onload = () => {
|
| 462 |
+
this.imageLoaded = true;
|
| 463 |
+
console.log('魔法锅图片加载成功');
|
| 464 |
+
};
|
| 465 |
+
this.potImage.onerror = () => {
|
| 466 |
+
console.warn('魔法锅图片加载失败,使用默认绘制');
|
| 467 |
+
this.imageLoaded = false;
|
| 468 |
+
};
|
| 469 |
+
this.potImage.src = 'assets/images/magic_pot.png';
|
| 470 |
+
}
|
| 471 |
+
}
|
js/textToImage.js
CHANGED
|
@@ -1,346 +1,346 @@
|
|
| 1 |
-
// 文生图API接口类
|
| 2 |
-
class TextToImageAPI {
|
| 3 |
-
constructor() {
|
| 4 |
-
this.apiEndpoint = 'https://api.openai.com/v1/images/generations'; // 示例API
|
| 5 |
-
this.apiKey = null; // 需要用户配置
|
| 6 |
-
this.cache = new Map(); // 图片缓存
|
| 7 |
-
this.isEnabled = false;
|
| 8 |
-
|
| 9 |
-
// 备用图片数据(Base64编码的小图标)
|
| 10 |
-
this.fallbackImages = this.initFallbackImages();
|
| 11 |
-
|
| 12 |
-
this.init();
|
| 13 |
-
}
|
| 14 |
-
|
| 15 |
-
init() {
|
| 16 |
-
// 检查是否有API密钥配置
|
| 17 |
-
this.apiKey = localStorage.getItem('textToImageApiKey');
|
| 18 |
-
this.isEnabled = !!this.apiKey;
|
| 19 |
-
|
| 20 |
-
if (!this.isEnabled) {
|
| 21 |
-
console.log('文生图API未配置,将使用备用图片');
|
| 22 |
-
}
|
| 23 |
-
}
|
| 24 |
-
|
| 25 |
-
async generateFood(foodName) {
|
| 26 |
-
try {
|
| 27 |
-
// 首先检查缓存
|
| 28 |
-
const cacheKey = `food_${foodName}`;
|
| 29 |
-
if (this.cache.has(cacheKey)) {
|
| 30 |
-
return this.cache.get(cacheKey);
|
| 31 |
-
}
|
| 32 |
-
|
| 33 |
-
let imageData;
|
| 34 |
-
|
| 35 |
-
if (this.isEnabled) {
|
| 36 |
-
// 使用真实API生成图片
|
| 37 |
-
imageData = await this.callAPI(`cartoon style ${foodName} food, cute, colorful, simple background`);
|
| 38 |
-
} else {
|
| 39 |
-
// 使用备用图片
|
| 40 |
-
imageData = this.getFallbackFoodImage(foodName);
|
| 41 |
-
}
|
| 42 |
-
|
| 43 |
-
// 缓存结果
|
| 44 |
-
this.cache.set(cacheKey, imageData);
|
| 45 |
-
return imageData;
|
| 46 |
-
|
| 47 |
-
} catch (error) {
|
| 48 |
-
console.error('生成食物图片失败:', error);
|
| 49 |
-
return this.getFallbackFoodImage(foodName);
|
| 50 |
-
}
|
| 51 |
-
}
|
| 52 |
-
|
| 53 |
-
async generateAnimal(foodName) {
|
| 54 |
-
try {
|
| 55 |
-
const cacheKey = `animal_${foodName}`;
|
| 56 |
-
if (this.cache.has(cacheKey)) {
|
| 57 |
-
return this.cache.get(cacheKey);
|
| 58 |
-
}
|
| 59 |
-
|
| 60 |
-
const animalType = this.getAnimalForFood(foodName);
|
| 61 |
-
let imageData;
|
| 62 |
-
|
| 63 |
-
if (this.isEnabled) {
|
| 64 |
-
imageData = await this.callAPI(`cartoon style cute ${animalType} animal, friendly, colorful, simple background`);
|
| 65 |
-
} else {
|
| 66 |
-
imageData = this.getFallbackAnimalImage(animalType);
|
| 67 |
-
}
|
| 68 |
-
|
| 69 |
-
this.cache.set(cacheKey, imageData);
|
| 70 |
-
return imageData;
|
| 71 |
-
|
| 72 |
-
} catch (error) {
|
| 73 |
-
console.error('生成动物图片失败:', error);
|
| 74 |
-
return this.getFallbackAnimalImage(this.getAnimalForFood(foodName));
|
| 75 |
-
}
|
| 76 |
-
}
|
| 77 |
-
|
| 78 |
-
async callAPI(prompt) {
|
| 79 |
-
if (!this.isEnabled) {
|
| 80 |
-
throw new Error('API未启用');
|
| 81 |
-
}
|
| 82 |
-
|
| 83 |
-
const response = await fetch(this.apiEndpoint, {
|
| 84 |
-
method: 'POST',
|
| 85 |
-
headers: {
|
| 86 |
-
'Content-Type': 'application/json',
|
| 87 |
-
'Authorization': `Bearer ${this.apiKey}`
|
| 88 |
-
},
|
| 89 |
-
body: JSON.stringify({
|
| 90 |
-
prompt: prompt,
|
| 91 |
-
n: 1,
|
| 92 |
-
size: '256x256',
|
| 93 |
-
style: 'cartoon'
|
| 94 |
-
})
|
| 95 |
-
});
|
| 96 |
-
|
| 97 |
-
if (!response.ok) {
|
| 98 |
-
throw new Error(`API请求失败: ${response.status}`);
|
| 99 |
-
}
|
| 100 |
-
|
| 101 |
-
const data = await response.json();
|
| 102 |
-
|
| 103 |
-
if (data.data && data.data.length > 0) {
|
| 104 |
-
// 下载图片并转换为本地数据
|
| 105 |
-
return await this.downloadImage(data.data[0].url);
|
| 106 |
-
} else {
|
| 107 |
-
throw new Error('API返回数据格式错误');
|
| 108 |
-
}
|
| 109 |
-
}
|
| 110 |
-
|
| 111 |
-
async downloadImage(url) {
|
| 112 |
-
const response = await fetch(url);
|
| 113 |
-
const blob = await response.blob();
|
| 114 |
-
|
| 115 |
-
return new Promise((resolve, reject) => {
|
| 116 |
-
const reader = new FileReader();
|
| 117 |
-
reader.onload = () => resolve(reader.result);
|
| 118 |
-
reader.onerror = reject;
|
| 119 |
-
reader.readAsDataURL(blob);
|
| 120 |
-
});
|
| 121 |
-
}
|
| 122 |
-
|
| 123 |
-
getFallbackFoodImage(foodName) {
|
| 124 |
-
// 返回备用的食物图片数据
|
| 125 |
-
const fallbackFood = this.fallbackImages.food[foodName] || this.fallbackImages.food.default;
|
| 126 |
-
return this.createSimpleImage(fallbackFood.emoji, fallbackFood.color);
|
| 127 |
-
}
|
| 128 |
-
|
| 129 |
-
getFallbackAnimalImage(animalType) {
|
| 130 |
-
// 返回备用的动物图片数据
|
| 131 |
-
const fallbackAnimal = this.fallbackImages.animals[animalType] || this.fallbackImages.animals.default;
|
| 132 |
-
return this.createSimpleImage(fallbackAnimal.emoji, fallbackAnimal.color);
|
| 133 |
-
}
|
| 134 |
-
|
| 135 |
-
createSimpleImage(emoji, backgroundColor = '#FFFFFF') {
|
| 136 |
-
// 创建一个简单的Canvas图片
|
| 137 |
-
const canvas = document.createElement('canvas');
|
| 138 |
-
const ctx = canvas.getContext('2d');
|
| 139 |
-
|
| 140 |
-
canvas.width = 64;
|
| 141 |
-
canvas.height = 64;
|
| 142 |
-
|
| 143 |
-
// 背景
|
| 144 |
-
ctx.fillStyle = backgroundColor;
|
| 145 |
-
ctx.fillRect(0, 0, 64, 64);
|
| 146 |
-
|
| 147 |
-
// 表情符号
|
| 148 |
-
ctx.font = '40px Arial';
|
| 149 |
-
ctx.textAlign = 'center';
|
| 150 |
-
ctx.textBaseline = 'middle';
|
| 151 |
-
ctx.fillText(emoji, 32, 32);
|
| 152 |
-
|
| 153 |
-
return canvas.toDataURL();
|
| 154 |
-
}
|
| 155 |
-
|
| 156 |
-
initFallbackImages() {
|
| 157 |
-
return {
|
| 158 |
-
food: {
|
| 159 |
-
'apple': { emoji: '🍎', color: '#FFE4E1' },
|
| 160 |
-
'banana': { emoji: '🍌', color: '#FFFACD' },
|
| 161 |
-
'orange': { emoji: '🍊', color: '#FFE4B5' },
|
| 162 |
-
'strawberry': { emoji: '🍓', color: '#FFB6C1' },
|
| 163 |
-
'watermelon': { emoji: '🍉', color: '#F0FFF0' },
|
| 164 |
-
'grape': { emoji: '🍇', color: '#E6E6FA' },
|
| 165 |
-
'pizza': { emoji: '🍕', color: '#FFEFD5' },
|
| 166 |
-
'burger': { emoji: '🍔', color: '#F5DEB3' },
|
| 167 |
-
'cake': { emoji: '🍰', color: '#FFF8DC' },
|
| 168 |
-
'cookie': { emoji: '🍪', color: '#DEB887' },
|
| 169 |
-
'bread': { emoji: '🍞', color: '#F5DEB3' },
|
| 170 |
-
'cheese': { emoji: '🧀', color: '#FFFACD' },
|
| 171 |
-
'fish': { emoji: '🐟', color: '#E0FFFF' },
|
| 172 |
-
'chicken': { emoji: '🍗', color: '#FFEFD5' },
|
| 173 |
-
'rice': { emoji: '🍚', color: '#F8F8FF' },
|
| 174 |
-
'noodles': { emoji: '🍜', color: '#FFF8DC' },
|
| 175 |
-
'default': { emoji: '🍽️', color: '#F0F8FF' }
|
| 176 |
-
},
|
| 177 |
-
animals: {
|
| 178 |
-
'rabbit': { emoji: '🐰', color: '#F5F5DC' },
|
| 179 |
-
'monkey': { emoji: '🐵', color: '#DEB887' },
|
| 180 |
-
'bird': { emoji: '🐦', color: '#E0F6FF' },
|
| 181 |
-
'bear': { emoji: '🐻', color: '#D2B48C' },
|
| 182 |
-
'elephant': { emoji: '🐘', color: '#DCDCDC' },
|
| 183 |
-
'fox': { emoji: '🦊', color: '#FFE4B5' },
|
| 184 |
-
'cat': { emoji: '🐱', color: '#FFB6C1' },
|
| 185 |
-
'dog': { emoji: '🐶', color: '#DEB887' },
|
| 186 |
-
'mouse': { emoji: '🐭', color: '#D3D3D3' },
|
| 187 |
-
'squirrel': { emoji: '🐿️', color: '#D2691E' },
|
| 188 |
-
'duck': { emoji: '🦆', color: '#FFFACD' },
|
| 189 |
-
'rat': { emoji: '🐀', color: '#A9A9A9' },
|
| 190 |
-
'panda': { emoji: '🐼', color: '#F0F8FF' },
|
| 191 |
-
'chicken': { emoji: '🐔', color: '#FFFACD' },
|
| 192 |
-
'default': { emoji: '🐱', color: '#FFB6C1' }
|
| 193 |
-
}
|
| 194 |
-
};
|
| 195 |
-
}
|
| 196 |
-
|
| 197 |
-
getAnimalForFood(foodName) {
|
| 198 |
-
const animalMap = {
|
| 199 |
-
'apple': 'rabbit',
|
| 200 |
-
'banana': 'monkey',
|
| 201 |
-
'orange': 'bird',
|
| 202 |
-
'strawberry': 'bear',
|
| 203 |
-
'watermelon': 'elephant',
|
| 204 |
-
'grape': 'fox',
|
| 205 |
-
'pizza': 'cat',
|
| 206 |
-
'burger': 'dog',
|
| 207 |
-
'cake': 'mouse',
|
| 208 |
-
'cookie': 'squirrel',
|
| 209 |
-
'bread': 'duck',
|
| 210 |
-
'cheese': 'rat',
|
| 211 |
-
'fish': 'cat',
|
| 212 |
-
'chicken': 'dog',
|
| 213 |
-
'rice': 'bird',
|
| 214 |
-
'noodles': 'panda',
|
| 215 |
-
'carrot': 'rabbit',
|
| 216 |
-
'corn': 'chicken'
|
| 217 |
-
};
|
| 218 |
-
|
| 219 |
-
return animalMap[foodName] || 'cat';
|
| 220 |
-
}
|
| 221 |
-
|
| 222 |
-
// 配置API密钥
|
| 223 |
-
setApiKey(apiKey) {
|
| 224 |
-
this.apiKey = apiKey;
|
| 225 |
-
this.isEnabled = !!apiKey;
|
| 226 |
-
|
| 227 |
-
if (apiKey) {
|
| 228 |
-
localStorage.setItem('textToImageApiKey', apiKey);
|
| 229 |
-
} else {
|
| 230 |
-
localStorage.removeItem('textToImageApiKey');
|
| 231 |
-
}
|
| 232 |
-
}
|
| 233 |
-
|
| 234 |
-
// 清除缓存
|
| 235 |
-
clearCache() {
|
| 236 |
-
this.cache.clear();
|
| 237 |
-
}
|
| 238 |
-
|
| 239 |
-
// 获取缓存大小
|
| 240 |
-
getCacheSize() {
|
| 241 |
-
return this.cache.size;
|
| 242 |
-
}
|
| 243 |
-
|
| 244 |
-
// 预加载常用图片
|
| 245 |
-
async preloadCommonImages() {
|
| 246 |
-
const commonFoods = ['apple', 'banana', 'orange', 'strawberry', 'watermelon'];
|
| 247 |
-
const promises = [];
|
| 248 |
-
|
| 249 |
-
for (const food of commonFoods) {
|
| 250 |
-
promises.push(this.generateFood(food));
|
| 251 |
-
promises.push(this.generateAnimal(food));
|
| 252 |
-
}
|
| 253 |
-
|
| 254 |
-
try {
|
| 255 |
-
await Promise.all(promises);
|
| 256 |
-
console.log('常用图片预加载完成');
|
| 257 |
-
} catch (error) {
|
| 258 |
-
console.error('预加载图片失败:', error);
|
| 259 |
-
}
|
| 260 |
-
}
|
| 261 |
-
|
| 262 |
-
// 创建配置UI
|
| 263 |
-
createConfigUI() {
|
| 264 |
-
const configDiv = document.createElement('div');
|
| 265 |
-
configDiv.id = 'textToImageConfig';
|
| 266 |
-
configDiv.style.cssText = `
|
| 267 |
-
position: fixed;
|
| 268 |
-
top: 50%;
|
| 269 |
-
left: 50%;
|
| 270 |
-
transform: translate(-50%, -50%);
|
| 271 |
-
background: white;
|
| 272 |
-
padding: 20px;
|
| 273 |
-
border-radius: 10px;
|
| 274 |
-
box-shadow: 0 4px 20px rgba(0,0,0,0.3);
|
| 275 |
-
z-index: 10000;
|
| 276 |
-
display: none;
|
| 277 |
-
`;
|
| 278 |
-
|
| 279 |
-
configDiv.innerHTML = `
|
| 280 |
-
<h3>文生图API配置</h3>
|
| 281 |
-
<p>输入您的API密钥以启用AI图片生成功能:</p>
|
| 282 |
-
<input type="text" id="apiKeyInput" placeholder="输入API密钥" style="width: 300px; padding: 8px; margin: 10px 0;">
|
| 283 |
-
<br>
|
| 284 |
-
<button id="saveApiKey" style="padding: 8px 16px; margin-right: 10px;">保存</button>
|
| 285 |
-
<button id="cancelConfig" style="padding: 8px 16px;">取消</button>
|
| 286 |
-
<p style="font-size: 12px; color: #666; margin-top: 10px;">
|
| 287 |
-
如果不配置API密钥,将使用备用的表情符号图片
|
| 288 |
-
</p>
|
| 289 |
-
`;
|
| 290 |
-
|
| 291 |
-
document.body.appendChild(configDiv);
|
| 292 |
-
|
| 293 |
-
// 事件监听
|
| 294 |
-
document.getElementById('saveApiKey').onclick = () => {
|
| 295 |
-
const apiKey = document.getElementById('apiKeyInput').value.trim();
|
| 296 |
-
this.setApiKey(apiKey);
|
| 297 |
-
configDiv.style.display = 'none';
|
| 298 |
-
|
| 299 |
-
if (apiKey) {
|
| 300 |
-
alert('API密钥已保存,现在将使用AI生成图片');
|
| 301 |
-
} else {
|
| 302 |
-
alert('API密钥已清除,将使用备用图片');
|
| 303 |
-
}
|
| 304 |
-
};
|
| 305 |
-
|
| 306 |
-
document.getElementById('cancelConfig').onclick = () => {
|
| 307 |
-
configDiv.style.display = 'none';
|
| 308 |
-
};
|
| 309 |
-
|
| 310 |
-
return configDiv;
|
| 311 |
-
}
|
| 312 |
-
|
| 313 |
-
// 显示配置界面
|
| 314 |
-
showConfig() {
|
| 315 |
-
let configDiv = document.getElementById('textToImageConfig');
|
| 316 |
-
if (!configDiv) {
|
| 317 |
-
configDiv = this.createConfigUI();
|
| 318 |
-
}
|
| 319 |
-
|
| 320 |
-
document.getElementById('apiKeyInput').value = this.apiKey || '';
|
| 321 |
-
configDiv.style.display = 'block';
|
| 322 |
-
}
|
| 323 |
-
|
| 324 |
-
// 测试API连接
|
| 325 |
-
async testAPI() {
|
| 326 |
-
if (!this.isEnabled) {
|
| 327 |
-
return { success: false, message: 'API未配置' };
|
| 328 |
-
}
|
| 329 |
-
|
| 330 |
-
try {
|
| 331 |
-
await this.callAPI('test image');
|
| 332 |
-
return { success: true, message: 'API连接正常' };
|
| 333 |
-
} catch (error) {
|
| 334 |
-
return { success: false, message: error.message };
|
| 335 |
-
}
|
| 336 |
-
}
|
| 337 |
-
}
|
| 338 |
-
|
| 339 |
-
// 添加全局快捷键来配置API
|
| 340 |
-
document.addEventListener('keydown', (e) => {
|
| 341 |
-
if (e.ctrlKey && e.shiftKey && e.key === 'I') {
|
| 342 |
-
if (window.game && window.game.textToImage) {
|
| 343 |
-
window.game.textToImage.showConfig();
|
| 344 |
-
}
|
| 345 |
-
}
|
| 346 |
-
});
|
|
|
|
| 1 |
+
// 文生图API接口类
|
| 2 |
+
class TextToImageAPI {
|
| 3 |
+
constructor() {
|
| 4 |
+
this.apiEndpoint = 'https://api.openai.com/v1/images/generations'; // 示例API
|
| 5 |
+
this.apiKey = null; // 需要用户配置
|
| 6 |
+
this.cache = new Map(); // 图片缓存
|
| 7 |
+
this.isEnabled = false;
|
| 8 |
+
|
| 9 |
+
// 备用图片数据(Base64编码的小图标)
|
| 10 |
+
this.fallbackImages = this.initFallbackImages();
|
| 11 |
+
|
| 12 |
+
this.init();
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
init() {
|
| 16 |
+
// 检查是否有API密钥配置
|
| 17 |
+
this.apiKey = localStorage.getItem('textToImageApiKey');
|
| 18 |
+
this.isEnabled = !!this.apiKey;
|
| 19 |
+
|
| 20 |
+
if (!this.isEnabled) {
|
| 21 |
+
console.log('文生图API未配置,将使用备用图片');
|
| 22 |
+
}
|
| 23 |
+
}
|
| 24 |
+
|
| 25 |
+
async generateFood(foodName) {
|
| 26 |
+
try {
|
| 27 |
+
// 首先检查缓存
|
| 28 |
+
const cacheKey = `food_${foodName}`;
|
| 29 |
+
if (this.cache.has(cacheKey)) {
|
| 30 |
+
return this.cache.get(cacheKey);
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
let imageData;
|
| 34 |
+
|
| 35 |
+
if (this.isEnabled) {
|
| 36 |
+
// 使用真实API生成图片
|
| 37 |
+
imageData = await this.callAPI(`cartoon style ${foodName} food, cute, colorful, simple background`);
|
| 38 |
+
} else {
|
| 39 |
+
// 使用备用图片
|
| 40 |
+
imageData = this.getFallbackFoodImage(foodName);
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
// 缓存结果
|
| 44 |
+
this.cache.set(cacheKey, imageData);
|
| 45 |
+
return imageData;
|
| 46 |
+
|
| 47 |
+
} catch (error) {
|
| 48 |
+
console.error('生成食物图片失败:', error);
|
| 49 |
+
return this.getFallbackFoodImage(foodName);
|
| 50 |
+
}
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
async generateAnimal(foodName) {
|
| 54 |
+
try {
|
| 55 |
+
const cacheKey = `animal_${foodName}`;
|
| 56 |
+
if (this.cache.has(cacheKey)) {
|
| 57 |
+
return this.cache.get(cacheKey);
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
const animalType = this.getAnimalForFood(foodName);
|
| 61 |
+
let imageData;
|
| 62 |
+
|
| 63 |
+
if (this.isEnabled) {
|
| 64 |
+
imageData = await this.callAPI(`cartoon style cute ${animalType} animal, friendly, colorful, simple background`);
|
| 65 |
+
} else {
|
| 66 |
+
imageData = this.getFallbackAnimalImage(animalType);
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
this.cache.set(cacheKey, imageData);
|
| 70 |
+
return imageData;
|
| 71 |
+
|
| 72 |
+
} catch (error) {
|
| 73 |
+
console.error('生成动物图片失败:', error);
|
| 74 |
+
return this.getFallbackAnimalImage(this.getAnimalForFood(foodName));
|
| 75 |
+
}
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
async callAPI(prompt) {
|
| 79 |
+
if (!this.isEnabled) {
|
| 80 |
+
throw new Error('API未启用');
|
| 81 |
+
}
|
| 82 |
+
|
| 83 |
+
const response = await fetch(this.apiEndpoint, {
|
| 84 |
+
method: 'POST',
|
| 85 |
+
headers: {
|
| 86 |
+
'Content-Type': 'application/json',
|
| 87 |
+
'Authorization': `Bearer ${this.apiKey}`
|
| 88 |
+
},
|
| 89 |
+
body: JSON.stringify({
|
| 90 |
+
prompt: prompt,
|
| 91 |
+
n: 1,
|
| 92 |
+
size: '256x256',
|
| 93 |
+
style: 'cartoon'
|
| 94 |
+
})
|
| 95 |
+
});
|
| 96 |
+
|
| 97 |
+
if (!response.ok) {
|
| 98 |
+
throw new Error(`API请求失败: ${response.status}`);
|
| 99 |
+
}
|
| 100 |
+
|
| 101 |
+
const data = await response.json();
|
| 102 |
+
|
| 103 |
+
if (data.data && data.data.length > 0) {
|
| 104 |
+
// 下载图片并转换为本地数据
|
| 105 |
+
return await this.downloadImage(data.data[0].url);
|
| 106 |
+
} else {
|
| 107 |
+
throw new Error('API返回数据格式错误');
|
| 108 |
+
}
|
| 109 |
+
}
|
| 110 |
+
|
| 111 |
+
async downloadImage(url) {
|
| 112 |
+
const response = await fetch(url);
|
| 113 |
+
const blob = await response.blob();
|
| 114 |
+
|
| 115 |
+
return new Promise((resolve, reject) => {
|
| 116 |
+
const reader = new FileReader();
|
| 117 |
+
reader.onload = () => resolve(reader.result);
|
| 118 |
+
reader.onerror = reject;
|
| 119 |
+
reader.readAsDataURL(blob);
|
| 120 |
+
});
|
| 121 |
+
}
|
| 122 |
+
|
| 123 |
+
getFallbackFoodImage(foodName) {
|
| 124 |
+
// 返回备用的食物图片数据
|
| 125 |
+
const fallbackFood = this.fallbackImages.food[foodName] || this.fallbackImages.food.default;
|
| 126 |
+
return this.createSimpleImage(fallbackFood.emoji, fallbackFood.color);
|
| 127 |
+
}
|
| 128 |
+
|
| 129 |
+
getFallbackAnimalImage(animalType) {
|
| 130 |
+
// 返回备用的动物图片数据
|
| 131 |
+
const fallbackAnimal = this.fallbackImages.animals[animalType] || this.fallbackImages.animals.default;
|
| 132 |
+
return this.createSimpleImage(fallbackAnimal.emoji, fallbackAnimal.color);
|
| 133 |
+
}
|
| 134 |
+
|
| 135 |
+
createSimpleImage(emoji, backgroundColor = '#FFFFFF') {
|
| 136 |
+
// 创建一个简单的Canvas图片
|
| 137 |
+
const canvas = document.createElement('canvas');
|
| 138 |
+
const ctx = canvas.getContext('2d');
|
| 139 |
+
|
| 140 |
+
canvas.width = 64;
|
| 141 |
+
canvas.height = 64;
|
| 142 |
+
|
| 143 |
+
// 背景
|
| 144 |
+
ctx.fillStyle = backgroundColor;
|
| 145 |
+
ctx.fillRect(0, 0, 64, 64);
|
| 146 |
+
|
| 147 |
+
// 表情符号
|
| 148 |
+
ctx.font = '40px Arial';
|
| 149 |
+
ctx.textAlign = 'center';
|
| 150 |
+
ctx.textBaseline = 'middle';
|
| 151 |
+
ctx.fillText(emoji, 32, 32);
|
| 152 |
+
|
| 153 |
+
return canvas.toDataURL();
|
| 154 |
+
}
|
| 155 |
+
|
| 156 |
+
initFallbackImages() {
|
| 157 |
+
return {
|
| 158 |
+
food: {
|
| 159 |
+
'apple': { emoji: '🍎', color: '#FFE4E1' },
|
| 160 |
+
'banana': { emoji: '🍌', color: '#FFFACD' },
|
| 161 |
+
'orange': { emoji: '🍊', color: '#FFE4B5' },
|
| 162 |
+
'strawberry': { emoji: '🍓', color: '#FFB6C1' },
|
| 163 |
+
'watermelon': { emoji: '🍉', color: '#F0FFF0' },
|
| 164 |
+
'grape': { emoji: '🍇', color: '#E6E6FA' },
|
| 165 |
+
'pizza': { emoji: '🍕', color: '#FFEFD5' },
|
| 166 |
+
'burger': { emoji: '🍔', color: '#F5DEB3' },
|
| 167 |
+
'cake': { emoji: '🍰', color: '#FFF8DC' },
|
| 168 |
+
'cookie': { emoji: '🍪', color: '#DEB887' },
|
| 169 |
+
'bread': { emoji: '🍞', color: '#F5DEB3' },
|
| 170 |
+
'cheese': { emoji: '🧀', color: '#FFFACD' },
|
| 171 |
+
'fish': { emoji: '🐟', color: '#E0FFFF' },
|
| 172 |
+
'chicken': { emoji: '🍗', color: '#FFEFD5' },
|
| 173 |
+
'rice': { emoji: '🍚', color: '#F8F8FF' },
|
| 174 |
+
'noodles': { emoji: '🍜', color: '#FFF8DC' },
|
| 175 |
+
'default': { emoji: '🍽️', color: '#F0F8FF' }
|
| 176 |
+
},
|
| 177 |
+
animals: {
|
| 178 |
+
'rabbit': { emoji: '🐰', color: '#F5F5DC' },
|
| 179 |
+
'monkey': { emoji: '🐵', color: '#DEB887' },
|
| 180 |
+
'bird': { emoji: '🐦', color: '#E0F6FF' },
|
| 181 |
+
'bear': { emoji: '🐻', color: '#D2B48C' },
|
| 182 |
+
'elephant': { emoji: '🐘', color: '#DCDCDC' },
|
| 183 |
+
'fox': { emoji: '🦊', color: '#FFE4B5' },
|
| 184 |
+
'cat': { emoji: '🐱', color: '#FFB6C1' },
|
| 185 |
+
'dog': { emoji: '🐶', color: '#DEB887' },
|
| 186 |
+
'mouse': { emoji: '🐭', color: '#D3D3D3' },
|
| 187 |
+
'squirrel': { emoji: '🐿️', color: '#D2691E' },
|
| 188 |
+
'duck': { emoji: '🦆', color: '#FFFACD' },
|
| 189 |
+
'rat': { emoji: '🐀', color: '#A9A9A9' },
|
| 190 |
+
'panda': { emoji: '🐼', color: '#F0F8FF' },
|
| 191 |
+
'chicken': { emoji: '🐔', color: '#FFFACD' },
|
| 192 |
+
'default': { emoji: '🐱', color: '#FFB6C1' }
|
| 193 |
+
}
|
| 194 |
+
};
|
| 195 |
+
}
|
| 196 |
+
|
| 197 |
+
getAnimalForFood(foodName) {
|
| 198 |
+
const animalMap = {
|
| 199 |
+
'apple': 'rabbit',
|
| 200 |
+
'banana': 'monkey',
|
| 201 |
+
'orange': 'bird',
|
| 202 |
+
'strawberry': 'bear',
|
| 203 |
+
'watermelon': 'elephant',
|
| 204 |
+
'grape': 'fox',
|
| 205 |
+
'pizza': 'cat',
|
| 206 |
+
'burger': 'dog',
|
| 207 |
+
'cake': 'mouse',
|
| 208 |
+
'cookie': 'squirrel',
|
| 209 |
+
'bread': 'duck',
|
| 210 |
+
'cheese': 'rat',
|
| 211 |
+
'fish': 'cat',
|
| 212 |
+
'chicken': 'dog',
|
| 213 |
+
'rice': 'bird',
|
| 214 |
+
'noodles': 'panda',
|
| 215 |
+
'carrot': 'rabbit',
|
| 216 |
+
'corn': 'chicken'
|
| 217 |
+
};
|
| 218 |
+
|
| 219 |
+
return animalMap[foodName] || 'cat';
|
| 220 |
+
}
|
| 221 |
+
|
| 222 |
+
// 配置API密钥
|
| 223 |
+
setApiKey(apiKey) {
|
| 224 |
+
this.apiKey = apiKey;
|
| 225 |
+
this.isEnabled = !!apiKey;
|
| 226 |
+
|
| 227 |
+
if (apiKey) {
|
| 228 |
+
localStorage.setItem('textToImageApiKey', apiKey);
|
| 229 |
+
} else {
|
| 230 |
+
localStorage.removeItem('textToImageApiKey');
|
| 231 |
+
}
|
| 232 |
+
}
|
| 233 |
+
|
| 234 |
+
// 清除缓存
|
| 235 |
+
clearCache() {
|
| 236 |
+
this.cache.clear();
|
| 237 |
+
}
|
| 238 |
+
|
| 239 |
+
// 获取缓存大小
|
| 240 |
+
getCacheSize() {
|
| 241 |
+
return this.cache.size;
|
| 242 |
+
}
|
| 243 |
+
|
| 244 |
+
// 预加载常用图片
|
| 245 |
+
async preloadCommonImages() {
|
| 246 |
+
const commonFoods = ['apple', 'banana', 'orange', 'strawberry', 'watermelon'];
|
| 247 |
+
const promises = [];
|
| 248 |
+
|
| 249 |
+
for (const food of commonFoods) {
|
| 250 |
+
promises.push(this.generateFood(food));
|
| 251 |
+
promises.push(this.generateAnimal(food));
|
| 252 |
+
}
|
| 253 |
+
|
| 254 |
+
try {
|
| 255 |
+
await Promise.all(promises);
|
| 256 |
+
console.log('常用图片预加载完成');
|
| 257 |
+
} catch (error) {
|
| 258 |
+
console.error('预加载图片失败:', error);
|
| 259 |
+
}
|
| 260 |
+
}
|
| 261 |
+
|
| 262 |
+
// 创建配置UI
|
| 263 |
+
createConfigUI() {
|
| 264 |
+
const configDiv = document.createElement('div');
|
| 265 |
+
configDiv.id = 'textToImageConfig';
|
| 266 |
+
configDiv.style.cssText = `
|
| 267 |
+
position: fixed;
|
| 268 |
+
top: 50%;
|
| 269 |
+
left: 50%;
|
| 270 |
+
transform: translate(-50%, -50%);
|
| 271 |
+
background: white;
|
| 272 |
+
padding: 20px;
|
| 273 |
+
border-radius: 10px;
|
| 274 |
+
box-shadow: 0 4px 20px rgba(0,0,0,0.3);
|
| 275 |
+
z-index: 10000;
|
| 276 |
+
display: none;
|
| 277 |
+
`;
|
| 278 |
+
|
| 279 |
+
configDiv.innerHTML = `
|
| 280 |
+
<h3>文生图API配置</h3>
|
| 281 |
+
<p>输入您的API密钥以启用AI图片生成功能:</p>
|
| 282 |
+
<input type="text" id="apiKeyInput" placeholder="输入API密钥" style="width: 300px; padding: 8px; margin: 10px 0;">
|
| 283 |
+
<br>
|
| 284 |
+
<button id="saveApiKey" style="padding: 8px 16px; margin-right: 10px;">保存</button>
|
| 285 |
+
<button id="cancelConfig" style="padding: 8px 16px;">取消</button>
|
| 286 |
+
<p style="font-size: 12px; color: #666; margin-top: 10px;">
|
| 287 |
+
如果不配置API密钥,将使用备用的表情符号图片
|
| 288 |
+
</p>
|
| 289 |
+
`;
|
| 290 |
+
|
| 291 |
+
document.body.appendChild(configDiv);
|
| 292 |
+
|
| 293 |
+
// 事件监听
|
| 294 |
+
document.getElementById('saveApiKey').onclick = () => {
|
| 295 |
+
const apiKey = document.getElementById('apiKeyInput').value.trim();
|
| 296 |
+
this.setApiKey(apiKey);
|
| 297 |
+
configDiv.style.display = 'none';
|
| 298 |
+
|
| 299 |
+
if (apiKey) {
|
| 300 |
+
alert('API密钥已保存,现在将使用AI生成图片');
|
| 301 |
+
} else {
|
| 302 |
+
alert('API密钥已清除,将使用备用图片');
|
| 303 |
+
}
|
| 304 |
+
};
|
| 305 |
+
|
| 306 |
+
document.getElementById('cancelConfig').onclick = () => {
|
| 307 |
+
configDiv.style.display = 'none';
|
| 308 |
+
};
|
| 309 |
+
|
| 310 |
+
return configDiv;
|
| 311 |
+
}
|
| 312 |
+
|
| 313 |
+
// 显示配置界面
|
| 314 |
+
showConfig() {
|
| 315 |
+
let configDiv = document.getElementById('textToImageConfig');
|
| 316 |
+
if (!configDiv) {
|
| 317 |
+
configDiv = this.createConfigUI();
|
| 318 |
+
}
|
| 319 |
+
|
| 320 |
+
document.getElementById('apiKeyInput').value = this.apiKey || '';
|
| 321 |
+
configDiv.style.display = 'block';
|
| 322 |
+
}
|
| 323 |
+
|
| 324 |
+
// 测试API连接
|
| 325 |
+
async testAPI() {
|
| 326 |
+
if (!this.isEnabled) {
|
| 327 |
+
return { success: false, message: 'API未配置' };
|
| 328 |
+
}
|
| 329 |
+
|
| 330 |
+
try {
|
| 331 |
+
await this.callAPI('test image');
|
| 332 |
+
return { success: true, message: 'API连接正常' };
|
| 333 |
+
} catch (error) {
|
| 334 |
+
return { success: false, message: error.message };
|
| 335 |
+
}
|
| 336 |
+
}
|
| 337 |
+
}
|
| 338 |
+
|
| 339 |
+
// 添加全局快捷键来配置API
|
| 340 |
+
document.addEventListener('keydown', (e) => {
|
| 341 |
+
if (e.ctrlKey && e.shiftKey && e.key === 'I') {
|
| 342 |
+
if (window.game && window.game.textToImage) {
|
| 343 |
+
window.game.textToImage.showConfig();
|
| 344 |
+
}
|
| 345 |
+
}
|
| 346 |
+
});
|
js/voice.js
CHANGED
|
@@ -8,6 +8,23 @@ class VoiceRecognition {
|
|
| 8 |
this.onError = null;
|
| 9 |
this.onStatusChange = null;
|
| 10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
this.init();
|
| 12 |
}
|
| 13 |
|
|
@@ -26,7 +43,21 @@ class VoiceRecognition {
|
|
| 26 |
}
|
| 27 |
|
| 28 |
this.setupRecognition();
|
| 29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
}
|
| 31 |
|
| 32 |
setupRecognition() {
|
|
@@ -53,16 +84,30 @@ class VoiceRecognition {
|
|
| 53 |
|
| 54 |
this.recognition.onend = () => {
|
| 55 |
this.isListening = false;
|
|
|
|
| 56 |
this.updateStatus('ready');
|
| 57 |
console.log('语音识别结束');
|
| 58 |
|
| 59 |
-
//
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
};
|
| 67 |
}
|
| 68 |
|
|
@@ -109,6 +154,18 @@ class VoiceRecognition {
|
|
| 109 |
console.error('语音识别错误:', error);
|
| 110 |
this.updateStatus('error');
|
| 111 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 112 |
if (this.onError) {
|
| 113 |
this.onError(error);
|
| 114 |
}
|
|
@@ -117,99 +174,471 @@ class VoiceRecognition {
|
|
| 117 |
switch (error) {
|
| 118 |
case 'not-allowed':
|
| 119 |
this.showPermissionError();
|
|
|
|
| 120 |
break;
|
| 121 |
case 'no-speech':
|
| 122 |
-
// 没有检测到语音,
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
}, 1000);
|
| 128 |
break;
|
| 129 |
case 'network':
|
| 130 |
this.showNetworkError();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 131 |
break;
|
| 132 |
default:
|
| 133 |
-
// 其他错误,
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 139 |
break;
|
| 140 |
}
|
| 141 |
}
|
| 142 |
|
| 143 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 144 |
if (!this.isSupported) {
|
| 145 |
this.showUnsupportedError();
|
| 146 |
return;
|
| 147 |
}
|
| 148 |
|
| 149 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 150 |
if (this.isListening) {
|
| 151 |
console.log('语音识别已在运行中,跳过启动');
|
| 152 |
return;
|
| 153 |
}
|
| 154 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 155 |
try {
|
| 156 |
-
//
|
| 157 |
-
|
| 158 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 159 |
}
|
| 160 |
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
try {
|
| 171 |
-
this.recognition.start();
|
| 172 |
-
} catch (retryError) {
|
| 173 |
-
console.error('重试启动失败:', retryError);
|
| 174 |
-
this.handleError('start-failed');
|
| 175 |
-
}
|
| 176 |
-
}, 500);
|
| 177 |
-
} else {
|
| 178 |
-
throw error;
|
| 179 |
-
}
|
| 180 |
-
}
|
| 181 |
-
}, 100);
|
| 182 |
|
| 183 |
} catch (error) {
|
| 184 |
console.error('启动语音识别失败:', error);
|
| 185 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 186 |
}
|
| 187 |
}
|
| 188 |
|
| 189 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 190 |
if (this.recognition && this.isListening) {
|
| 191 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 192 |
}
|
| 193 |
}
|
| 194 |
|
| 195 |
-
// 重启语音识别
|
| 196 |
-
restart() {
|
| 197 |
-
console.log('重启语音识别系统...');
|
| 198 |
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
this.
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 206 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 207 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 208 |
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
this.
|
| 212 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 213 |
}
|
| 214 |
|
| 215 |
updateStatus(status) {
|
|
@@ -365,9 +794,99 @@ class VoiceRecognition {
|
|
| 365 |
return {
|
| 366 |
isSupported: this.isSupported,
|
| 367 |
isListening: this.isListening,
|
| 368 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 369 |
};
|
| 370 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 371 |
}
|
| 372 |
|
| 373 |
// 添加CSS动画
|
|
@@ -401,4 +920,4 @@ style.textContent = `
|
|
| 401 |
word-wrap: break-word;
|
| 402 |
}
|
| 403 |
`;
|
| 404 |
-
document.head.appendChild(style);
|
|
|
|
| 8 |
this.onError = null;
|
| 9 |
this.onStatusChange = null;
|
| 10 |
|
| 11 |
+
// 错误重试控制
|
| 12 |
+
this.retryCount = 0;
|
| 13 |
+
this.maxRetries = 3;
|
| 14 |
+
this.retryDelay = 2000; // 2秒延迟
|
| 15 |
+
this.lastErrorTime = 0;
|
| 16 |
+
this.consecutiveErrors = 0;
|
| 17 |
+
this.isDisabled = false;
|
| 18 |
+
|
| 19 |
+
// 新增:防止并发启动的锁机制
|
| 20 |
+
this.isStarting = false;
|
| 21 |
+
this.isStopping = false;
|
| 22 |
+
this.restartTimer = null;
|
| 23 |
+
this.startupPromise = null;
|
| 24 |
+
|
| 25 |
+
// 双击恢复功能标志
|
| 26 |
+
this.doubleClickRecoveryAdded = false;
|
| 27 |
+
|
| 28 |
this.init();
|
| 29 |
}
|
| 30 |
|
|
|
|
| 43 |
}
|
| 44 |
|
| 45 |
this.setupRecognition();
|
| 46 |
+
|
| 47 |
+
// 使用更安全的异步启动
|
| 48 |
+
setTimeout(async () => {
|
| 49 |
+
try {
|
| 50 |
+
console.log('初始化语音识别...');
|
| 51 |
+
await this.startListening();
|
| 52 |
+
} catch (error) {
|
| 53 |
+
console.error('初始化启动失败:', error);
|
| 54 |
+
// 如果初始化失败,给用户提供恢复选项
|
| 55 |
+
setTimeout(() => {
|
| 56 |
+
this.showNotification('语音识别初始化遇到问题,双击页面重新尝试', 'warning');
|
| 57 |
+
this.addDoubleClickRecovery();
|
| 58 |
+
}, 2000);
|
| 59 |
+
}
|
| 60 |
+
}, 500); // 增加初始化延迟
|
| 61 |
}
|
| 62 |
|
| 63 |
setupRecognition() {
|
|
|
|
| 84 |
|
| 85 |
this.recognition.onend = () => {
|
| 86 |
this.isListening = false;
|
| 87 |
+
this.isStopping = false;
|
| 88 |
this.updateStatus('ready');
|
| 89 |
console.log('语音识别结束');
|
| 90 |
|
| 91 |
+
// 清除之前的重启定时器
|
| 92 |
+
if (this.restartTimer) {
|
| 93 |
+
clearTimeout(this.restartTimer);
|
| 94 |
+
this.restartTimer = null;
|
| 95 |
+
}
|
| 96 |
+
|
| 97 |
+
// 智能重启逻辑 - 避免在错误频发时无限重试
|
| 98 |
+
if (this.shouldAttemptRestart()) {
|
| 99 |
+
const delay = this.calculateRestartDelay();
|
| 100 |
+
console.log(`准备在 ${delay}ms 后重新启动语音识别...`);
|
| 101 |
+
|
| 102 |
+
this.restartTimer = setTimeout(async () => {
|
| 103 |
+
if (this.isSupported && !this.isListening && !this.isDisabled && !this.isStarting) {
|
| 104 |
+
await this.startListening();
|
| 105 |
+
}
|
| 106 |
+
}, delay);
|
| 107 |
+
} else {
|
| 108 |
+
console.log('由于频繁错误,暂停自动重启语音识别');
|
| 109 |
+
this.showNotification('语音识别暂停,请点击页面重新激活或使用键盘输入(F9)', 'warning');
|
| 110 |
+
}
|
| 111 |
};
|
| 112 |
}
|
| 113 |
|
|
|
|
| 154 |
console.error('语音识别错误:', error);
|
| 155 |
this.updateStatus('error');
|
| 156 |
|
| 157 |
+
// no-speech不算作真正的错误,不影响错误计数
|
| 158 |
+
if (error !== 'no-speech') {
|
| 159 |
+
// 记录错误时间和连续错误次数
|
| 160 |
+
const now = Date.now();
|
| 161 |
+
if (now - this.lastErrorTime < 5000) { // 5秒内的错误视为连续错误
|
| 162 |
+
this.consecutiveErrors++;
|
| 163 |
+
} else {
|
| 164 |
+
this.consecutiveErrors = 1;
|
| 165 |
+
}
|
| 166 |
+
this.lastErrorTime = now;
|
| 167 |
+
}
|
| 168 |
+
|
| 169 |
if (this.onError) {
|
| 170 |
this.onError(error);
|
| 171 |
}
|
|
|
|
| 174 |
switch (error) {
|
| 175 |
case 'not-allowed':
|
| 176 |
this.showPermissionError();
|
| 177 |
+
this.isDisabled = true; // 禁用自动重启
|
| 178 |
break;
|
| 179 |
case 'no-speech':
|
| 180 |
+
// 没有检测到语音是正常现象,不需要任何特殊处理
|
| 181 |
+
console.log('没有检测到语音(正常状态)- 继续监听');
|
| 182 |
+
|
| 183 |
+
// no-speech是正常状态,语音识别会自动继续运行
|
| 184 |
+
// 不需要重启、不需要延迟、不需要任何额外操作
|
|
|
|
| 185 |
break;
|
| 186 |
case 'network':
|
| 187 |
this.showNetworkError();
|
| 188 |
+
console.log('网络错误,准备重试...');
|
| 189 |
+
if (this.consecutiveErrors < 5) { // 网络问题容忍度适中
|
| 190 |
+
const delay = Math.min(3000 + (this.consecutiveErrors * 2000), 15000);
|
| 191 |
+
setTimeout(async () => {
|
| 192 |
+
if (this.isSupported && !this.isDisabled && !this.isListening) {
|
| 193 |
+
console.log('网络错误重试中...');
|
| 194 |
+
await this.safeRestart();
|
| 195 |
+
}
|
| 196 |
+
}, delay);
|
| 197 |
+
} else {
|
| 198 |
+
this.showNotification('网络连接持续异常,语音识别已暂停。请检查网络后双击页面重启', 'error');
|
| 199 |
+
this.addDoubleClickRecovery();
|
| 200 |
+
this.isDisabled = true;
|
| 201 |
+
}
|
| 202 |
+
break;
|
| 203 |
+
case 'aborted':
|
| 204 |
+
this.handleAbortedError();
|
| 205 |
break;
|
| 206 |
default:
|
| 207 |
+
// 其他错误,谨慎重试
|
| 208 |
+
console.log(`未知错误类型: ${error},准备重试...`);
|
| 209 |
+
if (this.consecutiveErrors < 4) {
|
| 210 |
+
const delay = this.retryDelay * Math.pow(1.5, this.consecutiveErrors - 1);
|
| 211 |
+
setTimeout(async () => {
|
| 212 |
+
if (this.isSupported && !this.isDisabled && !this.isListening) {
|
| 213 |
+
console.log(`未知错误重试中(第${this.consecutiveErrors}次)...`);
|
| 214 |
+
await this.safeRestart();
|
| 215 |
+
}
|
| 216 |
+
}, delay);
|
| 217 |
+
} else {
|
| 218 |
+
this.showNotification(`语音识别遇到未知错误:${error}。已暂停,双击页面重启`, 'error');
|
| 219 |
+
this.addDoubleClickRecovery();
|
| 220 |
+
}
|
| 221 |
break;
|
| 222 |
}
|
| 223 |
}
|
| 224 |
|
| 225 |
+
handleAbortedError() {
|
| 226 |
+
console.log('处理 aborted 错误,连续错误次数:', this.consecutiveErrors);
|
| 227 |
+
|
| 228 |
+
// 更宽松的错误处理策略
|
| 229 |
+
if (this.consecutiveErrors >= 5) {
|
| 230 |
+
this.handleAbortedErrorLoop();
|
| 231 |
+
} else {
|
| 232 |
+
// 先完全清理当前状态
|
| 233 |
+
this.forceCleanup();
|
| 234 |
+
|
| 235 |
+
// 使用指数退避算法计算延迟时间
|
| 236 |
+
const baseDelay = 2000;
|
| 237 |
+
const delay = Math.min(baseDelay * Math.pow(2, this.consecutiveErrors - 1), 30000);
|
| 238 |
+
console.log(`Aborted 错误(第${this.consecutiveErrors}次),${delay}ms 后重试`);
|
| 239 |
+
|
| 240 |
+
// 添加状态检查的重试逻辑
|
| 241 |
+
setTimeout(async () => {
|
| 242 |
+
if (this.isSupported && !this.isDisabled && !this.isListening && !this.isStarting) {
|
| 243 |
+
console.log('重试启动语音识别...');
|
| 244 |
+
await this.safeRestart();
|
| 245 |
+
} else {
|
| 246 |
+
console.log('跳过重试,当前状态不允许启动');
|
| 247 |
+
}
|
| 248 |
+
}, delay);
|
| 249 |
+
}
|
| 250 |
+
}
|
| 251 |
+
|
| 252 |
+
handleAbortedErrorLoop() {
|
| 253 |
+
console.warn('检测到 aborted 错误循环,暂停自动重启');
|
| 254 |
+
this.isDisabled = true;
|
| 255 |
+
|
| 256 |
+
// 显示更详细的错误信息和解决方案
|
| 257 |
+
this.showNotification(
|
| 258 |
+
'语音识别遇到连续错误已暂停。解决方案:\n' +
|
| 259 |
+
'1. 按Ctrl+R刷新页面\n' +
|
| 260 |
+
'2. 使用键盘输入(F9键)\n' +
|
| 261 |
+
'3. 检查麦克风权限\n' +
|
| 262 |
+
'4. 双击页面手动重启',
|
| 263 |
+
'warning'
|
| 264 |
+
);
|
| 265 |
+
|
| 266 |
+
// 添加页面双击恢复功能
|
| 267 |
+
this.addDoubleClickRecovery();
|
| 268 |
+
|
| 269 |
+
// 减少自动恢复时间到2分钟,但保持更保守的重启策略
|
| 270 |
+
setTimeout(() => {
|
| 271 |
+
this.resetErrorState();
|
| 272 |
+
this.showNotification('语音识别已重新启用,双击页面激活', 'info');
|
| 273 |
+
}, 120000); // 2分钟
|
| 274 |
+
}
|
| 275 |
+
|
| 276 |
+
// 添加双击恢复功能
|
| 277 |
+
addDoubleClickRecovery() {
|
| 278 |
+
if (this.doubleClickRecoveryAdded) return;
|
| 279 |
+
|
| 280 |
+
const handleDoubleClick = async (event) => {
|
| 281 |
+
if (this.isDisabled) {
|
| 282 |
+
console.log('用户双击恢复语音识别');
|
| 283 |
+
this.showNotification('正在重启语音识别...', 'info');
|
| 284 |
+
|
| 285 |
+
// 完全重置并重启
|
| 286 |
+
this.resetErrorState();
|
| 287 |
+
await this.forceCleanup();
|
| 288 |
+
await new Promise(resolve => setTimeout(resolve, 1000));
|
| 289 |
+
|
| 290 |
+
if (this.isSupported) {
|
| 291 |
+
try {
|
| 292 |
+
await this.startListening();
|
| 293 |
+
this.showNotification('语音识别已成功重启!', 'info');
|
| 294 |
+
} catch (error) {
|
| 295 |
+
this.showNotification('重启失败,请稍后再试或刷新页面', 'error');
|
| 296 |
+
}
|
| 297 |
+
}
|
| 298 |
+
}
|
| 299 |
+
};
|
| 300 |
+
|
| 301 |
+
document.addEventListener('dblclick', handleDoubleClick);
|
| 302 |
+
this.doubleClickRecoveryAdded = true;
|
| 303 |
+
|
| 304 |
+
console.log('已添加双击恢复功能');
|
| 305 |
+
}
|
| 306 |
+
|
| 307 |
+
shouldAttemptRestart() {
|
| 308 |
+
// 判断是否应该尝试重启
|
| 309 |
+
if (this.isDisabled) return false;
|
| 310 |
+
if (this.consecutiveErrors >= 5) return false;
|
| 311 |
+
|
| 312 |
+
return true;
|
| 313 |
+
}
|
| 314 |
+
|
| 315 |
+
calculateRestartDelay() {
|
| 316 |
+
// 计算重启延迟时间
|
| 317 |
+
let baseDelay = this.retryDelay;
|
| 318 |
+
|
| 319 |
+
// 根据连续错误次数增加延迟
|
| 320 |
+
const multiplier = Math.min(this.consecutiveErrors, 5);
|
| 321 |
+
baseDelay *= multiplier;
|
| 322 |
+
|
| 323 |
+
return Math.min(baseDelay, 30000); // 最大30秒
|
| 324 |
+
}
|
| 325 |
+
|
| 326 |
+
resetErrorState() {
|
| 327 |
+
// 重置错误状态
|
| 328 |
+
this.consecutiveErrors = 0;
|
| 329 |
+
this.retryCount = 0;
|
| 330 |
+
this.isDisabled = false;
|
| 331 |
+
this.lastErrorTime = 0;
|
| 332 |
+
console.log('错误状态已重置');
|
| 333 |
+
}
|
| 334 |
+
|
| 335 |
+
// 强制清理所有状态和资源
|
| 336 |
+
forceCleanup() {
|
| 337 |
+
console.log('执行强制清理...');
|
| 338 |
+
|
| 339 |
+
// 清除所有定时器
|
| 340 |
+
if (this.restartTimer) {
|
| 341 |
+
clearTimeout(this.restartTimer);
|
| 342 |
+
this.restartTimer = null;
|
| 343 |
+
}
|
| 344 |
+
|
| 345 |
+
if (this.hideTimer) {
|
| 346 |
+
clearTimeout(this.hideTimer);
|
| 347 |
+
this.hideTimer = null;
|
| 348 |
+
}
|
| 349 |
+
|
| 350 |
+
// 强制停止语音识别
|
| 351 |
+
if (this.recognition) {
|
| 352 |
+
try {
|
| 353 |
+
this.recognition.abort();
|
| 354 |
+
} catch (error) {
|
| 355 |
+
console.log('强制停止时出错:', error);
|
| 356 |
+
}
|
| 357 |
+
}
|
| 358 |
+
|
| 359 |
+
// 重置所有状态
|
| 360 |
+
this.isListening = false;
|
| 361 |
+
this.isStarting = false;
|
| 362 |
+
this.isStopping = false;
|
| 363 |
+
|
| 364 |
+
console.log('强制清理完成');
|
| 365 |
+
}
|
| 366 |
+
|
| 367 |
+
// 安全重启 - 带有更完善的状态检查
|
| 368 |
+
async safeRestart() {
|
| 369 |
+
console.log('执行安全重启...');
|
| 370 |
+
|
| 371 |
+
try {
|
| 372 |
+
// 1. 强制清理
|
| 373 |
+
this.forceCleanup();
|
| 374 |
+
|
| 375 |
+
// 2. 等待一段时间确保清理完成
|
| 376 |
+
await new Promise(resolve => setTimeout(resolve, 1000));
|
| 377 |
+
|
| 378 |
+
// 3. 状态验证
|
| 379 |
+
if (this.isDisabled) {
|
| 380 |
+
console.log('语音识别已禁用,取消重启');
|
| 381 |
+
return;
|
| 382 |
+
}
|
| 383 |
+
|
| 384 |
+
if (this.isListening || this.isStarting) {
|
| 385 |
+
console.log('语音识别状态异常,取消重启');
|
| 386 |
+
return;
|
| 387 |
+
}
|
| 388 |
+
|
| 389 |
+
// 4. 重新初始化并启动
|
| 390 |
+
if (this.recognition) {
|
| 391 |
+
console.log('重新配置语音识别...');
|
| 392 |
+
this.setupRecognition();
|
| 393 |
+
await new Promise(resolve => setTimeout(resolve, 500));
|
| 394 |
+
|
| 395 |
+
console.log('启动语音识别...');
|
| 396 |
+
this.recognition.start();
|
| 397 |
+
console.log('安全重启成功');
|
| 398 |
+
}
|
| 399 |
+
|
| 400 |
+
} catch (error) {
|
| 401 |
+
console.error('安全重启失败:', error);
|
| 402 |
+
this.consecutiveErrors++;
|
| 403 |
+
|
| 404 |
+
// 如果安全重启也失败,增加更长的延迟后再试
|
| 405 |
+
if (this.consecutiveErrors < 5) {
|
| 406 |
+
setTimeout(() => this.safeRestart(), 5000);
|
| 407 |
+
}
|
| 408 |
+
}
|
| 409 |
+
}
|
| 410 |
+
|
| 411 |
+
async startListening() {
|
| 412 |
if (!this.isSupported) {
|
| 413 |
this.showUnsupportedError();
|
| 414 |
return;
|
| 415 |
}
|
| 416 |
|
| 417 |
+
if (this.isDisabled) {
|
| 418 |
+
console.log('语音识别已禁用,需要手动重启');
|
| 419 |
+
return;
|
| 420 |
+
}
|
| 421 |
+
|
| 422 |
+
// 增强的并发控制
|
| 423 |
+
if (this.isStarting) {
|
| 424 |
+
console.log('语音识别正在启动中,等待完成...');
|
| 425 |
+
// 等待当前启动完成
|
| 426 |
+
let attempts = 0;
|
| 427 |
+
while (this.isStarting && attempts < 10) {
|
| 428 |
+
await new Promise(resolve => setTimeout(resolve, 500));
|
| 429 |
+
attempts++;
|
| 430 |
+
}
|
| 431 |
+
if (this.isStarting) {
|
| 432 |
+
console.error('启动超时,强制清理');
|
| 433 |
+
this.forceCleanup();
|
| 434 |
+
}
|
| 435 |
+
return;
|
| 436 |
+
}
|
| 437 |
+
|
| 438 |
if (this.isListening) {
|
| 439 |
console.log('语音识别已在运行中,跳过启动');
|
| 440 |
return;
|
| 441 |
}
|
| 442 |
|
| 443 |
+
// 如果正在停止,等待停止完成
|
| 444 |
+
if (this.isStopping) {
|
| 445 |
+
console.log('等待停止完成后重新启动...');
|
| 446 |
+
let stopAttempts = 0;
|
| 447 |
+
while (this.isStopping && stopAttempts < 6) {
|
| 448 |
+
await new Promise(resolve => setTimeout(resolve, 500));
|
| 449 |
+
stopAttempts++;
|
| 450 |
+
}
|
| 451 |
+
if (this.isStopping) {
|
| 452 |
+
console.log('停止超时,强制清理');
|
| 453 |
+
this.forceCleanup();
|
| 454 |
+
}
|
| 455 |
+
}
|
| 456 |
+
|
| 457 |
+
this.isStarting = true;
|
| 458 |
+
console.log('开始启动语音识别...');
|
| 459 |
+
|
| 460 |
try {
|
| 461 |
+
// 1. 完全清理之前的状态
|
| 462 |
+
await this.ensureFullyStoppedAsync();
|
| 463 |
+
|
| 464 |
+
// 2. 额外的清理延迟
|
| 465 |
+
await new Promise(resolve => setTimeout(resolve, 800));
|
| 466 |
+
|
| 467 |
+
// 3. 最终状态检查
|
| 468 |
+
if (this.isDisabled) {
|
| 469 |
+
console.log('启动被取消:语音识别已禁用');
|
| 470 |
+
return;
|
| 471 |
}
|
| 472 |
|
| 473 |
+
if (this.isListening) {
|
| 474 |
+
console.log('启动被取消:语音识别已在运行');
|
| 475 |
+
return;
|
| 476 |
+
}
|
| 477 |
+
|
| 478 |
+
// 4. 尝试启动
|
| 479 |
+
console.log('尝试启动语音识别...');
|
| 480 |
+
this.recognition.start();
|
| 481 |
+
console.log('语音识别启动命令已发送');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 482 |
|
| 483 |
} catch (error) {
|
| 484 |
console.error('启动语音识别失败:', error);
|
| 485 |
+
|
| 486 |
+
// 特别处理常见错误
|
| 487 |
+
if (error.toString().includes('already started')) {
|
| 488 |
+
console.log('检测到重复启动错误,清理状态');
|
| 489 |
+
this.forceCleanup();
|
| 490 |
+
} else {
|
| 491 |
+
this.handleError('start-failed');
|
| 492 |
+
}
|
| 493 |
+
} finally {
|
| 494 |
+
// 延迟清除启动标志,确保onstart事件有时间触发
|
| 495 |
+
setTimeout(() => {
|
| 496 |
+
this.isStarting = false;
|
| 497 |
+
}, 1000);
|
| 498 |
}
|
| 499 |
}
|
| 500 |
|
| 501 |
+
// 确保语音识别完全停止
|
| 502 |
+
async ensureFullyStoppedAsync() {
|
| 503 |
+
if (!this.recognition) return;
|
| 504 |
+
|
| 505 |
+
return new Promise((resolve) => {
|
| 506 |
+
if (!this.isListening) {
|
| 507 |
+
resolve();
|
| 508 |
+
return;
|
| 509 |
+
}
|
| 510 |
+
|
| 511 |
+
this.isStopping = true;
|
| 512 |
+
|
| 513 |
+
// 设置停止完成监听器
|
| 514 |
+
const onStopComplete = () => {
|
| 515 |
+
this.recognition.removeEventListener('end', onStopComplete);
|
| 516 |
+
this.isStopping = false;
|
| 517 |
+
this.isListening = false;
|
| 518 |
+
console.log('语音识别已完全停止');
|
| 519 |
+
resolve();
|
| 520 |
+
};
|
| 521 |
+
|
| 522 |
+
this.recognition.addEventListener('end', onStopComplete);
|
| 523 |
+
|
| 524 |
+
// 强制停止
|
| 525 |
+
try {
|
| 526 |
+
this.recognition.abort();
|
| 527 |
+
} catch (error) {
|
| 528 |
+
console.log('停止时出现错误:', error);
|
| 529 |
+
// 即使出错也要继续
|
| 530 |
+
setTimeout(() => {
|
| 531 |
+
this.isStopping = false;
|
| 532 |
+
this.isListening = false;
|
| 533 |
+
resolve();
|
| 534 |
+
}, 1000);
|
| 535 |
+
}
|
| 536 |
+
|
| 537 |
+
// 超时保护
|
| 538 |
+
setTimeout(() => {
|
| 539 |
+
if (this.isStopping) {
|
| 540 |
+
console.log('停止超时,强制完成');
|
| 541 |
+
this.recognition.removeEventListener('end', onStopComplete);
|
| 542 |
+
this.isStopping = false;
|
| 543 |
+
this.isListening = false;
|
| 544 |
+
resolve();
|
| 545 |
+
}
|
| 546 |
+
}, 3000);
|
| 547 |
+
});
|
| 548 |
+
}
|
| 549 |
+
|
| 550 |
+
async stopListening() {
|
| 551 |
if (this.recognition && this.isListening) {
|
| 552 |
+
console.log('停止语音识别...');
|
| 553 |
+
// 清除重启定时器
|
| 554 |
+
if (this.restartTimer) {
|
| 555 |
+
clearTimeout(this.restartTimer);
|
| 556 |
+
this.restartTimer = null;
|
| 557 |
+
}
|
| 558 |
+
|
| 559 |
+
await this.ensureFullyStoppedAsync();
|
| 560 |
}
|
| 561 |
}
|
| 562 |
|
| 563 |
+
// 重启语音识别
|
| 564 |
+
async restart() {
|
| 565 |
+
console.log('手动重启语音识别系统...');
|
| 566 |
|
| 567 |
+
try {
|
| 568 |
+
// 显示重启进度
|
| 569 |
+
this.showNotification('正在重启语音识别...', 'info');
|
| 570 |
+
|
| 571 |
+
// 1. 重置错误状态
|
| 572 |
+
this.resetErrorState();
|
| 573 |
+
|
| 574 |
+
// 2. 强制清理所有状态
|
| 575 |
+
this.forceCleanup();
|
| 576 |
+
|
| 577 |
+
// 3. 等待清理完成
|
| 578 |
+
await new Promise(resolve => setTimeout(resolve, 1500));
|
| 579 |
+
|
| 580 |
+
// 4. 检查支持状态
|
| 581 |
+
if (!this.isSupported) {
|
| 582 |
+
this.showNotification('当前浏览器不支持语音识别', 'error');
|
| 583 |
+
return;
|
| 584 |
}
|
| 585 |
+
|
| 586 |
+
// 5. 重新初始化
|
| 587 |
+
this.setupRecognition();
|
| 588 |
+
await new Promise(resolve => setTimeout(resolve, 500));
|
| 589 |
+
|
| 590 |
+
// 6. 启动语音识别
|
| 591 |
+
if (!this.isDisabled) {
|
| 592 |
+
console.log('执行重启...');
|
| 593 |
+
await this.startListening();
|
| 594 |
+
this.showNotification('语音识别已成功重启!', 'info');
|
| 595 |
+
} else {
|
| 596 |
+
this.showNotification('语音识别重启完成,但仍处于禁用状态', 'warning');
|
| 597 |
+
}
|
| 598 |
+
|
| 599 |
+
} catch (error) {
|
| 600 |
+
console.error('重启失败:', error);
|
| 601 |
+
this.showNotification('重启失败,建议刷新页面重试', 'error');
|
| 602 |
+
|
| 603 |
+
// 重启失败时的降级方案
|
| 604 |
+
this.resetErrorState();
|
| 605 |
}
|
| 606 |
+
}
|
| 607 |
+
|
| 608 |
+
// 手动激活语音识别(用于用户点击按钮)
|
| 609 |
+
async manualActivate() {
|
| 610 |
+
console.log('手动激活语音识别');
|
| 611 |
+
this.resetErrorState();
|
| 612 |
|
| 613 |
+
if (this.isSupported) {
|
| 614 |
+
await this.startListening();
|
| 615 |
+
this.showNotification('语音识别已激活', 'info');
|
| 616 |
+
} else {
|
| 617 |
+
this.showNotification('当前浏览器不支持语音识别', 'error');
|
| 618 |
+
}
|
| 619 |
+
}
|
| 620 |
+
|
| 621 |
+
// 永久禁用语音识别
|
| 622 |
+
disable() {
|
| 623 |
+
console.log('禁用语音识别');
|
| 624 |
+
this.isDisabled = true;
|
| 625 |
+
|
| 626 |
+
if (this.recognition && this.isListening) {
|
| 627 |
+
this.recognition.abort();
|
| 628 |
+
}
|
| 629 |
+
|
| 630 |
+
this.showNotification('语音识别已禁用', 'warning');
|
| 631 |
+
}
|
| 632 |
+
|
| 633 |
+
// 启用语音识别
|
| 634 |
+
async enable() {
|
| 635 |
+
console.log('启用语音识别');
|
| 636 |
+
this.resetErrorState();
|
| 637 |
+
|
| 638 |
+
if (this.isSupported) {
|
| 639 |
+
this.showNotification('语音识别已启用', 'info');
|
| 640 |
+
await this.startListening();
|
| 641 |
+
}
|
| 642 |
}
|
| 643 |
|
| 644 |
updateStatus(status) {
|
|
|
|
| 794 |
return {
|
| 795 |
isSupported: this.isSupported,
|
| 796 |
isListening: this.isListening,
|
| 797 |
+
isDisabled: this.isDisabled,
|
| 798 |
+
isStarting: this.isStarting,
|
| 799 |
+
isStopping: this.isStopping,
|
| 800 |
+
consecutiveErrors: this.consecutiveErrors,
|
| 801 |
+
hasRestartTimer: !!this.restartTimer,
|
| 802 |
+
currentLanguage: this.recognition ? this.recognition.lang : null,
|
| 803 |
+
doubleClickRecoveryEnabled: this.doubleClickRecoveryAdded,
|
| 804 |
+
healthStatus: this.getHealthStatus()
|
| 805 |
};
|
| 806 |
}
|
| 807 |
+
|
| 808 |
+
// 获取系统健康状况
|
| 809 |
+
getHealthStatus() {
|
| 810 |
+
if (!this.isSupported) return 'unsupported';
|
| 811 |
+
if (this.isDisabled) return 'disabled';
|
| 812 |
+
if (this.consecutiveErrors >= 5) return 'critical';
|
| 813 |
+
if (this.consecutiveErrors >= 3) return 'warning';
|
| 814 |
+
if (this.isListening) return 'healthy';
|
| 815 |
+
if (this.isStarting) return 'starting';
|
| 816 |
+
return 'ready';
|
| 817 |
+
}
|
| 818 |
+
|
| 819 |
+
// 快速诊断和修复
|
| 820 |
+
async quickFix() {
|
| 821 |
+
console.log('执行快速诊断和修复...');
|
| 822 |
+
|
| 823 |
+
const status = this.getHealthStatus();
|
| 824 |
+
console.log('当前健康状况:', status);
|
| 825 |
+
|
| 826 |
+
switch (status) {
|
| 827 |
+
case 'unsupported':
|
| 828 |
+
this.showNotification('浏览器不支持语音识别功能', 'error');
|
| 829 |
+
return false;
|
| 830 |
+
|
| 831 |
+
case 'disabled':
|
| 832 |
+
case 'critical':
|
| 833 |
+
case 'warning':
|
| 834 |
+
console.log('检测到问题,执行完整重启...');
|
| 835 |
+
await this.restart();
|
| 836 |
+
return true;
|
| 837 |
+
|
| 838 |
+
case 'starting':
|
| 839 |
+
console.log('正在启动中,等待完成...');
|
| 840 |
+
return true;
|
| 841 |
+
|
| 842 |
+
case 'ready':
|
| 843 |
+
console.log('系统就绪,尝试启动...');
|
| 844 |
+
await this.startListening();
|
| 845 |
+
return true;
|
| 846 |
+
|
| 847 |
+
case 'healthy':
|
| 848 |
+
console.log('系统运行正常');
|
| 849 |
+
return true;
|
| 850 |
+
|
| 851 |
+
default:
|
| 852 |
+
console.log('未知状态,执行重启...');
|
| 853 |
+
await this.restart();
|
| 854 |
+
return true;
|
| 855 |
+
}
|
| 856 |
+
}
|
| 857 |
+
|
| 858 |
+
// 清理所有资源和状态
|
| 859 |
+
cleanup() {
|
| 860 |
+
console.log('清理语音识别资源...');
|
| 861 |
+
|
| 862 |
+
// 清除所有定时器
|
| 863 |
+
if (this.restartTimer) {
|
| 864 |
+
clearTimeout(this.restartTimer);
|
| 865 |
+
this.restartTimer = null;
|
| 866 |
+
}
|
| 867 |
+
|
| 868 |
+
if (this.hideTimer) {
|
| 869 |
+
clearTimeout(this.hideTimer);
|
| 870 |
+
this.hideTimer = null;
|
| 871 |
+
}
|
| 872 |
+
|
| 873 |
+
// 停止语音识别
|
| 874 |
+
if (this.recognition) {
|
| 875 |
+
try {
|
| 876 |
+
this.recognition.abort();
|
| 877 |
+
} catch (error) {
|
| 878 |
+
console.log('清理时停止识别出错:', error);
|
| 879 |
+
}
|
| 880 |
+
}
|
| 881 |
+
|
| 882 |
+
// 重置状态
|
| 883 |
+
this.isListening = false;
|
| 884 |
+
this.isStarting = false;
|
| 885 |
+
this.isStopping = false;
|
| 886 |
+
this.isDisabled = true;
|
| 887 |
+
|
| 888 |
+
console.log('语音识别资源清理完成');
|
| 889 |
+
}
|
| 890 |
}
|
| 891 |
|
| 892 |
// 添加CSS动画
|
|
|
|
| 920 |
word-wrap: break-word;
|
| 921 |
}
|
| 922 |
`;
|
| 923 |
+
document.head.appendChild(style);
|
nginx.conf
CHANGED
|
@@ -1,69 +1,69 @@
|
|
| 1 |
-
server {
|
| 2 |
-
listen 80;
|
| 3 |
-
server_name localhost;
|
| 4 |
-
|
| 5 |
-
# 设置根目录
|
| 6 |
-
root /usr/share/nginx/html;
|
| 7 |
-
index index.html;
|
| 8 |
-
|
| 9 |
-
# 设置字符编码
|
| 10 |
-
charset utf-8;
|
| 11 |
-
|
| 12 |
-
# 主页面
|
| 13 |
-
location / {
|
| 14 |
-
try_files $uri $uri/ /index.html;
|
| 15 |
-
}
|
| 16 |
-
|
| 17 |
-
# 静态资源缓存设置
|
| 18 |
-
location ~* \.(css|js|png|jpg|jpeg|gif|ico|svg|mp3|wav|ogg)$ {
|
| 19 |
-
expires 1y;
|
| 20 |
-
add_header Cache-Control "public, immutable";
|
| 21 |
-
add_header Access-Control-Allow-Origin "*";
|
| 22 |
-
}
|
| 23 |
-
|
| 24 |
-
# HTML文件缓存设置
|
| 25 |
-
location ~* \.html$ {
|
| 26 |
-
expires 1h;
|
| 27 |
-
add_header Cache-Control "public";
|
| 28 |
-
}
|
| 29 |
-
|
| 30 |
-
# 启用gzip压缩
|
| 31 |
-
gzip on;
|
| 32 |
-
gzip_vary on;
|
| 33 |
-
gzip_min_length 1024;
|
| 34 |
-
gzip_proxied any;
|
| 35 |
-
gzip_comp_level 6;
|
| 36 |
-
gzip_types
|
| 37 |
-
application/atom+xml
|
| 38 |
-
application/geo+json
|
| 39 |
-
application/javascript
|
| 40 |
-
application/x-javascript
|
| 41 |
-
application/json
|
| 42 |
-
application/ld+json
|
| 43 |
-
application/manifest+json
|
| 44 |
-
application/rdf+xml
|
| 45 |
-
application/rss+xml
|
| 46 |
-
application/xhtml+xml
|
| 47 |
-
application/xml
|
| 48 |
-
font/eot
|
| 49 |
-
font/otf
|
| 50 |
-
font/ttf
|
| 51 |
-
image/svg+xml
|
| 52 |
-
text/css
|
| 53 |
-
text/javascript
|
| 54 |
-
text/plain
|
| 55 |
-
text/xml;
|
| 56 |
-
|
| 57 |
-
# 安全头设置
|
| 58 |
-
add_header X-Frame-Options "SAMEORIGIN" always;
|
| 59 |
-
add_header X-Content-Type-Options "nosniff" always;
|
| 60 |
-
add_header X-XSS-Protection "1; mode=block" always;
|
| 61 |
-
add_header Referrer-Policy "no-referrer-when-downgrade" always;
|
| 62 |
-
|
| 63 |
-
# 错误页面
|
| 64 |
-
error_page 404 /index.html;
|
| 65 |
-
|
| 66 |
-
# 日志
|
| 67 |
-
access_log /var/log/nginx/access.log;
|
| 68 |
-
error_log /var/log/nginx/error.log;
|
| 69 |
-
}
|
|
|
|
| 1 |
+
server {
|
| 2 |
+
listen 80;
|
| 3 |
+
server_name localhost;
|
| 4 |
+
|
| 5 |
+
# 设置根目录
|
| 6 |
+
root /usr/share/nginx/html;
|
| 7 |
+
index index.html;
|
| 8 |
+
|
| 9 |
+
# 设置字符编码
|
| 10 |
+
charset utf-8;
|
| 11 |
+
|
| 12 |
+
# 主页面
|
| 13 |
+
location / {
|
| 14 |
+
try_files $uri $uri/ /index.html;
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
# 静态资源缓存设置
|
| 18 |
+
location ~* \.(css|js|png|jpg|jpeg|gif|ico|svg|mp3|wav|ogg)$ {
|
| 19 |
+
expires 1y;
|
| 20 |
+
add_header Cache-Control "public, immutable";
|
| 21 |
+
add_header Access-Control-Allow-Origin "*";
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
# HTML文件缓存设置
|
| 25 |
+
location ~* \.html$ {
|
| 26 |
+
expires 1h;
|
| 27 |
+
add_header Cache-Control "public";
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
# 启用gzip压缩
|
| 31 |
+
gzip on;
|
| 32 |
+
gzip_vary on;
|
| 33 |
+
gzip_min_length 1024;
|
| 34 |
+
gzip_proxied any;
|
| 35 |
+
gzip_comp_level 6;
|
| 36 |
+
gzip_types
|
| 37 |
+
application/atom+xml
|
| 38 |
+
application/geo+json
|
| 39 |
+
application/javascript
|
| 40 |
+
application/x-javascript
|
| 41 |
+
application/json
|
| 42 |
+
application/ld+json
|
| 43 |
+
application/manifest+json
|
| 44 |
+
application/rdf+xml
|
| 45 |
+
application/rss+xml
|
| 46 |
+
application/xhtml+xml
|
| 47 |
+
application/xml
|
| 48 |
+
font/eot
|
| 49 |
+
font/otf
|
| 50 |
+
font/ttf
|
| 51 |
+
image/svg+xml
|
| 52 |
+
text/css
|
| 53 |
+
text/javascript
|
| 54 |
+
text/plain
|
| 55 |
+
text/xml;
|
| 56 |
+
|
| 57 |
+
# 安全头设置
|
| 58 |
+
add_header X-Frame-Options "SAMEORIGIN" always;
|
| 59 |
+
add_header X-Content-Type-Options "nosniff" always;
|
| 60 |
+
add_header X-XSS-Protection "1; mode=block" always;
|
| 61 |
+
add_header Referrer-Policy "no-referrer-when-downgrade" always;
|
| 62 |
+
|
| 63 |
+
# 错误页面
|
| 64 |
+
error_page 404 /index.html;
|
| 65 |
+
|
| 66 |
+
# 日志
|
| 67 |
+
access_log /var/log/nginx/access.log;
|
| 68 |
+
error_log /var/log/nginx/error.log;
|
| 69 |
+
}
|
package-lock.json
CHANGED
|
The diff for this file is too large to render.
See raw diff
|
|
|
package.json
CHANGED
|
@@ -1,36 +1,36 @@
|
|
| 1 |
-
{
|
| 2 |
-
"name": "magic-pot-game",
|
| 3 |
-
"version": "1.0.0",
|
| 4 |
-
"description": "一个卡通手绘风格的语音交互魔法锅游戏",
|
| 5 |
-
"main": "index.html",
|
| 6 |
-
"scripts": {
|
| 7 |
-
"start": "python -m http.server 8000",
|
| 8 |
-
"serve": "npx http-server -p 8000 -o",
|
| 9 |
-
"dev": "npx live-server --port=8000 --open=/index.html"
|
| 10 |
-
},
|
| 11 |
-
"keywords": [
|
| 12 |
-
"game",
|
| 13 |
-
"voice-recognition",
|
| 14 |
-
"canvas",
|
| 15 |
-
"javascript",
|
| 16 |
-
"cartoon",
|
| 17 |
-
"magic-pot"
|
| 18 |
-
],
|
| 19 |
-
"author": "MagicPot Game Developer",
|
| 20 |
-
"license": "MIT",
|
| 21 |
-
"devDependencies": {
|
| 22 |
-
"http-server": "^14.1.1",
|
| 23 |
-
"live-server": "^1.2.2"
|
| 24 |
-
},
|
| 25 |
-
"engines": {
|
| 26 |
-
"node": ">=14.0.0"
|
| 27 |
-
},
|
| 28 |
-
"repository": {
|
| 29 |
-
"type": "git",
|
| 30 |
-
"url": "https://github.com/your-username/magic-pot-game.git"
|
| 31 |
-
},
|
| 32 |
-
"bugs": {
|
| 33 |
-
"url": "https://github.com/your-username/magic-pot-game/issues"
|
| 34 |
-
},
|
| 35 |
-
"homepage": "https://github.com/your-username/magic-pot-game#readme"
|
| 36 |
-
}
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "magic-pot-game",
|
| 3 |
+
"version": "1.0.0",
|
| 4 |
+
"description": "一个卡通手绘风格的语音交互魔法锅游戏",
|
| 5 |
+
"main": "index.html",
|
| 6 |
+
"scripts": {
|
| 7 |
+
"start": "python -m http.server 8000",
|
| 8 |
+
"serve": "npx http-server -p 8000 -o",
|
| 9 |
+
"dev": "npx live-server --port=8000 --open=/index.html"
|
| 10 |
+
},
|
| 11 |
+
"keywords": [
|
| 12 |
+
"game",
|
| 13 |
+
"voice-recognition",
|
| 14 |
+
"canvas",
|
| 15 |
+
"javascript",
|
| 16 |
+
"cartoon",
|
| 17 |
+
"magic-pot"
|
| 18 |
+
],
|
| 19 |
+
"author": "MagicPot Game Developer",
|
| 20 |
+
"license": "MIT",
|
| 21 |
+
"devDependencies": {
|
| 22 |
+
"http-server": "^14.1.1",
|
| 23 |
+
"live-server": "^1.2.2"
|
| 24 |
+
},
|
| 25 |
+
"engines": {
|
| 26 |
+
"node": ">=14.0.0"
|
| 27 |
+
},
|
| 28 |
+
"repository": {
|
| 29 |
+
"type": "git",
|
| 30 |
+
"url": "https://github.com/your-username/magic-pot-game.git"
|
| 31 |
+
},
|
| 32 |
+
"bugs": {
|
| 33 |
+
"url": "https://github.com/your-username/magic-pot-game/issues"
|
| 34 |
+
},
|
| 35 |
+
"homepage": "https://github.com/your-username/magic-pot-game#readme"
|
| 36 |
+
}
|
style.css
CHANGED
|
@@ -1,1164 +1,1164 @@
|
|
| 1 |
-
/* 全局样式 */
|
| 2 |
-
* {
|
| 3 |
-
margin: 0;
|
| 4 |
-
padding: 0;
|
| 5 |
-
box-sizing: border-box;
|
| 6 |
-
}
|
| 7 |
-
|
| 8 |
-
body {
|
| 9 |
-
font-family: 'Comic Neue', cursive;
|
| 10 |
-
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
| 11 |
-
min-height: 100vh;
|
| 12 |
-
overflow: hidden;
|
| 13 |
-
}
|
| 14 |
-
|
| 15 |
-
/* 游戏容器 */
|
| 16 |
-
.game-container {
|
| 17 |
-
width: 100vw;
|
| 18 |
-
height: 100vh;
|
| 19 |
-
display: flex;
|
| 20 |
-
flex-direction: column;
|
| 21 |
-
position: relative;
|
| 22 |
-
}
|
| 23 |
-
|
| 24 |
-
/* 游戏标题区域 */
|
| 25 |
-
.game-header {
|
| 26 |
-
background: rgba(255, 255, 255, 0.95);
|
| 27 |
-
padding: 15px 20px;
|
| 28 |
-
display: flex;
|
| 29 |
-
justify-content: space-between;
|
| 30 |
-
align-items: center;
|
| 31 |
-
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
|
| 32 |
-
border-bottom: 3px solid #ff6b6b;
|
| 33 |
-
}
|
| 34 |
-
|
| 35 |
-
.header-controls {
|
| 36 |
-
display: flex;
|
| 37 |
-
align-items: center;
|
| 38 |
-
gap: 15px;
|
| 39 |
-
}
|
| 40 |
-
|
| 41 |
-
.audio-button, .voice-activate-button, .help-button {
|
| 42 |
-
background: #ff6b6b;
|
| 43 |
-
color: white;
|
| 44 |
-
border: none;
|
| 45 |
-
border-radius: 50%;
|
| 46 |
-
width: 40px;
|
| 47 |
-
height: 40px;
|
| 48 |
-
font-size: 18px;
|
| 49 |
-
cursor: pointer;
|
| 50 |
-
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
|
| 51 |
-
transition: all 0.3s ease;
|
| 52 |
-
font-family: 'Comic Neue', cursive;
|
| 53 |
-
font-weight: bold;
|
| 54 |
-
}
|
| 55 |
-
|
| 56 |
-
.audio-button:hover, .voice-activate-button:hover, .help-button:hover {
|
| 57 |
-
background: #e55555;
|
| 58 |
-
transform: scale(1.1);
|
| 59 |
-
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
|
| 60 |
-
}
|
| 61 |
-
|
| 62 |
-
.audio-button:active, .voice-activate-button:active, .help-button:active {
|
| 63 |
-
transform: scale(0.95);
|
| 64 |
-
}
|
| 65 |
-
|
| 66 |
-
/* 语音激活按钮特殊样式 */
|
| 67 |
-
.voice-activate-button {
|
| 68 |
-
background: #4ecdc4;
|
| 69 |
-
position: relative;
|
| 70 |
-
overflow: hidden;
|
| 71 |
-
}
|
| 72 |
-
|
| 73 |
-
.voice-activate-button:hover {
|
| 74 |
-
background: #44a08d;
|
| 75 |
-
}
|
| 76 |
-
|
| 77 |
-
.voice-activate-button.active {
|
| 78 |
-
background: #27ae60;
|
| 79 |
-
animation: voice-active-pulse 2s infinite;
|
| 80 |
-
}
|
| 81 |
-
|
| 82 |
-
.voice-activate-button.disabled {
|
| 83 |
-
background: #95a5a6;
|
| 84 |
-
opacity: 0.6;
|
| 85 |
-
cursor: not-allowed;
|
| 86 |
-
}
|
| 87 |
-
|
| 88 |
-
.voice-activate-button.disabled:hover {
|
| 89 |
-
background: #95a5a6;
|
| 90 |
-
transform: none;
|
| 91 |
-
}
|
| 92 |
-
|
| 93 |
-
@keyframes voice-active-pulse {
|
| 94 |
-
0% {
|
| 95 |
-
box-shadow: 0 2px 8px rgba(39, 174, 96, 0.3);
|
| 96 |
-
}
|
| 97 |
-
50% {
|
| 98 |
-
box-shadow: 0 2px 8px rgba(39, 174, 96, 0.6), 0 0 0 10px rgba(39, 174, 96, 0);
|
| 99 |
-
}
|
| 100 |
-
100% {
|
| 101 |
-
box-shadow: 0 2px 8px rgba(39, 174, 96, 0.3);
|
| 102 |
-
}
|
| 103 |
-
}
|
| 104 |
-
|
| 105 |
-
.audio-button.muted {
|
| 106 |
-
background: #95a5a6;
|
| 107 |
-
color: #bdc3c7;
|
| 108 |
-
}
|
| 109 |
-
|
| 110 |
-
.audio-button.muted:hover {
|
| 111 |
-
background: #7f8c8d;
|
| 112 |
-
}
|
| 113 |
-
|
| 114 |
-
.game-title {
|
| 115 |
-
font-family: 'Fredoka One', cursive;
|
| 116 |
-
font-size: 2.2em;
|
| 117 |
-
color: #ff6b6b;
|
| 118 |
-
text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.1);
|
| 119 |
-
margin: 0;
|
| 120 |
-
}
|
| 121 |
-
|
| 122 |
-
.voice-status {
|
| 123 |
-
display: flex;
|
| 124 |
-
align-items: center;
|
| 125 |
-
gap: 10px;
|
| 126 |
-
background: #4ecdc4;
|
| 127 |
-
padding: 8px 15px;
|
| 128 |
-
border-radius: 25px;
|
| 129 |
-
color: white;
|
| 130 |
-
font-weight: bold;
|
| 131 |
-
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
|
| 132 |
-
}
|
| 133 |
-
|
| 134 |
-
.mic-icon {
|
| 135 |
-
font-size: 1.2em;
|
| 136 |
-
animation: pulse 2s infinite;
|
| 137 |
-
}
|
| 138 |
-
|
| 139 |
-
@keyframes pulse {
|
| 140 |
-
0%, 100% { transform: scale(1); }
|
| 141 |
-
50% { transform: scale(1.1); }
|
| 142 |
-
}
|
| 143 |
-
|
| 144 |
-
/* 主游戏区域 */
|
| 145 |
-
.game-main {
|
| 146 |
-
flex: 1;
|
| 147 |
-
position: relative;
|
| 148 |
-
display: flex;
|
| 149 |
-
justify-content: center;
|
| 150 |
-
align-items: center;
|
| 151 |
-
}
|
| 152 |
-
|
| 153 |
-
#gameCanvas {
|
| 154 |
-
border: 4px solid #fff;
|
| 155 |
-
border-radius: 20px;
|
| 156 |
-
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
|
| 157 |
-
background: linear-gradient(45deg, #ffeaa7, #fab1a0);
|
| 158 |
-
}
|
| 159 |
-
|
| 160 |
-
/* 游戏UI覆盖层 */
|
| 161 |
-
.game-ui {
|
| 162 |
-
position: absolute;
|
| 163 |
-
top: 0;
|
| 164 |
-
left: 0;
|
| 165 |
-
width: 100%;
|
| 166 |
-
height: 100%;
|
| 167 |
-
pointer-events: none;
|
| 168 |
-
z-index: 10;
|
| 169 |
-
}
|
| 170 |
-
|
| 171 |
-
/* 键盘面板在game-ui内,需要特殊处理 */
|
| 172 |
-
.game-ui .keyboard-input-panel {
|
| 173 |
-
pointer-events: auto;
|
| 174 |
-
}
|
| 175 |
-
|
| 176 |
-
.game-ui .keyboard-input-panel.inactive {
|
| 177 |
-
pointer-events: none;
|
| 178 |
-
}
|
| 179 |
-
|
| 180 |
-
.game-ui .keyboard-input-panel.active {
|
| 181 |
-
pointer-events: auto !important;
|
| 182 |
-
}
|
| 183 |
-
|
| 184 |
-
/* 确保激活状态下所有子元素都可以交互 */
|
| 185 |
-
.keyboard-input-panel.active,
|
| 186 |
-
.keyboard-input-panel.active *,
|
| 187 |
-
.keyboard-input-panel.active .input-content,
|
| 188 |
-
.keyboard-input-panel.active .command-input,
|
| 189 |
-
.keyboard-input-panel.active .send-btn,
|
| 190 |
-
.keyboard-input-panel.active .quick-cmd,
|
| 191 |
-
.keyboard-input-panel.active .toggle-panel-btn,
|
| 192 |
-
.keyboard-input-panel.active .history-item {
|
| 193 |
-
pointer-events: auto !important;
|
| 194 |
-
}
|
| 195 |
-
|
| 196 |
-
/* 魔法锅状态 */
|
| 197 |
-
.pot-status {
|
| 198 |
-
position: absolute;
|
| 199 |
-
top: 20px;
|
| 200 |
-
left: 50%;
|
| 201 |
-
transform: translateX(-50%);
|
| 202 |
-
pointer-events: auto;
|
| 203 |
-
}
|
| 204 |
-
|
| 205 |
-
.status-indicator {
|
| 206 |
-
padding: 10px 20px;
|
| 207 |
-
border-radius: 25px;
|
| 208 |
-
font-weight: bold;
|
| 209 |
-
text-align: center;
|
| 210 |
-
box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
|
| 211 |
-
transition: all 0.3s ease;
|
| 212 |
-
}
|
| 213 |
-
|
| 214 |
-
.status-indicator.inactive {
|
| 215 |
-
background: #95a5a6;
|
| 216 |
-
color: white;
|
| 217 |
-
}
|
| 218 |
-
|
| 219 |
-
.status-indicator.active {
|
| 220 |
-
background: #e74c3c;
|
| 221 |
-
color: white;
|
| 222 |
-
animation: glow 2s infinite alternate;
|
| 223 |
-
}
|
| 224 |
-
|
| 225 |
-
.status-indicator.cooking {
|
| 226 |
-
background: #f39c12;
|
| 227 |
-
color: white;
|
| 228 |
-
animation: cooking-pulse 1s infinite;
|
| 229 |
-
}
|
| 230 |
-
|
| 231 |
-
.status-indicator.overflowing {
|
| 232 |
-
background: #27ae60;
|
| 233 |
-
color: white;
|
| 234 |
-
animation: overflow-shake 0.5s infinite;
|
| 235 |
-
}
|
| 236 |
-
|
| 237 |
-
@keyframes glow {
|
| 238 |
-
from { box-shadow: 0 4px 15px rgba(231, 76, 60, 0.3); }
|
| 239 |
-
to { box-shadow: 0 4px 25px rgba(231, 76, 60, 0.8); }
|
| 240 |
-
}
|
| 241 |
-
|
| 242 |
-
@keyframes cooking-pulse {
|
| 243 |
-
0%, 100% { transform: scale(1); }
|
| 244 |
-
50% { transform: scale(1.05); }
|
| 245 |
-
}
|
| 246 |
-
|
| 247 |
-
@keyframes overflow-shake {
|
| 248 |
-
0%, 100% { transform: translateX(0); }
|
| 249 |
-
25% { transform: translateX(-2px); }
|
| 250 |
-
75% { transform: translateX(2px); }
|
| 251 |
-
}
|
| 252 |
-
|
| 253 |
-
/* 烹饪信息 */
|
| 254 |
-
.cooking-info {
|
| 255 |
-
position: absolute;
|
| 256 |
-
top: 80px;
|
| 257 |
-
left: 50%;
|
| 258 |
-
transform: translateX(-50%);
|
| 259 |
-
background: rgba(255, 255, 255, 0.95);
|
| 260 |
-
padding: 15px 25px;
|
| 261 |
-
border-radius: 15px;
|
| 262 |
-
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
|
| 263 |
-
text-align: center;
|
| 264 |
-
min-width: 200px;
|
| 265 |
-
}
|
| 266 |
-
|
| 267 |
-
.cooking-food {
|
| 268 |
-
font-size: 1.2em;
|
| 269 |
-
font-weight: bold;
|
| 270 |
-
color: #2c3e50;
|
| 271 |
-
margin-bottom: 10px;
|
| 272 |
-
}
|
| 273 |
-
|
| 274 |
-
.progress-bar {
|
| 275 |
-
width: 100%;
|
| 276 |
-
height: 8px;
|
| 277 |
-
background: #ecf0f1;
|
| 278 |
-
border-radius: 4px;
|
| 279 |
-
overflow: hidden;
|
| 280 |
-
}
|
| 281 |
-
|
| 282 |
-
.progress-fill {
|
| 283 |
-
height: 100%;
|
| 284 |
-
background: linear-gradient(90deg, #ff6b6b, #4ecdc4);
|
| 285 |
-
border-radius: 4px;
|
| 286 |
-
transition: width 0.3s ease;
|
| 287 |
-
width: 0%;
|
| 288 |
-
}
|
| 289 |
-
|
| 290 |
-
/* 食物计数器 */
|
| 291 |
-
.food-counter {
|
| 292 |
-
position: absolute;
|
| 293 |
-
top: 20px;
|
| 294 |
-
right: 20px;
|
| 295 |
-
background: rgba(255, 255, 255, 0.95);
|
| 296 |
-
padding: 15px 20px;
|
| 297 |
-
border-radius: 15px;
|
| 298 |
-
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
|
| 299 |
-
display: flex;
|
| 300 |
-
align-items: center;
|
| 301 |
-
gap: 10px;
|
| 302 |
-
}
|
| 303 |
-
|
| 304 |
-
/* 性能监控 */
|
| 305 |
-
.performance-monitor {
|
| 306 |
-
position: absolute;
|
| 307 |
-
top: 20px;
|
| 308 |
-
left: 20px;
|
| 309 |
-
background: rgba(0, 0, 0, 0.8);
|
| 310 |
-
color: white;
|
| 311 |
-
padding: 10px 15px;
|
| 312 |
-
border-radius: 10px;
|
| 313 |
-
font-family: 'Courier New', monospace;
|
| 314 |
-
font-size: 0.9em;
|
| 315 |
-
box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
|
| 316 |
-
min-width: 120px;
|
| 317 |
-
}
|
| 318 |
-
|
| 319 |
-
.perf-item {
|
| 320 |
-
display: flex;
|
| 321 |
-
justify-content: space-between;
|
| 322 |
-
margin-bottom: 5px;
|
| 323 |
-
align-items: center;
|
| 324 |
-
}
|
| 325 |
-
|
| 326 |
-
.perf-item:last-child {
|
| 327 |
-
margin-bottom: 0;
|
| 328 |
-
}
|
| 329 |
-
|
| 330 |
-
.perf-label {
|
| 331 |
-
color: #4ecdc4;
|
| 332 |
-
font-weight: bold;
|
| 333 |
-
}
|
| 334 |
-
|
| 335 |
-
.perf-value {
|
| 336 |
-
color: #ffffff;
|
| 337 |
-
font-weight: bold;
|
| 338 |
-
text-align: right;
|
| 339 |
-
min-width: 30px;
|
| 340 |
-
}
|
| 341 |
-
|
| 342 |
-
.food-emoji {
|
| 343 |
-
font-size: 2em;
|
| 344 |
-
}
|
| 345 |
-
|
| 346 |
-
.count {
|
| 347 |
-
font-size: 1.5em;
|
| 348 |
-
font-weight: bold;
|
| 349 |
-
color: #2c3e50;
|
| 350 |
-
min-width: 30px;
|
| 351 |
-
text-align: center;
|
| 352 |
-
}
|
| 353 |
-
|
| 354 |
-
/* 语音提示 */
|
| 355 |
-
.voice-hints {
|
| 356 |
-
position: absolute;
|
| 357 |
-
bottom: 20px;
|
| 358 |
-
left: 50%;
|
| 359 |
-
transform: translateX(-50%);
|
| 360 |
-
display: flex;
|
| 361 |
-
flex-direction: column;
|
| 362 |
-
gap: 10px;
|
| 363 |
-
align-items: center;
|
| 364 |
-
}
|
| 365 |
-
|
| 366 |
-
.hint-item {
|
| 367 |
-
background: rgba(0, 0, 0, 0.8);
|
| 368 |
-
color: white;
|
| 369 |
-
padding: 8px 15px;
|
| 370 |
-
border-radius: 20px;
|
| 371 |
-
display: flex;
|
| 372 |
-
align-items: center;
|
| 373 |
-
gap: 10px;
|
| 374 |
-
font-size: 0.9em;
|
| 375 |
-
animation: hint-fade-in 0.5s ease;
|
| 376 |
-
}
|
| 377 |
-
|
| 378 |
-
.hint-command {
|
| 379 |
-
background: #ff6b6b;
|
| 380 |
-
padding: 4px 8px;
|
| 381 |
-
border-radius: 10px;
|
| 382 |
-
font-weight: bold;
|
| 383 |
-
font-size: 0.8em;
|
| 384 |
-
}
|
| 385 |
-
|
| 386 |
-
.hint-desc {
|
| 387 |
-
opacity: 0.9;
|
| 388 |
-
}
|
| 389 |
-
|
| 390 |
-
@keyframes hint-fade-in {
|
| 391 |
-
from { opacity: 0; transform: translateY(10px); }
|
| 392 |
-
to { opacity: 1; transform: translateY(0); }
|
| 393 |
-
}
|
| 394 |
-
|
| 395 |
-
/* 调试信息 */
|
| 396 |
-
.debug-info {
|
| 397 |
-
position: absolute;
|
| 398 |
-
top: 10px;
|
| 399 |
-
left: 10px;
|
| 400 |
-
background: rgba(0, 0, 0, 0.8);
|
| 401 |
-
color: white;
|
| 402 |
-
padding: 10px;
|
| 403 |
-
border-radius: 5px;
|
| 404 |
-
font-family: monospace;
|
| 405 |
-
font-size: 0.8em;
|
| 406 |
-
max-width: 300px;
|
| 407 |
-
max-height: 200px;
|
| 408 |
-
overflow-y: auto;
|
| 409 |
-
z-index: 1000;
|
| 410 |
-
}
|
| 411 |
-
|
| 412 |
-
/* 响应式设计 */
|
| 413 |
-
@media (max-width: 768px) {
|
| 414 |
-
.game-title {
|
| 415 |
-
font-size: 1.5em;
|
| 416 |
-
}
|
| 417 |
-
|
| 418 |
-
#gameCanvas {
|
| 419 |
-
width: 95vw;
|
| 420 |
-
height: 70vh;
|
| 421 |
-
}
|
| 422 |
-
|
| 423 |
-
.voice-hints {
|
| 424 |
-
bottom: 10px;
|
| 425 |
-
}
|
| 426 |
-
|
| 427 |
-
.hint-item {
|
| 428 |
-
font-size: 0.8em;
|
| 429 |
-
padding: 6px 12px;
|
| 430 |
-
}
|
| 431 |
-
}
|
| 432 |
-
|
| 433 |
-
/* 动画效果 */
|
| 434 |
-
.bounce-in {
|
| 435 |
-
animation: bounceIn 0.6s ease;
|
| 436 |
-
}
|
| 437 |
-
|
| 438 |
-
@keyframes bounceIn {
|
| 439 |
-
0% { transform: scale(0.3); opacity: 0; }
|
| 440 |
-
50% { transform: scale(1.05); }
|
| 441 |
-
70% { transform: scale(0.9); }
|
| 442 |
-
100% { transform: scale(1); opacity: 1; }
|
| 443 |
-
}
|
| 444 |
-
|
| 445 |
-
.fade-out {
|
| 446 |
-
animation: fadeOut 0.5s ease forwards;
|
| 447 |
-
}
|
| 448 |
-
|
| 449 |
-
@keyframes fadeOut {
|
| 450 |
-
from { opacity: 1; }
|
| 451 |
-
to { opacity: 0; }
|
| 452 |
-
}
|
| 453 |
-
|
| 454 |
-
/* 特殊效果 */
|
| 455 |
-
.sparkle {
|
| 456 |
-
position: absolute;
|
| 457 |
-
width: 4px;
|
| 458 |
-
height: 4px;
|
| 459 |
-
background: #ffd700;
|
| 460 |
-
border-radius: 50%;
|
| 461 |
-
animation: sparkle 1s ease-in-out infinite;
|
| 462 |
-
}
|
| 463 |
-
|
| 464 |
-
@keyframes sparkle {
|
| 465 |
-
0%, 100% { opacity: 0; transform: scale(0); }
|
| 466 |
-
50% { opacity: 1; transform: scale(1); }
|
| 467 |
-
}
|
| 468 |
-
|
| 469 |
-
/* 音频激活提示 */
|
| 470 |
-
.audio-activation-hint {
|
| 471 |
-
position: absolute;
|
| 472 |
-
top: 30%;
|
| 473 |
-
left: 50%;
|
| 474 |
-
transform: translate(-50%, -50%);
|
| 475 |
-
z-index: 200;
|
| 476 |
-
pointer-events: none;
|
| 477 |
-
animation: audioHintPulse 2s infinite;
|
| 478 |
-
}
|
| 479 |
-
|
| 480 |
-
.hint-bubble {
|
| 481 |
-
background: rgba(255, 107, 107, 0.95);
|
| 482 |
-
border: 3px solid #e74c3c;
|
| 483 |
-
border-radius: 20px;
|
| 484 |
-
padding: 15px 25px;
|
| 485 |
-
display: flex;
|
| 486 |
-
align-items: center;
|
| 487 |
-
gap: 10px;
|
| 488 |
-
box-shadow: 0 8px 32px rgba(231, 76, 60, 0.3);
|
| 489 |
-
color: white;
|
| 490 |
-
font-family: 'Comic Neue', cursive;
|
| 491 |
-
font-weight: bold;
|
| 492 |
-
}
|
| 493 |
-
|
| 494 |
-
.hint-icon {
|
| 495 |
-
font-size: 1.5em;
|
| 496 |
-
animation: audioIconBounce 1s infinite;
|
| 497 |
-
}
|
| 498 |
-
|
| 499 |
-
.hint-text {
|
| 500 |
-
font-size: 1.1em;
|
| 501 |
-
}
|
| 502 |
-
|
| 503 |
-
@keyframes audioHintPulse {
|
| 504 |
-
0%, 100% {
|
| 505 |
-
transform: translate(-50%, -50%) scale(1);
|
| 506 |
-
opacity: 0.9;
|
| 507 |
-
}
|
| 508 |
-
50% {
|
| 509 |
-
transform: translate(-50%, -50%) scale(1.05);
|
| 510 |
-
opacity: 1;
|
| 511 |
-
}
|
| 512 |
-
}
|
| 513 |
-
|
| 514 |
-
@keyframes audioIconBounce {
|
| 515 |
-
0%, 100% {
|
| 516 |
-
transform: translateY(0);
|
| 517 |
-
}
|
| 518 |
-
50% {
|
| 519 |
-
transform: translateY(-3px);
|
| 520 |
-
}
|
| 521 |
-
}
|
| 522 |
-
|
| 523 |
-
/* 语音输入显示 */
|
| 524 |
-
.voice-input-display {
|
| 525 |
-
position: absolute;
|
| 526 |
-
top: 50%;
|
| 527 |
-
left: 50%;
|
| 528 |
-
transform: translate(-50%, -50%);
|
| 529 |
-
z-index: 100;
|
| 530 |
-
pointer-events: none;
|
| 531 |
-
}
|
| 532 |
-
|
| 533 |
-
.speech-bubble {
|
| 534 |
-
background: rgba(255, 255, 255, 0.95);
|
| 535 |
-
border: 3px solid #ff6b6b;
|
| 536 |
-
border-radius: 25px;
|
| 537 |
-
padding: 20px 30px;
|
| 538 |
-
position: relative;
|
| 539 |
-
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
|
| 540 |
-
animation: speechBubble 0.3s ease-out;
|
| 541 |
-
max-width: 400px;
|
| 542 |
-
text-align: center;
|
| 543 |
-
}
|
| 544 |
-
|
| 545 |
-
.speech-bubble::before {
|
| 546 |
-
content: '';
|
| 547 |
-
position: absolute;
|
| 548 |
-
bottom: -15px;
|
| 549 |
-
left: 50%;
|
| 550 |
-
transform: translateX(-50%);
|
| 551 |
-
width: 0;
|
| 552 |
-
height: 0;
|
| 553 |
-
border-left: 15px solid transparent;
|
| 554 |
-
border-right: 15px solid transparent;
|
| 555 |
-
border-top: 15px solid #ff6b6b;
|
| 556 |
-
}
|
| 557 |
-
|
| 558 |
-
.speech-bubble::after {
|
| 559 |
-
content: '';
|
| 560 |
-
position: absolute;
|
| 561 |
-
bottom: -12px;
|
| 562 |
-
left: 50%;
|
| 563 |
-
transform: translateX(-50%);
|
| 564 |
-
width: 0;
|
| 565 |
-
height: 0;
|
| 566 |
-
border-left: 12px solid transparent;
|
| 567 |
-
border-right: 12px solid transparent;
|
| 568 |
-
border-top: 12px solid rgba(255, 255, 255, 0.95);
|
| 569 |
-
}
|
| 570 |
-
|
| 571 |
-
.speech-text {
|
| 572 |
-
font-size: 1.4em;
|
| 573 |
-
font-weight: bold;
|
| 574 |
-
color: #2c3e50;
|
| 575 |
-
margin-bottom: 8px;
|
| 576 |
-
font-family: 'Comic Neue', cursive;
|
| 577 |
-
line-height: 1.3;
|
| 578 |
-
}
|
| 579 |
-
|
| 580 |
-
.speech-confidence {
|
| 581 |
-
font-size: 0.9em;
|
| 582 |
-
color: #7f8c8d;
|
| 583 |
-
font-style: italic;
|
| 584 |
-
}
|
| 585 |
-
|
| 586 |
-
@keyframes speechBubble {
|
| 587 |
-
0% {
|
| 588 |
-
opacity: 0;
|
| 589 |
-
transform: scale(0.3) translateY(20px);
|
| 590 |
-
}
|
| 591 |
-
50% {
|
| 592 |
-
transform: scale(1.1) translateY(-5px);
|
| 593 |
-
}
|
| 594 |
-
100% {
|
| 595 |
-
opacity: 1;
|
| 596 |
-
transform: scale(1) translateY(0);
|
| 597 |
-
}
|
| 598 |
-
}
|
| 599 |
-
|
| 600 |
-
/* 语音识别状态动画 */
|
| 601 |
-
.speech-bubble.listening {
|
| 602 |
-
border-color: #e74c3c;
|
| 603 |
-
animation: listening-pulse 1.5s infinite;
|
| 604 |
-
}
|
| 605 |
-
|
| 606 |
-
.speech-bubble.processing {
|
| 607 |
-
border-color: #f39c12;
|
| 608 |
-
animation: processing-spin 2s infinite linear;
|
| 609 |
-
}
|
| 610 |
-
|
| 611 |
-
.speech-bubble.recognized {
|
| 612 |
-
border-color: #27ae60;
|
| 613 |
-
animation: recognized-bounce 0.6s ease-out;
|
| 614 |
-
}
|
| 615 |
-
|
| 616 |
-
@keyframes listening-pulse {
|
| 617 |
-
0%, 100% {
|
| 618 |
-
border-color: #e74c3c;
|
| 619 |
-
box-shadow: 0 8px 32px rgba(231, 76, 60, 0.2);
|
| 620 |
-
}
|
| 621 |
-
50% {
|
| 622 |
-
border-color: #c0392b;
|
| 623 |
-
box-shadow: 0 8px 32px rgba(231, 76, 60, 0.4);
|
| 624 |
-
}
|
| 625 |
-
}
|
| 626 |
-
|
| 627 |
-
@keyframes processing-spin {
|
| 628 |
-
0% {
|
| 629 |
-
border-color: #f39c12;
|
| 630 |
-
transform: rotate(0deg);
|
| 631 |
-
}
|
| 632 |
-
100% {
|
| 633 |
-
border-color: #e67e22;
|
| 634 |
-
transform: rotate(360deg);
|
| 635 |
-
}
|
| 636 |
-
}
|
| 637 |
-
|
| 638 |
-
@keyframes recognized-bounce {
|
| 639 |
-
0% { transform: scale(1); }
|
| 640 |
-
30% { transform: scale(1.1); }
|
| 641 |
-
60% { transform: scale(0.95); }
|
| 642 |
-
100% { transform: scale(1); }
|
| 643 |
-
}
|
| 644 |
-
|
| 645 |
-
/* 帮助模态框 */
|
| 646 |
-
.help-modal {
|
| 647 |
-
position: fixed;
|
| 648 |
-
top: 0;
|
| 649 |
-
left: 0;
|
| 650 |
-
width: 100%;
|
| 651 |
-
height: 100%;
|
| 652 |
-
z-index: 10000;
|
| 653 |
-
animation: modalFadeIn 0.3s ease-out;
|
| 654 |
-
}
|
| 655 |
-
|
| 656 |
-
.modal-overlay {
|
| 657 |
-
position: absolute;
|
| 658 |
-
top: 0;
|
| 659 |
-
left: 0;
|
| 660 |
-
width: 100%;
|
| 661 |
-
height: 100%;
|
| 662 |
-
background: rgba(0, 0, 0, 0.5);
|
| 663 |
-
backdrop-filter: blur(5px);
|
| 664 |
-
}
|
| 665 |
-
|
| 666 |
-
.modal-content {
|
| 667 |
-
position: absolute;
|
| 668 |
-
top: 50%;
|
| 669 |
-
left: 50%;
|
| 670 |
-
transform: translate(-50%, -50%);
|
| 671 |
-
background: white;
|
| 672 |
-
border-radius: 20px;
|
| 673 |
-
box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
|
| 674 |
-
max-width: 600px;
|
| 675 |
-
max-height: 80vh;
|
| 676 |
-
overflow: hidden;
|
| 677 |
-
font-family: 'Comic Neue', cursive;
|
| 678 |
-
}
|
| 679 |
-
|
| 680 |
-
.modal-header {
|
| 681 |
-
background: linear-gradient(45deg, #ff6b6b, #4ecdc4);
|
| 682 |
-
color: white;
|
| 683 |
-
padding: 20px 30px;
|
| 684 |
-
display: flex;
|
| 685 |
-
justify-content: space-between;
|
| 686 |
-
align-items: center;
|
| 687 |
-
}
|
| 688 |
-
|
| 689 |
-
.modal-header h2 {
|
| 690 |
-
margin: 0;
|
| 691 |
-
font-family: 'Fredoka One', cursive;
|
| 692 |
-
font-size: 1.5em;
|
| 693 |
-
}
|
| 694 |
-
|
| 695 |
-
.modal-close {
|
| 696 |
-
background: none;
|
| 697 |
-
border: none;
|
| 698 |
-
color: white;
|
| 699 |
-
font-size: 24px;
|
| 700 |
-
cursor: pointer;
|
| 701 |
-
padding: 5px;
|
| 702 |
-
border-radius: 50%;
|
| 703 |
-
width: 35px;
|
| 704 |
-
height: 35px;
|
| 705 |
-
display: flex;
|
| 706 |
-
align-items: center;
|
| 707 |
-
justify-content: center;
|
| 708 |
-
transition: background 0.3s ease;
|
| 709 |
-
}
|
| 710 |
-
|
| 711 |
-
.modal-close:hover {
|
| 712 |
-
background: rgba(255, 255, 255, 0.2);
|
| 713 |
-
}
|
| 714 |
-
|
| 715 |
-
.modal-body {
|
| 716 |
-
padding: 30px;
|
| 717 |
-
overflow-y: auto;
|
| 718 |
-
max-height: calc(80vh - 100px);
|
| 719 |
-
}
|
| 720 |
-
|
| 721 |
-
.help-section {
|
| 722 |
-
margin-bottom: 25px;
|
| 723 |
-
padding-bottom: 20px;
|
| 724 |
-
border-bottom: 2px solid #f0f0f0;
|
| 725 |
-
}
|
| 726 |
-
|
| 727 |
-
.help-section:last-child {
|
| 728 |
-
border-bottom: none;
|
| 729 |
-
margin-bottom: 0;
|
| 730 |
-
}
|
| 731 |
-
|
| 732 |
-
.help-section h4 {
|
| 733 |
-
color: #ff6b6b;
|
| 734 |
-
margin-bottom: 10px;
|
| 735 |
-
font-size: 1.2em;
|
| 736 |
-
}
|
| 737 |
-
|
| 738 |
-
.help-section p {
|
| 739 |
-
margin-bottom: 10px;
|
| 740 |
-
line-height: 1.5;
|
| 741 |
-
color: #2c3e50;
|
| 742 |
-
}
|
| 743 |
-
|
| 744 |
-
.help-section ul {
|
| 745 |
-
margin: 10px 0;
|
| 746 |
-
padding-left: 20px;
|
| 747 |
-
}
|
| 748 |
-
|
| 749 |
-
.help-section li {
|
| 750 |
-
margin-bottom: 5px;
|
| 751 |
-
color: #34495e;
|
| 752 |
-
line-height: 1.4;
|
| 753 |
-
}
|
| 754 |
-
|
| 755 |
-
.help-section strong {
|
| 756 |
-
color: #e74c3c;
|
| 757 |
-
}
|
| 758 |
-
|
| 759 |
-
@keyframes modalFadeIn {
|
| 760 |
-
0% {
|
| 761 |
-
opacity: 0;
|
| 762 |
-
transform: scale(0.9);
|
| 763 |
-
}
|
| 764 |
-
100% {
|
| 765 |
-
opacity: 1;
|
| 766 |
-
transform: scale(1);
|
| 767 |
-
}
|
| 768 |
-
}
|
| 769 |
-
|
| 770 |
-
@keyframes modalFadeOut {
|
| 771 |
-
0% {
|
| 772 |
-
opacity: 1;
|
| 773 |
-
transform: scale(1);
|
| 774 |
-
}
|
| 775 |
-
100% {
|
| 776 |
-
opacity: 0;
|
| 777 |
-
transform: scale(0.9);
|
| 778 |
-
}
|
| 779 |
-
}
|
| 780 |
-
|
| 781 |
-
/* 特殊消息动画 */
|
| 782 |
-
@keyframes specialMessage {
|
| 783 |
-
0% {
|
| 784 |
-
opacity: 0;
|
| 785 |
-
transform: translate(-50%, -50%) scale(0.3);
|
| 786 |
-
}
|
| 787 |
-
20% {
|
| 788 |
-
opacity: 1;
|
| 789 |
-
transform: translate(-50%, -50%) scale(1.1);
|
| 790 |
-
}
|
| 791 |
-
30% {
|
| 792 |
-
transform: translate(-50%, -50%) scale(1);
|
| 793 |
-
}
|
| 794 |
-
70% {
|
| 795 |
-
opacity: 1;
|
| 796 |
-
transform: translate(-50%, -50%) scale(1);
|
| 797 |
-
}
|
| 798 |
-
100% {
|
| 799 |
-
opacity: 0;
|
| 800 |
-
transform: translate(-50%, -50%) scale(0.8);
|
| 801 |
-
}
|
| 802 |
-
}
|
| 803 |
-
|
| 804 |
-
/* 键盘输入调试面板 */
|
| 805 |
-
.keyboard-input-panel {
|
| 806 |
-
position: fixed;
|
| 807 |
-
bottom: 20px;
|
| 808 |
-
right: 20px;
|
| 809 |
-
background: rgba(44, 62, 80, 0.95);
|
| 810 |
-
border: 2px solid #4ecdc4;
|
| 811 |
-
border-radius: 15px;
|
| 812 |
-
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
|
| 813 |
-
backdrop-filter: blur(10px);
|
| 814 |
-
color: white;
|
| 815 |
-
font-family: 'Comic Neue', cursive;
|
| 816 |
-
min-width: 300px;
|
| 817 |
-
max-width: 400px;
|
| 818 |
-
transition: all 0.4s ease;
|
| 819 |
-
z-index: 50;
|
| 820 |
-
pointer-events: auto;
|
| 821 |
-
cursor: move;
|
| 822 |
-
user-select: none;
|
| 823 |
-
}
|
| 824 |
-
|
| 825 |
-
/* 面板激活状态 */
|
| 826 |
-
.keyboard-input-panel.active {
|
| 827 |
-
z-index: 10000 !important;
|
| 828 |
-
transform: scale(1.02);
|
| 829 |
-
box-shadow: 0 12px 40px rgba(78, 205, 196, 0.4);
|
| 830 |
-
border-color: #ff6b6b;
|
| 831 |
-
background: rgba(44, 62, 80, 0.98);
|
| 832 |
-
pointer-events: auto !important;
|
| 833 |
-
}
|
| 834 |
-
|
| 835 |
-
/* 拖拽状态 */
|
| 836 |
-
.keyboard-input-panel.dragging {
|
| 837 |
-
transition: none !important;
|
| 838 |
-
transform: scale(1.05) rotate(2deg);
|
| 839 |
-
box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
|
| 840 |
-
z-index: 15000 !important;
|
| 841 |
-
}
|
| 842 |
-
|
| 843 |
-
.keyboard-input-panel.dragging .input-content {
|
| 844 |
-
pointer-events: none;
|
| 845 |
-
}
|
| 846 |
-
|
| 847 |
-
.keyboard-input-panel.dragging .input-header {
|
| 848 |
-
background: linear-gradient(45deg, #ff6b6b, #e74c3c);
|
| 849 |
-
}
|
| 850 |
-
|
| 851 |
-
/* 面板非激活状态(灰色透明) */
|
| 852 |
-
.keyboard-input-panel.inactive {
|
| 853 |
-
opacity: 0.4;
|
| 854 |
-
background: rgba(108, 117, 125, 0.7);
|
| 855 |
-
border-color: #6c757d;
|
| 856 |
-
transform: scale(0.95);
|
| 857 |
-
pointer-events: none;
|
| 858 |
-
}
|
| 859 |
-
|
| 860 |
-
.keyboard-input-panel.inactive .input-header {
|
| 861 |
-
background: linear-gradient(45deg, #6c757d, #495057);
|
| 862 |
-
}
|
| 863 |
-
|
| 864 |
-
.keyboard-input-panel.inactive .command-input {
|
| 865 |
-
border-color: #6c757d;
|
| 866 |
-
background: rgba(108, 117, 125, 0.3);
|
| 867 |
-
color: rgba(255, 255, 255, 0.6);
|
| 868 |
-
}
|
| 869 |
-
|
| 870 |
-
.keyboard-input-panel.inactive .send-btn {
|
| 871 |
-
background: linear-gradient(45deg, #6c757d, #495057);
|
| 872 |
-
opacity: 0.6;
|
| 873 |
-
}
|
| 874 |
-
|
| 875 |
-
.keyboard-input-panel.inactive .quick-cmd {
|
| 876 |
-
border-color: #6c757d;
|
| 877 |
-
background: rgba(108, 117, 125, 0.2);
|
| 878 |
-
color: rgba(255, 255, 255, 0.6);
|
| 879 |
-
}
|
| 880 |
-
|
| 881 |
-
.keyboard-input-panel:hover:not(.inactive) {
|
| 882 |
-
transform: translateY(-5px);
|
| 883 |
-
box-shadow: 0 12px 40px rgba(0, 0, 0, 0.4);
|
| 884 |
-
}
|
| 885 |
-
|
| 886 |
-
.keyboard-input-panel.active:hover {
|
| 887 |
-
transform: scale(1.02) translateY(-5px);
|
| 888 |
-
box-shadow: 0 16px 50px rgba(78, 205, 196, 0.5);
|
| 889 |
-
}
|
| 890 |
-
|
| 891 |
-
.input-header {
|
| 892 |
-
background: linear-gradient(45deg, #4ecdc4, #44a08d);
|
| 893 |
-
padding: 15px 20px;
|
| 894 |
-
border-radius: 13px 13px 0 0;
|
| 895 |
-
display: flex;
|
| 896 |
-
justify-content: space-between;
|
| 897 |
-
align-items: center;
|
| 898 |
-
border-bottom: 2px solid rgba(255, 255, 255, 0.1);
|
| 899 |
-
cursor: move;
|
| 900 |
-
user-select: none;
|
| 901 |
-
}
|
| 902 |
-
|
| 903 |
-
.input-header h4 {
|
| 904 |
-
margin: 0;
|
| 905 |
-
font-size: 1.1em;
|
| 906 |
-
font-weight: bold;
|
| 907 |
-
color: white;
|
| 908 |
-
text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.3);
|
| 909 |
-
}
|
| 910 |
-
|
| 911 |
-
.toggle-panel-btn {
|
| 912 |
-
background: rgba(255, 255, 255, 0.2);
|
| 913 |
-
border: none;
|
| 914 |
-
border-radius: 50%;
|
| 915 |
-
width: 35px;
|
| 916 |
-
height: 35px;
|
| 917 |
-
color: white;
|
| 918 |
-
font-size: 16px;
|
| 919 |
-
cursor: pointer;
|
| 920 |
-
transition: all 0.3s ease;
|
| 921 |
-
display: flex;
|
| 922 |
-
align-items: center;
|
| 923 |
-
justify-content: center;
|
| 924 |
-
}
|
| 925 |
-
|
| 926 |
-
.toggle-panel-btn:hover {
|
| 927 |
-
background: rgba(255, 255, 255, 0.3);
|
| 928 |
-
transform: scale(1.1);
|
| 929 |
-
}
|
| 930 |
-
|
| 931 |
-
.toggle-panel-btn:active {
|
| 932 |
-
transform: scale(0.95);
|
| 933 |
-
}
|
| 934 |
-
|
| 935 |
-
.input-content {
|
| 936 |
-
padding: 20px;
|
| 937 |
-
transition: all 0.3s ease;
|
| 938 |
-
}
|
| 939 |
-
|
| 940 |
-
.input-content.collapsed {
|
| 941 |
-
display: none;
|
| 942 |
-
}
|
| 943 |
-
|
| 944 |
-
.input-group {
|
| 945 |
-
display: flex;
|
| 946 |
-
gap: 10px;
|
| 947 |
-
margin-bottom: 20px;
|
| 948 |
-
}
|
| 949 |
-
|
| 950 |
-
.command-input {
|
| 951 |
-
flex: 1;
|
| 952 |
-
padding: 12px 15px;
|
| 953 |
-
border: 2px solid #4ecdc4;
|
| 954 |
-
border-radius: 25px;
|
| 955 |
-
background: rgba(255, 255, 255, 0.1);
|
| 956 |
-
color: white;
|
| 957 |
-
font-family: 'Comic Neue', cursive;
|
| 958 |
-
font-size: 14px;
|
| 959 |
-
outline: none;
|
| 960 |
-
transition: all 0.3s ease;
|
| 961 |
-
}
|
| 962 |
-
|
| 963 |
-
.command-input::placeholder {
|
| 964 |
-
color: rgba(255, 255, 255, 0.7);
|
| 965 |
-
}
|
| 966 |
-
|
| 967 |
-
.command-input:focus {
|
| 968 |
-
border-color: #ff6b6b;
|
| 969 |
-
background: rgba(255, 255, 255, 0.2);
|
| 970 |
-
box-shadow: 0 0 15px rgba(255, 107, 107, 0.3);
|
| 971 |
-
}
|
| 972 |
-
|
| 973 |
-
.send-btn {
|
| 974 |
-
background: linear-gradient(45deg, #ff6b6b, #e55555);
|
| 975 |
-
border: none;
|
| 976 |
-
border-radius: 25px;
|
| 977 |
-
padding: 12px 20px;
|
| 978 |
-
color: white;
|
| 979 |
-
font-family: 'Comic Neue', cursive;
|
| 980 |
-
font-weight: bold;
|
| 981 |
-
font-size: 14px;
|
| 982 |
-
cursor: pointer;
|
| 983 |
-
transition: all 0.3s ease;
|
| 984 |
-
box-shadow: 0 4px 15px rgba(255, 107, 107, 0.3);
|
| 985 |
-
}
|
| 986 |
-
|
| 987 |
-
.send-btn:hover {
|
| 988 |
-
background: linear-gradient(45deg, #e55555, #d63447);
|
| 989 |
-
transform: translateY(-2px);
|
| 990 |
-
box-shadow: 0 6px 20px rgba(255, 107, 107, 0.4);
|
| 991 |
-
}
|
| 992 |
-
|
| 993 |
-
.send-btn:active {
|
| 994 |
-
transform: translateY(0);
|
| 995 |
-
}
|
| 996 |
-
|
| 997 |
-
.quick-commands {
|
| 998 |
-
margin-bottom: 20px;
|
| 999 |
-
}
|
| 1000 |
-
|
| 1001 |
-
.quick-commands h5 {
|
| 1002 |
-
margin: 0 0 10px 0;
|
| 1003 |
-
color: #4ecdc4;
|
| 1004 |
-
font-size: 0.9em;
|
| 1005 |
-
font-weight: bold;
|
| 1006 |
-
text-transform: uppercase;
|
| 1007 |
-
letter-spacing: 1px;
|
| 1008 |
-
}
|
| 1009 |
-
|
| 1010 |
-
.command-buttons {
|
| 1011 |
-
display: grid;
|
| 1012 |
-
grid-template-columns: 1fr 1fr;
|
| 1013 |
-
gap: 8px;
|
| 1014 |
-
}
|
| 1015 |
-
|
| 1016 |
-
.quick-cmd {
|
| 1017 |
-
background: rgba(78, 205, 196, 0.2);
|
| 1018 |
-
border: 1px solid #4ecdc4;
|
| 1019 |
-
border-radius: 20px;
|
| 1020 |
-
padding: 8px 12px;
|
| 1021 |
-
color: white;
|
| 1022 |
-
font-family: 'Comic Neue', cursive;
|
| 1023 |
-
font-size: 0.8em;
|
| 1024 |
-
cursor: pointer;
|
| 1025 |
-
transition: all 0.3s ease;
|
| 1026 |
-
text-align: center;
|
| 1027 |
-
}
|
| 1028 |
-
|
| 1029 |
-
.quick-cmd:hover {
|
| 1030 |
-
background: rgba(78, 205, 196, 0.4);
|
| 1031 |
-
border-color: #44a08d;
|
| 1032 |
-
transform: scale(1.05);
|
| 1033 |
-
}
|
| 1034 |
-
|
| 1035 |
-
.quick-cmd:active {
|
| 1036 |
-
transform: scale(0.95);
|
| 1037 |
-
}
|
| 1038 |
-
|
| 1039 |
-
.command-history {
|
| 1040 |
-
border-top: 1px solid rgba(255, 255, 255, 0.1);
|
| 1041 |
-
padding-top: 15px;
|
| 1042 |
-
}
|
| 1043 |
-
|
| 1044 |
-
.command-history h5 {
|
| 1045 |
-
margin: 0 0 10px 0;
|
| 1046 |
-
color: #4ecdc4;
|
| 1047 |
-
font-size: 0.9em;
|
| 1048 |
-
font-weight: bold;
|
| 1049 |
-
text-transform: uppercase;
|
| 1050 |
-
letter-spacing: 1px;
|
| 1051 |
-
}
|
| 1052 |
-
|
| 1053 |
-
.history-list {
|
| 1054 |
-
max-height: 120px;
|
| 1055 |
-
overflow-y: auto;
|
| 1056 |
-
border-radius: 8px;
|
| 1057 |
-
background: rgba(0, 0, 0, 0.2);
|
| 1058 |
-
padding: 8px;
|
| 1059 |
-
}
|
| 1060 |
-
|
| 1061 |
-
.history-item {
|
| 1062 |
-
background: rgba(255, 255, 255, 0.1);
|
| 1063 |
-
border-radius: 15px;
|
| 1064 |
-
padding: 6px 12px;
|
| 1065 |
-
margin-bottom: 5px;
|
| 1066 |
-
font-size: 0.8em;
|
| 1067 |
-
color: rgba(255, 255, 255, 0.9);
|
| 1068 |
-
display: flex;
|
| 1069 |
-
justify-content: space-between;
|
| 1070 |
-
align-items: center;
|
| 1071 |
-
cursor: pointer;
|
| 1072 |
-
transition: all 0.3s ease;
|
| 1073 |
-
}
|
| 1074 |
-
|
| 1075 |
-
.history-item:hover {
|
| 1076 |
-
background: rgba(255, 255, 255, 0.2);
|
| 1077 |
-
transform: translateX(5px);
|
| 1078 |
-
}
|
| 1079 |
-
|
| 1080 |
-
.history-item:last-child {
|
| 1081 |
-
margin-bottom: 0;
|
| 1082 |
-
}
|
| 1083 |
-
|
| 1084 |
-
.history-command {
|
| 1085 |
-
flex: 1;
|
| 1086 |
-
white-space: nowrap;
|
| 1087 |
-
overflow: hidden;
|
| 1088 |
-
text-overflow: ellipsis;
|
| 1089 |
-
}
|
| 1090 |
-
|
| 1091 |
-
.history-time {
|
| 1092 |
-
color: rgba(255, 255, 255, 0.6);
|
| 1093 |
-
font-size: 0.7em;
|
| 1094 |
-
margin-left: 10px;
|
| 1095 |
-
}
|
| 1096 |
-
|
| 1097 |
-
/* 滚动条样式 */
|
| 1098 |
-
.history-list::-webkit-scrollbar {
|
| 1099 |
-
width: 4px;
|
| 1100 |
-
}
|
| 1101 |
-
|
| 1102 |
-
.history-list::-webkit-scrollbar-track {
|
| 1103 |
-
background: rgba(255, 255, 255, 0.1);
|
| 1104 |
-
border-radius: 2px;
|
| 1105 |
-
}
|
| 1106 |
-
|
| 1107 |
-
.history-list::-webkit-scrollbar-thumb {
|
| 1108 |
-
background: #4ecdc4;
|
| 1109 |
-
border-radius: 2px;
|
| 1110 |
-
}
|
| 1111 |
-
|
| 1112 |
-
.history-list::-webkit-scrollbar-thumb:hover {
|
| 1113 |
-
background: #44a08d;
|
| 1114 |
-
}
|
| 1115 |
-
|
| 1116 |
-
/* 面板折叠状态 */
|
| 1117 |
-
.keyboard-input-panel.collapsed {
|
| 1118 |
-
min-width: auto;
|
| 1119 |
-
width: auto;
|
| 1120 |
-
}
|
| 1121 |
-
|
| 1122 |
-
.keyboard-input-panel.collapsed .input-content {
|
| 1123 |
-
display: none;
|
| 1124 |
-
}
|
| 1125 |
-
|
| 1126 |
-
/* 面板动画 */
|
| 1127 |
-
@keyframes panelSlideIn {
|
| 1128 |
-
from {
|
| 1129 |
-
transform: translateX(100%);
|
| 1130 |
-
opacity: 0;
|
| 1131 |
-
}
|
| 1132 |
-
to {
|
| 1133 |
-
transform: translateX(0);
|
| 1134 |
-
opacity: 1;
|
| 1135 |
-
}
|
| 1136 |
-
}
|
| 1137 |
-
|
| 1138 |
-
.keyboard-input-panel {
|
| 1139 |
-
animation: panelSlideIn 0.5s ease-out;
|
| 1140 |
-
}
|
| 1141 |
-
|
| 1142 |
-
/* 响应式设计 */
|
| 1143 |
-
@media (max-width: 768px) {
|
| 1144 |
-
.keyboard-input-panel {
|
| 1145 |
-
bottom: 10px;
|
| 1146 |
-
right: 10px;
|
| 1147 |
-
left: 10px;
|
| 1148 |
-
min-width: auto;
|
| 1149 |
-
max-width: none;
|
| 1150 |
-
}
|
| 1151 |
-
|
| 1152 |
-
.command-buttons {
|
| 1153 |
-
grid-template-columns: 1fr;
|
| 1154 |
-
}
|
| 1155 |
-
|
| 1156 |
-
.input-group {
|
| 1157 |
-
flex-direction: column;
|
| 1158 |
-
}
|
| 1159 |
-
|
| 1160 |
-
.send-btn {
|
| 1161 |
-
align-self: flex-end;
|
| 1162 |
-
min-width: 100px;
|
| 1163 |
-
}
|
| 1164 |
}
|
|
|
|
| 1 |
+
/* 全局样式 */
|
| 2 |
+
* {
|
| 3 |
+
margin: 0;
|
| 4 |
+
padding: 0;
|
| 5 |
+
box-sizing: border-box;
|
| 6 |
+
}
|
| 7 |
+
|
| 8 |
+
body {
|
| 9 |
+
font-family: 'Comic Neue', cursive;
|
| 10 |
+
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
| 11 |
+
min-height: 100vh;
|
| 12 |
+
overflow: hidden;
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
/* 游戏容器 */
|
| 16 |
+
.game-container {
|
| 17 |
+
width: 100vw;
|
| 18 |
+
height: 100vh;
|
| 19 |
+
display: flex;
|
| 20 |
+
flex-direction: column;
|
| 21 |
+
position: relative;
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
/* 游戏标题区域 */
|
| 25 |
+
.game-header {
|
| 26 |
+
background: rgba(255, 255, 255, 0.95);
|
| 27 |
+
padding: 15px 20px;
|
| 28 |
+
display: flex;
|
| 29 |
+
justify-content: space-between;
|
| 30 |
+
align-items: center;
|
| 31 |
+
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
|
| 32 |
+
border-bottom: 3px solid #ff6b6b;
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
.header-controls {
|
| 36 |
+
display: flex;
|
| 37 |
+
align-items: center;
|
| 38 |
+
gap: 15px;
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
.audio-button, .voice-activate-button, .help-button {
|
| 42 |
+
background: #ff6b6b;
|
| 43 |
+
color: white;
|
| 44 |
+
border: none;
|
| 45 |
+
border-radius: 50%;
|
| 46 |
+
width: 40px;
|
| 47 |
+
height: 40px;
|
| 48 |
+
font-size: 18px;
|
| 49 |
+
cursor: pointer;
|
| 50 |
+
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
|
| 51 |
+
transition: all 0.3s ease;
|
| 52 |
+
font-family: 'Comic Neue', cursive;
|
| 53 |
+
font-weight: bold;
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
.audio-button:hover, .voice-activate-button:hover, .help-button:hover {
|
| 57 |
+
background: #e55555;
|
| 58 |
+
transform: scale(1.1);
|
| 59 |
+
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
.audio-button:active, .voice-activate-button:active, .help-button:active {
|
| 63 |
+
transform: scale(0.95);
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
/* 语音激活按钮特殊样式 */
|
| 67 |
+
.voice-activate-button {
|
| 68 |
+
background: #4ecdc4;
|
| 69 |
+
position: relative;
|
| 70 |
+
overflow: hidden;
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
.voice-activate-button:hover {
|
| 74 |
+
background: #44a08d;
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
.voice-activate-button.active {
|
| 78 |
+
background: #27ae60;
|
| 79 |
+
animation: voice-active-pulse 2s infinite;
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
.voice-activate-button.disabled {
|
| 83 |
+
background: #95a5a6;
|
| 84 |
+
opacity: 0.6;
|
| 85 |
+
cursor: not-allowed;
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
.voice-activate-button.disabled:hover {
|
| 89 |
+
background: #95a5a6;
|
| 90 |
+
transform: none;
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
@keyframes voice-active-pulse {
|
| 94 |
+
0% {
|
| 95 |
+
box-shadow: 0 2px 8px rgba(39, 174, 96, 0.3);
|
| 96 |
+
}
|
| 97 |
+
50% {
|
| 98 |
+
box-shadow: 0 2px 8px rgba(39, 174, 96, 0.6), 0 0 0 10px rgba(39, 174, 96, 0);
|
| 99 |
+
}
|
| 100 |
+
100% {
|
| 101 |
+
box-shadow: 0 2px 8px rgba(39, 174, 96, 0.3);
|
| 102 |
+
}
|
| 103 |
+
}
|
| 104 |
+
|
| 105 |
+
.audio-button.muted {
|
| 106 |
+
background: #95a5a6;
|
| 107 |
+
color: #bdc3c7;
|
| 108 |
+
}
|
| 109 |
+
|
| 110 |
+
.audio-button.muted:hover {
|
| 111 |
+
background: #7f8c8d;
|
| 112 |
+
}
|
| 113 |
+
|
| 114 |
+
.game-title {
|
| 115 |
+
font-family: 'Fredoka One', cursive;
|
| 116 |
+
font-size: 2.2em;
|
| 117 |
+
color: #ff6b6b;
|
| 118 |
+
text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.1);
|
| 119 |
+
margin: 0;
|
| 120 |
+
}
|
| 121 |
+
|
| 122 |
+
.voice-status {
|
| 123 |
+
display: flex;
|
| 124 |
+
align-items: center;
|
| 125 |
+
gap: 10px;
|
| 126 |
+
background: #4ecdc4;
|
| 127 |
+
padding: 8px 15px;
|
| 128 |
+
border-radius: 25px;
|
| 129 |
+
color: white;
|
| 130 |
+
font-weight: bold;
|
| 131 |
+
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
|
| 132 |
+
}
|
| 133 |
+
|
| 134 |
+
.mic-icon {
|
| 135 |
+
font-size: 1.2em;
|
| 136 |
+
animation: pulse 2s infinite;
|
| 137 |
+
}
|
| 138 |
+
|
| 139 |
+
@keyframes pulse {
|
| 140 |
+
0%, 100% { transform: scale(1); }
|
| 141 |
+
50% { transform: scale(1.1); }
|
| 142 |
+
}
|
| 143 |
+
|
| 144 |
+
/* 主游戏区域 */
|
| 145 |
+
.game-main {
|
| 146 |
+
flex: 1;
|
| 147 |
+
position: relative;
|
| 148 |
+
display: flex;
|
| 149 |
+
justify-content: center;
|
| 150 |
+
align-items: center;
|
| 151 |
+
}
|
| 152 |
+
|
| 153 |
+
#gameCanvas {
|
| 154 |
+
border: 4px solid #fff;
|
| 155 |
+
border-radius: 20px;
|
| 156 |
+
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
|
| 157 |
+
background: linear-gradient(45deg, #ffeaa7, #fab1a0);
|
| 158 |
+
}
|
| 159 |
+
|
| 160 |
+
/* 游戏UI覆盖层 */
|
| 161 |
+
.game-ui {
|
| 162 |
+
position: absolute;
|
| 163 |
+
top: 0;
|
| 164 |
+
left: 0;
|
| 165 |
+
width: 100%;
|
| 166 |
+
height: 100%;
|
| 167 |
+
pointer-events: none;
|
| 168 |
+
z-index: 10;
|
| 169 |
+
}
|
| 170 |
+
|
| 171 |
+
/* 键盘面板在game-ui内,需要特殊处理 */
|
| 172 |
+
.game-ui .keyboard-input-panel {
|
| 173 |
+
pointer-events: auto;
|
| 174 |
+
}
|
| 175 |
+
|
| 176 |
+
.game-ui .keyboard-input-panel.inactive {
|
| 177 |
+
pointer-events: none;
|
| 178 |
+
}
|
| 179 |
+
|
| 180 |
+
.game-ui .keyboard-input-panel.active {
|
| 181 |
+
pointer-events: auto !important;
|
| 182 |
+
}
|
| 183 |
+
|
| 184 |
+
/* 确保激活状态下所有子元素都可以交互 */
|
| 185 |
+
.keyboard-input-panel.active,
|
| 186 |
+
.keyboard-input-panel.active *,
|
| 187 |
+
.keyboard-input-panel.active .input-content,
|
| 188 |
+
.keyboard-input-panel.active .command-input,
|
| 189 |
+
.keyboard-input-panel.active .send-btn,
|
| 190 |
+
.keyboard-input-panel.active .quick-cmd,
|
| 191 |
+
.keyboard-input-panel.active .toggle-panel-btn,
|
| 192 |
+
.keyboard-input-panel.active .history-item {
|
| 193 |
+
pointer-events: auto !important;
|
| 194 |
+
}
|
| 195 |
+
|
| 196 |
+
/* 魔法锅状态 */
|
| 197 |
+
.pot-status {
|
| 198 |
+
position: absolute;
|
| 199 |
+
top: 20px;
|
| 200 |
+
left: 50%;
|
| 201 |
+
transform: translateX(-50%);
|
| 202 |
+
pointer-events: auto;
|
| 203 |
+
}
|
| 204 |
+
|
| 205 |
+
.status-indicator {
|
| 206 |
+
padding: 10px 20px;
|
| 207 |
+
border-radius: 25px;
|
| 208 |
+
font-weight: bold;
|
| 209 |
+
text-align: center;
|
| 210 |
+
box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
|
| 211 |
+
transition: all 0.3s ease;
|
| 212 |
+
}
|
| 213 |
+
|
| 214 |
+
.status-indicator.inactive {
|
| 215 |
+
background: #95a5a6;
|
| 216 |
+
color: white;
|
| 217 |
+
}
|
| 218 |
+
|
| 219 |
+
.status-indicator.active {
|
| 220 |
+
background: #e74c3c;
|
| 221 |
+
color: white;
|
| 222 |
+
animation: glow 2s infinite alternate;
|
| 223 |
+
}
|
| 224 |
+
|
| 225 |
+
.status-indicator.cooking {
|
| 226 |
+
background: #f39c12;
|
| 227 |
+
color: white;
|
| 228 |
+
animation: cooking-pulse 1s infinite;
|
| 229 |
+
}
|
| 230 |
+
|
| 231 |
+
.status-indicator.overflowing {
|
| 232 |
+
background: #27ae60;
|
| 233 |
+
color: white;
|
| 234 |
+
animation: overflow-shake 0.5s infinite;
|
| 235 |
+
}
|
| 236 |
+
|
| 237 |
+
@keyframes glow {
|
| 238 |
+
from { box-shadow: 0 4px 15px rgba(231, 76, 60, 0.3); }
|
| 239 |
+
to { box-shadow: 0 4px 25px rgba(231, 76, 60, 0.8); }
|
| 240 |
+
}
|
| 241 |
+
|
| 242 |
+
@keyframes cooking-pulse {
|
| 243 |
+
0%, 100% { transform: scale(1); }
|
| 244 |
+
50% { transform: scale(1.05); }
|
| 245 |
+
}
|
| 246 |
+
|
| 247 |
+
@keyframes overflow-shake {
|
| 248 |
+
0%, 100% { transform: translateX(0); }
|
| 249 |
+
25% { transform: translateX(-2px); }
|
| 250 |
+
75% { transform: translateX(2px); }
|
| 251 |
+
}
|
| 252 |
+
|
| 253 |
+
/* 烹饪信息 */
|
| 254 |
+
.cooking-info {
|
| 255 |
+
position: absolute;
|
| 256 |
+
top: 80px;
|
| 257 |
+
left: 50%;
|
| 258 |
+
transform: translateX(-50%);
|
| 259 |
+
background: rgba(255, 255, 255, 0.95);
|
| 260 |
+
padding: 15px 25px;
|
| 261 |
+
border-radius: 15px;
|
| 262 |
+
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
|
| 263 |
+
text-align: center;
|
| 264 |
+
min-width: 200px;
|
| 265 |
+
}
|
| 266 |
+
|
| 267 |
+
.cooking-food {
|
| 268 |
+
font-size: 1.2em;
|
| 269 |
+
font-weight: bold;
|
| 270 |
+
color: #2c3e50;
|
| 271 |
+
margin-bottom: 10px;
|
| 272 |
+
}
|
| 273 |
+
|
| 274 |
+
.progress-bar {
|
| 275 |
+
width: 100%;
|
| 276 |
+
height: 8px;
|
| 277 |
+
background: #ecf0f1;
|
| 278 |
+
border-radius: 4px;
|
| 279 |
+
overflow: hidden;
|
| 280 |
+
}
|
| 281 |
+
|
| 282 |
+
.progress-fill {
|
| 283 |
+
height: 100%;
|
| 284 |
+
background: linear-gradient(90deg, #ff6b6b, #4ecdc4);
|
| 285 |
+
border-radius: 4px;
|
| 286 |
+
transition: width 0.3s ease;
|
| 287 |
+
width: 0%;
|
| 288 |
+
}
|
| 289 |
+
|
| 290 |
+
/* 食物计数器 */
|
| 291 |
+
.food-counter {
|
| 292 |
+
position: absolute;
|
| 293 |
+
top: 20px;
|
| 294 |
+
right: 20px;
|
| 295 |
+
background: rgba(255, 255, 255, 0.95);
|
| 296 |
+
padding: 15px 20px;
|
| 297 |
+
border-radius: 15px;
|
| 298 |
+
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
|
| 299 |
+
display: flex;
|
| 300 |
+
align-items: center;
|
| 301 |
+
gap: 10px;
|
| 302 |
+
}
|
| 303 |
+
|
| 304 |
+
/* 性能监控 */
|
| 305 |
+
.performance-monitor {
|
| 306 |
+
position: absolute;
|
| 307 |
+
top: 20px;
|
| 308 |
+
left: 20px;
|
| 309 |
+
background: rgba(0, 0, 0, 0.8);
|
| 310 |
+
color: white;
|
| 311 |
+
padding: 10px 15px;
|
| 312 |
+
border-radius: 10px;
|
| 313 |
+
font-family: 'Courier New', monospace;
|
| 314 |
+
font-size: 0.9em;
|
| 315 |
+
box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
|
| 316 |
+
min-width: 120px;
|
| 317 |
+
}
|
| 318 |
+
|
| 319 |
+
.perf-item {
|
| 320 |
+
display: flex;
|
| 321 |
+
justify-content: space-between;
|
| 322 |
+
margin-bottom: 5px;
|
| 323 |
+
align-items: center;
|
| 324 |
+
}
|
| 325 |
+
|
| 326 |
+
.perf-item:last-child {
|
| 327 |
+
margin-bottom: 0;
|
| 328 |
+
}
|
| 329 |
+
|
| 330 |
+
.perf-label {
|
| 331 |
+
color: #4ecdc4;
|
| 332 |
+
font-weight: bold;
|
| 333 |
+
}
|
| 334 |
+
|
| 335 |
+
.perf-value {
|
| 336 |
+
color: #ffffff;
|
| 337 |
+
font-weight: bold;
|
| 338 |
+
text-align: right;
|
| 339 |
+
min-width: 30px;
|
| 340 |
+
}
|
| 341 |
+
|
| 342 |
+
.food-emoji {
|
| 343 |
+
font-size: 2em;
|
| 344 |
+
}
|
| 345 |
+
|
| 346 |
+
.count {
|
| 347 |
+
font-size: 1.5em;
|
| 348 |
+
font-weight: bold;
|
| 349 |
+
color: #2c3e50;
|
| 350 |
+
min-width: 30px;
|
| 351 |
+
text-align: center;
|
| 352 |
+
}
|
| 353 |
+
|
| 354 |
+
/* 语音提示 */
|
| 355 |
+
.voice-hints {
|
| 356 |
+
position: absolute;
|
| 357 |
+
bottom: 20px;
|
| 358 |
+
left: 50%;
|
| 359 |
+
transform: translateX(-50%);
|
| 360 |
+
display: flex;
|
| 361 |
+
flex-direction: column;
|
| 362 |
+
gap: 10px;
|
| 363 |
+
align-items: center;
|
| 364 |
+
}
|
| 365 |
+
|
| 366 |
+
.hint-item {
|
| 367 |
+
background: rgba(0, 0, 0, 0.8);
|
| 368 |
+
color: white;
|
| 369 |
+
padding: 8px 15px;
|
| 370 |
+
border-radius: 20px;
|
| 371 |
+
display: flex;
|
| 372 |
+
align-items: center;
|
| 373 |
+
gap: 10px;
|
| 374 |
+
font-size: 0.9em;
|
| 375 |
+
animation: hint-fade-in 0.5s ease;
|
| 376 |
+
}
|
| 377 |
+
|
| 378 |
+
.hint-command {
|
| 379 |
+
background: #ff6b6b;
|
| 380 |
+
padding: 4px 8px;
|
| 381 |
+
border-radius: 10px;
|
| 382 |
+
font-weight: bold;
|
| 383 |
+
font-size: 0.8em;
|
| 384 |
+
}
|
| 385 |
+
|
| 386 |
+
.hint-desc {
|
| 387 |
+
opacity: 0.9;
|
| 388 |
+
}
|
| 389 |
+
|
| 390 |
+
@keyframes hint-fade-in {
|
| 391 |
+
from { opacity: 0; transform: translateY(10px); }
|
| 392 |
+
to { opacity: 1; transform: translateY(0); }
|
| 393 |
+
}
|
| 394 |
+
|
| 395 |
+
/* 调试信息 */
|
| 396 |
+
.debug-info {
|
| 397 |
+
position: absolute;
|
| 398 |
+
top: 10px;
|
| 399 |
+
left: 10px;
|
| 400 |
+
background: rgba(0, 0, 0, 0.8);
|
| 401 |
+
color: white;
|
| 402 |
+
padding: 10px;
|
| 403 |
+
border-radius: 5px;
|
| 404 |
+
font-family: monospace;
|
| 405 |
+
font-size: 0.8em;
|
| 406 |
+
max-width: 300px;
|
| 407 |
+
max-height: 200px;
|
| 408 |
+
overflow-y: auto;
|
| 409 |
+
z-index: 1000;
|
| 410 |
+
}
|
| 411 |
+
|
| 412 |
+
/* 响应式设计 */
|
| 413 |
+
@media (max-width: 768px) {
|
| 414 |
+
.game-title {
|
| 415 |
+
font-size: 1.5em;
|
| 416 |
+
}
|
| 417 |
+
|
| 418 |
+
#gameCanvas {
|
| 419 |
+
width: 95vw;
|
| 420 |
+
height: 70vh;
|
| 421 |
+
}
|
| 422 |
+
|
| 423 |
+
.voice-hints {
|
| 424 |
+
bottom: 10px;
|
| 425 |
+
}
|
| 426 |
+
|
| 427 |
+
.hint-item {
|
| 428 |
+
font-size: 0.8em;
|
| 429 |
+
padding: 6px 12px;
|
| 430 |
+
}
|
| 431 |
+
}
|
| 432 |
+
|
| 433 |
+
/* 动画效果 */
|
| 434 |
+
.bounce-in {
|
| 435 |
+
animation: bounceIn 0.6s ease;
|
| 436 |
+
}
|
| 437 |
+
|
| 438 |
+
@keyframes bounceIn {
|
| 439 |
+
0% { transform: scale(0.3); opacity: 0; }
|
| 440 |
+
50% { transform: scale(1.05); }
|
| 441 |
+
70% { transform: scale(0.9); }
|
| 442 |
+
100% { transform: scale(1); opacity: 1; }
|
| 443 |
+
}
|
| 444 |
+
|
| 445 |
+
.fade-out {
|
| 446 |
+
animation: fadeOut 0.5s ease forwards;
|
| 447 |
+
}
|
| 448 |
+
|
| 449 |
+
@keyframes fadeOut {
|
| 450 |
+
from { opacity: 1; }
|
| 451 |
+
to { opacity: 0; }
|
| 452 |
+
}
|
| 453 |
+
|
| 454 |
+
/* 特殊效果 */
|
| 455 |
+
.sparkle {
|
| 456 |
+
position: absolute;
|
| 457 |
+
width: 4px;
|
| 458 |
+
height: 4px;
|
| 459 |
+
background: #ffd700;
|
| 460 |
+
border-radius: 50%;
|
| 461 |
+
animation: sparkle 1s ease-in-out infinite;
|
| 462 |
+
}
|
| 463 |
+
|
| 464 |
+
@keyframes sparkle {
|
| 465 |
+
0%, 100% { opacity: 0; transform: scale(0); }
|
| 466 |
+
50% { opacity: 1; transform: scale(1); }
|
| 467 |
+
}
|
| 468 |
+
|
| 469 |
+
/* 音频激活提示 */
|
| 470 |
+
.audio-activation-hint {
|
| 471 |
+
position: absolute;
|
| 472 |
+
top: 30%;
|
| 473 |
+
left: 50%;
|
| 474 |
+
transform: translate(-50%, -50%);
|
| 475 |
+
z-index: 200;
|
| 476 |
+
pointer-events: none;
|
| 477 |
+
animation: audioHintPulse 2s infinite;
|
| 478 |
+
}
|
| 479 |
+
|
| 480 |
+
.hint-bubble {
|
| 481 |
+
background: rgba(255, 107, 107, 0.95);
|
| 482 |
+
border: 3px solid #e74c3c;
|
| 483 |
+
border-radius: 20px;
|
| 484 |
+
padding: 15px 25px;
|
| 485 |
+
display: flex;
|
| 486 |
+
align-items: center;
|
| 487 |
+
gap: 10px;
|
| 488 |
+
box-shadow: 0 8px 32px rgba(231, 76, 60, 0.3);
|
| 489 |
+
color: white;
|
| 490 |
+
font-family: 'Comic Neue', cursive;
|
| 491 |
+
font-weight: bold;
|
| 492 |
+
}
|
| 493 |
+
|
| 494 |
+
.hint-icon {
|
| 495 |
+
font-size: 1.5em;
|
| 496 |
+
animation: audioIconBounce 1s infinite;
|
| 497 |
+
}
|
| 498 |
+
|
| 499 |
+
.hint-text {
|
| 500 |
+
font-size: 1.1em;
|
| 501 |
+
}
|
| 502 |
+
|
| 503 |
+
@keyframes audioHintPulse {
|
| 504 |
+
0%, 100% {
|
| 505 |
+
transform: translate(-50%, -50%) scale(1);
|
| 506 |
+
opacity: 0.9;
|
| 507 |
+
}
|
| 508 |
+
50% {
|
| 509 |
+
transform: translate(-50%, -50%) scale(1.05);
|
| 510 |
+
opacity: 1;
|
| 511 |
+
}
|
| 512 |
+
}
|
| 513 |
+
|
| 514 |
+
@keyframes audioIconBounce {
|
| 515 |
+
0%, 100% {
|
| 516 |
+
transform: translateY(0);
|
| 517 |
+
}
|
| 518 |
+
50% {
|
| 519 |
+
transform: translateY(-3px);
|
| 520 |
+
}
|
| 521 |
+
}
|
| 522 |
+
|
| 523 |
+
/* 语音输入显示 */
|
| 524 |
+
.voice-input-display {
|
| 525 |
+
position: absolute;
|
| 526 |
+
top: 50%;
|
| 527 |
+
left: 50%;
|
| 528 |
+
transform: translate(-50%, -50%);
|
| 529 |
+
z-index: 100;
|
| 530 |
+
pointer-events: none;
|
| 531 |
+
}
|
| 532 |
+
|
| 533 |
+
.speech-bubble {
|
| 534 |
+
background: rgba(255, 255, 255, 0.95);
|
| 535 |
+
border: 3px solid #ff6b6b;
|
| 536 |
+
border-radius: 25px;
|
| 537 |
+
padding: 20px 30px;
|
| 538 |
+
position: relative;
|
| 539 |
+
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
|
| 540 |
+
animation: speechBubble 0.3s ease-out;
|
| 541 |
+
max-width: 400px;
|
| 542 |
+
text-align: center;
|
| 543 |
+
}
|
| 544 |
+
|
| 545 |
+
.speech-bubble::before {
|
| 546 |
+
content: '';
|
| 547 |
+
position: absolute;
|
| 548 |
+
bottom: -15px;
|
| 549 |
+
left: 50%;
|
| 550 |
+
transform: translateX(-50%);
|
| 551 |
+
width: 0;
|
| 552 |
+
height: 0;
|
| 553 |
+
border-left: 15px solid transparent;
|
| 554 |
+
border-right: 15px solid transparent;
|
| 555 |
+
border-top: 15px solid #ff6b6b;
|
| 556 |
+
}
|
| 557 |
+
|
| 558 |
+
.speech-bubble::after {
|
| 559 |
+
content: '';
|
| 560 |
+
position: absolute;
|
| 561 |
+
bottom: -12px;
|
| 562 |
+
left: 50%;
|
| 563 |
+
transform: translateX(-50%);
|
| 564 |
+
width: 0;
|
| 565 |
+
height: 0;
|
| 566 |
+
border-left: 12px solid transparent;
|
| 567 |
+
border-right: 12px solid transparent;
|
| 568 |
+
border-top: 12px solid rgba(255, 255, 255, 0.95);
|
| 569 |
+
}
|
| 570 |
+
|
| 571 |
+
.speech-text {
|
| 572 |
+
font-size: 1.4em;
|
| 573 |
+
font-weight: bold;
|
| 574 |
+
color: #2c3e50;
|
| 575 |
+
margin-bottom: 8px;
|
| 576 |
+
font-family: 'Comic Neue', cursive;
|
| 577 |
+
line-height: 1.3;
|
| 578 |
+
}
|
| 579 |
+
|
| 580 |
+
.speech-confidence {
|
| 581 |
+
font-size: 0.9em;
|
| 582 |
+
color: #7f8c8d;
|
| 583 |
+
font-style: italic;
|
| 584 |
+
}
|
| 585 |
+
|
| 586 |
+
@keyframes speechBubble {
|
| 587 |
+
0% {
|
| 588 |
+
opacity: 0;
|
| 589 |
+
transform: scale(0.3) translateY(20px);
|
| 590 |
+
}
|
| 591 |
+
50% {
|
| 592 |
+
transform: scale(1.1) translateY(-5px);
|
| 593 |
+
}
|
| 594 |
+
100% {
|
| 595 |
+
opacity: 1;
|
| 596 |
+
transform: scale(1) translateY(0);
|
| 597 |
+
}
|
| 598 |
+
}
|
| 599 |
+
|
| 600 |
+
/* 语音识别状态动画 */
|
| 601 |
+
.speech-bubble.listening {
|
| 602 |
+
border-color: #e74c3c;
|
| 603 |
+
animation: listening-pulse 1.5s infinite;
|
| 604 |
+
}
|
| 605 |
+
|
| 606 |
+
.speech-bubble.processing {
|
| 607 |
+
border-color: #f39c12;
|
| 608 |
+
animation: processing-spin 2s infinite linear;
|
| 609 |
+
}
|
| 610 |
+
|
| 611 |
+
.speech-bubble.recognized {
|
| 612 |
+
border-color: #27ae60;
|
| 613 |
+
animation: recognized-bounce 0.6s ease-out;
|
| 614 |
+
}
|
| 615 |
+
|
| 616 |
+
@keyframes listening-pulse {
|
| 617 |
+
0%, 100% {
|
| 618 |
+
border-color: #e74c3c;
|
| 619 |
+
box-shadow: 0 8px 32px rgba(231, 76, 60, 0.2);
|
| 620 |
+
}
|
| 621 |
+
50% {
|
| 622 |
+
border-color: #c0392b;
|
| 623 |
+
box-shadow: 0 8px 32px rgba(231, 76, 60, 0.4);
|
| 624 |
+
}
|
| 625 |
+
}
|
| 626 |
+
|
| 627 |
+
@keyframes processing-spin {
|
| 628 |
+
0% {
|
| 629 |
+
border-color: #f39c12;
|
| 630 |
+
transform: rotate(0deg);
|
| 631 |
+
}
|
| 632 |
+
100% {
|
| 633 |
+
border-color: #e67e22;
|
| 634 |
+
transform: rotate(360deg);
|
| 635 |
+
}
|
| 636 |
+
}
|
| 637 |
+
|
| 638 |
+
@keyframes recognized-bounce {
|
| 639 |
+
0% { transform: scale(1); }
|
| 640 |
+
30% { transform: scale(1.1); }
|
| 641 |
+
60% { transform: scale(0.95); }
|
| 642 |
+
100% { transform: scale(1); }
|
| 643 |
+
}
|
| 644 |
+
|
| 645 |
+
/* 帮助模态框 */
|
| 646 |
+
.help-modal {
|
| 647 |
+
position: fixed;
|
| 648 |
+
top: 0;
|
| 649 |
+
left: 0;
|
| 650 |
+
width: 100%;
|
| 651 |
+
height: 100%;
|
| 652 |
+
z-index: 10000;
|
| 653 |
+
animation: modalFadeIn 0.3s ease-out;
|
| 654 |
+
}
|
| 655 |
+
|
| 656 |
+
.modal-overlay {
|
| 657 |
+
position: absolute;
|
| 658 |
+
top: 0;
|
| 659 |
+
left: 0;
|
| 660 |
+
width: 100%;
|
| 661 |
+
height: 100%;
|
| 662 |
+
background: rgba(0, 0, 0, 0.5);
|
| 663 |
+
backdrop-filter: blur(5px);
|
| 664 |
+
}
|
| 665 |
+
|
| 666 |
+
.modal-content {
|
| 667 |
+
position: absolute;
|
| 668 |
+
top: 50%;
|
| 669 |
+
left: 50%;
|
| 670 |
+
transform: translate(-50%, -50%);
|
| 671 |
+
background: white;
|
| 672 |
+
border-radius: 20px;
|
| 673 |
+
box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
|
| 674 |
+
max-width: 600px;
|
| 675 |
+
max-height: 80vh;
|
| 676 |
+
overflow: hidden;
|
| 677 |
+
font-family: 'Comic Neue', cursive;
|
| 678 |
+
}
|
| 679 |
+
|
| 680 |
+
.modal-header {
|
| 681 |
+
background: linear-gradient(45deg, #ff6b6b, #4ecdc4);
|
| 682 |
+
color: white;
|
| 683 |
+
padding: 20px 30px;
|
| 684 |
+
display: flex;
|
| 685 |
+
justify-content: space-between;
|
| 686 |
+
align-items: center;
|
| 687 |
+
}
|
| 688 |
+
|
| 689 |
+
.modal-header h2 {
|
| 690 |
+
margin: 0;
|
| 691 |
+
font-family: 'Fredoka One', cursive;
|
| 692 |
+
font-size: 1.5em;
|
| 693 |
+
}
|
| 694 |
+
|
| 695 |
+
.modal-close {
|
| 696 |
+
background: none;
|
| 697 |
+
border: none;
|
| 698 |
+
color: white;
|
| 699 |
+
font-size: 24px;
|
| 700 |
+
cursor: pointer;
|
| 701 |
+
padding: 5px;
|
| 702 |
+
border-radius: 50%;
|
| 703 |
+
width: 35px;
|
| 704 |
+
height: 35px;
|
| 705 |
+
display: flex;
|
| 706 |
+
align-items: center;
|
| 707 |
+
justify-content: center;
|
| 708 |
+
transition: background 0.3s ease;
|
| 709 |
+
}
|
| 710 |
+
|
| 711 |
+
.modal-close:hover {
|
| 712 |
+
background: rgba(255, 255, 255, 0.2);
|
| 713 |
+
}
|
| 714 |
+
|
| 715 |
+
.modal-body {
|
| 716 |
+
padding: 30px;
|
| 717 |
+
overflow-y: auto;
|
| 718 |
+
max-height: calc(80vh - 100px);
|
| 719 |
+
}
|
| 720 |
+
|
| 721 |
+
.help-section {
|
| 722 |
+
margin-bottom: 25px;
|
| 723 |
+
padding-bottom: 20px;
|
| 724 |
+
border-bottom: 2px solid #f0f0f0;
|
| 725 |
+
}
|
| 726 |
+
|
| 727 |
+
.help-section:last-child {
|
| 728 |
+
border-bottom: none;
|
| 729 |
+
margin-bottom: 0;
|
| 730 |
+
}
|
| 731 |
+
|
| 732 |
+
.help-section h4 {
|
| 733 |
+
color: #ff6b6b;
|
| 734 |
+
margin-bottom: 10px;
|
| 735 |
+
font-size: 1.2em;
|
| 736 |
+
}
|
| 737 |
+
|
| 738 |
+
.help-section p {
|
| 739 |
+
margin-bottom: 10px;
|
| 740 |
+
line-height: 1.5;
|
| 741 |
+
color: #2c3e50;
|
| 742 |
+
}
|
| 743 |
+
|
| 744 |
+
.help-section ul {
|
| 745 |
+
margin: 10px 0;
|
| 746 |
+
padding-left: 20px;
|
| 747 |
+
}
|
| 748 |
+
|
| 749 |
+
.help-section li {
|
| 750 |
+
margin-bottom: 5px;
|
| 751 |
+
color: #34495e;
|
| 752 |
+
line-height: 1.4;
|
| 753 |
+
}
|
| 754 |
+
|
| 755 |
+
.help-section strong {
|
| 756 |
+
color: #e74c3c;
|
| 757 |
+
}
|
| 758 |
+
|
| 759 |
+
@keyframes modalFadeIn {
|
| 760 |
+
0% {
|
| 761 |
+
opacity: 0;
|
| 762 |
+
transform: scale(0.9);
|
| 763 |
+
}
|
| 764 |
+
100% {
|
| 765 |
+
opacity: 1;
|
| 766 |
+
transform: scale(1);
|
| 767 |
+
}
|
| 768 |
+
}
|
| 769 |
+
|
| 770 |
+
@keyframes modalFadeOut {
|
| 771 |
+
0% {
|
| 772 |
+
opacity: 1;
|
| 773 |
+
transform: scale(1);
|
| 774 |
+
}
|
| 775 |
+
100% {
|
| 776 |
+
opacity: 0;
|
| 777 |
+
transform: scale(0.9);
|
| 778 |
+
}
|
| 779 |
+
}
|
| 780 |
+
|
| 781 |
+
/* 特殊消息动画 */
|
| 782 |
+
@keyframes specialMessage {
|
| 783 |
+
0% {
|
| 784 |
+
opacity: 0;
|
| 785 |
+
transform: translate(-50%, -50%) scale(0.3);
|
| 786 |
+
}
|
| 787 |
+
20% {
|
| 788 |
+
opacity: 1;
|
| 789 |
+
transform: translate(-50%, -50%) scale(1.1);
|
| 790 |
+
}
|
| 791 |
+
30% {
|
| 792 |
+
transform: translate(-50%, -50%) scale(1);
|
| 793 |
+
}
|
| 794 |
+
70% {
|
| 795 |
+
opacity: 1;
|
| 796 |
+
transform: translate(-50%, -50%) scale(1);
|
| 797 |
+
}
|
| 798 |
+
100% {
|
| 799 |
+
opacity: 0;
|
| 800 |
+
transform: translate(-50%, -50%) scale(0.8);
|
| 801 |
+
}
|
| 802 |
+
}
|
| 803 |
+
|
| 804 |
+
/* 键盘输入调试面板 */
|
| 805 |
+
.keyboard-input-panel {
|
| 806 |
+
position: fixed;
|
| 807 |
+
bottom: 20px;
|
| 808 |
+
right: 20px;
|
| 809 |
+
background: rgba(44, 62, 80, 0.95);
|
| 810 |
+
border: 2px solid #4ecdc4;
|
| 811 |
+
border-radius: 15px;
|
| 812 |
+
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
|
| 813 |
+
backdrop-filter: blur(10px);
|
| 814 |
+
color: white;
|
| 815 |
+
font-family: 'Comic Neue', cursive;
|
| 816 |
+
min-width: 300px;
|
| 817 |
+
max-width: 400px;
|
| 818 |
+
transition: all 0.4s ease;
|
| 819 |
+
z-index: 50;
|
| 820 |
+
pointer-events: auto;
|
| 821 |
+
cursor: move;
|
| 822 |
+
user-select: none;
|
| 823 |
+
}
|
| 824 |
+
|
| 825 |
+
/* 面板激活状态 */
|
| 826 |
+
.keyboard-input-panel.active {
|
| 827 |
+
z-index: 10000 !important;
|
| 828 |
+
transform: scale(1.02);
|
| 829 |
+
box-shadow: 0 12px 40px rgba(78, 205, 196, 0.4);
|
| 830 |
+
border-color: #ff6b6b;
|
| 831 |
+
background: rgba(44, 62, 80, 0.98);
|
| 832 |
+
pointer-events: auto !important;
|
| 833 |
+
}
|
| 834 |
+
|
| 835 |
+
/* 拖拽状态 */
|
| 836 |
+
.keyboard-input-panel.dragging {
|
| 837 |
+
transition: none !important;
|
| 838 |
+
transform: scale(1.05) rotate(2deg);
|
| 839 |
+
box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
|
| 840 |
+
z-index: 15000 !important;
|
| 841 |
+
}
|
| 842 |
+
|
| 843 |
+
.keyboard-input-panel.dragging .input-content {
|
| 844 |
+
pointer-events: none;
|
| 845 |
+
}
|
| 846 |
+
|
| 847 |
+
.keyboard-input-panel.dragging .input-header {
|
| 848 |
+
background: linear-gradient(45deg, #ff6b6b, #e74c3c);
|
| 849 |
+
}
|
| 850 |
+
|
| 851 |
+
/* 面板非激活状态(灰色透明) */
|
| 852 |
+
.keyboard-input-panel.inactive {
|
| 853 |
+
opacity: 0.4;
|
| 854 |
+
background: rgba(108, 117, 125, 0.7);
|
| 855 |
+
border-color: #6c757d;
|
| 856 |
+
transform: scale(0.95);
|
| 857 |
+
pointer-events: none;
|
| 858 |
+
}
|
| 859 |
+
|
| 860 |
+
.keyboard-input-panel.inactive .input-header {
|
| 861 |
+
background: linear-gradient(45deg, #6c757d, #495057);
|
| 862 |
+
}
|
| 863 |
+
|
| 864 |
+
.keyboard-input-panel.inactive .command-input {
|
| 865 |
+
border-color: #6c757d;
|
| 866 |
+
background: rgba(108, 117, 125, 0.3);
|
| 867 |
+
color: rgba(255, 255, 255, 0.6);
|
| 868 |
+
}
|
| 869 |
+
|
| 870 |
+
.keyboard-input-panel.inactive .send-btn {
|
| 871 |
+
background: linear-gradient(45deg, #6c757d, #495057);
|
| 872 |
+
opacity: 0.6;
|
| 873 |
+
}
|
| 874 |
+
|
| 875 |
+
.keyboard-input-panel.inactive .quick-cmd {
|
| 876 |
+
border-color: #6c757d;
|
| 877 |
+
background: rgba(108, 117, 125, 0.2);
|
| 878 |
+
color: rgba(255, 255, 255, 0.6);
|
| 879 |
+
}
|
| 880 |
+
|
| 881 |
+
.keyboard-input-panel:hover:not(.inactive) {
|
| 882 |
+
transform: translateY(-5px);
|
| 883 |
+
box-shadow: 0 12px 40px rgba(0, 0, 0, 0.4);
|
| 884 |
+
}
|
| 885 |
+
|
| 886 |
+
.keyboard-input-panel.active:hover {
|
| 887 |
+
transform: scale(1.02) translateY(-5px);
|
| 888 |
+
box-shadow: 0 16px 50px rgba(78, 205, 196, 0.5);
|
| 889 |
+
}
|
| 890 |
+
|
| 891 |
+
.input-header {
|
| 892 |
+
background: linear-gradient(45deg, #4ecdc4, #44a08d);
|
| 893 |
+
padding: 15px 20px;
|
| 894 |
+
border-radius: 13px 13px 0 0;
|
| 895 |
+
display: flex;
|
| 896 |
+
justify-content: space-between;
|
| 897 |
+
align-items: center;
|
| 898 |
+
border-bottom: 2px solid rgba(255, 255, 255, 0.1);
|
| 899 |
+
cursor: move;
|
| 900 |
+
user-select: none;
|
| 901 |
+
}
|
| 902 |
+
|
| 903 |
+
.input-header h4 {
|
| 904 |
+
margin: 0;
|
| 905 |
+
font-size: 1.1em;
|
| 906 |
+
font-weight: bold;
|
| 907 |
+
color: white;
|
| 908 |
+
text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.3);
|
| 909 |
+
}
|
| 910 |
+
|
| 911 |
+
.toggle-panel-btn {
|
| 912 |
+
background: rgba(255, 255, 255, 0.2);
|
| 913 |
+
border: none;
|
| 914 |
+
border-radius: 50%;
|
| 915 |
+
width: 35px;
|
| 916 |
+
height: 35px;
|
| 917 |
+
color: white;
|
| 918 |
+
font-size: 16px;
|
| 919 |
+
cursor: pointer;
|
| 920 |
+
transition: all 0.3s ease;
|
| 921 |
+
display: flex;
|
| 922 |
+
align-items: center;
|
| 923 |
+
justify-content: center;
|
| 924 |
+
}
|
| 925 |
+
|
| 926 |
+
.toggle-panel-btn:hover {
|
| 927 |
+
background: rgba(255, 255, 255, 0.3);
|
| 928 |
+
transform: scale(1.1);
|
| 929 |
+
}
|
| 930 |
+
|
| 931 |
+
.toggle-panel-btn:active {
|
| 932 |
+
transform: scale(0.95);
|
| 933 |
+
}
|
| 934 |
+
|
| 935 |
+
.input-content {
|
| 936 |
+
padding: 20px;
|
| 937 |
+
transition: all 0.3s ease;
|
| 938 |
+
}
|
| 939 |
+
|
| 940 |
+
.input-content.collapsed {
|
| 941 |
+
display: none;
|
| 942 |
+
}
|
| 943 |
+
|
| 944 |
+
.input-group {
|
| 945 |
+
display: flex;
|
| 946 |
+
gap: 10px;
|
| 947 |
+
margin-bottom: 20px;
|
| 948 |
+
}
|
| 949 |
+
|
| 950 |
+
.command-input {
|
| 951 |
+
flex: 1;
|
| 952 |
+
padding: 12px 15px;
|
| 953 |
+
border: 2px solid #4ecdc4;
|
| 954 |
+
border-radius: 25px;
|
| 955 |
+
background: rgba(255, 255, 255, 0.1);
|
| 956 |
+
color: white;
|
| 957 |
+
font-family: 'Comic Neue', cursive;
|
| 958 |
+
font-size: 14px;
|
| 959 |
+
outline: none;
|
| 960 |
+
transition: all 0.3s ease;
|
| 961 |
+
}
|
| 962 |
+
|
| 963 |
+
.command-input::placeholder {
|
| 964 |
+
color: rgba(255, 255, 255, 0.7);
|
| 965 |
+
}
|
| 966 |
+
|
| 967 |
+
.command-input:focus {
|
| 968 |
+
border-color: #ff6b6b;
|
| 969 |
+
background: rgba(255, 255, 255, 0.2);
|
| 970 |
+
box-shadow: 0 0 15px rgba(255, 107, 107, 0.3);
|
| 971 |
+
}
|
| 972 |
+
|
| 973 |
+
.send-btn {
|
| 974 |
+
background: linear-gradient(45deg, #ff6b6b, #e55555);
|
| 975 |
+
border: none;
|
| 976 |
+
border-radius: 25px;
|
| 977 |
+
padding: 12px 20px;
|
| 978 |
+
color: white;
|
| 979 |
+
font-family: 'Comic Neue', cursive;
|
| 980 |
+
font-weight: bold;
|
| 981 |
+
font-size: 14px;
|
| 982 |
+
cursor: pointer;
|
| 983 |
+
transition: all 0.3s ease;
|
| 984 |
+
box-shadow: 0 4px 15px rgba(255, 107, 107, 0.3);
|
| 985 |
+
}
|
| 986 |
+
|
| 987 |
+
.send-btn:hover {
|
| 988 |
+
background: linear-gradient(45deg, #e55555, #d63447);
|
| 989 |
+
transform: translateY(-2px);
|
| 990 |
+
box-shadow: 0 6px 20px rgba(255, 107, 107, 0.4);
|
| 991 |
+
}
|
| 992 |
+
|
| 993 |
+
.send-btn:active {
|
| 994 |
+
transform: translateY(0);
|
| 995 |
+
}
|
| 996 |
+
|
| 997 |
+
.quick-commands {
|
| 998 |
+
margin-bottom: 20px;
|
| 999 |
+
}
|
| 1000 |
+
|
| 1001 |
+
.quick-commands h5 {
|
| 1002 |
+
margin: 0 0 10px 0;
|
| 1003 |
+
color: #4ecdc4;
|
| 1004 |
+
font-size: 0.9em;
|
| 1005 |
+
font-weight: bold;
|
| 1006 |
+
text-transform: uppercase;
|
| 1007 |
+
letter-spacing: 1px;
|
| 1008 |
+
}
|
| 1009 |
+
|
| 1010 |
+
.command-buttons {
|
| 1011 |
+
display: grid;
|
| 1012 |
+
grid-template-columns: 1fr 1fr;
|
| 1013 |
+
gap: 8px;
|
| 1014 |
+
}
|
| 1015 |
+
|
| 1016 |
+
.quick-cmd {
|
| 1017 |
+
background: rgba(78, 205, 196, 0.2);
|
| 1018 |
+
border: 1px solid #4ecdc4;
|
| 1019 |
+
border-radius: 20px;
|
| 1020 |
+
padding: 8px 12px;
|
| 1021 |
+
color: white;
|
| 1022 |
+
font-family: 'Comic Neue', cursive;
|
| 1023 |
+
font-size: 0.8em;
|
| 1024 |
+
cursor: pointer;
|
| 1025 |
+
transition: all 0.3s ease;
|
| 1026 |
+
text-align: center;
|
| 1027 |
+
}
|
| 1028 |
+
|
| 1029 |
+
.quick-cmd:hover {
|
| 1030 |
+
background: rgba(78, 205, 196, 0.4);
|
| 1031 |
+
border-color: #44a08d;
|
| 1032 |
+
transform: scale(1.05);
|
| 1033 |
+
}
|
| 1034 |
+
|
| 1035 |
+
.quick-cmd:active {
|
| 1036 |
+
transform: scale(0.95);
|
| 1037 |
+
}
|
| 1038 |
+
|
| 1039 |
+
.command-history {
|
| 1040 |
+
border-top: 1px solid rgba(255, 255, 255, 0.1);
|
| 1041 |
+
padding-top: 15px;
|
| 1042 |
+
}
|
| 1043 |
+
|
| 1044 |
+
.command-history h5 {
|
| 1045 |
+
margin: 0 0 10px 0;
|
| 1046 |
+
color: #4ecdc4;
|
| 1047 |
+
font-size: 0.9em;
|
| 1048 |
+
font-weight: bold;
|
| 1049 |
+
text-transform: uppercase;
|
| 1050 |
+
letter-spacing: 1px;
|
| 1051 |
+
}
|
| 1052 |
+
|
| 1053 |
+
.history-list {
|
| 1054 |
+
max-height: 120px;
|
| 1055 |
+
overflow-y: auto;
|
| 1056 |
+
border-radius: 8px;
|
| 1057 |
+
background: rgba(0, 0, 0, 0.2);
|
| 1058 |
+
padding: 8px;
|
| 1059 |
+
}
|
| 1060 |
+
|
| 1061 |
+
.history-item {
|
| 1062 |
+
background: rgba(255, 255, 255, 0.1);
|
| 1063 |
+
border-radius: 15px;
|
| 1064 |
+
padding: 6px 12px;
|
| 1065 |
+
margin-bottom: 5px;
|
| 1066 |
+
font-size: 0.8em;
|
| 1067 |
+
color: rgba(255, 255, 255, 0.9);
|
| 1068 |
+
display: flex;
|
| 1069 |
+
justify-content: space-between;
|
| 1070 |
+
align-items: center;
|
| 1071 |
+
cursor: pointer;
|
| 1072 |
+
transition: all 0.3s ease;
|
| 1073 |
+
}
|
| 1074 |
+
|
| 1075 |
+
.history-item:hover {
|
| 1076 |
+
background: rgba(255, 255, 255, 0.2);
|
| 1077 |
+
transform: translateX(5px);
|
| 1078 |
+
}
|
| 1079 |
+
|
| 1080 |
+
.history-item:last-child {
|
| 1081 |
+
margin-bottom: 0;
|
| 1082 |
+
}
|
| 1083 |
+
|
| 1084 |
+
.history-command {
|
| 1085 |
+
flex: 1;
|
| 1086 |
+
white-space: nowrap;
|
| 1087 |
+
overflow: hidden;
|
| 1088 |
+
text-overflow: ellipsis;
|
| 1089 |
+
}
|
| 1090 |
+
|
| 1091 |
+
.history-time {
|
| 1092 |
+
color: rgba(255, 255, 255, 0.6);
|
| 1093 |
+
font-size: 0.7em;
|
| 1094 |
+
margin-left: 10px;
|
| 1095 |
+
}
|
| 1096 |
+
|
| 1097 |
+
/* 滚动条样式 */
|
| 1098 |
+
.history-list::-webkit-scrollbar {
|
| 1099 |
+
width: 4px;
|
| 1100 |
+
}
|
| 1101 |
+
|
| 1102 |
+
.history-list::-webkit-scrollbar-track {
|
| 1103 |
+
background: rgba(255, 255, 255, 0.1);
|
| 1104 |
+
border-radius: 2px;
|
| 1105 |
+
}
|
| 1106 |
+
|
| 1107 |
+
.history-list::-webkit-scrollbar-thumb {
|
| 1108 |
+
background: #4ecdc4;
|
| 1109 |
+
border-radius: 2px;
|
| 1110 |
+
}
|
| 1111 |
+
|
| 1112 |
+
.history-list::-webkit-scrollbar-thumb:hover {
|
| 1113 |
+
background: #44a08d;
|
| 1114 |
+
}
|
| 1115 |
+
|
| 1116 |
+
/* 面板折叠状态 */
|
| 1117 |
+
.keyboard-input-panel.collapsed {
|
| 1118 |
+
min-width: auto;
|
| 1119 |
+
width: auto;
|
| 1120 |
+
}
|
| 1121 |
+
|
| 1122 |
+
.keyboard-input-panel.collapsed .input-content {
|
| 1123 |
+
display: none;
|
| 1124 |
+
}
|
| 1125 |
+
|
| 1126 |
+
/* 面板动画 */
|
| 1127 |
+
@keyframes panelSlideIn {
|
| 1128 |
+
from {
|
| 1129 |
+
transform: translateX(100%);
|
| 1130 |
+
opacity: 0;
|
| 1131 |
+
}
|
| 1132 |
+
to {
|
| 1133 |
+
transform: translateX(0);
|
| 1134 |
+
opacity: 1;
|
| 1135 |
+
}
|
| 1136 |
+
}
|
| 1137 |
+
|
| 1138 |
+
.keyboard-input-panel {
|
| 1139 |
+
animation: panelSlideIn 0.5s ease-out;
|
| 1140 |
+
}
|
| 1141 |
+
|
| 1142 |
+
/* 响应式设计 */
|
| 1143 |
+
@media (max-width: 768px) {
|
| 1144 |
+
.keyboard-input-panel {
|
| 1145 |
+
bottom: 10px;
|
| 1146 |
+
right: 10px;
|
| 1147 |
+
left: 10px;
|
| 1148 |
+
min-width: auto;
|
| 1149 |
+
max-width: none;
|
| 1150 |
+
}
|
| 1151 |
+
|
| 1152 |
+
.command-buttons {
|
| 1153 |
+
grid-template-columns: 1fr;
|
| 1154 |
+
}
|
| 1155 |
+
|
| 1156 |
+
.input-group {
|
| 1157 |
+
flex-direction: column;
|
| 1158 |
+
}
|
| 1159 |
+
|
| 1160 |
+
.send-btn {
|
| 1161 |
+
align-self: flex-end;
|
| 1162 |
+
min-width: 100px;
|
| 1163 |
+
}
|
| 1164 |
}
|
voice.js
DELETED
|
@@ -1,667 +0,0 @@
|
|
| 1 |
-
// 语音识别类
|
| 2 |
-
class VoiceRecognition {
|
| 3 |
-
constructor() {
|
| 4 |
-
this.recognition = null;
|
| 5 |
-
this.isListening = false;
|
| 6 |
-
this.isSupported = false;
|
| 7 |
-
this.onResult = null;
|
| 8 |
-
this.onError = null;
|
| 9 |
-
this.onStatusChange = null;
|
| 10 |
-
|
| 11 |
-
// 错误重试控制
|
| 12 |
-
this.retryCount = 0;
|
| 13 |
-
this.maxRetries = 3;
|
| 14 |
-
this.retryDelay = 2000; // 2秒延迟
|
| 15 |
-
this.lastErrorTime = 0;
|
| 16 |
-
this.consecutiveErrors = 0;
|
| 17 |
-
this.isDisabled = false;
|
| 18 |
-
|
| 19 |
-
// 环境检测
|
| 20 |
-
this.isHuggingFaceSpace = this.detectHuggingFaceSpace();
|
| 21 |
-
this.isInIframe = window.parent !== window;
|
| 22 |
-
this.hasUserInteraction = false;
|
| 23 |
-
|
| 24 |
-
this.init();
|
| 25 |
-
}
|
| 26 |
-
|
| 27 |
-
init() {
|
| 28 |
-
// 环境兼容性检查
|
| 29 |
-
if (this.isHuggingFaceSpace || this.isInIframe) {
|
| 30 |
-
console.warn('检测到特殊环境,语音识别可能受限:', {
|
| 31 |
-
isHuggingFaceSpace: this.isHuggingFaceSpace,
|
| 32 |
-
isInIframe: this.isInIframe
|
| 33 |
-
});
|
| 34 |
-
this.showEnvironmentWarning();
|
| 35 |
-
}
|
| 36 |
-
|
| 37 |
-
// 检查浏览器支持
|
| 38 |
-
if ('webkitSpeechRecognition' in window) {
|
| 39 |
-
this.recognition = new webkitSpeechRecognition();
|
| 40 |
-
this.isSupported = true;
|
| 41 |
-
} else if ('SpeechRecognition' in window) {
|
| 42 |
-
this.recognition = new SpeechRecognition();
|
| 43 |
-
this.isSupported = true;
|
| 44 |
-
} else {
|
| 45 |
-
console.warn('浏览器不支持语音识别');
|
| 46 |
-
this.handleError('浏览器不支持语音识别');
|
| 47 |
-
return;
|
| 48 |
-
}
|
| 49 |
-
|
| 50 |
-
this.setupRecognition();
|
| 51 |
-
|
| 52 |
-
// 在特殊环境中,不自动启动语音识别
|
| 53 |
-
if (!this.isHuggingFaceSpace && !this.isInIframe) {
|
| 54 |
-
this.startListening();
|
| 55 |
-
} else {
|
| 56 |
-
console.log('在受限环境中,语音识别需要用户手动启动');
|
| 57 |
-
this.showNotification('在当前环境中,请点击页面任意位置启动语音识别', 'info');
|
| 58 |
-
}
|
| 59 |
-
}
|
| 60 |
-
|
| 61 |
-
detectHuggingFaceSpace() {
|
| 62 |
-
// 检测是否在 Hugging Face Space 环境中
|
| 63 |
-
const hostname = window.location.hostname;
|
| 64 |
-
const userAgent = navigator.userAgent.toLowerCase();
|
| 65 |
-
|
| 66 |
-
return hostname.includes('hf.space') ||
|
| 67 |
-
hostname.includes('huggingface.co') ||
|
| 68 |
-
hostname.includes('gradio.live') ||
|
| 69 |
-
userAgent.includes('huggingface');
|
| 70 |
-
}
|
| 71 |
-
|
| 72 |
-
showEnvironmentWarning() {
|
| 73 |
-
// 显示环境警告
|
| 74 |
-
console.warn('当前运行在受限环境中,语音识别功能可能不稳定');
|
| 75 |
-
|
| 76 |
-
// 调整配置以适应受限环境
|
| 77 |
-
this.maxRetries = 1; // 减少重试次数
|
| 78 |
-
this.retryDelay = 5000; // 增加延迟时间
|
| 79 |
-
|
| 80 |
-
setTimeout(() => {
|
| 81 |
-
this.showNotification(
|
| 82 |
-
'检测到受限环境,语音功能可能需要手动激活。如遇问题请使用键盘输入(按F9)',
|
| 83 |
-
'info'
|
| 84 |
-
);
|
| 85 |
-
}, 2000);
|
| 86 |
-
}
|
| 87 |
-
|
| 88 |
-
setupRecognition() {
|
| 89 |
-
// 配置语音识别
|
| 90 |
-
this.recognition.continuous = true;
|
| 91 |
-
this.recognition.interimResults = false;
|
| 92 |
-
this.recognition.lang = 'en-US'; // 使用英文识别食物名称
|
| 93 |
-
this.recognition.maxAlternatives = 3;
|
| 94 |
-
|
| 95 |
-
// 事件监听
|
| 96 |
-
this.recognition.onstart = () => {
|
| 97 |
-
this.isListening = true;
|
| 98 |
-
this.updateStatus('listening');
|
| 99 |
-
console.log('语音识别开始');
|
| 100 |
-
};
|
| 101 |
-
|
| 102 |
-
this.recognition.onresult = (event) => {
|
| 103 |
-
this.handleResult(event);
|
| 104 |
-
};
|
| 105 |
-
|
| 106 |
-
this.recognition.onerror = (event) => {
|
| 107 |
-
this.handleError(event.error);
|
| 108 |
-
};
|
| 109 |
-
|
| 110 |
-
this.recognition.onend = () => {
|
| 111 |
-
this.isListening = false;
|
| 112 |
-
this.updateStatus('ready');
|
| 113 |
-
console.log('语音识别结束');
|
| 114 |
-
|
| 115 |
-
// 智能重启逻辑 - 避免在错误频发时无限重试
|
| 116 |
-
if (this.shouldAttemptRestart()) {
|
| 117 |
-
const delay = this.calculateRestartDelay();
|
| 118 |
-
console.log(`准备在 ${delay}ms 后重新启动语音识别...`);
|
| 119 |
-
|
| 120 |
-
setTimeout(() => {
|
| 121 |
-
if (this.isSupported && !this.isListening && !this.isDisabled) {
|
| 122 |
-
this.startListening();
|
| 123 |
-
}
|
| 124 |
-
}, delay);
|
| 125 |
-
} else {
|
| 126 |
-
console.log('由于频繁错误,暂停自动重启语音识别');
|
| 127 |
-
this.showNotification('语音识别暂停,请点击页面重新激活或使用键盘输入(F9)', 'warning');
|
| 128 |
-
}
|
| 129 |
-
};
|
| 130 |
-
}
|
| 131 |
-
|
| 132 |
-
handleResult(event) {
|
| 133 |
-
this.updateStatus('processing');
|
| 134 |
-
|
| 135 |
-
let finalTranscript = '';
|
| 136 |
-
let interimTranscript = '';
|
| 137 |
-
let confidence = 0;
|
| 138 |
-
|
| 139 |
-
// 处理识别结果
|
| 140 |
-
for (let i = event.resultIndex; i < event.results.length; i++) {
|
| 141 |
-
const transcript = event.results[i][0].transcript;
|
| 142 |
-
confidence = event.results[i][0].confidence || 0;
|
| 143 |
-
|
| 144 |
-
if (event.results[i].isFinal) {
|
| 145 |
-
finalTranscript += transcript;
|
| 146 |
-
} else {
|
| 147 |
-
interimTranscript += transcript;
|
| 148 |
-
}
|
| 149 |
-
}
|
| 150 |
-
|
| 151 |
-
// 显示实时语音输入
|
| 152 |
-
const currentText = finalTranscript || interimTranscript;
|
| 153 |
-
if (currentText) {
|
| 154 |
-
this.showVoiceInput(currentText, confidence, !finalTranscript);
|
| 155 |
-
}
|
| 156 |
-
|
| 157 |
-
// 如果有最终结果,触发回调
|
| 158 |
-
if (finalTranscript && this.onResult) {
|
| 159 |
-
console.log('语音识别结果:', finalTranscript);
|
| 160 |
-
this.onResult(finalTranscript.trim());
|
| 161 |
-
|
| 162 |
-
// 短暂显示识别成功状态
|
| 163 |
-
setTimeout(() => {
|
| 164 |
-
this.hideVoiceInput();
|
| 165 |
-
}, 2000);
|
| 166 |
-
}
|
| 167 |
-
|
| 168 |
-
this.updateStatus('ready');
|
| 169 |
-
}
|
| 170 |
-
|
| 171 |
-
handleError(error) {
|
| 172 |
-
console.error('语音识别错误:', error);
|
| 173 |
-
this.updateStatus('error');
|
| 174 |
-
|
| 175 |
-
// 记录错误时间和连续错误次数
|
| 176 |
-
const now = Date.now();
|
| 177 |
-
if (now - this.lastErrorTime < 5000) { // 5秒内的错误视为连续错误
|
| 178 |
-
this.consecutiveErrors++;
|
| 179 |
-
} else {
|
| 180 |
-
this.consecutiveErrors = 1;
|
| 181 |
-
}
|
| 182 |
-
this.lastErrorTime = now;
|
| 183 |
-
|
| 184 |
-
if (this.onError) {
|
| 185 |
-
this.onError(error);
|
| 186 |
-
}
|
| 187 |
-
|
| 188 |
-
// 特殊处理频繁的 aborted 错误
|
| 189 |
-
if (error === 'aborted' && this.consecutiveErrors >= 3) {
|
| 190 |
-
console.warn('检测到频繁的 aborted 错误,可能是环境限制导致');
|
| 191 |
-
this.handleAbortedErrorLoop();
|
| 192 |
-
return;
|
| 193 |
-
}
|
| 194 |
-
|
| 195 |
-
// 根据错误类型处理
|
| 196 |
-
switch (error) {
|
| 197 |
-
case 'not-allowed':
|
| 198 |
-
this.showPermissionError();
|
| 199 |
-
this.isDisabled = true; // 禁用自动重启
|
| 200 |
-
break;
|
| 201 |
-
case 'no-speech':
|
| 202 |
-
// 没有检测到语音,继续监听(但要控制频率)
|
| 203 |
-
if (this.consecutiveErrors < 5) {
|
| 204 |
-
setTimeout(() => {
|
| 205 |
-
if (this.isSupported && !this.isDisabled) {
|
| 206 |
-
this.startListening();
|
| 207 |
-
}
|
| 208 |
-
}, 1000);
|
| 209 |
-
}
|
| 210 |
-
break;
|
| 211 |
-
case 'network':
|
| 212 |
-
this.showNetworkError();
|
| 213 |
-
if (this.consecutiveErrors < 3) {
|
| 214 |
-
setTimeout(() => {
|
| 215 |
-
if (this.isSupported && !this.isDisabled) {
|
| 216 |
-
this.startListening();
|
| 217 |
-
}
|
| 218 |
-
}, 3000);
|
| 219 |
-
}
|
| 220 |
-
break;
|
| 221 |
-
case 'aborted':
|
| 222 |
-
this.handleAbortedError();
|
| 223 |
-
break;
|
| 224 |
-
default:
|
| 225 |
-
// 其他错误,谨慎重试
|
| 226 |
-
if (this.consecutiveErrors < 3) {
|
| 227 |
-
setTimeout(() => {
|
| 228 |
-
if (this.isSupported && !this.isDisabled) {
|
| 229 |
-
this.startListening();
|
| 230 |
-
}
|
| 231 |
-
}, this.retryDelay);
|
| 232 |
-
}
|
| 233 |
-
break;
|
| 234 |
-
}
|
| 235 |
-
}
|
| 236 |
-
|
| 237 |
-
handleAbortedError() {
|
| 238 |
-
console.log('处理 aborted 错误,连续错误次数:', this.consecutiveErrors);
|
| 239 |
-
|
| 240 |
-
if (this.consecutiveErrors >= 3) {
|
| 241 |
-
this.handleAbortedErrorLoop();
|
| 242 |
-
} else {
|
| 243 |
-
// 延长重试时间
|
| 244 |
-
const delay = this.retryDelay * this.consecutiveErrors;
|
| 245 |
-
console.log(`Aborted 错误,${delay}ms 后重试`);
|
| 246 |
-
|
| 247 |
-
setTimeout(() => {
|
| 248 |
-
if (this.isSupported && !this.isDisabled) {
|
| 249 |
-
this.startListening();
|
| 250 |
-
}
|
| 251 |
-
}, delay);
|
| 252 |
-
}
|
| 253 |
-
}
|
| 254 |
-
|
| 255 |
-
handleAbortedErrorLoop() {
|
| 256 |
-
console.warn('检测到 aborted 错误循环,暂停自动重启');
|
| 257 |
-
this.isDisabled = true;
|
| 258 |
-
|
| 259 |
-
this.showNotification(
|
| 260 |
-
'语音识别在当前环境中不稳定,已暂停自动重启。\n请使用键盘输入(按F9键)或点击页面手动重启',
|
| 261 |
-
'warning'
|
| 262 |
-
);
|
| 263 |
-
|
| 264 |
-
// 5分钟后重新尝试
|
| 265 |
-
setTimeout(() => {
|
| 266 |
-
this.resetErrorState();
|
| 267 |
-
this.showNotification('语音识别已重新启用,点击页面激活', 'info');
|
| 268 |
-
}, 300000); // 5分钟
|
| 269 |
-
}
|
| 270 |
-
|
| 271 |
-
shouldAttemptRestart() {
|
| 272 |
-
// 判断是否应该尝试重启
|
| 273 |
-
if (this.isDisabled) return false;
|
| 274 |
-
if (this.consecutiveErrors >= 5) return false;
|
| 275 |
-
if (this.isHuggingFaceSpace && this.consecutiveErrors >= 2) return false;
|
| 276 |
-
|
| 277 |
-
return true;
|
| 278 |
-
}
|
| 279 |
-
|
| 280 |
-
calculateRestartDelay() {
|
| 281 |
-
// 计算重启延迟时间
|
| 282 |
-
let baseDelay = this.retryDelay;
|
| 283 |
-
|
| 284 |
-
// 根据连续错误次数增加延迟
|
| 285 |
-
const multiplier = Math.min(this.consecutiveErrors, 5);
|
| 286 |
-
baseDelay *= multiplier;
|
| 287 |
-
|
| 288 |
-
// 在受限环境中增加额外延迟
|
| 289 |
-
if (this.isHuggingFaceSpace || this.isInIframe) {
|
| 290 |
-
baseDelay *= 2;
|
| 291 |
-
}
|
| 292 |
-
|
| 293 |
-
return Math.min(baseDelay, 30000); // 最大30秒
|
| 294 |
-
}
|
| 295 |
-
|
| 296 |
-
resetErrorState() {
|
| 297 |
-
// 重置错误状态
|
| 298 |
-
this.consecutiveErrors = 0;
|
| 299 |
-
this.retryCount = 0;
|
| 300 |
-
this.isDisabled = false;
|
| 301 |
-
this.lastErrorTime = 0;
|
| 302 |
-
console.log('错误状态已重置');
|
| 303 |
-
}
|
| 304 |
-
|
| 305 |
-
startListening() {
|
| 306 |
-
if (!this.isSupported) {
|
| 307 |
-
this.showUnsupportedError();
|
| 308 |
-
return;
|
| 309 |
-
}
|
| 310 |
-
|
| 311 |
-
if (this.isDisabled) {
|
| 312 |
-
console.log('语音识别已禁用,需要手动重启');
|
| 313 |
-
return;
|
| 314 |
-
}
|
| 315 |
-
|
| 316 |
-
// 增强的状态检查
|
| 317 |
-
if (this.isListening) {
|
| 318 |
-
console.log('语音识别已在运行中,跳过启动');
|
| 319 |
-
return;
|
| 320 |
-
}
|
| 321 |
-
|
| 322 |
-
// 在受限环境中需要用户交互才能启动
|
| 323 |
-
if ((this.isHuggingFaceSpace || this.isInIframe) && !this.hasUserInteraction) {
|
| 324 |
-
this.waitForUserInteraction();
|
| 325 |
-
return;
|
| 326 |
-
}
|
| 327 |
-
|
| 328 |
-
try {
|
| 329 |
-
// 确保之前的识别已完全停止
|
| 330 |
-
if (this.recognition) {
|
| 331 |
-
this.recognition.abort(); // 强制停止之前的识别
|
| 332 |
-
}
|
| 333 |
-
|
| 334 |
-
// 根据环境调整延迟
|
| 335 |
-
const delay = this.isHuggingFaceSpace ? 500 : 100;
|
| 336 |
-
|
| 337 |
-
setTimeout(() => {
|
| 338 |
-
try {
|
| 339 |
-
if (!this.isListening && !this.isDisabled) {
|
| 340 |
-
this.recognition.start();
|
| 341 |
-
console.log('语音识别启动尝试');
|
| 342 |
-
}
|
| 343 |
-
} catch (error) {
|
| 344 |
-
if (error.message.includes('recognition has already started')) {
|
| 345 |
-
console.log('识别已启动,尝试停止后重新启动');
|
| 346 |
-
this.recognition.stop();
|
| 347 |
-
setTimeout(() => {
|
| 348 |
-
try {
|
| 349 |
-
if (!this.isDisabled) {
|
| 350 |
-
this.recognition.start();
|
| 351 |
-
}
|
| 352 |
-
} catch (retryError) {
|
| 353 |
-
console.error('重试启动失败:', retryError);
|
| 354 |
-
this.handleError('start-failed');
|
| 355 |
-
}
|
| 356 |
-
}, 1000);
|
| 357 |
-
} else {
|
| 358 |
-
throw error;
|
| 359 |
-
}
|
| 360 |
-
}
|
| 361 |
-
}, delay);
|
| 362 |
-
|
| 363 |
-
} catch (error) {
|
| 364 |
-
console.error('启动语音识别失败:', error);
|
| 365 |
-
this.handleError('start-failed');
|
| 366 |
-
}
|
| 367 |
-
}
|
| 368 |
-
|
| 369 |
-
waitForUserInteraction() {
|
| 370 |
-
if (this.hasUserInteraction) return;
|
| 371 |
-
|
| 372 |
-
console.log('等待用户交互以启动语音识别');
|
| 373 |
-
|
| 374 |
-
const startOnInteraction = () => {
|
| 375 |
-
this.hasUserInteraction = true;
|
| 376 |
-
console.log('检测到用户交互,启动语音识别');
|
| 377 |
-
this.startListening();
|
| 378 |
-
|
| 379 |
-
// 移除事件监听器
|
| 380 |
-
document.removeEventListener('click', startOnInteraction);
|
| 381 |
-
document.removeEventListener('keydown', startOnInteraction);
|
| 382 |
-
document.removeEventListener('touchstart', startOnInteraction);
|
| 383 |
-
};
|
| 384 |
-
|
| 385 |
-
// 监听用户交互事件
|
| 386 |
-
document.addEventListener('click', startOnInteraction, { once: true });
|
| 387 |
-
document.addEventListener('keydown', startOnInteraction, { once: true });
|
| 388 |
-
document.addEventListener('touchstart', startOnInteraction, { once: true });
|
| 389 |
-
|
| 390 |
-
this.showNotification('请点击页面任意位置激活语音识别', 'info');
|
| 391 |
-
}
|
| 392 |
-
|
| 393 |
-
stopListening() {
|
| 394 |
-
if (this.recognition && this.isListening) {
|
| 395 |
-
this.recognition.stop();
|
| 396 |
-
}
|
| 397 |
-
}
|
| 398 |
-
|
| 399 |
-
// 重启语音识别
|
| 400 |
-
restart() {
|
| 401 |
-
console.log('手动重启语音识别系统...');
|
| 402 |
-
|
| 403 |
-
// 重置错误状态
|
| 404 |
-
this.resetErrorState();
|
| 405 |
-
|
| 406 |
-
// 强制停止当前识别
|
| 407 |
-
if (this.recognition) {
|
| 408 |
-
this.isListening = false;
|
| 409 |
-
try {
|
| 410 |
-
this.recognition.abort();
|
| 411 |
-
} catch (error) {
|
| 412 |
-
console.log('停止识别时出错:', error);
|
| 413 |
-
}
|
| 414 |
-
}
|
| 415 |
-
|
| 416 |
-
// 清除可能存在的定时器
|
| 417 |
-
clearTimeout(this.restartTimer);
|
| 418 |
-
|
| 419 |
-
// 等待一段时间后重新启动
|
| 420 |
-
this.restartTimer = setTimeout(() => {
|
| 421 |
-
if (this.isSupported) {
|
| 422 |
-
console.log('执行重启...');
|
| 423 |
-
this.startListening();
|
| 424 |
-
this.showNotification('语音识别已重启', 'info');
|
| 425 |
-
}
|
| 426 |
-
}, 1000);
|
| 427 |
-
}
|
| 428 |
-
|
| 429 |
-
// 手动激活语音识别(用于用户点击按钮)
|
| 430 |
-
manualActivate() {
|
| 431 |
-
console.log('手动激活语音识别');
|
| 432 |
-
this.hasUserInteraction = true;
|
| 433 |
-
this.resetErrorState();
|
| 434 |
-
|
| 435 |
-
if (this.isSupported) {
|
| 436 |
-
this.startListening();
|
| 437 |
-
this.showNotification('语音识别已激活', 'info');
|
| 438 |
-
} else {
|
| 439 |
-
this.showNotification('当前浏览器不支持语音识别', 'error');
|
| 440 |
-
}
|
| 441 |
-
}
|
| 442 |
-
|
| 443 |
-
// 永久禁用语音识别
|
| 444 |
-
disable() {
|
| 445 |
-
console.log('禁用语音识别');
|
| 446 |
-
this.isDisabled = true;
|
| 447 |
-
|
| 448 |
-
if (this.recognition && this.isListening) {
|
| 449 |
-
this.recognition.abort();
|
| 450 |
-
}
|
| 451 |
-
|
| 452 |
-
this.showNotification('语音识别已禁用', 'warning');
|
| 453 |
-
}
|
| 454 |
-
|
| 455 |
-
// 启用语音识别
|
| 456 |
-
enable() {
|
| 457 |
-
console.log('启用语音识别');
|
| 458 |
-
this.resetErrorState();
|
| 459 |
-
|
| 460 |
-
if (this.isSupported) {
|
| 461 |
-
this.showNotification('语音识别已启用,点击页面激活', 'info');
|
| 462 |
-
|
| 463 |
-
// 在受限环境中等待用户交互
|
| 464 |
-
if (this.isHuggingFaceSpace || this.isInIframe) {
|
| 465 |
-
this.hasUserInteraction = false;
|
| 466 |
-
this.waitForUserInteraction();
|
| 467 |
-
} else {
|
| 468 |
-
this.startListening();
|
| 469 |
-
}
|
| 470 |
-
}
|
| 471 |
-
}
|
| 472 |
-
|
| 473 |
-
updateStatus(status) {
|
| 474 |
-
if (this.onStatusChange) {
|
| 475 |
-
this.onStatusChange(status);
|
| 476 |
-
}
|
| 477 |
-
}
|
| 478 |
-
|
| 479 |
-
showVoiceInput(text, confidence = 0, isInterim = false) {
|
| 480 |
-
const voiceDisplay = document.getElementById('voiceInputDisplay');
|
| 481 |
-
const speechText = document.getElementById('speechText');
|
| 482 |
-
const speechConfidence = document.getElementById('speechConfidence');
|
| 483 |
-
const speechBubble = voiceDisplay.querySelector('.speech-bubble');
|
| 484 |
-
|
| 485 |
-
if (!voiceDisplay || !speechText) return;
|
| 486 |
-
|
| 487 |
-
// 显示语音输入框
|
| 488 |
-
voiceDisplay.style.display = 'block';
|
| 489 |
-
|
| 490 |
-
// 更新文本内容
|
| 491 |
-
speechText.textContent = text;
|
| 492 |
-
|
| 493 |
-
// 显示置信度
|
| 494 |
-
if (confidence > 0) {
|
| 495 |
-
speechConfidence.textContent = `置信度: ${Math.round(confidence * 100)}%`;
|
| 496 |
-
} else {
|
| 497 |
-
speechConfidence.textContent = isInterim ? '正在识别...' : '';
|
| 498 |
-
}
|
| 499 |
-
|
| 500 |
-
// 更新样式状态
|
| 501 |
-
speechBubble.className = 'speech-bubble';
|
| 502 |
-
if (isInterim) {
|
| 503 |
-
speechBubble.classList.add('listening');
|
| 504 |
-
} else {
|
| 505 |
-
speechBubble.classList.add('recognized');
|
| 506 |
-
}
|
| 507 |
-
|
| 508 |
-
// 清除之前的隐藏定时器
|
| 509 |
-
if (this.hideTimer) {
|
| 510 |
-
clearTimeout(this.hideTimer);
|
| 511 |
-
}
|
| 512 |
-
|
| 513 |
-
// 如果是临时结果,设置自动隐藏
|
| 514 |
-
if (isInterim) {
|
| 515 |
-
this.hideTimer = setTimeout(() => {
|
| 516 |
-
this.hideVoiceInput();
|
| 517 |
-
}, 3000);
|
| 518 |
-
}
|
| 519 |
-
}
|
| 520 |
-
|
| 521 |
-
hideVoiceInput() {
|
| 522 |
-
const voiceDisplay = document.getElementById('voiceInputDisplay');
|
| 523 |
-
if (voiceDisplay) {
|
| 524 |
-
voiceDisplay.style.display = 'none';
|
| 525 |
-
}
|
| 526 |
-
|
| 527 |
-
if (this.hideTimer) {
|
| 528 |
-
clearTimeout(this.hideTimer);
|
| 529 |
-
this.hideTimer = null;
|
| 530 |
-
}
|
| 531 |
-
}
|
| 532 |
-
|
| 533 |
-
showPermissionError() {
|
| 534 |
-
this.showNotification('需要麦克风权限才能使用语音功能', 'error');
|
| 535 |
-
}
|
| 536 |
-
|
| 537 |
-
showNetworkError() {
|
| 538 |
-
this.showNotification('网络连接错误,语音识别暂时不可用', 'error');
|
| 539 |
-
}
|
| 540 |
-
|
| 541 |
-
showUnsupportedError() {
|
| 542 |
-
this.showNotification('您的浏览器不支持语音识别功能', 'error');
|
| 543 |
-
}
|
| 544 |
-
|
| 545 |
-
showNotification(message, type = 'info') {
|
| 546 |
-
// 创建通知元素
|
| 547 |
-
const notification = document.createElement('div');
|
| 548 |
-
notification.className = `voice-notification ${type}`;
|
| 549 |
-
notification.textContent = message;
|
| 550 |
-
|
| 551 |
-
// 样式
|
| 552 |
-
Object.assign(notification.style, {
|
| 553 |
-
position: 'fixed',
|
| 554 |
-
top: '20px',
|
| 555 |
-
right: '20px',
|
| 556 |
-
background: type === 'error' ? '#e74c3c' : '#4ecdc4',
|
| 557 |
-
color: 'white',
|
| 558 |
-
padding: '15px 20px',
|
| 559 |
-
borderRadius: '10px',
|
| 560 |
-
boxShadow: '0 4px 15px rgba(0,0,0,0.2)',
|
| 561 |
-
zIndex: '10000',
|
| 562 |
-
fontSize: '14px',
|
| 563 |
-
maxWidth: '300px',
|
| 564 |
-
animation: 'slideInRight 0.3s ease'
|
| 565 |
-
});
|
| 566 |
-
|
| 567 |
-
document.body.appendChild(notification);
|
| 568 |
-
|
| 569 |
-
// 自动移除
|
| 570 |
-
setTimeout(() => {
|
| 571 |
-
notification.style.animation = 'slideOutRight 0.3s ease';
|
| 572 |
-
setTimeout(() => {
|
| 573 |
-
if (notification.parentNode) {
|
| 574 |
-
notification.parentNode.removeChild(notification);
|
| 575 |
-
}
|
| 576 |
-
}, 300);
|
| 577 |
-
}, 5000);
|
| 578 |
-
}
|
| 579 |
-
|
| 580 |
-
// 测试语音识别功能
|
| 581 |
-
test() {
|
| 582 |
-
if (!this.isSupported) {
|
| 583 |
-
console.log('语音识别不支持');
|
| 584 |
-
return false;
|
| 585 |
-
}
|
| 586 |
-
|
| 587 |
-
console.log('语音识别测试开始...');
|
| 588 |
-
|
| 589 |
-
// 设置测试回调
|
| 590 |
-
const originalOnResult = this.onResult;
|
| 591 |
-
this.onResult = (transcript) => {
|
| 592 |
-
console.log('测试结果:', transcript);
|
| 593 |
-
this.onResult = originalOnResult;
|
| 594 |
-
};
|
| 595 |
-
|
| 596 |
-
return true;
|
| 597 |
-
}
|
| 598 |
-
|
| 599 |
-
// 获取支持的语言列表
|
| 600 |
-
getSupportedLanguages() {
|
| 601 |
-
return [
|
| 602 |
-
{ code: 'en-US', name: 'English (US)' },
|
| 603 |
-
{ code: 'zh-CN', name: '中文 (普通话)' },
|
| 604 |
-
{ code: 'ja-JP', name: '日本語' },
|
| 605 |
-
{ code: 'ko-KR', name: '한국어' },
|
| 606 |
-
{ code: 'fr-FR', name: 'Français' },
|
| 607 |
-
{ code: 'de-DE', name: 'Deutsch' },
|
| 608 |
-
{ code: 'es-ES', name: 'Español' },
|
| 609 |
-
{ code: 'it-IT', name: 'Italiano' }
|
| 610 |
-
];
|
| 611 |
-
}
|
| 612 |
-
|
| 613 |
-
// 切换语言
|
| 614 |
-
setLanguage(langCode) {
|
| 615 |
-
if (this.recognition) {
|
| 616 |
-
this.recognition.lang = langCode;
|
| 617 |
-
console.log(`语音识别语言切换为: ${langCode}`);
|
| 618 |
-
}
|
| 619 |
-
}
|
| 620 |
-
|
| 621 |
-
// 获取当前状态
|
| 622 |
-
getStatus() {
|
| 623 |
-
return {
|
| 624 |
-
isSupported: this.isSupported,
|
| 625 |
-
isListening: this.isListening,
|
| 626 |
-
isDisabled: this.isDisabled,
|
| 627 |
-
hasUserInteraction: this.hasUserInteraction,
|
| 628 |
-
consecutiveErrors: this.consecutiveErrors,
|
| 629 |
-
isHuggingFaceSpace: this.isHuggingFaceSpace,
|
| 630 |
-
isInIframe: this.isInIframe,
|
| 631 |
-
currentLanguage: this.recognition ? this.recognition.lang : null
|
| 632 |
-
};
|
| 633 |
-
}
|
| 634 |
-
}
|
| 635 |
-
|
| 636 |
-
// 添加CSS动画
|
| 637 |
-
const style = document.createElement('style');
|
| 638 |
-
style.textContent = `
|
| 639 |
-
@keyframes slideInRight {
|
| 640 |
-
from {
|
| 641 |
-
transform: translateX(100%);
|
| 642 |
-
opacity: 0;
|
| 643 |
-
}
|
| 644 |
-
to {
|
| 645 |
-
transform: translateX(0);
|
| 646 |
-
opacity: 1;
|
| 647 |
-
}
|
| 648 |
-
}
|
| 649 |
-
|
| 650 |
-
@keyframes slideOutRight {
|
| 651 |
-
from {
|
| 652 |
-
transform: translateX(0);
|
| 653 |
-
opacity: 1;
|
| 654 |
-
}
|
| 655 |
-
to {
|
| 656 |
-
transform: translateX(100%);
|
| 657 |
-
opacity: 0;
|
| 658 |
-
}
|
| 659 |
-
}
|
| 660 |
-
|
| 661 |
-
.voice-notification {
|
| 662 |
-
font-family: 'Comic Neue', cursive;
|
| 663 |
-
font-weight: bold;
|
| 664 |
-
word-wrap: break-word;
|
| 665 |
-
}
|
| 666 |
-
`;
|
| 667 |
-
document.head.appendChild(style);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|