@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,154 @@
|
|
|
1
|
+
import * as Phaser from 'phaser';
|
|
2
|
+
import { PreloadScene } from './scenes/PreloadScene';
|
|
3
|
+
import { MainScene } from './scenes/MainScene';
|
|
4
|
+
|
|
5
|
+
// 设计基准宽度(横屏设计)
|
|
6
|
+
const DESIGN_WIDTH = 1280;
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Phaser Game 包装器
|
|
10
|
+
*
|
|
11
|
+
* 负责:
|
|
12
|
+
* - Phaser 游戏实例的创建与销毁
|
|
13
|
+
* - 场景注册
|
|
14
|
+
* - 响应式适配
|
|
15
|
+
* - 横竖屏切换时销毁重建(不使用 location.reload)
|
|
16
|
+
* - SDK 生命周期回调
|
|
17
|
+
*/
|
|
18
|
+
export class Game {
|
|
19
|
+
// 当前 Phaser 游戏实例
|
|
20
|
+
private game!: Phaser.Game;
|
|
21
|
+
// 记录当前屏幕方向
|
|
22
|
+
private currentIsLandscape: boolean;
|
|
23
|
+
// 当前尺寸
|
|
24
|
+
private currentWidth: number;
|
|
25
|
+
private currentHeight: number;
|
|
26
|
+
// 是否正在重建
|
|
27
|
+
private isRebuilding: boolean = false;
|
|
28
|
+
|
|
29
|
+
constructor(width: number, height: number) {
|
|
30
|
+
this.currentWidth = width;
|
|
31
|
+
this.currentHeight = height;
|
|
32
|
+
this.currentIsLandscape = width > height;
|
|
33
|
+
|
|
34
|
+
this.createGame(width, height);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* 创建 Phaser 游戏实例
|
|
39
|
+
*/
|
|
40
|
+
private createGame(width: number, height: number): void {
|
|
41
|
+
const gameWidth = DESIGN_WIDTH;
|
|
42
|
+
const gameHeight = height * (DESIGN_WIDTH / width);
|
|
43
|
+
|
|
44
|
+
this.game = new Phaser.Game({
|
|
45
|
+
type: Phaser.AUTO,
|
|
46
|
+
width: gameWidth,
|
|
47
|
+
height: gameHeight,
|
|
48
|
+
backgroundColor: '#1c1c1c',
|
|
49
|
+
parent: document.body,
|
|
50
|
+
scale: {
|
|
51
|
+
mode: Phaser.Scale.WIDTH_CONTROLS_HEIGHT,
|
|
52
|
+
autoCenter: Phaser.Scale.CENTER_BOTH
|
|
53
|
+
},
|
|
54
|
+
render: {
|
|
55
|
+
antialias: true,
|
|
56
|
+
antialiasGL: true,
|
|
57
|
+
pixelArt: false,
|
|
58
|
+
},
|
|
59
|
+
scene: [PreloadScene, MainScene]
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* 响应容器尺寸变化
|
|
65
|
+
* 横竖屏切换时:销毁旧游戏实例,重建新实例
|
|
66
|
+
* 同方向尺寸变化时:仅 resize
|
|
67
|
+
*/
|
|
68
|
+
public resize(width: number, height: number): void {
|
|
69
|
+
const newIsLandscape = width > height;
|
|
70
|
+
|
|
71
|
+
this.currentWidth = width;
|
|
72
|
+
this.currentHeight = height;
|
|
73
|
+
|
|
74
|
+
// 横竖屏切换:销毁重建
|
|
75
|
+
if (newIsLandscape !== this.currentIsLandscape) {
|
|
76
|
+
console.log('Screen orientation changed:',
|
|
77
|
+
this.currentIsLandscape ? 'landscape→portrait' : 'portrait→landscape');
|
|
78
|
+
this.currentIsLandscape = newIsLandscape;
|
|
79
|
+
|
|
80
|
+
this.rebuildGame(width, height);
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// 方向不变时,只调整画布尺寸
|
|
85
|
+
// 防御性检查:如果游戏正在重建,跳过 resize
|
|
86
|
+
if (!this.game || this.isRebuilding) {
|
|
87
|
+
console.warn('Game not ready for resize, skipping');
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const gameHeight = height * (DESIGN_WIDTH / width);
|
|
92
|
+
this.game.scale.resize(DESIGN_WIDTH, gameHeight);
|
|
93
|
+
console.log('Game resized to:', DESIGN_WIDTH, gameHeight);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* 销毁旧游戏实例并重建新实例
|
|
98
|
+
*/
|
|
99
|
+
private rebuildGame(width: number, height: number): void {
|
|
100
|
+
if (this.isRebuilding) {
|
|
101
|
+
console.warn('Already rebuilding, skip');
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
this.isRebuilding = true;
|
|
105
|
+
|
|
106
|
+
console.log('Rebuilding game for new orientation...');
|
|
107
|
+
|
|
108
|
+
// 销毁旧实例(true = 移除 canvas)
|
|
109
|
+
try {
|
|
110
|
+
this.game.destroy(true);
|
|
111
|
+
} catch (e) {
|
|
112
|
+
console.warn('Error destroying old game:', e);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// 短暂延迟确保旧 WebGL 上下文完全释放
|
|
116
|
+
setTimeout(() => {
|
|
117
|
+
try {
|
|
118
|
+
this.createGame(width, height);
|
|
119
|
+
console.log('Game rebuilt successfully for:', width, height);
|
|
120
|
+
} catch (e) {
|
|
121
|
+
console.error('Error rebuilding game:', e);
|
|
122
|
+
}
|
|
123
|
+
this.isRebuilding = false;
|
|
124
|
+
}, 100);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
public pause(): void {
|
|
128
|
+
if (this.isRebuilding) return;
|
|
129
|
+
this.game.scene.pause('MainScene');
|
|
130
|
+
console.log('Game paused');
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
public resume(): void {
|
|
134
|
+
if (this.isRebuilding) return;
|
|
135
|
+
this.game.scene.resume('MainScene');
|
|
136
|
+
console.log('Game resumed');
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
public volume(value: number): void {
|
|
140
|
+
if (this.isRebuilding) return;
|
|
141
|
+
this.game.sound.setVolume(value);
|
|
142
|
+
console.log(`Volume changed to: ${value}`);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
public finish(): void {
|
|
146
|
+
if (this.isRebuilding) return;
|
|
147
|
+
// 游戏结束时清理 AudioManager
|
|
148
|
+
const mainScene = this.game.scene.getScene('MainScene') as MainScene;
|
|
149
|
+
if (mainScene && mainScene.audioManager) {
|
|
150
|
+
mainScene.audioManager.setGameEnded(true);
|
|
151
|
+
}
|
|
152
|
+
console.log('Game finished');
|
|
153
|
+
}
|
|
154
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Loading 页面配置
|
|
3
|
+
* 通过 sdk.getConfig() 动态获取配置
|
|
4
|
+
*/
|
|
5
|
+
import { sdk } from '@playcraft/adsdk';
|
|
6
|
+
|
|
7
|
+
// 辅助函数:安全获取嵌套配置值
|
|
8
|
+
function get<T>(path: string, fallback: T): T {
|
|
9
|
+
const config = sdk.getConfig();
|
|
10
|
+
const keys = path.split('.');
|
|
11
|
+
let value: any = config;
|
|
12
|
+
for (const key of keys) {
|
|
13
|
+
if (value === undefined || value === null) return fallback;
|
|
14
|
+
value = value[key];
|
|
15
|
+
}
|
|
16
|
+
return value !== undefined ? value : fallback;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// ⚠️ 使用 getter 延迟获取,避免模块顶层缓存问题
|
|
20
|
+
export const LoadingConfig = {
|
|
21
|
+
// ========== 资源配置 ==========
|
|
22
|
+
get LOGO_IMAGE(): string { return get('loading.logoImage', ''); },
|
|
23
|
+
|
|
24
|
+
// ========== 文案配置 ==========
|
|
25
|
+
get APP_TITLE(): string { return get('loading.appTitle', 'Sola Mahjong'); },
|
|
26
|
+
get APP_STARS(): string { return get('loading.appStars', '★★★★★'); },
|
|
27
|
+
get APP_DESC(): string { return get('loading.appDesc', 'Sola Mahjong: Classic Tile\nPairing for a Relaxing Puzzle'); },
|
|
28
|
+
get LOADING_TEXT(): string { return get('loading.loadingText', 'Loading Playable Ads'); },
|
|
29
|
+
GAMEPAD_ICON: '🎮',
|
|
30
|
+
|
|
31
|
+
// ========== 时间配置 ==========
|
|
32
|
+
get SCENE_DURATION(): number { return get('loading.sceneDuration', 100); },
|
|
33
|
+
DOT_ANIM_DELAY: 200,
|
|
34
|
+
|
|
35
|
+
// ========== 跳跃动画配置 ==========
|
|
36
|
+
BOUNCE_HEIGHT_LANDSCAPE: 8,
|
|
37
|
+
BOUNCE_HEIGHT_PORTRAIT: 10,
|
|
38
|
+
BOUNCE_DURATION: 300,
|
|
39
|
+
BOUNCE_REPEAT_DELAY: 100,
|
|
40
|
+
};
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 主题配置接口
|
|
3
|
+
*
|
|
4
|
+
* 通过 sdk.getConfig() 动态获取配置
|
|
5
|
+
* 配置来源:theme.schema.json5(默认值)+ theme.data.json5(覆盖值)
|
|
6
|
+
*/
|
|
7
|
+
import { sdk } from '@playcraft/adsdk';
|
|
8
|
+
|
|
9
|
+
// 辅助函数:安全获取嵌套配置值
|
|
10
|
+
function get<T>(path: string, fallback: T): T {
|
|
11
|
+
const config = sdk.getConfig();
|
|
12
|
+
const keys = path.split('.');
|
|
13
|
+
let value: any = config;
|
|
14
|
+
for (const key of keys) {
|
|
15
|
+
if (value === undefined || value === null) return fallback;
|
|
16
|
+
value = value[key];
|
|
17
|
+
}
|
|
18
|
+
return value !== undefined ? value : fallback;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface ThemeConfig {
|
|
22
|
+
// 基础信息
|
|
23
|
+
name: string;
|
|
24
|
+
id: string;
|
|
25
|
+
|
|
26
|
+
// 视觉配置
|
|
27
|
+
backgroundColor: number;
|
|
28
|
+
primaryColor: number;
|
|
29
|
+
secondaryColor: number;
|
|
30
|
+
textColor: string;
|
|
31
|
+
|
|
32
|
+
// 字体配置
|
|
33
|
+
fontSize: {
|
|
34
|
+
title: string;
|
|
35
|
+
body: string;
|
|
36
|
+
button: string;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
// 游戏参数
|
|
40
|
+
difficulty?: number;
|
|
41
|
+
enableHints?: boolean;
|
|
42
|
+
|
|
43
|
+
// 资源配置
|
|
44
|
+
assets?: {
|
|
45
|
+
buttonImage?: string;
|
|
46
|
+
backgroundImage?: string;
|
|
47
|
+
logoImage?: string;
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// 主题配置获取器(使用 getter 延迟获取,避免模块顶层缓存问题)
|
|
52
|
+
export const GameThemeConfig = {
|
|
53
|
+
// ========== 基础信息 ==========
|
|
54
|
+
get NAME(): string { return get('name', 'Default Theme'); },
|
|
55
|
+
get ID(): string { return get('id', 'default'); },
|
|
56
|
+
|
|
57
|
+
// ========== 视觉配置 ==========
|
|
58
|
+
get BACKGROUND_COLOR(): number { return get('visual.backgroundColor', 0xf7d37f); },
|
|
59
|
+
get PRIMARY_COLOR(): number { return get('visual.primaryColor', 0x4a90e2); },
|
|
60
|
+
get SECONDARY_COLOR(): number { return get('visual.secondaryColor', 0x3498db); },
|
|
61
|
+
get TEXT_COLOR(): string { return get('visual.textColor', '#ffffff'); },
|
|
62
|
+
|
|
63
|
+
// ========== 字体配置 ==========
|
|
64
|
+
get FONT_SIZE_TITLE(): string { return get('fontSize.title', '48px'); },
|
|
65
|
+
get FONT_SIZE_BODY(): string { return get('fontSize.body', '24px'); },
|
|
66
|
+
get FONT_SIZE_BUTTON(): string { return get('fontSize.button', '32px'); },
|
|
67
|
+
|
|
68
|
+
// ========== 游戏参数 ==========
|
|
69
|
+
get DIFFICULTY(): number { return get('gameplay.difficulty', 5); },
|
|
70
|
+
get ENABLE_HINTS(): boolean { return get('gameplay.enableHints', true); },
|
|
71
|
+
|
|
72
|
+
// ========== 资源配置 ==========
|
|
73
|
+
get ASSET_LOGO(): string { return get('assets.logo', ''); },
|
|
74
|
+
get ASSET_BUTTON(): string { return get('assets.buttonImage', ''); },
|
|
75
|
+
get ASSET_BACKGROUND(): string { return get('assets.backgroundImage', ''); },
|
|
76
|
+
|
|
77
|
+
// ========== 获取当前渠道 ==========
|
|
78
|
+
get CURRENT_CHANNEL(): string {
|
|
79
|
+
return typeof AD_NETWORK !== 'undefined' ? AD_NETWORK : 'preview';
|
|
80
|
+
},
|
|
81
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
body,
|
|
2
|
+
html {
|
|
3
|
+
margin: 0;
|
|
4
|
+
padding: 0;
|
|
5
|
+
}
|
|
6
|
+
html {
|
|
7
|
+
background-color: #fff;
|
|
8
|
+
overflow: hidden;
|
|
9
|
+
width: 100%;
|
|
10
|
+
height: 100%;
|
|
11
|
+
}
|
|
12
|
+
body {
|
|
13
|
+
height: inherit;
|
|
14
|
+
width: inherit;
|
|
15
|
+
}
|
|
16
|
+
* {
|
|
17
|
+
-webkit-tap-highlight-color: transparent;
|
|
18
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Game } from './Game';
|
|
2
|
+
import './index.css';
|
|
3
|
+
import { sdk } from '@playcraft/adsdk';
|
|
4
|
+
|
|
5
|
+
// 主题系统
|
|
6
|
+
import ThemeConfig from './theme/theme.schema.json5';
|
|
7
|
+
import Theme from './theme';
|
|
8
|
+
|
|
9
|
+
// ⚠️ 重要:setConfig 必须在 playcraftInit 之前调用
|
|
10
|
+
// SDK 会合并 schema 默认值 + themeData 覆盖值,并通过 assetRecordByPath 解析路径
|
|
11
|
+
sdk.setConfig([ThemeConfig, Theme.themeData], {
|
|
12
|
+
assetRecordByPath: Theme.assetRecordByPath,
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
// Initialize the SDK
|
|
16
|
+
sdk.playcraftInit((width: number, height: number) => {
|
|
17
|
+
// Initialize game with container dimensions
|
|
18
|
+
const game = new Game(width, height);
|
|
19
|
+
|
|
20
|
+
// Set up all event listeners
|
|
21
|
+
sdk.on('playcraftResize', game.resize, game);
|
|
22
|
+
sdk.on('playcraftPause', game.pause, game);
|
|
23
|
+
sdk.on('playcraftResume', game.resume, game);
|
|
24
|
+
sdk.on('playcraftVolume', game.volume, game);
|
|
25
|
+
sdk.on('playcraftFinish', game.finish, game);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
if (__DEV__) {
|
|
29
|
+
console.log('Development mode');
|
|
30
|
+
}
|