@playcraft/cli 0.0.40 → 0.0.42

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.
Files changed (130) hide show
  1. package/README.md +66 -3
  2. package/dist/atom-plan/validate-atom-plan.js +298 -0
  3. package/dist/cli-root-help.js +1 -1
  4. package/dist/commands/3d.js +363 -0
  5. package/dist/commands/create.js +337 -0
  6. package/dist/commands/image.js +1337 -43
  7. package/dist/commands/recommend.js +1 -1
  8. package/dist/commands/remix.js +213 -0
  9. package/dist/commands/skills.js +1379 -0
  10. package/dist/commands/tools-3d.js +473 -0
  11. package/dist/commands/tools-generation.js +452 -0
  12. package/dist/commands/tools-project.js +400 -0
  13. package/dist/commands/tools-research.js +37 -0
  14. package/dist/commands/tools-research.test.js +216 -0
  15. package/dist/commands/tools-utils.js +183 -0
  16. package/dist/commands/tools.js +7 -616
  17. package/dist/config.js +2 -0
  18. package/dist/index.js +19 -1
  19. package/dist/utils/version-checker.js +8 -11
  20. package/package.json +9 -3
  21. package/project-template/.claude/agents/designer.md +120 -0
  22. package/project-template/.claude/agents/developer.md +124 -0
  23. package/project-template/.claude/agents/pm.md +164 -0
  24. package/project-template/.claude/agents/refs/README.md +73 -0
  25. package/project-template/.claude/agents/refs/designer-art-style-catalog.md +533 -0
  26. package/project-template/.claude/agents/refs/designer-color-audio-recipes.md +153 -0
  27. package/project-template/.claude/agents/refs/designer-deliverable-spec.md +191 -0
  28. package/project-template/.claude/agents/refs/designer-dimension-axis.md +27 -0
  29. package/project-template/.claude/agents/refs/designer-handoff-v2-checklist.md +68 -0
  30. package/project-template/.claude/agents/refs/designer-master-composite-recipes.md +208 -0
  31. package/project-template/.claude/agents/refs/designer-style-exploration-flow.md +37 -0
  32. package/project-template/.claude/agents/refs/developer-dev-handoff.md +109 -0
  33. package/project-template/.claude/agents/refs/developer-impl-cookbook.md +134 -0
  34. package/project-template/.claude/agents/refs/developer-phase1-flow.md +136 -0
  35. package/project-template/.claude/agents/refs/pm-workflow-detail.md +551 -0
  36. package/project-template/.claude/agents/refs/reviewer-convergence-eval.md +130 -0
  37. package/project-template/.claude/agents/refs/reviewer-six-dimension-eval.md +6 -0
  38. package/project-template/.claude/agents/refs/ta-3d-flip-recipe.md +85 -0
  39. package/project-template/.claude/agents/refs/ta-atlas-deliverable-standard.md +67 -0
  40. package/project-template/.claude/agents/refs/ta-batch-pipeline-recipes.md +120 -0
  41. package/project-template/.claude/agents/refs/ta-image-generation-detail.md +356 -0
  42. package/project-template/.claude/agents/refs/ta-image-ops-reference.md +495 -0
  43. package/project-template/.claude/agents/refs/ta-pipeline-cookbook.md +1108 -0
  44. package/project-template/.claude/agents/refs/ta-tools-reference.md +111 -0
  45. package/project-template/.claude/agents/refs/ta-vfx-preset-catalog.md +365 -0
  46. package/project-template/.claude/agents/reviewer.md +127 -0
  47. package/project-template/.claude/agents/technical-artist.md +122 -0
  48. package/project-template/.claude/hooks/README.md +44 -0
  49. package/project-template/.claude/hooks/validate-atom-plan.mjs +224 -0
  50. package/project-template/.claude/hooks/validate-workflow-stop.mjs +343 -0
  51. package/project-template/.claude/settings.json +36 -0
  52. package/project-template/.claude/settings.local.json +4 -0
  53. package/project-template/.claude/skills/playcraft-ad-psychology/SKILL.md +182 -0
  54. package/project-template/.claude/skills/playcraft-art-style-guide/SKILL.md +123 -0
  55. package/project-template/.claude/skills/playcraft-asset-state-sheet/SKILL.md +141 -0
  56. package/project-template/.claude/skills/playcraft-audio-generation/SKILL.md +280 -0
  57. package/project-template/.claude/skills/playcraft-batch-pipeline/SKILL.md +184 -0
  58. package/project-template/.claude/skills/playcraft-build-optimizer/SKILL.md +306 -0
  59. package/project-template/.claude/skills/playcraft-image-generation/SKILL.md +279 -0
  60. package/project-template/.claude/skills/playcraft-image-generation/reference/build-sprite-sheet.template.mjs +123 -0
  61. package/project-template/.claude/skills/playcraft-image-generation/reference/compare-style.template.mjs +254 -0
  62. package/project-template/.claude/skills/playcraft-image-generation/reference/gen-batch-sprite.template.mjs +235 -0
  63. package/project-template/.claude/skills/playcraft-image-generation/reference/gen-batch.template.mjs +97 -0
  64. package/project-template/.claude/skills/playcraft-image-generation/reference/gen-edit-variants.template.mjs +118 -0
  65. package/project-template/.claude/skills/playcraft-image-generation/reference/process-batch.template.mjs +137 -0
  66. package/project-template/.claude/skills/playcraft-image-generation/reference/prompt-cookbook.md +397 -0
  67. package/project-template/.claude/skills/playcraft-image-generation/reference/validate-sprite-sheet.template.mjs +296 -0
  68. package/project-template/.claude/skills/playcraft-image-ops/SKILL.md +122 -0
  69. package/project-template/.claude/skills/playcraft-masking/SKILL.md +373 -0
  70. package/project-template/.claude/skills/playcraft-research/SKILL.md +212 -0
  71. package/project-template/.claude/skills/playcraft-sprite-generation/SKILL.md +423 -0
  72. package/project-template/.claude/skills/playcraft-storyboard/SKILL.md +167 -0
  73. package/project-template/.claude/skills/playcraft-style-qa/SKILL.md +270 -0
  74. package/project-template/.claude/skills/playcraft-text-rendering/SKILL.md +236 -0
  75. package/project-template/.claude/skills/playcraft-vfx-animation/SKILL.md +130 -0
  76. package/project-template/.claude/skills/playcraft-workflow/SKILL.md +485 -0
  77. package/project-template/.claude/skills/playwright-cli/SKILL.md +390 -0
  78. package/project-template/.claude/skills/playwright-cli/references/element-attributes.md +23 -0
  79. package/project-template/.claude/skills/playwright-cli/references/playwright-tests.md +39 -0
  80. package/project-template/.claude/skills/playwright-cli/references/request-mocking.md +87 -0
  81. package/project-template/.claude/skills/playwright-cli/references/running-code.md +240 -0
  82. package/project-template/.claude/skills/playwright-cli/references/session-management.md +226 -0
  83. package/project-template/.claude/skills/playwright-cli/references/spec-driven-testing.md +312 -0
  84. package/project-template/.claude/skills/playwright-cli/references/storage-state.md +275 -0
  85. package/project-template/.claude/skills/playwright-cli/references/test-generation.md +138 -0
  86. package/project-template/.claude/skills/playwright-cli/references/tracing.md +142 -0
  87. package/project-template/.claude/skills/playwright-cli/references/video-recording.md +157 -0
  88. package/project-template/.cursor/hooks.json +17 -0
  89. package/project-template/.cursor/rules/playcraft-orchestrator.mdc +137 -0
  90. package/project-template/.cursor/rules/playcraft-subagent-boundary.mdc +18 -0
  91. package/project-template/CLAUDE.md +280 -0
  92. package/project-template/assets/audio/bgm/.gitkeep +0 -0
  93. package/project-template/assets/audio/sfx/.gitkeep +0 -0
  94. package/project-template/assets/bundles/.gitkeep +0 -0
  95. package/project-template/assets/images/bg/.gitkeep +0 -0
  96. package/project-template/assets/images/reference/.gitkeep +0 -0
  97. package/project-template/assets/images/storyboard/.gitkeep +0 -0
  98. package/project-template/assets/images/tiles/.gitkeep +0 -0
  99. package/project-template/assets/images/ui/.gitkeep +0 -0
  100. package/project-template/assets/images/vfx/.gitkeep +0 -0
  101. package/project-template/assets/models/.gitkeep +0 -0
  102. package/project-template/docs/team/agent-conduct.md +121 -0
  103. package/project-template/docs/team/agent-runtime-matrix.md +62 -0
  104. package/project-template/docs/team/atom-plan-format.md +105 -0
  105. package/project-template/docs/team/collaboration.md +297 -0
  106. package/project-template/docs/team/core-model.md +50 -0
  107. package/project-template/docs/team/platform-capabilities.md +15 -0
  108. package/project-template/docs/team/workflow-changelog.md +65 -0
  109. package/project-template/docs/team/workflow-consistency-checklist.md +140 -0
  110. package/project-template/game/config/.gitkeep +0 -0
  111. package/project-template/game/gameplay/.gitkeep +0 -0
  112. package/project-template/game/scenes/.gitkeep +0 -0
  113. package/project-template/logs/.gitkeep +0 -0
  114. package/project-template/ta-workspace/logs/.gitkeep +0 -0
  115. package/project-template/ta-workspace/scripts/.gitkeep +0 -0
  116. package/project-template/ta-workspace/tmp/.gitkeep +0 -0
  117. package/project-template/templates/atom-plan.template.json +26 -0
  118. package/project-template/templates/atom-plan.template.md +108 -0
  119. package/project-template/templates/design-brief.template.md +195 -0
  120. package/project-template/templates/design-lens-checklist.reference.md +117 -0
  121. package/project-template/templates/design-methodology.md +99 -0
  122. package/project-template/templates/designer-log.template.md +114 -0
  123. package/project-template/templates/developer-log.template.md +134 -0
  124. package/project-template/templates/five-axis-framework.md +186 -0
  125. package/project-template/templates/intent-clarifications.template.md +58 -0
  126. package/project-template/templates/layout-spec.template.md +146 -0
  127. package/project-template/templates/project-state.template.md +237 -0
  128. package/project-template/templates/review-report.template.md +91 -0
  129. package/project-template/templates/style-exploration.template.md +93 -0
  130. package/project-template/templates/ta-log.template.md +343 -0
