feat: adaptive bitrate support, engine improvements, demo updates, and electron preload

This commit is contained in:
2026-06-12 17:15:30 +08:00
parent 6575b0be0f
commit b6231e4efd
17 changed files with 139 additions and 4 deletions

View File

@@ -23,6 +23,58 @@
- [ ] `src/App.vue` — 整合 VideoErrorOverlay
- [ ] 验证:断网播放 → 错误画面 → 重试恢复 → 跳过下一场景
### P24 多画质视频 — 本地 + CDN 流双模式 ✅ 已完成 2026-06-10
目标:桌面版用本地 `videoUrl`Web 版用 CDN `streamingUrl`HLS 流)。
Web 版不打包视频文件,用户手动选择超清/高清/标清,系统提示各画质所需网速。
**设计决策:**
| 决策 | 做法 |
|------|------|
| **环境检测** | Electron `preload.js` 注入 `__ELECTRON__``VideoManager` 判断走本地还是 CDN |
| **Web 画质** | 用户从设置面板手动选择(超清/高清/标清非带宽自适应。localStorage 持久化 |
| **Web 打包** | `pack:html` 跳过 `videos/` 目录,音频/图片/字幕保留 |
| **HLS 兼容** | Safari 原生播放 `.m3u8`Chrome/Edge 按需动态 `import('hls.js')`~100KB |
**场景数据设计:**
```json
{
"id": "intro",
"videoUrl": "/videos/intro.mp4",
"streamingUrl": {
"超清 (1080P)": "https://cdn.example.com/hls/intro/1080p.m3u8",
"高清 (720P)": "https://cdn.example.com/hls/intro/720p.m3u8",
"标清 (480P)": "https://cdn.example.com/hls/intro/480p.m3u8"
}
}
```
**设置面板画质选项:**
| 选项 | 网速提示 |
|------|---------|
| 超清 (1080P) | 需要 2.5 Mbps |
| 高清 (720P) | 需要 2 Mbps |
| 标清 (480P) | 需要 0.8 Mbps |
**实现清单:**
- [x] `engine/types.ts``SceneNode.streamingUrl?: Record<string, string>`
- [x] `engine/core/VideoManager.ts``resolveVideoUrl(scene, quality)` + `streamingQuality` 属性
- [x] `engine/core/Engine.ts``goToScene``resolveVideoUrl` 替代直接 `scene.videoUrl`
- [x] `electron/preload.js``contextBridge.exposeInMainWorld('__ELECTRON__', true)`
- [x] `electron/main.js``webPreferences.preload` 加载 preload.js
- [x] `src/stores/gameStore.ts``preferredQuality` + localStorage 持久化
- [x] `src/components/AccessibilitySettings.vue` — Web 模式新增画质下拉(附网速提示)
- [x] `src/App.vue` — watch `preferredQuality` → sync 到 `engine.videoManager.streamingQuality`
- [x] `scripts/pack-html.cjs` — 跳过 `videos/` 目录
- [x] 验证TypeScript + Vite build 通过
- [ ] 验证Electron `window.__ELECTRON__` = true使用本地 `videoUrl`
- [ ] 验证:浏览器 `window.__ELECTRON__` = undefined设置面板显示画质下拉
- [ ] 验证:`pack:html` 产物不包含 `videos/` 目录
## 已完成
P0~P23 全部实现(除 P18。详见 [CHANGELOG.md](CHANGELOG.md)。