@playcraft/cli 0.0.53 → 0.0.56
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +21 -0
- package/REMIX.md +103 -19
- package/dist/atom-tree/fusion-hints.js +8 -3
- package/dist/atom-tree/fusion-intent.js +62 -0
- package/dist/atom-tree/selection.js +3 -1
- package/dist/commands/create.js +439 -159
- package/dist/commands/image.js +79 -69
- package/dist/commands/levels.js +29 -0
- package/dist/commands/patterns.js +75 -0
- package/dist/commands/remix.js +47 -0
- package/dist/commands/skills.js +48 -17
- package/dist/index.js +13 -6
- package/dist/remix/clone-source.js +208 -0
- package/dist/remix/clone.js +255 -0
- package/dist/scaffold/templates.js +35 -0
- package/dist/utils/agent-api-client.js +10 -3
- package/dist/utils/remix-image-attachments.js +4 -32
- package/dist/utils/sandbox-path.js +20 -0
- package/package.json +3 -3
- package/project-template/.claude/agents/creative-director.md +114 -0
- package/project-template/.claude/agents/developer.md +5 -2
- package/project-template/.claude/agents/game-designer.md +41 -20
- package/project-template/.claude/agents/refs/README.md +8 -0
- package/project-template/.claude/agents/refs/creative-director-guide.md +35 -0
- package/project-template/.claude/agents/refs/creative-director-kickoff-guide.md +52 -0
- package/project-template/.claude/agents/refs/creative-discovery-guide.md +76 -0
- package/project-template/.claude/agents/refs/creative-north-star-examples.md +82 -0
- package/project-template/.claude/agents/refs/developer-dev-handoff.md +1 -1
- package/project-template/.claude/agents/refs/game-designer-fusion-depth-playbook.md +28 -0
- package/project-template/.claude/agents/refs/game-designer-gameplay-sufficiency.md +4 -4
- package/project-template/.claude/agents/reviewer.md +11 -0
- package/project-template/.claude/hooks/README.md +12 -12
- package/project-template/.claude/hooks/block-developer-preflight.mjs +49 -13
- package/project-template/.claude/hooks/block-ring1-tasklist.mjs +1 -1
- package/project-template/.claude/hooks/user-prompt.mjs +3 -13
- package/project-template/.claude/hooks/validate-workflow-stop.mjs +209 -12
- package/project-template/.claude/settings.json +2 -2
- package/project-template/.claude/skills/playcraft-playable-optimization/SKILL.md +20 -20
- package/project-template/.claude/skills/session-analyzer/scripts/resolve-session.mjs +0 -1
- package/project-template/.claude/snapshot.mjs +0 -1
- package/project-template/.codebuddy/settings.json +1 -1
- package/project-template/.cursor/rules/playcraft-orchestrator.mdc +1 -1
- package/project-template/CLAUDE.md +9 -9
- package/project-template/docs/project-state.md +1 -1
- package/project-template/docs/team/agent-conduct.md +18 -18
- package/project-template/docs/team/collaboration.md +19 -7
- package/project-template/docs/team/workflow-changelog.md +15 -0
- package/project-template/fusion-patterns/catalog.json +77 -0
- package/project-template/package.json +2 -0
- package/project-template/skills/_shared/scripts/create-playable.mjs +31 -11
- package/project-template/skills/_shared/scripts/dev-start.mjs +3 -3
- package/project-template/skills/_shared/scripts/disclosure-config.mjs +65 -39
- package/project-template/skills/_shared/scripts/harness-smoke.mjs +3 -1
- package/project-template/skills/_shared/scripts/lib/fusion-intent.mjs +88 -0
- package/project-template/skills/_shared/scripts/lib/skill-fidelity.mjs +185 -0
- package/project-template/skills/_shared/scripts/slice-set.mjs +29 -2
- package/project-template/skills/_shared/scripts/state-get.mjs +124 -7
- package/project-template/skills/_shared/scripts/state-store.mjs +25 -2
- package/project-template/skills/_shared/scripts/validate-level-sketch.mjs +444 -0
- package/project-template/skills/_shared/scripts/verify-design-consistency.mjs +728 -0
- package/project-template/skills/playable-record/scripts/lib/dev-server.mjs +46 -11
- package/project-template/skills/playable-record/scripts/record-playable.mjs +2 -1
- package/project-template/skills/playable-record/scripts/verify-contract.mjs +4 -4
- package/project-template/skills/playable-record/scripts/verify-firstwin.mjs +3 -3
- package/project-template/skills/playable-record/scripts/verify-fusion.mjs +37 -2
- package/project-template/skills/playable-record/scripts/verify-slice.mjs +2 -2
- package/project-template/templates/design-brief.template.md +34 -0
- package/project-template/templates/design-methodology.md +1 -2
- package/project-template/templates/design.template.md +65 -0
- package/project-template/templates/developer-log.template.md +12 -1
- package/project-template/templates/five-axis-framework.md +12 -0
- package/project-template/templates/game-designer-creative-process.template.md +99 -0
- package/project-template/templates/level-sketch.template.json +56 -0
- package/project-template/templates/north-star.template.md +43 -0
- package/project-template/templates/project-state.template.md +1 -1
- package/project-template/vite.config.ts +4 -5
- package/project-templates/phaser/.claude/agents/creative-director.md +114 -0
- package/project-templates/phaser/.claude/agents/game-designer.md +41 -20
- package/project-templates/phaser/.claude/agents/refs/creative-director-guide.md +35 -0
- package/project-templates/phaser/.claude/agents/refs/creative-director-kickoff-guide.md +52 -0
- package/project-templates/phaser/.claude/agents/refs/creative-discovery-guide.md +76 -0
- package/project-templates/phaser/.claude/agents/refs/creative-north-star-examples.md +82 -0
- package/project-templates/phaser/.claude/agents/refs/developer-dev-handoff.md +1 -1
- package/project-templates/phaser/.claude/agents/refs/game-designer-fusion-depth-playbook.md +28 -0
- package/project-templates/phaser/.claude/agents/reviewer.md +11 -0
- package/project-templates/phaser/.claude/hooks/block-ring1-tasklist.mjs +2 -2
- package/project-templates/phaser/.claude/hooks/user-prompt.mjs +17 -18
- package/project-templates/phaser/.claude/hooks/validate-workflow-stop.mjs +209 -12
- package/project-templates/phaser/.claude/skills/playcraft-playable-optimization/SKILL.md +20 -20
- package/project-templates/phaser/.cursor/rules/playcraft-orchestrator.mdc +1 -1
- package/project-templates/phaser/CLAUDE.md +88 -54
- package/project-templates/phaser/docs/DESIGN.md +25 -0
- package/project-templates/phaser/docs/project-state.md +1 -1
- package/project-templates/phaser/docs/team/collaboration.md +19 -7
- package/project-templates/phaser/docs/team/workflow-changelog.md +14 -0
- package/project-templates/phaser/fusion-patterns/catalog.json +77 -0
- package/project-templates/phaser/package.json +3 -1
- package/project-templates/phaser/skills/_shared/scripts/dev-start.mjs +3 -3
- package/project-templates/phaser/skills/_shared/scripts/disclosure-config.mjs +65 -39
- package/project-templates/phaser/skills/_shared/scripts/harness-smoke.mjs +3 -1
- package/project-templates/phaser/skills/_shared/scripts/lib/fusion-intent.mjs +88 -0
- package/project-templates/phaser/skills/_shared/scripts/lib/skill-fidelity.mjs +185 -0
- package/project-templates/phaser/skills/_shared/scripts/state-get.mjs +124 -7
- package/project-templates/phaser/skills/_shared/scripts/state-store.mjs +25 -2
- package/project-templates/phaser/skills/_shared/scripts/validate-level-sketch.mjs +444 -0
- package/project-templates/phaser/skills/_shared/scripts/verify-design-consistency.mjs +728 -0
- package/project-templates/phaser/skills/playable-record/scripts/lib/dev-server.mjs +46 -11
- package/project-templates/phaser/skills/playable-record/scripts/record-playable.mjs +2 -1
- package/project-templates/phaser/skills/playable-record/scripts/verify-contract.mjs +4 -4
- package/project-templates/phaser/skills/playable-record/scripts/verify-firstwin.mjs +3 -3
- package/project-templates/phaser/skills/playable-record/scripts/verify-fusion.mjs +37 -2
- package/project-templates/phaser/skills/playable-record/scripts/verify-slice.mjs +2 -2
- package/project-templates/phaser/templates/design-brief.template.md +42 -11
- package/project-templates/phaser/templates/design-methodology.md +1 -2
- package/project-templates/phaser/templates/design.template.md +77 -0
- package/project-templates/phaser/templates/five-axis-framework.md +50 -1
- package/project-templates/phaser/templates/game-designer-creative-process.template.md +99 -0
- package/project-templates/phaser/templates/level-sketch.template.json +56 -0
- package/project-templates/phaser/templates/north-star.template.md +43 -0
- package/project-templates/phaser/templates/project-state.template.md +1 -1
- package/project-templates/phaser/vite.config.ts +4 -5
- package/project-templates/playable-template-phaser/.playcraftignore +10 -0
- package/project-templates/playable-template-phaser/CLAUDE.md +178 -0
- package/project-templates/playable-template-phaser/PLAYCRAFT-MIGRATION.md +328 -0
- package/project-templates/playable-template-phaser/README.md +381 -0
- package/project-templates/playable-template-phaser/assets/brain.png +0 -0
- package/project-templates/playable-template-phaser/assets/button.png +0 -0
- package/project-templates/playable-template-phaser/assets/interact.png +0 -0
- package/project-templates/playable-template-phaser/assets/logo.webp +0 -0
- package/project-templates/playable-template-phaser/assets/warn_brain.png +0 -0
- package/project-templates/playable-template-phaser/builds.config.js +12 -0
- package/project-templates/playable-template-phaser/globals.d.ts +2 -0
- package/project-templates/playable-template-phaser/index.html +12 -0
- package/project-templates/playable-template-phaser/package.json +45 -0
- package/project-templates/playable-template-phaser/scripts/base64-to-mp3.js +340 -0
- package/project-templates/playable-template-phaser/scripts/convert-to-webp.js +370 -0
- package/project-templates/playable-template-phaser/src/Game.ts +154 -0
- package/project-templates/playable-template-phaser/src/config/LoadingConfig.ts +40 -0
- package/project-templates/playable-template-phaser/src/config/ThemeConfig.ts +81 -0
- package/project-templates/playable-template-phaser/src/index.css +18 -0
- package/project-templates/playable-template-phaser/src/index.html +9 -0
- package/project-templates/playable-template-phaser/src/index.ts +30 -0
- package/project-templates/playable-template-phaser/src/json5.d.ts +4 -0
- package/project-templates/playable-template-phaser/src/managers/AudioManager.ts +559 -0
- package/project-templates/playable-template-phaser/src/scenes/MainScene.ts +301 -0
- package/project-templates/playable-template-phaser/src/scenes/PreloadScene.ts +256 -0
- package/project-templates/playable-template-phaser/src/theme/README.md +194 -0
- package/project-templates/playable-template-phaser/src/theme/blue-theme/assets/.gitkeep +24 -0
- package/project-templates/playable-template-phaser/src/theme/blue-theme/index.ts +27 -0
- package/project-templates/playable-template-phaser/src/theme/blue-theme/theme.data.json5 +19 -0
- package/project-templates/playable-template-phaser/src/theme/green-theme/assets/.gitkeep +3 -0
- package/project-templates/playable-template-phaser/src/theme/green-theme/index.ts +20 -0
- package/project-templates/playable-template-phaser/src/theme/green-theme/theme.data.json5 +19 -0
- package/project-templates/playable-template-phaser/src/theme/index.ts +1 -0
- package/project-templates/playable-template-phaser/src/theme/red-theme/assets/.gitkeep +3 -0
- package/project-templates/playable-template-phaser/src/theme/red-theme/index.ts +20 -0
- package/project-templates/playable-template-phaser/src/theme/red-theme/theme.data.json5 +19 -0
- package/project-templates/playable-template-phaser/src/theme/theme.metadata.md +60 -0
- package/project-templates/playable-template-phaser/src/theme/theme.schema.json5 +149 -0
- package/project-templates/playable-template-phaser/src/ui/BrainAgeUI.ts +681 -0
- package/project-templates/playable-template-phaser/src/ui/CountdownUI.ts +565 -0
- package/project-templates/playable-template-phaser/src/ui/PlayButton.ts +51 -0
- package/project-templates/playable-template-phaser/src/ui/ScoreUI.ts +207 -0
- package/project-templates/playable-template-phaser/src/ui/SuccessUI.ts +43 -0
- package/project-templates/playable-template-phaser/src/ui/index.ts +15 -0
- package/project-templates/playable-template-phaser/tsconfig.json +26 -0
- package/project-templates/playable-template-phaser/vite.config.ts +64 -0
- package/project-templates/playable-template-phaser//346/226/260/346/211/213/345/274/200/345/217/221/346/214/207/345/215/227.md +209 -0
- package/project-templates/playable-template-three/README.md +795 -0
- package/project-templates/playable-template-three/assets/Stork.glb +0 -0
- package/project-templates/playable-template-three/assets/button.png +0 -0
- package/project-templates/playable-template-three/assets/logo.webp +0 -0
- package/project-templates/playable-template-three/build.json +7 -0
- package/project-templates/playable-template-three/builds.config.example.js +151 -0
- package/project-templates/playable-template-three/builds.config.js +158 -0
- package/project-templates/playable-template-three/package.json +36 -0
- package/project-templates/playable-template-three/scripts/convert-to-webp.js +370 -0
- package/project-templates/playable-template-three/scripts/theme-builds.js +514 -0
- package/project-templates/playable-template-three/src/Game.ts +215 -0
- package/project-templates/playable-template-three/src/config/LoadingConfig.ts +27 -0
- package/project-templates/playable-template-three/src/config/ThemeConfig.ts +36 -0
- package/project-templates/playable-template-three/src/global.d.ts +108 -0
- package/project-templates/playable-template-three/src/index.css +18 -0
- package/project-templates/playable-template-three/src/index.html +9 -0
- package/project-templates/playable-template-three/src/index.ts +20 -0
- package/project-templates/playable-template-three/src/managers/AudioManager.ts +538 -0
- package/project-templates/playable-template-three/src/scenes/PreloadScene.ts +305 -0
- package/project-templates/playable-template-three/src/theme/README.md +225 -0
- package/project-templates/playable-template-three/src/theme/blue-theme/assets/.gitkeep +28 -0
- package/project-templates/playable-template-three/src/theme/blue-theme/index.ts +45 -0
- package/project-templates/playable-template-three/src/theme/current.ts +12 -0
- package/project-templates/playable-template-three/src/theme/green-theme/assets/.gitkeep +3 -0
- package/project-templates/playable-template-three/src/theme/green-theme/index.ts +34 -0
- package/project-templates/playable-template-three/src/theme/red-theme/assets/.gitkeep +3 -0
- package/project-templates/playable-template-three/src/theme/red-theme/index.ts +34 -0
- package/project-templates/playable-template-three/tsconfig.json +24 -0
- package/project-templates/threejs/.claude/agents/creative-director.md +114 -0
- package/project-templates/threejs/.claude/agents/game-designer.md +41 -20
- package/project-templates/threejs/.claude/agents/refs/creative-director-guide.md +35 -0
- package/project-templates/threejs/.claude/agents/refs/creative-director-kickoff-guide.md +52 -0
- package/project-templates/threejs/.claude/agents/refs/creative-discovery-guide.md +76 -0
- package/project-templates/threejs/.claude/agents/refs/creative-north-star-examples.md +82 -0
- package/project-templates/threejs/.claude/agents/refs/developer-dev-handoff.md +1 -1
- package/project-templates/threejs/.claude/agents/refs/game-designer-fusion-depth-playbook.md +28 -0
- package/project-templates/threejs/.claude/agents/reviewer.md +11 -0
- package/project-templates/threejs/.claude/hooks/block-ring1-tasklist.mjs +2 -2
- package/project-templates/threejs/.claude/hooks/user-prompt.mjs +17 -18
- package/project-templates/threejs/.claude/hooks/validate-workflow-stop.mjs +209 -12
- package/project-templates/threejs/.claude/skills/playcraft-playable-optimization/SKILL.md +20 -20
- package/project-templates/threejs/.cursor/rules/playcraft-orchestrator.mdc +1 -1
- package/project-templates/threejs/CLAUDE.md +88 -54
- package/project-templates/threejs/docs/DESIGN.md +25 -0
- package/project-templates/threejs/docs/project-state.md +1 -1
- package/project-templates/threejs/docs/team/collaboration.md +19 -7
- package/project-templates/threejs/docs/team/workflow-changelog.md +14 -0
- package/project-templates/threejs/fusion-patterns/catalog.json +77 -0
- package/project-templates/threejs/package.json +3 -1
- package/project-templates/threejs/skills/_shared/scripts/dev-start.mjs +3 -3
- package/project-templates/threejs/skills/_shared/scripts/disclosure-config.mjs +65 -39
- package/project-templates/threejs/skills/_shared/scripts/harness-smoke.mjs +3 -1
- package/project-templates/threejs/skills/_shared/scripts/lib/fusion-intent.mjs +88 -0
- package/project-templates/threejs/skills/_shared/scripts/lib/skill-fidelity.mjs +185 -0
- package/project-templates/threejs/skills/_shared/scripts/state-get.mjs +124 -7
- package/project-templates/threejs/skills/_shared/scripts/state-store.mjs +25 -2
- package/project-templates/threejs/skills/_shared/scripts/validate-level-sketch.mjs +444 -0
- package/project-templates/threejs/skills/_shared/scripts/verify-design-consistency.mjs +728 -0
- package/project-templates/threejs/skills/playable-record/scripts/lib/dev-server.mjs +46 -11
- package/project-templates/threejs/skills/playable-record/scripts/record-playable.mjs +2 -1
- package/project-templates/threejs/skills/playable-record/scripts/verify-contract.mjs +4 -4
- package/project-templates/threejs/skills/playable-record/scripts/verify-firstwin.mjs +3 -3
- package/project-templates/threejs/skills/playable-record/scripts/verify-fusion.mjs +37 -2
- package/project-templates/threejs/skills/playable-record/scripts/verify-slice.mjs +2 -2
- package/project-templates/threejs/templates/design-brief.template.md +42 -11
- package/project-templates/threejs/templates/design-methodology.md +1 -2
- package/project-templates/threejs/templates/design.template.md +77 -0
- package/project-templates/threejs/templates/five-axis-framework.md +50 -1
- package/project-templates/threejs/templates/game-designer-creative-process.template.md +99 -0
- package/project-templates/threejs/templates/level-sketch.template.json +56 -0
- package/project-templates/threejs/templates/north-star.template.md +43 -0
- package/project-templates/threejs/templates/project-state.template.md +1 -1
- package/project-templates/threejs/vite.config.ts +4 -5
- package/project-template/docs/DESIGN.md +0 -65
|
@@ -0,0 +1,381 @@
|
|
|
1
|
+
# Playable Template - Phaser
|
|
2
|
+
|
|
3
|
+
基于 Phaser 3 游戏框架的可玩广告开发模板,使用 PlayCraft 平台架构,支持 TypeScript。
|
|
4
|
+
|
|
5
|
+
## 技术栈
|
|
6
|
+
|
|
7
|
+
- [Phaser 3](https://phaser.io/) - 高性能 2D 游戏框架
|
|
8
|
+
- [@playcraft/adsdk](https://www.npmjs.com/package/@playcraft/adsdk) - 可玩广告 SDK
|
|
9
|
+
- [@playcraft/devkit](https://www.npmjs.com/package/@playcraft/devkit) - 构建工具
|
|
10
|
+
- [Vite](https://vitejs.dev/) - 本地开发服务器(支持 HMR)
|
|
11
|
+
|
|
12
|
+
## 功能特性
|
|
13
|
+
|
|
14
|
+
- ✅ Phaser 3 集成,支持高性能 2D 游戏开发
|
|
15
|
+
- ✅ TypeScript 支持
|
|
16
|
+
- ✅ **配置化主题系统** - JSON5 Schema + 覆盖配置
|
|
17
|
+
- ✅ **Vite 本地开发** - 超快的 HMR 热更新
|
|
18
|
+
- ✅ **响应式适配** - 自动适配横竖屏和不同设备
|
|
19
|
+
- ✅ **批量构建** - 支持多主题、多渠道批量打包
|
|
20
|
+
- ✅ SDK 事件处理(resize、pause、resume、volume 等)
|
|
21
|
+
|
|
22
|
+
## 快速开始
|
|
23
|
+
|
|
24
|
+
### 1. 安装依赖
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
npm install
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
### 2. 启动开发服务器
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
# 使用 Vite 开发服务器(推荐,速度快,支持 HMR)
|
|
34
|
+
npm run dev
|
|
35
|
+
|
|
36
|
+
# 使用 playable-scripts 开发服务器(与构建环境一致)
|
|
37
|
+
npm run dev:wp
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
开发服务器默认运行在 `http://localhost:3000`(Vite)或 `http://localhost:8080`(playable-scripts)
|
|
41
|
+
|
|
42
|
+
### 3. 构建生产版本
|
|
43
|
+
|
|
44
|
+
#### 单渠道构建
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
npm run build -- <network>
|
|
48
|
+
|
|
49
|
+
# 示例
|
|
50
|
+
npm run build -- google # Google Ads
|
|
51
|
+
npm run build -- facebook # Meta
|
|
52
|
+
npm run build -- unity # Unity Ads
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
#### 批量构建
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
npm run builds # 构建所有主题和渠道
|
|
59
|
+
npm run builds -- -t "theme1,theme2" # 构建指定主题
|
|
60
|
+
npm run builds -- -c "google,facebook" # 构建指定渠道
|
|
61
|
+
npm run builds -- -t "theme1" -c "google" # 组合使用
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
#### 打包为 PlayCraft 模板
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
npm run pack-to-playcraft-template-zip
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## 脚本命令
|
|
71
|
+
|
|
72
|
+
| 命令 | 说明 |
|
|
73
|
+
| ---------------------------------------- | -------------------------------- |
|
|
74
|
+
| `npm run dev` | 启动 Vite 开发服务器(推荐) |
|
|
75
|
+
| `npm run dev:wp` | 启动 playable-scripts 开发服务器 |
|
|
76
|
+
| `npm run build -- <network>` | 构建指定渠道 |
|
|
77
|
+
| `npm run builds` | 批量构建所有主题和渠道 |
|
|
78
|
+
| `npm run pack-to-playcraft-template-zip` | 打包为 PlayCraft 模板 ZIP |
|
|
79
|
+
| `npm run webp` | 将图片转为 WebP 格式(质量 90) |
|
|
80
|
+
| `npm run webp:80` | 将图片转为 WebP 格式(质量 80) |
|
|
81
|
+
|
|
82
|
+
## 项目结构
|
|
83
|
+
|
|
84
|
+
```
|
|
85
|
+
playable-template-phaser/
|
|
86
|
+
├── assets/ # 公共资源目录
|
|
87
|
+
│ └── logo.webp
|
|
88
|
+
├── src/
|
|
89
|
+
│ ├── theme/ # 主题系统
|
|
90
|
+
│ │ ├── theme.schema.json5 # 配置协议(默认值)
|
|
91
|
+
│ │ ├── theme.metadata.md # 主题元数据
|
|
92
|
+
│ │ ├── blue-theme/ # 蓝色主题
|
|
93
|
+
│ │ │ ├── index.ts # 主题入口
|
|
94
|
+
│ │ │ ├── theme.data.json5 # 配置覆盖
|
|
95
|
+
│ │ │ └── assets/ # 主题资源
|
|
96
|
+
│ │ ├── green-theme/ # 绿色主题
|
|
97
|
+
│ │ ├── red-theme/ # 红色主题
|
|
98
|
+
│ │ └── index.ts # 主题统一出口
|
|
99
|
+
│ ├── scenes/ # Phaser 场景
|
|
100
|
+
│ │ ├── PreloadScene.ts # 预加载场景
|
|
101
|
+
│ │ └── MainScene.ts # 主游戏场景
|
|
102
|
+
│ ├── config/ # 配置管理
|
|
103
|
+
│ │ ├── ThemeConfig.ts # 主题配置获取器
|
|
104
|
+
│ │ └── LoadingConfig.ts # Loading 配置
|
|
105
|
+
│ ├── managers/ # 管理器
|
|
106
|
+
│ │ └── AudioManager.ts # 音频管理器
|
|
107
|
+
│ ├── ui/ # UI 组件
|
|
108
|
+
│ ├── Game.ts # Phaser.Game 配置
|
|
109
|
+
│ ├── index.ts # 入口文件
|
|
110
|
+
│ ├── index.css # 样式文件
|
|
111
|
+
│ └── json5.d.ts # JSON5 类型声明
|
|
112
|
+
├── vite.config.ts # Vite 配置
|
|
113
|
+
├── index.html # Vite 入口 HTML
|
|
114
|
+
├── builds.config.js # 批量构建配置
|
|
115
|
+
├── tsconfig.json # TypeScript 配置
|
|
116
|
+
├── globals.d.ts # 全局类型声明
|
|
117
|
+
├── .playcraftignore # 构建排除配置
|
|
118
|
+
├── CLAUDE.md # 项目说明(详细版)
|
|
119
|
+
└── package.json
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
## 主题系统
|
|
123
|
+
|
|
124
|
+
### 配置化架构
|
|
125
|
+
|
|
126
|
+
项目采用 PlayCraft 平台的配置化架构:
|
|
127
|
+
|
|
128
|
+
1. **配置协议**(`theme.schema.json5`)- 定义所有可配置项及默认值
|
|
129
|
+
2. **配置覆盖**(`theme.data.json5`)- 各主题只需写与默认值不同的配置
|
|
130
|
+
3. **资源映射**(`assetRecordByPath`)- 自动将配置中的路径解析为真实 URL
|
|
131
|
+
|
|
132
|
+
### 配置优先级
|
|
133
|
+
|
|
134
|
+
```
|
|
135
|
+
theme.data.json5(主题覆盖)> theme.schema.json5(默认值)
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
### 切换主题
|
|
139
|
+
|
|
140
|
+
修改 `src/theme/index.ts`:
|
|
141
|
+
|
|
142
|
+
```typescript
|
|
143
|
+
export { default } from './blue-theme'; // 蓝色主题
|
|
144
|
+
// export { default } from './green-theme'; // 绿色主题
|
|
145
|
+
// export { default } from './red-theme'; // 红色主题
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
### 添加新主题
|
|
149
|
+
|
|
150
|
+
1. 复制现有主题目录(如 `blue-theme`)
|
|
151
|
+
2. 修改 `theme.data.json5` 配置
|
|
152
|
+
3. 添加主题特定资源到 `assets/` 目录
|
|
153
|
+
4. 更新 `index.ts` 的资源映射
|
|
154
|
+
5. 在 `theme/index.ts` 切换主题
|
|
155
|
+
|
|
156
|
+
### 主题列表
|
|
157
|
+
|
|
158
|
+
| 主题 ID | 难度 | 提示 | 说明 |
|
|
159
|
+
| ------- | ---- | ---- | ------------------------------------- |
|
|
160
|
+
| blue | 5 | ✅ | 蓝色主题 - 适合海洋、天空、科技类游戏 |
|
|
161
|
+
| green | 3 | ✅ | 绿色主题 - 适合自然、森林、环保类游戏 |
|
|
162
|
+
| red | 7 | ❌ | 红色主题 - 适合动作、冒险、激情类游戏 |
|
|
163
|
+
|
|
164
|
+
## 配置系统
|
|
165
|
+
|
|
166
|
+
### 读取配置
|
|
167
|
+
|
|
168
|
+
使用 `sdk.getConfig()` 或封装的配置获取器:
|
|
169
|
+
|
|
170
|
+
```typescript
|
|
171
|
+
import { GameThemeConfig } from './config/ThemeConfig';
|
|
172
|
+
|
|
173
|
+
// 获取配置值
|
|
174
|
+
const backgroundColor = GameThemeConfig.BACKGROUND_COLOR;
|
|
175
|
+
const difficulty = GameThemeConfig.DIFFICULTY;
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
### 资源路径解析
|
|
179
|
+
|
|
180
|
+
资源路径通过 `assetRecordByPath` 自动解析为真实 URL:
|
|
181
|
+
|
|
182
|
+
```typescript
|
|
183
|
+
// theme.schema.json5 中定义路径
|
|
184
|
+
assets: {
|
|
185
|
+
logo: {
|
|
186
|
+
default: "./assets/logo.webp"
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
// theme/index.ts 中映射路径
|
|
191
|
+
import logoWebp from 'assets/logo.webp';
|
|
192
|
+
const assetRecordByPath = {
|
|
193
|
+
'./assets/logo.webp': logoWebp,
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
// 代码中获取 URL
|
|
197
|
+
const logoUrl = GameThemeConfig.ASSET_LOGO; // 解析后的真实 URL
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
## 响应式适配
|
|
201
|
+
|
|
202
|
+
模板采用 `WIDTH_CONTROLS_HEIGHT` 缩放模式:
|
|
203
|
+
|
|
204
|
+
- ✅ 固定设计宽度(1280px)
|
|
205
|
+
- ✅ 高度自适应
|
|
206
|
+
- ✅ 自动画布缩放
|
|
207
|
+
- ✅ 横竖屏切换时自动刷新
|
|
208
|
+
|
|
209
|
+
```typescript
|
|
210
|
+
// Game.ts
|
|
211
|
+
const DESIGN_WIDTH = 1280;
|
|
212
|
+
|
|
213
|
+
export class Game extends Phaser.Game {
|
|
214
|
+
constructor(width: number, height: number) {
|
|
215
|
+
const gameWidth = DESIGN_WIDTH;
|
|
216
|
+
const gameHeight = height * (DESIGN_WIDTH / width);
|
|
217
|
+
|
|
218
|
+
super({
|
|
219
|
+
width: gameWidth,
|
|
220
|
+
height: gameHeight,
|
|
221
|
+
scale: {
|
|
222
|
+
mode: Phaser.Scale.WIDTH_CONTROLS_HEIGHT,
|
|
223
|
+
autoCenter: Phaser.Scale.CENTER_BOTH,
|
|
224
|
+
},
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
## SDK 使用
|
|
231
|
+
|
|
232
|
+
### 初始化
|
|
233
|
+
|
|
234
|
+
```typescript
|
|
235
|
+
import { sdk } from '@playcraft/adsdk';
|
|
236
|
+
import ThemeConfig from './theme/theme.schema.json5';
|
|
237
|
+
import Theme from './theme';
|
|
238
|
+
|
|
239
|
+
// 1. 设置配置(必须在 playcraftInit 之前)
|
|
240
|
+
sdk.setConfig([ThemeConfig, Theme.themeData], {
|
|
241
|
+
assetRecordByPath: Theme.assetRecordByPath,
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
// 2. 初始化 SDK
|
|
245
|
+
sdk.playcraftInit((width: number, height: number) => {
|
|
246
|
+
const game = new Game(width, height);
|
|
247
|
+
|
|
248
|
+
// 3. 监听事件
|
|
249
|
+
sdk.on('playcraftResize', game.resize, game);
|
|
250
|
+
sdk.on('playcraftPause', game.pause, game);
|
|
251
|
+
sdk.on('playcraftResume', game.resume, game);
|
|
252
|
+
sdk.on('playcraftVolume', game.volume, game);
|
|
253
|
+
sdk.on('playcraftFinish', game.finish, game);
|
|
254
|
+
});
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
### SDK 事件
|
|
258
|
+
|
|
259
|
+
| 事件 | 说明 |
|
|
260
|
+
| ----------------- | ------------ |
|
|
261
|
+
| `playcraftResize` | 屏幕尺寸变化 |
|
|
262
|
+
| `playcraftPause` | 游戏暂停 |
|
|
263
|
+
| `playcraftResume` | 游戏恢复 |
|
|
264
|
+
| `playcraftVolume` | 音量变化 |
|
|
265
|
+
| `playcraftFinish` | 游戏结束 |
|
|
266
|
+
|
|
267
|
+
### SDK 生命周期
|
|
268
|
+
|
|
269
|
+
```typescript
|
|
270
|
+
sdk.playcraftInit(); // 初始化,获取容器尺寸
|
|
271
|
+
sdk.start(); // 游戏资源加载完成后调用
|
|
272
|
+
sdk.finish(); // 游戏结束时调用
|
|
273
|
+
sdk.install(); // 跳转应用商店
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
## 批量构建配置
|
|
277
|
+
|
|
278
|
+
创建 `builds.config.js`:
|
|
279
|
+
|
|
280
|
+
```javascript
|
|
281
|
+
module.exports = {
|
|
282
|
+
// 项目名称(用于 html title 生成)
|
|
283
|
+
title: 'Phaser-Template',
|
|
284
|
+
|
|
285
|
+
// 可玩广告对应的 App 名称
|
|
286
|
+
appName: 'Sola Mahjong',
|
|
287
|
+
|
|
288
|
+
// 商店链接(可选)
|
|
289
|
+
googlePlayUrl: 'https://play.google.com/...',
|
|
290
|
+
appStoreUrl: 'https://apps.apple.com/...',
|
|
291
|
+
|
|
292
|
+
// 渠道列表(可选,有默认值)
|
|
293
|
+
channels: ['google', 'facebook', 'unity', 'bigoads'],
|
|
294
|
+
|
|
295
|
+
// 主题配置(可选)
|
|
296
|
+
themes: {
|
|
297
|
+
enabled: true,
|
|
298
|
+
sourceDir: 'src/theme',
|
|
299
|
+
entryFile: 'src/theme/index.ts',
|
|
300
|
+
},
|
|
301
|
+
|
|
302
|
+
// 文件命名(可选,有默认值)
|
|
303
|
+
naming: {
|
|
304
|
+
language: 'EN',
|
|
305
|
+
format: '无',
|
|
306
|
+
supplier: 'AIX',
|
|
307
|
+
follower: 'ZQL',
|
|
308
|
+
},
|
|
309
|
+
|
|
310
|
+
// 构建配置(可选,有默认值)
|
|
311
|
+
build: {
|
|
312
|
+
outputDir: 'dist-all',
|
|
313
|
+
continueOnError: true,
|
|
314
|
+
},
|
|
315
|
+
|
|
316
|
+
// 混淆配置(可选)
|
|
317
|
+
obfuscate: {
|
|
318
|
+
level: 2, // 0=不混淆, 1=简单, 2=标准, 3=最高
|
|
319
|
+
},
|
|
320
|
+
};
|
|
321
|
+
```
|
|
322
|
+
|
|
323
|
+
## 支持的渠道
|
|
324
|
+
|
|
325
|
+
- google (Google Ads)
|
|
326
|
+
- facebook (Meta)
|
|
327
|
+
- tiktok (TikTok)
|
|
328
|
+
- applovin (AppLovin)
|
|
329
|
+
- ironSource (IronSource)
|
|
330
|
+
- unity (Unity Ads)
|
|
331
|
+
- moloco (Moloco)
|
|
332
|
+
- liftoff (Liftoff)
|
|
333
|
+
- bigoads (BigoAds)
|
|
334
|
+
- adikteev (Adikteev)
|
|
335
|
+
- inmobi (InMobi)
|
|
336
|
+
- snapchat (Snapchat)
|
|
337
|
+
|
|
338
|
+
## 环境要求
|
|
339
|
+
|
|
340
|
+
- Node.js >= 16.0.0
|
|
341
|
+
- npm >= 7.0.0
|
|
342
|
+
|
|
343
|
+
## 常见问题
|
|
344
|
+
|
|
345
|
+
### Q1: 资源 URL 为空
|
|
346
|
+
|
|
347
|
+
**原因**:`assetRecordByPath` 缺少路径映射
|
|
348
|
+
|
|
349
|
+
**解决**:在主题 `index.ts` 中添加资源映射
|
|
350
|
+
|
|
351
|
+
### Q2: 配置值为 undefined
|
|
352
|
+
|
|
353
|
+
**原因**:`theme.schema.json5` 缺少该字段的 `default` 值
|
|
354
|
+
|
|
355
|
+
**解决**:在 schema 中添加字段定义及默认值
|
|
356
|
+
|
|
357
|
+
### Q3: 模块顶层缓存导致配置为空
|
|
358
|
+
|
|
359
|
+
**原因**:在模块加载时立即读取配置,此时 `sdk.setConfig()` 还没执行
|
|
360
|
+
|
|
361
|
+
**解决**:使用 getter 延迟获取,或在运行时获取配置
|
|
362
|
+
|
|
363
|
+
## 相关技能
|
|
364
|
+
|
|
365
|
+
如需进行以下操作,请加载对应技能:
|
|
366
|
+
|
|
367
|
+
- **SDK 埋点检查**:`playable-sdk-tracking`
|
|
368
|
+
- **构建产物检查**:`playable-output-checker`
|
|
369
|
+
- **项目初始化**:`playable-project-scaffold`
|
|
370
|
+
- **资源提取/重打包**:`game-asset-extractor`
|
|
371
|
+
|
|
372
|
+
## 参考资料
|
|
373
|
+
|
|
374
|
+
- [Phaser 3 官方文档](https://photonstorm.github.io/phaser3-docs/)
|
|
375
|
+
- [Phaser 3 示例](https://phaser.io/examples)
|
|
376
|
+
- [PlayCraft 平台改造指南](./playable-template/skills/playable-platform-refactor/SKILL.md)
|
|
377
|
+
- [项目详细说明](./CLAUDE.md)
|
|
378
|
+
|
|
379
|
+
## 许可证
|
|
380
|
+
|
|
381
|
+
MIT
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
|
|
6
|
+
<title>Phaser Template - Playable Ads</title>
|
|
7
|
+
</head>
|
|
8
|
+
<body>
|
|
9
|
+
<div id="game-container"></div>
|
|
10
|
+
<script type="module" src="/src/index.ts"></script>
|
|
11
|
+
</body>
|
|
12
|
+
</html>
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "playable-template-phaser",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "A starter template for creating playable ads using Phaser and @playcraft/adsdk with TypeScript support",
|
|
5
|
+
"scripts": {
|
|
6
|
+
"dev": "vite",
|
|
7
|
+
"dev:wp": "playable-scripts dev",
|
|
8
|
+
"build": "playable-scripts build",
|
|
9
|
+
"builds": "playable-scripts builds",
|
|
10
|
+
"pack-to-playcraft-template-zip": "playable-scripts pack",
|
|
11
|
+
"webp": "node scripts/convert-to-webp.js",
|
|
12
|
+
"webp:80": "node scripts/convert-to-webp.js 80"
|
|
13
|
+
},
|
|
14
|
+
"keywords": [
|
|
15
|
+
"playable",
|
|
16
|
+
"ads",
|
|
17
|
+
"template",
|
|
18
|
+
"phaser",
|
|
19
|
+
"webgl",
|
|
20
|
+
"2d",
|
|
21
|
+
"typescript",
|
|
22
|
+
"game"
|
|
23
|
+
],
|
|
24
|
+
"author": "Smoud",
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"@playcraft/adsdk": "*",
|
|
27
|
+
"phaser": "^3.88.2",
|
|
28
|
+
"json5": "^2.2.3"
|
|
29
|
+
},
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"@playcraft/devkit": "*",
|
|
32
|
+
"@types/node": "^22.10.5",
|
|
33
|
+
"vite": "^5.4.0",
|
|
34
|
+
"typescript": "~5.7.2",
|
|
35
|
+
"prettier": "^2.7.1",
|
|
36
|
+
"babel-loader": "^10.0.0",
|
|
37
|
+
"css-loader": "^7.1.2",
|
|
38
|
+
"esbuild-loader": "^4.4.1",
|
|
39
|
+
"json5-loader": "^4.0.1",
|
|
40
|
+
"style-loader": "^4.0.0"
|
|
41
|
+
},
|
|
42
|
+
"engines": {
|
|
43
|
+
"node": ">=16.0.0"
|
|
44
|
+
}
|
|
45
|
+
}
|