@@ -0,0 +1,235 @@
1
+ // ============================================================
2
+ // gen-batch-sprite.template.mjs — gpt-image-2 精灵图直出脚本模板
3
+ //
4
+ // 核心原则:让 gpt-image-2 一次 API 调用直接生成包含多个元素的
5
+ // 网格精灵图,然后用 sprite-split 切分。比逐个生成效率高 N 倍。
6
+ //
7
+ // 适用场景:
8
+ // - 卡牌(扑克/麻将/游戏卡):一批 13 张以内
9
+ // - 图标集:一批 9-16 张以内
10
+ // - 数字/字母贴图:一批 ≤16 个
11
+ //
12
+ // 使用方式:
13
+ // 1. cp .claude/skills/playcraft-image-generation/reference/gen-batch-sprite.template.mjs ta-workspace/scripts/gen-<name>-sprite.mjs
14
+ // 2. 修改下方 CONFIG 和 BATCHES 区域
15
+ // 3. node ta-workspace/scripts/gen-<name>-sprite.mjs
16
+ // ============================================================
17
+
18
+ import { execSync } from 'child_process';
19
+ import { existsSync, mkdirSync, appendFileSync } from 'fs';
20
+
21
+ // ============ CONFIG — 修改这里 ============
22
+ const CONFIG = {
23
+ /**
24
+ * 精灵图直出模型:永远用 gpt-image-2(图像理解 + 布局能力最强)
25
+ * mulerouter 质量更高(建议作为主模型),iegg 更快(备用)
26
+ * 注意:精灵图生成比单图慢,通常需要 90-150s,timeout 设 240 以上
27
+ */
28
+ model: 'mulerouter/gpt-image-2',
29
+
30
+ /**
31
+ * 每批精灵图的列数
32
+ * 行数由 items.length / columns 自动计算。
33
+ * 推荐:每批 ≤16 个元素(如 columns=4 则每批最多 4 行),超过会出现混乱。
34
+ */
35
+ columns: 4,
36
+
37
+ /**
38
+ * 宽高比:根据 columns/rows 比例选择
39
+ * - 1:1 → 4×4 方形网格
40
+ * - 3:2 → 4×3 横向网格(4列3行)
41
+ * - 2:3 → 3×4 纵向网格(3列4行)
42
+ * - 16:9 → 适合宽横向布局
43
+ */
44
+ aspectRatio: '1:1',
45
+
46
+ /** 生成的精灵图输出目录 */
47
+ sheetDir: 'assets/gen/sheets',
48
+ /** sprite-split 切分后的单图输出目录 */
49
+ outputDir: 'assets/images/batch',
50
+
51
+ /**
52
+ * 通用风格描述(追加到每个批次 prompt 末尾)
53
+ *
54
+ * 元素需要透明背景(独立元素:角色/车/道具/图标)→ 绿幕策略:
55
+ * style: 'flat 2D illustration, isolated on solid bright green #00FF00 background, centered, no shadow'
56
+ * removeBg: true (切分后逐帧去背景)
57
+ *
58
+ * 元素本身就是矩形(卡牌/棋子/UI 面板)→ 白底策略:
59
+ * style: 'flat 2D, white background, no shadow, no drop shadow, clean edges'
60
+ * removeBg: false
61
+ */
62
+ style: 'flat 2D illustration, isolated on solid bright green #00FF00 background, centered, no shadow',
63
+ /**
64
+ * 切分后是否对每帧执行 remove-background(绿幕去背景)
65
+ * true → 独立元素(需透明通道):remove-background --tolerance 25
66
+ * false → 卡牌/UI 面板等矩形元素:直接 resize,不去背景
67
+ */
68
+ removeBg: true,
69
+ };
70
+
71
+ // ============ DATA — 分批定义元素 ============
72
+ // 规则:每批 ≤ CONFIG.columns × CONFIG.rows 个元素
73
+ // 每个元素必须有 name(输出文件名)和 desc(精灵图中该格的内容描述)
74
+ const BATCHES = [
75
+ {
76
+ sheetName: 'sheet_batch_1',
77
+ items: [
78
+ { name: 'item_01', desc: '<格 1 内容描述>' },
79
+ { name: 'item_02', desc: '<格 2 内容描述>' },
80
+ { name: 'item_03', desc: '<格 3 内容描述>' },
81
+ { name: 'item_04', desc: '<格 4 内容描述>' },
82
+ // 最多 CONFIG.columns × CONFIG.rows 个
83
+ ],
84
+ },
85
+ {
86
+ sheetName: 'sheet_batch_2',
87
+ items: [
88
+ { name: 'item_05', desc: '<格 5 内容描述>' },
89
+ { name: 'item_06', desc: '<格 6 内容描述>' },
90
+ // ...
91
+ ],
92
+ },
93
+ // 继续添加批次...
94
+ ];
95
+
96
+ // ============ 精灵图 Prompt 构建器 ============
97
+ /**
98
+ * 根据 items 列表构建精灵图网格 prompt
99
+ * 关键词组合让 gpt-image-2 理解"网格布局"意图
100
+ */
101
+ function buildSpriteSheetPrompt(items, columns, style, removeBg) {
102
+ const actualRows = Math.ceil(items.length / columns);
103
+ const cellDescs = items.map((item, i) => {
104
+ const col = (i % columns) + 1;
105
+ const row = Math.floor(i / columns) + 1;
106
+ return `[Row${row},Col${col}]: ${item.desc}`;
107
+ }).join('; ');
108
+
109
+ // 绿幕模式强制在 prompt 里明确背景色,避免模型用白底
110
+ const bgInstruction = removeBg
111
+ ? 'Each element isolated on solid bright green #00FF00 background, no shadow, no gradient background.'
112
+ : 'Each element on clean white background.';
113
+
114
+ return [
115
+ `Sprite sheet grid layout, ${columns} columns × ${actualRows} rows.`,
116
+ `Each cell contains one element. Cell contents: ${cellDescs}.`,
117
+ bgInstruction,
118
+ `Grid layout, uniform cell size, equal spacing, elements perfectly centered in each cell.`,
119
+ `No borders between cells, no labels, no numbers on cells.`,
120
+ style,
121
+ ].join(' ');
122
+ }
123
+
124
+ // ============ LOGIC — 通常不需要修改 ============
125
+
126
+ const LOG_FILE = 'ta-workspace/logs/gen-batch-sprite.log';
127
+ mkdirSync(CONFIG.sheetDir, { recursive: true });
128
+ mkdirSync(CONFIG.outputDir, { recursive: true });
129
+ mkdirSync('ta-workspace/logs', { recursive: true });
130
+
131
+ function log(msg) {
132
+ const line = `[${new Date().toISOString()}] ${msg}`;
133
+ console.log(line);
134
+ appendFileSync(LOG_FILE, line + '\n');
135
+ }
136
+
137
+ const totalElements = BATCHES.reduce((s, b) => s + b.items.length, 0);
138
+ log(`=== Batch Sprite Generation Start ===`);
139
+ log(`Total: ${BATCHES.length} batches, ${totalElements} elements`);
140
+ log(`Model: ${CONFIG.model}`);
141
+
142
+ let doneBatches = 0, failedBatches = 0;
143
+
144
+ for (let bi = 0; bi < BATCHES.length; bi++) {
145
+ const batch = BATCHES[bi];
146
+ const sheetPath = `${CONFIG.sheetDir}/${batch.sheetName}.png`;
147
+
148
+ // ── Step 1: 生成精灵图(幂等跳过)────────────────────────────────
149
+ if (existsSync(sheetPath)) {
150
+ log(`[SKIP-SHEET] (${bi + 1}/${BATCHES.length}) ${batch.sheetName} already exists`);
151
+ } else {
152
+ log(`[GEN-SHEET ] (${bi + 1}/${BATCHES.length}) Generating ${batch.sheetName} (${batch.items.length} elements)`);
153
+ const prompt = buildSpriteSheetPrompt(batch.items, CONFIG.columns, CONFIG.style, CONFIG.removeBg);
154
+ const promptEscaped = prompt.replace(/"/g, '\\"');
155
+
156
+ const cmd =
157
+ `playcraft tools generate-image` +
158
+ ` --prompt "${promptEscaped}"` +
159
+ ` --output "${sheetPath}"` +
160
+ ` --aspect-ratio ${CONFIG.aspectRatio}` +
161
+ ` --image-model "${CONFIG.model}"` +
162
+ ` --timeout 240`;
163
+
164
+ try {
165
+ execSync(cmd, { stdio: 'inherit', timeout: 300_000 });
166
+ log(`[OK-SHEET ] ${batch.sheetName}`);
167
+ } catch (e) {
168
+ log(`[FAIL-SHEET] ${batch.sheetName}: ${e.message?.slice(0, 200)}`);
169
+ failedBatches++;
170
+ continue;
171
+ }
172
+ }
173
+
174
+ // ── Step 2: sprite-split 切分精灵图 ──────────────────────────────
175
+ const actualRows = Math.ceil(batch.items.length / CONFIG.columns);
176
+ // 检查第一个切分结果是否已存在(幂等)
177
+ const firstItemPath = `${CONFIG.outputDir}/${batch.items[0]?.name}.png`;
178
+ if (batch.items[0] && existsSync(firstItemPath)) {
179
+ log(`[SKIP-SPLIT] ${batch.sheetName} already split`);
180
+ doneBatches++;
181
+ continue;
182
+ }
183
+
184
+ log(`[SPLIT ] Splitting ${batch.sheetName} (${CONFIG.columns}×${actualRows})`);
185
+ const splitCmd =
186
+ `playcraft image sprite-split` +
187
+ ` --input "${sheetPath}"` +
188
+ ` --output-dir "ta-workspace/tmp/${batch.sheetName}"` +
189
+ ` --rows ${actualRows}` +
190
+ ` --columns ${CONFIG.columns}`;
191
+
192
+ try {
193
+ execSync(splitCmd, { stdio: 'inherit' });
194
+ } catch (e) {
195
+ log(`[FAIL-SPLIT] ${batch.sheetName}: ${e.message?.slice(0, 200)}`);
196
+ failedBatches++;
197
+ continue;
198
+ }
199
+
200
+ // ── Step 3: 重命名(+可选绿幕去背景)切分结果到最终位置 ─────────
201
+ log(`[RENAME ] Renaming ${batch.items.length} cells${CONFIG.removeBg ? ' + remove-background' : ''}`);
202
+ for (let j = 0; j < batch.items.length; j++) {
203
+ const item = batch.items[j];
204
+ const row = Math.floor(j / CONFIG.columns);
205
+ const col = j % CONFIG.columns;
206
+ // sprite-split 默认命名:frame_r{row}_c{col}.png(0-indexed)
207
+ const srcPath = `ta-workspace/tmp/${batch.sheetName}/frame_r${row}_c${col}.png`;
208
+ const dstPath = `${CONFIG.outputDir}/${item.name}.png`;
209
+
210
+ if (!existsSync(srcPath)) {
211
+ log(`[WARN] Expected cell not found: ${srcPath} (index ${j} out of ${batch.items.length})`);
212
+ continue;
213
+ }
214
+ try {
215
+ if (CONFIG.removeBg) {
216
+ // 绿幕去背景(tolerance 25 适合纯绿色 #00FF00 背景)
217
+ execSync(`playcraft image remove-background --input "${srcPath}" --output "${dstPath}" --tolerance 25`);
218
+ } else {
219
+ execSync(`cp "${srcPath}" "${dstPath}"`);
220
+ }
221
+ } catch (e) {
222
+ log(`[WARN] Failed to process ${srcPath} → ${dstPath}: ${e.message?.slice(0, 80)}`);
223
+ }
224
+ }
225
+
226
+ log(`[OK-BATCH ] (${bi + 1}/${BATCHES.length}) ${batch.sheetName} → ${batch.items.length} files`);
227
+ doneBatches++;
228
+ }
229
+
230
+ log(`\n=== Complete: Done=${doneBatches} Failed=${failedBatches}/${BATCHES.length} batches ===`);
231
+ log(`Output: ${CONFIG.outputDir}`);
232
+ if (failedBatches > 0) {
233
+ log('Re-run to retry failed batches (successful batches will be skipped)');
234
+ process.exit(1);
235
+ }
@@ -0,0 +1,97 @@
1
+ // ============================================================
2
+ // gen-batch.template.mjs — 批量 AI 生图脚本模板
3
+ // 用途:从零批量生成一组风格一致的素材(reference-image 模式)
4
+ //
5
+ // 使用方式:
6
+ // 1. cp .claude/skills/playcraft-image-generation/reference/gen-batch.template.mjs ta-workspace/scripts/gen-<name>.mjs
7
+ // 2. 修改下方 CONFIG 和 ITEMS 区域
8
+ // 3. node ta-workspace/scripts/gen-<name>.mjs
9
+ // ============================================================
10
+
11
+ import { execSync } from 'child_process';
12
+ import { existsSync, mkdirSync, appendFileSync } from 'fs';
13
+
14
+ // ============ CONFIG — 修改这里 ============
15
+ const CONFIG = {
16
+ /**
17
+ * 生图模型。
18
+ * - Phase 1 概念图(追求质量):用 gpt-image-2
19
+ * model: 'iegg-litellm/gpt-image-2'
20
+ * - Phase 2 批量(reference-image 一致性):用 google/,更稳定
21
+ * model: 'google/gemini-3.1-flash-image-preview'
22
+ *
23
+ * 后端按优先级自动 fallback 多个 provider,无需手动指定 provider。
24
+ * text+image CAPABILITY 的模型才支持 --reference-image
25
+ */
26
+ model: 'google/gemini-3.1-flash-image-preview',
27
+ /** 概念图路径(确认过风格的样本,所有后续图的参考来源) */
28
+ referenceImage: 'assets/images/concept/approved_sample.png',
29
+ /** 输出目录 */
30
+ outputDir: 'assets/images/batch',
31
+ /** 图片比例 */
32
+ aspectRatio: '1:1',
33
+ /**
34
+ * 统一风格描述(从 design-brief.md 复制,粘贴到每个 prompt 末尾)
35
+ * 示例:"flat 2D icon, vibrant colors, clean edges, white background, no shadow"
36
+ */
37
+ style: '<从 design-brief 复制的统一风格描述>',
38
+ };
39
+ // ============ DATA — 定义要生成的素材列表 ============
40
+ const ITEMS = [
41
+ { name: 'item_01', desc: '<素材描述 1>' },
42
+ { name: 'item_02', desc: '<素材描述 2>' },
43
+ // 继续添加...
44
+ ];
45
+ // ============ LOGIC — 通常不需要修改 ============
46
+
47
+ const LOG_FILE = 'ta-workspace/logs/gen-batch.log';
48
+ mkdirSync(CONFIG.outputDir, { recursive: true });
49
+ mkdirSync('ta-workspace/logs', { recursive: true });
50
+
51
+ function log(msg) {
52
+ const line = `[${new Date().toISOString()}] ${msg}`;
53
+ console.log(line);
54
+ appendFileSync(LOG_FILE, line + '\n');
55
+ }
56
+
57
+ log(`=== Batch Generation Start ===`);
58
+ log(`Total: ${ITEMS.length} | Model: ${CONFIG.model}`);
59
+
60
+ let done = 0, skipped = 0, failed = 0;
61
+ const failures = [];
62
+
63
+ for (let i = 0; i < ITEMS.length; i++) {
64
+ const item = ITEMS[i];
65
+ const outPath = `${CONFIG.outputDir}/${item.name}.png`;
66
+
67
+ if (existsSync(outPath)) {
68
+ log(`[SKIP] (${i + 1}/${ITEMS.length}) ${item.name}`);
69
+ skipped++;
70
+ continue;
71
+ }
72
+
73
+ log(`[GEN ] (${i + 1}/${ITEMS.length}) ${item.name}`);
74
+
75
+ const promptEscaped = `${item.desc}. ${CONFIG.style}`.replace(/"/g, '\\"');
76
+ const cmd =
77
+ `playcraft tools generate-image` +
78
+ ` --prompt "${promptEscaped}"` +
79
+ ` --output "${outPath}"` +
80
+ ` --aspect-ratio ${CONFIG.aspectRatio}` +
81
+ ` --reference-image "${CONFIG.referenceImage}"` +
82
+ ` --image-model "${CONFIG.model}"`;
83
+
84
+ try {
85
+ execSync(cmd, { stdio: 'inherit', timeout: 120_000 });
86
+ done++;
87
+ log(`[OK ] ${item.name}`);
88
+ } catch (e) {
89
+ log(`[FAIL] ${item.name}: ${e.message?.slice(0, 100)}`);
90
+ failures.push(item.name);
91
+ failed++;
92
+ }
93
+ }
94
+
95
+ log(`\n=== Complete: Done=${done} Skipped=${skipped} Failed=${failed}/${ITEMS.length} ===`);
96
+ if (failures.length > 0) log(`Failed: ${failures.join(', ')}`);
97
+ if (failed > 0) process.exit(1);
@@ -0,0 +1,118 @@
1
+ // ============================================================
2
+ // gen-edit-variants.template.mjs — 基图 + Edit 模型生成变体脚本模板
3
+ // 用途:先用高质量模型生成 1 张完美基图,再用 edit 模型批量修改出一组变体
4
+ //
5
+ // 适用场景:结构相同、只改局部的变体集合
6
+ // - 扑克牌(换花色/换数字)
7
+ // - 棋子系列(换颜色/换图案)
8
+ // - 图标集(换内容符号)
9
+ //
10
+ // 使用方式:
11
+ // 1. cp .claude/skills/playcraft-image-generation/reference/gen-edit-variants.template.mjs ta-workspace/scripts/gen-<name>-variants.mjs
12
+ // 2. Phase 1:先手动生成基图(见下方说明),存为 CONFIG.baseImage 路径
13
+ // 3. 填写 CONFIG 和 VARIANTS,然后 node ta-workspace/scripts/gen-<name>-variants.mjs
14
+ //
15
+ // Edit 模型决策(按优先级):
16
+ // 1. mulerouter/qwen-image-edit-max — 纯 edit,局部修改能力最强
17
+ // 2. mulerouter/gpt-image-2 — 有图走 /edit 端点,质量高
18
+ // 3. mulerouter/wan2.6-image — 图生图,回退选项
19
+ // ============================================================
20
+
21
+ import { execSync } from 'child_process';
22
+ import { existsSync, mkdirSync, appendFileSync } from 'fs';
23
+
24
+ // ============ CONFIG — 修改这里 ============
25
+ const CONFIG = {
26
+ /**
27
+ * Phase 1 基图路径(必须已存在)
28
+ * 生成基图的命令示例(gpt-image-2 质量最高,双 provider 回退):
29
+ * playcraft tools generate-image \
30
+ * --prompt "A playing card: Ace of Spades. [完整风格描述]" \
31
+ * --output assets/images/cards/base_ace_spades.png \
32
+ * --aspect-ratio 3:4 \
33
+ * --image-model iegg-litellm/gpt-image-2
34
+ */
35
+ baseImage: 'assets/images/cards/base_ace_spades.png',
36
+ /** Edit 模型(qwen-image-edit-max 局部修改能力最强) */
37
+ editModel: 'mulerouter/qwen-image-edit-max',
38
+ /** 输出目录 */
39
+ outputDir: 'assets/images/cards',
40
+ /** 图片比例(建议与基图相同) */
41
+ aspectRatio: '3:4',
42
+ };
43
+ // ============ DATA — 定义要生成的变体列表 ============
44
+ // editPrompt 应该描述"修改指令"而不是"完整重新描述"
45
+ // 好的写法:'Change the rank symbol from A to 2, show two spade symbols in center'
46
+ // 差的写法:'A playing card with two spade symbols...'(这是重新生成,不是编辑)
47
+ const VARIANTS = [
48
+ {
49
+ name: 'spades_2',
50
+ editPrompt: 'Change the rank symbol from A to 2. Show two spade suit symbols in center.',
51
+ },
52
+ {
53
+ name: 'spades_3',
54
+ editPrompt: 'Change the rank symbol from A to 3. Show three spade suit symbols in center.',
55
+ },
56
+ // 继续添加变体...
57
+ ];
58
+ // ============ LOGIC — 通常不需要修改 ============
59
+
60
+ const LOG_FILE = 'ta-workspace/logs/gen-edit-variants.log';
61
+ mkdirSync(CONFIG.outputDir, { recursive: true });
62
+ mkdirSync('ta-workspace/logs', { recursive: true });
63
+
64
+ function log(msg) {
65
+ const line = `[${new Date().toISOString()}] ${msg}`;
66
+ console.log(line);
67
+ appendFileSync(LOG_FILE, line + '\n');
68
+ }
69
+
70
+ // 检查基图
71
+ if (!existsSync(CONFIG.baseImage)) {
72
+ log(`ERROR: Base image not found: ${CONFIG.baseImage}`);
73
+ log(`Please generate the base image first (Phase 1), then run this script.`);
74
+ process.exit(1);
75
+ }
76
+
77
+ log(`=== Edit Variants Start ===`);
78
+ log(`Base: ${CONFIG.baseImage} | Model: ${CONFIG.editModel}`);
79
+ log(`Total variants: ${VARIANTS.length}`);
80
+
81
+ let done = 0, skipped = 0, failed = 0;
82
+ const failures = [];
83
+
84
+ for (let i = 0; i < VARIANTS.length; i++) {
85
+ const variant = VARIANTS[i];
86
+ const outPath = `${CONFIG.outputDir}/${variant.name}.png`;
87
+
88
+ if (existsSync(outPath)) {
89
+ log(`[SKIP] (${i + 1}/${VARIANTS.length}) ${variant.name}`);
90
+ skipped++;
91
+ continue;
92
+ }
93
+
94
+ log(`[EDIT] (${i + 1}/${VARIANTS.length}) ${variant.name}: ${variant.editPrompt.slice(0, 60)}...`);
95
+
96
+ const promptEscaped = variant.editPrompt.replace(/"/g, '\\"');
97
+ const cmd =
98
+ `playcraft tools generate-image` +
99
+ ` --prompt "${promptEscaped}"` +
100
+ ` --output "${outPath}"` +
101
+ ` --aspect-ratio ${CONFIG.aspectRatio}` +
102
+ ` --reference-image "${CONFIG.baseImage}"` +
103
+ ` --image-model "${CONFIG.editModel}"`;
104
+
105
+ try {
106
+ execSync(cmd, { stdio: 'inherit', timeout: 120_000 });
107
+ done++;
108
+ log(`[OK ] ${variant.name}`);
109
+ } catch (e) {
110
+ log(`[FAIL] ${variant.name}: ${e.message?.slice(0, 100)}`);
111
+ failures.push(variant.name);
112
+ failed++;
113
+ }
114
+ }
115
+
116
+ log(`\n=== Complete: Done=${done} Skipped=${skipped} Failed=${failed}/${VARIANTS.length} ===`);
117
+ if (failures.length > 0) log(`Failed: ${failures.join(', ')}`);
118
+ if (failed > 0) process.exit(1);
@@ -0,0 +1,137 @@
1
+ // ============================================================
2
+ // process-batch.template.mjs — 批量图片处理脚本模板
3
+ // 用途:对一批图片执行去背景 / trim + resize + 验证
4
+ //
5
+ // 使用方式:
6
+ // 1. cp .claude/skills/playcraft-image-generation/reference/process-batch.template.mjs ta-workspace/scripts/process-<name>.mjs
7
+ // 2. 修改下方 CONFIG 区域(特别是 SKIP_REMOVE_BG 选项)
8
+ // 3. node ta-workspace/scripts/process-<name>.mjs
9
+ //
10
+ // 背景处理决策(修改 CONFIG.skipRemoveBg 前请阅读):
11
+ // - 独立元素(角色/道具/图标)需透明背景 → skipRemoveBg = false(默认)
12
+ // 建议生图时 prompt 加 "on solid bright green #00FF00 background, isolated"
13
+ // - 卡牌/棋子/UI面板(矩形本体不需透明)→ skipRemoveBg = true
14
+ // 生图时 prompt 加 "flat 2D, no shadow, no 3D effect, clean edges"
15
+ // ============================================================
16
+
17
+ import { execSync } from 'child_process';
18
+ import { readdirSync, existsSync, mkdirSync, appendFileSync, unlinkSync } from 'fs';
19
+ import { join, basename, extname } from 'path';
20
+
21
+ // ============ CONFIG — 修改这里 ============
22
+ const CONFIG = {
23
+ /** 输入目录(gen-batch 的输出目录) */
24
+ inputDir: 'assets/images/batch',
25
+ /** 输出目录 */
26
+ outputDir: 'assets/images/processed',
27
+ /** 临时文件目录(去背景中间结果) */
28
+ tmpDir: 'ta-workspace/tmp',
29
+ /** 目标宽度(像素) */
30
+ targetW: 128,
31
+ /** 目标高度(像素) */
32
+ targetH: 128,
33
+ /**
34
+ * 跳过去背景步骤
35
+ * - false(默认):执行 remove-background(绿幕素材/独立元素)
36
+ * - true:跳过,只做 trim + resize(卡牌/棋子等矩形本体素材)
37
+ */
38
+ skipRemoveBg: false,
39
+ /**
40
+ * floodfill 容差(0–255)
41
+ * 绿幕背景建议 25;默认白背景可用 15
42
+ * 仅在 skipRemoveBg = false 时生效
43
+ */
44
+ removeBgTolerance: 25,
45
+ /** resize 时的 fit 模式:contain / cover / fill / inside / outside */
46
+ resizeFit: 'contain',
47
+ };
48
+ // ============ LOGIC — 通常不需要修改 ============
49
+
50
+ const LOG_FILE = 'ta-workspace/logs/process-batch.log';
51
+ mkdirSync(CONFIG.outputDir, { recursive: true });
52
+ mkdirSync(CONFIG.tmpDir, { recursive: true });
53
+ mkdirSync('ta-workspace/logs', { recursive: true });
54
+
55
+ function log(msg) {
56
+ const line = `[${new Date().toISOString()}] ${msg}`;
57
+ console.log(line);
58
+ appendFileSync(LOG_FILE, line + '\n');
59
+ }
60
+
61
+ const SUPPORTED_EXTS = new Set(['.png', '.jpg', '.jpeg', '.webp']);
62
+ const files = readdirSync(CONFIG.inputDir)
63
+ .filter(f => SUPPORTED_EXTS.has(extname(f).toLowerCase()))
64
+ .sort()
65
+ .map(f => join(CONFIG.inputDir, f));
66
+
67
+ log(`=== Batch Processing Start ===`);
68
+ log(`Files: ${files.length} | skipRemoveBg: ${CONFIG.skipRemoveBg} | Target: ${CONFIG.targetW}x${CONFIG.targetH}`);
69
+
70
+ let done = 0, skipped = 0, failed = 0;
71
+ const failures = [];
72
+
73
+ for (let i = 0; i < files.length; i++) {
74
+ const inputPath = files[i];
75
+ const name = basename(inputPath, extname(inputPath));
76
+ const outPath = join(CONFIG.outputDir, `${name}.png`);
77
+
78
+ if (existsSync(outPath)) {
79
+ log(`[SKIP] (${i + 1}/${files.length}) ${name}`);
80
+ skipped++;
81
+ continue;
82
+ }
83
+
84
+ log(`[PROC] (${i + 1}/${files.length}) ${name}`);
85
+
86
+ try {
87
+ if (CONFIG.skipRemoveBg) {
88
+ // 卡牌/棋子等矩形本体:直接 resize(不需要去背景)
89
+ execSync(
90
+ `playcraft image resize` +
91
+ ` --input "${inputPath}"` +
92
+ ` --output "${outPath}"` +
93
+ ` --width ${CONFIG.targetW}` +
94
+ ` --height ${CONFIG.targetH}` +
95
+ ` --fit ${CONFIG.resizeFit}`,
96
+ { stdio: 'inherit' },
97
+ );
98
+ } else {
99
+ // 独立元素:先去背景,再 resize
100
+ const tmpNobg = join(CONFIG.tmpDir, `${name}_nobg.png`);
101
+
102
+ // 步骤 1:去背景(绿幕 tolerance=25 效果最好)
103
+ execSync(
104
+ `playcraft image remove-background` +
105
+ ` --input "${inputPath}"` +
106
+ ` --output "${tmpNobg}"` +
107
+ ` --tolerance ${CONFIG.removeBgTolerance}`,
108
+ { stdio: 'inherit' },
109
+ );
110
+
111
+ // 步骤 2:resize 到目标尺寸
112
+ execSync(
113
+ `playcraft image resize` +
114
+ ` --input "${tmpNobg}"` +
115
+ ` --output "${outPath}"` +
116
+ ` --width ${CONFIG.targetW}` +
117
+ ` --height ${CONFIG.targetH}` +
118
+ ` --fit ${CONFIG.resizeFit}`,
119
+ { stdio: 'inherit' },
120
+ );
121
+
122
+ // 清理临时文件
123
+ if (existsSync(tmpNobg)) unlinkSync(tmpNobg);
124
+ }
125
+
126
+ log(`[OK ] ${name}`);
127
+ done++;
128
+ } catch (e) {
129
+ log(`[FAIL] ${name}: ${e.message?.slice(0, 100)}`);
130
+ failures.push(name);
131
+ failed++;
132
+ }
133
+ }
134
+
135
+ log(`\n=== Complete: Done=${done} Skipped=${skipped} Failed=${failed}/${files.length} ===`);
136
+ if (failures.length > 0) log(`Failed: ${failures.join(', ')}`);
137
+ if (failed > 0) process.exit(1);