@taptap/maker 0.0.37-beta.3 → 0.0.37-beta.5

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.
@@ -0,0 +1,148 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ const fs = require("fs");
4
+ const path = require("path");
5
+ const { checkDocument } = require("./ui-json-check.cjs");
6
+
7
+ function inside(root, file) {
8
+ const rel = path.relative(root, file);
9
+ return rel === "" || (!rel.startsWith(".." + path.sep) && rel !== ".." && !path.isAbsolute(rel));
10
+ }
11
+ function readProjectConfig(root) {
12
+ const source = ".project/project.json";
13
+ const file = path.join(root, source);
14
+ try {
15
+ const raw = JSON.parse(fs.readFileSync(file, "utf8").replace(/^\uFEFF/, ""));
16
+ const publish = raw && typeof raw.taptap_publish === "object" ? raw.taptap_publish : raw;
17
+ const orientation = publish && (publish.screen_orientation || publish.orientation);
18
+ return { orientation: orientation === "landscape" || orientation === "portrait" ? orientation : null, source };
19
+ } catch (error) {
20
+ if (error.code === "ENOENT") return { orientation: null, source, missing: true };
21
+ return { orientation: null, source, error: error.message };
22
+ }
23
+ }
24
+ function checkExportManifest(root, assets, files, diagnostics) {
25
+ const relative = "assets/ui/ui-export-manifest.ui.json";
26
+ const file = path.join(assets, "ui", "ui-export-manifest.ui.json");
27
+ if (!fs.existsSync(file)) return;
28
+ let manifest;
29
+ try {
30
+ manifest = JSON.parse(fs.readFileSync(file, "utf8").replace(/^\uFEFF/, ""));
31
+ } catch (error) {
32
+ diagnostics.push({ code: "UI_MANIFEST_PARSE", severity: "error", file: relative, pointer: "",
33
+ message: error.message });
34
+ return;
35
+ }
36
+ const categories = ["pages", "components", "templates"];
37
+ const actual = new Set(files.map(item => path.relative(assets, item).split(path.sep).join("/")));
38
+ categories.forEach(kind => {
39
+ const listed = Array.isArray(manifest[kind]) ? manifest[kind].filter(item => typeof item === "string") : [];
40
+ const listedSet = new Set(listed);
41
+ const actualFiles = [...actual].filter(item => item.startsWith("ui/" + kind + "/"));
42
+ const missing = listed.filter(item => !actual.has(item));
43
+ const unlisted = actualFiles.filter(item => !listedSet.has(item));
44
+ if (missing.length) diagnostics.push({ code: "UI_MANIFEST_MISSING_FILE", severity: "error",
45
+ file: relative, pointer: "/" + kind, message: "导出清单登记了不存在的文件:" + missing.join(", ") });
46
+ if (unlisted.length) diagnostics.push({ code: "UI_MANIFEST_STALE", severity: "warning",
47
+ file: relative, pointer: "/" + kind, message: "目录中有 " + unlisted.length +
48
+ " 个 " + kind + " 文件未登记,清单可能来自旧导出:" + unlisted.slice(0, 5).join(", ") +
49
+ (unlisted.length > 5 ? " …" : "") });
50
+ });
51
+ }
52
+ function main(argv) {
53
+ if (argv.includes("--help")) {
54
+ console.log("node check-ui.cjs --project <game-root> [--file assets/ui/page.ui.json] [--format json|text]");
55
+ return 0;
56
+ }
57
+ const args = {};
58
+ for (let i = 0; i < argv.length; i += 2) {
59
+ if (!["--project", "--file", "--format"].includes(argv[i]) || !argv[i + 1] || argv[i + 1].startsWith("--")) {
60
+ throw new Error("Unknown or incomplete argument: " + argv[i]);
61
+ }
62
+ args[argv[i]] = argv[i + 1];
63
+ }
64
+ if (!args["--project"]) throw new Error("--project is required");
65
+ const format = args["--format"] || "text";
66
+ if (!["json", "text"].includes(format)) throw new Error("--format must be json or text");
67
+ const root = fs.realpathSync(args["--project"]);
68
+ const assets = fs.realpathSync(path.join(root, "assets"));
69
+ if (!inside(root, assets)) throw new Error("assets must be inside the project");
70
+ const files = [], scanDiagnostics = [];
71
+ function scan(dir) {
72
+ for (const entry of fs.readdirSync(dir, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name))) {
73
+ if ([".git", "node_modules"].includes(entry.name)) continue;
74
+ const file = path.join(dir, entry.name);
75
+ if (entry.isSymbolicLink()) {
76
+ scanDiagnostics.push({ code: "UI_SCAN_SYMLINK", severity: "warning",
77
+ file: path.relative(root, file), pointer: "", message: "未递归扫描符号链接,请检查其目标。" });
78
+ } else if (entry.isDirectory()) scan(file);
79
+ else if (/\.ui\.json$/i.test(entry.name)) files.push(file);
80
+ }
81
+ }
82
+ if (args["--file"]) {
83
+ const target = path.resolve(root, args["--file"]);
84
+ if (!inside(assets, target) || !/\.ui\.json$/i.test(target)) throw new Error("--file must be a .ui.json inside assets");
85
+ const real = fs.realpathSync(target);
86
+ if (!inside(assets, real)) throw new Error("--file symlink escapes assets");
87
+ files.push(real);
88
+ } else scan(assets);
89
+ const projectConfig = readProjectConfig(root);
90
+ const report = { version: 1, files: files.length, errors: 0, warnings: 0,
91
+ projectConfig,
92
+ diagnostics: scanDiagnostics, skipped: [] };
93
+ checkExportManifest(root, assets, files, report.diagnostics);
94
+ if (projectConfig.error) report.diagnostics.push({ code: "UI_PROJECT_CONFIG_PARSE", severity: "error",
95
+ file: projectConfig.source, pointer: "", message: projectConfig.error });
96
+ else if (projectConfig.missing) report.diagnostics.push({ code: "UI_PROJECT_CONFIG_MISSING", severity: "warning",
97
+ file: projectConfig.source, pointer: "", message: "未找到项目屏幕方向配置;页面预览可能使用错误的横竖屏设备。" });
98
+ const skipped = new Set();
99
+ function resourceExists(ref) {
100
+ const file = path.resolve(assets, ref);
101
+ if (!inside(assets, file)) return false;
102
+ try {
103
+ const real = fs.realpathSync(file);
104
+ if (!inside(assets, real)) return false;
105
+ fs.accessSync(real, fs.constants.R_OK);
106
+ return fs.statSync(real).isFile();
107
+ } catch (_) { return false; }
108
+ }
109
+ for (const file of files) {
110
+ const relative = path.relative(root, file).split(path.sep).join("/");
111
+ let tree;
112
+ try {
113
+ if (fs.statSync(file).size > 4 * 1024 * 1024) throw new Error("File exceeds 4 MiB");
114
+ tree = JSON.parse(fs.readFileSync(file, "utf8").replace(/^\uFEFF/, ""));
115
+ } catch (error) {
116
+ report.diagnostics.push({ code: "UI_JSON_PARSE", severity: "error",
117
+ file: relative, pointer: "", message: error.message });
118
+ continue;
119
+ }
120
+ const result = checkDocument({ file: relative, tree, resourceExists });
121
+ report.diagnostics.push(...result.diagnostics);
122
+ if (projectConfig.orientation && /assets\/ui\/pages\//i.test(relative) &&
123
+ typeof tree.width === "number" && typeof tree.height === "number") {
124
+ const landscape = tree.width >= tree.height;
125
+ if ((projectConfig.orientation === "landscape") !== landscape) {
126
+ report.diagnostics.push({ code: "UI_DESIGN_ORIENTATION", severity: "error", file: relative,
127
+ pointer: "/width", message: "页面根尺寸 " + tree.width + "×" + tree.height +
128
+ " 与项目配置的 " + projectConfig.orientation + " 方向不一致。" });
129
+ }
130
+ }
131
+ result.skipped.forEach(item => skipped.add(item));
132
+ }
133
+ if (!files.length) report.diagnostics.push({ code: "UI_NO_FILES", severity: "error",
134
+ file: "assets", pointer: "", message: "未找到 .ui.json;先确认项目根目录,或使用 lua-ui-to-json 提取。" });
135
+ report.errors = report.diagnostics.filter(d => d.severity === "error").length;
136
+ report.warnings = report.diagnostics.filter(d => d.severity === "warning").length;
137
+ report.skipped = [...skipped];
138
+ if (format === "json") console.log(JSON.stringify(report, null, 2));
139
+ else {
140
+ console.log(`${report.files} files, ${report.errors} errors, ${report.warnings} warnings`);
141
+ for (const d of report.diagnostics) console.log(`[${d.severity}] ${d.code} ${d.file}${d.pointer}: ${d.message}`);
142
+ console.log("Not verified: " + (report.skipped.join(", ") || "No documents checked"));
143
+ console.log("Static checks do not prove runtime or visual equivalence.");
144
+ }
145
+ return report.errors ? 1 : 0;
146
+ }
147
+ try { process.exitCode = main(process.argv.slice(2)); }
148
+ catch (error) { console.error(error.message); process.exitCode = 2; }
@@ -0,0 +1,206 @@
1
+ (function (root) {
2
+ "use strict";
3
+ var previewTypes = new Set(["Panel", "Label", "Button", "NanoVG"]);
4
+ // An allowlist shared by the browser, CLI and standalone document checker.
5
+ var nanoOps = {
6
+ save: "", restore: "", beginPath: "", closePath: "", fill: "", stroke: "",
7
+ moveTo: "nn", lineTo: "nn", bezierTo: "nnnnnn", quadTo: "nnnn", arcTo: "nnnnn",
8
+ rect: "nnnn", roundedRect: "nnnnn", roundedRectVarying: "nnnnnnnn",
9
+ circle: "nnn", ellipse: "nnnn", arc: "nnnnnn",
10
+ translate: "nn", scale: "nn", rotate: "n", skewX: "n", skewY: "n", transform: "nnnnnn",
11
+ scissor: "nnnn", intersectScissor: "nnnn",
12
+ fillColor: "c", strokeColor: "c", fillPaint: "p", strokePaint: "p",
13
+ strokeWidth: "n", miterLimit: "n", lineCap: "n", lineJoin: "n", globalAlpha: "n",
14
+ fontSize: "n", fontFace: "s", textAlign: "n", textLetterSpacing: "n", text: "nns", textBox: "nnns",
15
+ };
16
+ function nanoColor(value) {
17
+ return typeof value === "string" && /^#[0-9a-f]{6}([0-9a-f]{2})?$/i.test(value) ||
18
+ Array.isArray(value) && value.length === 4 && value.every(function (n) {
19
+ return typeof n === "number" && Number.isFinite(n) && n >= 0 && n <= 255;
20
+ });
21
+ }
22
+ function checkNanoVG(node, issue, resource) {
23
+ var box = node.viewBox, commands = node.commands, depth = 0;
24
+ if (!Array.isArray(box) || box.length !== 4 || box.some(function (n) {
25
+ return typeof n !== "number" || !Number.isFinite(n);
26
+ }) || box[2] <= 0 || box[3] <= 0) issue("/viewBox", "viewBox 必须是 [x, y, 正宽度, 正高度]。");
27
+ if (!Array.isArray(commands) || commands.length > 20000) {
28
+ issue("/commands", "绘制指令必须是数组,最多 20000 条。"); return;
29
+ }
30
+ function paint(value, at) {
31
+ if (!value || typeof value !== "object" || Array.isArray(value) || typeof value.kind !== "string") return false;
32
+ var signatures = { linearGradient: "nnnncc", radialGradient: "nnnncc", imagePattern: "nnnnnsn" };
33
+ var sig = Object.prototype.hasOwnProperty.call(signatures, value.kind) && signatures[value.kind];
34
+ if (!sig || !args(value.args, sig, at + "/args")) return false;
35
+ if (value.kind === "radialGradient" && (value.args[2] < 0 || value.args[3] <= value.args[2])) return false;
36
+ if (value.kind === "imagePattern") {
37
+ if (value.args[2] <= 0 || value.args[3] <= 0 || value.args[6] < 0 || value.args[6] > 1) return false;
38
+ resource(value.args[5], at + "/args/5");
39
+ }
40
+ return true;
41
+ }
42
+ function args(values, sig, at) {
43
+ return Array.isArray(values) && values.length === sig.length && values.every(function (value, i) {
44
+ var type = sig[i];
45
+ return type === "n" ? typeof value === "number" && Number.isFinite(value) :
46
+ type === "s" ? typeof value === "string" : type === "c" ? nanoColor(value) : paint(value, at + "/" + i);
47
+ });
48
+ }
49
+ commands.forEach(function (command, i) {
50
+ var at = "/commands/" + i;
51
+ if (!Array.isArray(command) || typeof command[0] !== "string" || !Object.prototype.hasOwnProperty.call(nanoOps, command[0]) ||
52
+ !args(command.slice(1), nanoOps[command[0]], at)) {
53
+ issue(at, "不支持的 NanoVG 指令或参数。使用 ui capabilities 查询支持范围。"); return;
54
+ }
55
+ var op = command[0], a = command.slice(1);
56
+ if (op === "save" && ++depth > 32) issue(at, "NanoVG 图层状态栈超过 32 层,需为引擎保留栈空间。");
57
+ if (op === "restore" && --depth < 0) { issue(at, "restore 没有对应的 save。"); depth = 0; }
58
+ if (op === "globalAlpha" && (a[0] < 0 || a[0] > 1)) issue(at, "透明度必须在 0 到 1 之间。");
59
+ if (["strokeWidth", "miterLimit", "fontSize"].includes(op) && a[0] <= 0) issue(at, "值必须大于 0。");
60
+ if (op === "lineCap" && ![0, 1, 2].includes(a[0]) || op === "lineJoin" && ![1, 3, 4].includes(a[0]) ||
61
+ op === "arc" && ![1, 2].includes(a[5])) issue(at, "无效的 NanoVG 枚举值。");
62
+ if (op === "textBox" && a[2] <= 0) issue(at, "文本框宽度必须大于 0。");
63
+ if (op === "textAlign" && ![0, 1, 2, 4].some(function (h) {
64
+ return [0, 8, 16, 32, 64].some(function (v) { return a[0] === h + v; });
65
+ })) issue(at, "文本对齐每个方向最多指定一个 NanoVG 标志。");
66
+ if (op === "circle" && a[2] < 0 || op === "ellipse" && (a[2] < 0 || a[3] < 0) ||
67
+ op === "arc" && a[2] < 0 || op === "arcTo" && a[4] < 0 ||
68
+ op.startsWith("roundedRect") && a.slice(4).some(function (n) { return n < 0; })) issue(at, "半径不能为负数。");
69
+ });
70
+ if (depth) issue("/commands", "save/restore 必须配对。");
71
+ }
72
+ var lengths = ["width", "height", "minWidth", "minHeight", "maxWidth", "maxHeight",
73
+ "left", "right", "top", "bottom", "padding", "paddingLeft", "paddingRight",
74
+ "paddingTop", "paddingBottom", "paddingHorizontal", "paddingVertical",
75
+ "margin", "marginLeft", "marginRight", "marginTop", "marginBottom",
76
+ "marginHorizontal", "marginVertical", "gap", "flexBasis"];
77
+ var enums = {
78
+ position: ["relative", "absolute"],
79
+ backgroundFit: ["fill", "contain", "cover", "sliced"],
80
+ overflow: ["visible", "hidden", "scroll"],
81
+ flexDirection: ["row", "column", "row-reverse", "column-reverse"],
82
+ textAlign: ["left", "center", "right"],
83
+ verticalAlign: ["top", "middle", "bottom"],
84
+ };
85
+ function token(value) { return typeof value === "string" && value.charAt(0) === "$"; }
86
+ function length(value) {
87
+ return typeof value === "number" && Number.isFinite(value) ||
88
+ typeof value === "string" && /^(auto|-?\d+(?:\.\d+)?%?)$/.test(value);
89
+ }
90
+ function checkDocument(options) {
91
+ var diagnostics = [], ids = new Map(), count = 0, limited = false, parameterized = false;
92
+ function issue(code, severity, pointer, message) {
93
+ diagnostics.push({ code: code, severity: severity, file: options.file || "",
94
+ pointer: pointer, message: message });
95
+ }
96
+ function resource(value, pointer) {
97
+ if (value == null || value === "" || token(value)) return;
98
+ if (typeof value !== "string") {
99
+ issue("UI_RESOURCE_TYPE", "error", pointer, "资源引用必须是字符串。"); return;
100
+ }
101
+ if (/^uuid:\/\//.test(value)) {
102
+ issue("UI_RESOURCE_UNRESOLVED", "warning", pointer, "UUID 引用需要引擎资源索引,尚未验证。"); return;
103
+ }
104
+ if (/^(\/|\\|[a-z]+:)/i.test(value) || value.includes("\\") || value.split("/").includes("..")) {
105
+ issue("UI_RESOURCE_PATH", "error", pointer, "使用 assets 内相对资源路径,不允许绝对路径或越界引用。"); return;
106
+ }
107
+ if (value.startsWith("assets/")) {
108
+ issue("UI_RESOURCE_PREFIX", "warning", pointer, "游戏资源通常相对 assets 根,请核对是否多写了 assets/。");
109
+ }
110
+ if (options.resourceExists && !options.resourceExists(value)) {
111
+ issue("UI_RESOURCE_MISSING", "error", pointer, "找不到或无法读取资源:" + value);
112
+ }
113
+ }
114
+ function visit(node, pointer, depth) {
115
+ if (++count > 10000 || depth > 128) {
116
+ if (!limited) issue("UI_LIMIT", "error", pointer, "节点数量或深度超过检查上限。");
117
+ limited = true; return;
118
+ }
119
+ if (!node || typeof node !== "object" || Array.isArray(node)) {
120
+ issue("UI_NODE", "error", pointer, "节点必须是对象。"); return;
121
+ }
122
+ if (typeof node.type !== "string" || !node.type.trim()) {
123
+ issue("UI_NODE_TYPE", "error", pointer + "/type", "每个节点都需要非空 type。");
124
+ } else if (!previewTypes.has(node.type)) {
125
+ issue("UI_PREVIEW_TYPE", "warning", pointer + "/type",
126
+ "此类型需要核对引擎注册及编辑器预览支持:" + node.type + ";不应自动改成 Panel。");
127
+ }
128
+ if (node.id != null && !token(node.id)) {
129
+ if (typeof node.id !== "string" || !node.id.trim()) {
130
+ issue("UI_ID_TYPE", "error", pointer + "/id", "id 必须是非空字符串。");
131
+ } else if (ids.has(node.id)) {
132
+ issue("UI_DUPLICATE_ID", "error", pointer + "/id", "同一文档的 id 重复:" + node.id +
133
+ ";首次出现于 " + ids.get(node.id));
134
+ } else ids.set(node.id, pointer + "/id");
135
+ }
136
+ Object.keys(node).forEach(function (key) {
137
+ var value = node[key], at = pointer + "/" + key.replace(/~/g, "~0").replace(/\//g, "~1");
138
+ if (key.charAt(0) === "_") issue("UI_INTERNAL_FIELD", "error", at, "导出含编辑器内部字段。");
139
+ if (/^on[A-Z]/.test(key)) issue("UI_CALLBACK", "error", at, "回调保留在 Lua 中,不写入 UI JSON。");
140
+ if (token(value)) { parameterized = true; return; }
141
+ if (typeof value === "number" && !Number.isFinite(value)) {
142
+ issue("UI_NUMBER", "error", at, "数值必须有限。"); return;
143
+ }
144
+ if (lengths.includes(key) && !length(value)) {
145
+ issue("UI_LENGTH", "error", at, "尺寸/位置必须是有限数值、百分比或受支持的 auto。");
146
+ }
147
+ if (["width", "height"].includes(key) && typeof value === "number" && value <= 0) {
148
+ issue("UI_ZERO_SIZE", "warning", at, "非正尺寸可能不可见;动态尺寸需在运行时确认。");
149
+ }
150
+ if (enums[key] && !enums[key].includes(value)) {
151
+ issue("UI_ENUM", "error", at, "不支持的枚举值:" + String(value));
152
+ }
153
+ if (["visible", "disabled", "locked"].includes(key) && typeof value !== "boolean") {
154
+ issue("UI_BOOLEAN", "error", at, "此字段必须是布尔值。");
155
+ }
156
+ if (key === "opacity" && (typeof value !== "number" || value < 0 || value > 1)) {
157
+ issue("UI_OPACITY", "error", at, "透明度应为 0 到 1 的数值。");
158
+ }
159
+ if (key === "backgroundSlice" && (!Array.isArray(value) || value.length !== 4 ||
160
+ value.some(function (n) { return typeof n !== "number" || !Number.isFinite(n) || n < 0; }))) {
161
+ issue("UI_SLICE", "error", at, "九宫格切边使用四个非负数:[上, 右, 下, 左]。");
162
+ }
163
+ });
164
+ resource(node.backgroundImage, pointer + "/backgroundImage");
165
+ resource(node.pressedBackgroundImage, pointer + "/pressedBackgroundImage");
166
+ if (node.type === "NanoVG") checkNanoVG(node, function (at, message) {
167
+ issue("UI_NANOVG", "error", pointer + at, message);
168
+ }, function (ref, at) { resource(ref, pointer + at); });
169
+ if (node.component != null) {
170
+ if (token(node.component)) {
171
+ parameterized = true;
172
+ } else if (typeof node.component !== "string" || !node.component.trim()) {
173
+ issue("UI_COMPONENT_TYPE", "error", pointer + "/component", "组件引用必须是非空字符串。");
174
+ } else if (options.resourceExists && !options.resourceExists(node.component)) {
175
+ issue("UI_COMPONENT_MISSING", "error", pointer + "/component", "找不到组件文件:" + node.component);
176
+ }
177
+ }
178
+ if (node.$repeat) {
179
+ issue("UI_EDITOR_REPEAT", "warning", pointer + "/$repeat",
180
+ "$repeat 是编辑器扩展,不证明引擎会生成列表;运行时应核对模板实例化。");
181
+ resource(node.$repeat.template, pointer + "/$repeat/template");
182
+ }
183
+ if (node.children != null && !Array.isArray(node.children)) {
184
+ issue("UI_CHILDREN", "error", pointer + "/children", "children 必须是数组。");
185
+ } else (node.children || []).some(function (child, i) {
186
+ visit(child, pointer + "/children/" + i, depth + 1);
187
+ return limited;
188
+ });
189
+ }
190
+ visit(options.tree, "", 0);
191
+ if (parameterized) issue("UI_TEMPLATE_CONTEXT", "warning", "",
192
+ "含模板参数。请验证调用方 props、默认值及模板加载模式;此检查没有展开模板。");
193
+ return {
194
+ version: 1, nodes: count,
195
+ errors: diagnostics.filter(function (d) { return d.severity === "error"; }).length,
196
+ warnings: diagnostics.filter(function (d) { return d.severity === "warning"; }).length,
197
+ diagnostics: diagnostics,
198
+ skipped: ["runtime-equivalence", "layout-and-fonts", "component-expansion", "lua-bindings",
199
+ "image-decoding", "meta-and-font-resources", "source-coverage", "duplicate-json-keys"]
200
+ .concat(options.resourceExists ? [] : ["resource-existence"]),
201
+ };
202
+ }
203
+ var api = { checkDocument: checkDocument, checkNanoVG: checkNanoVG, nanoOps: nanoOps };
204
+ if (typeof module !== "undefined" && module.exports) module.exports = api;
205
+ else root.UrhoxUICheck = api;
206
+ })(typeof window !== "undefined" ? window : globalThis);
@@ -0,0 +1,115 @@
1
+ ---
2
+ name: maker-ui-workflow
3
+ description: 'TapTap Maker 游戏 UI 设计稿拆解、按钮/图标/背景切图、已有素材组装 UI.json,以及在控制台 UI 编辑器中对照还原。适用于‘照这张图做游戏 UI’‘拆这个界面’‘把切图拼回 UI’‘生成 UI.json’‘和设计稿对比调整’;按用户目的进入相应阶段,普通单个 UI 属性修改不重跑拆图。'
4
+ ---
5
+
6
+ # Maker UI 设计稿拆解与还原
7
+
8
+ Maker 是流程入口;自由画布展示分析与切图,脚本按显式布局组装,控制台 UI 编辑器负责对照和调整。
9
+ 本 Skill 不新增 MCP tool,不执行游戏构建、提交或更换游戏加载入口。
10
+
11
+ ## 从用户需要的阶段开始
12
+
13
+ - 有设计稿,要做成可编辑 UI:识别布局 → 分层切图 → 资源入项目 → 组装 → 编辑器对照。
14
+ - 只要按钮、图标、背景等切图:在资源导出结束,不自动扩展为整屏 UI 重建。
15
+ - 已有切图,要拼回界面:先找布局清单和素材绑定;缺失时对照原稿补录并说明来源,不能猜配相似素材。
16
+ - 已有 UI.json,要调位置或对照:直接打开编辑器,不重新生图或覆盖现有文档。
17
+ - 只说“做个背包/商店界面”:从上下文找原稿及风格要求;缺少会改变结果的设计意图时再询问。
18
+
19
+ 已有 UI 的命令行编辑使用同包 taptap-maker ui:capabilities 查看格式,list 找文档,
20
+ inspect 读取保存版本及 revision,patch 按节点 ID(或 children pointer)批量增删改和移动。
21
+ 先用 --dry-run 检查,再带同一 revision 执行;版本冲突时重读并合并,不强制覆盖。
22
+ check 检查声明和资源,open --no-open 返回控制台 UI 编辑器地址。CLI 不读取网页未保存草稿;
23
+ 网页有草稿时先保留,CLI 写入后通过文档菜单重新从磁盘加载或打开保存版本。
24
+
25
+ ## 准备
26
+
27
+ 读取 Maker 状态并绑定明确的项目目录;沿用对话中已选项目。控制台打开、画布 CLI 和付费生成遵循
28
+ 同包 taptap-maker-local 与工具实际 schema。保持同一 target-dir,不凭全局当前项目推断。
29
+ 打开控制台后用 canvas pages / snapshot 读取当前页面、画布和 revision;通过页面桥接操作和保存,
30
+ 不能直接覆写打开中的画布文件。命令参数先读当前 CLI 的 canvas 帮助。
31
+ 修改卡片显示大小使用 canvas update-nodes,例如 input 为
32
+ `{"nodes":[{"id":"卡片ID","width":800}]}`。图片卡设置 width 或 height 即等比调整另一边,
33
+ 它只改变卡片,不改变图片像素、其它卡片位置或画布缩放;具体范围以 canvas capabilities 为准。
34
+
35
+ 尺寸以图片像素为准,不使用画布卡片的 width/height:inspect 的 imageInfo 是当前图片实际宽高和比例,
36
+ originalImage 是沿引用链取得的原稿坐标基准。去文字、背景准备和整屏标注默认 parameters.aspectRatio=source,
37
+ 跟随原稿;图集保持自己的行列排版。固定比例可用 canvas capabilities 的选项显式覆盖。
38
+ 非常见比例先向用户说明可能影响构图和切图;跟随的比例不被接口支持时,在运行前选择支持的比例,
39
+ 不静默拉伸、裁剪原稿,也不把 9:21 当成已支持的输出。原图尺寸和请求/结果尺寸分别保留。
40
+ 生成记录的 referenceImages、originalImage、parameters.targetSize、resultImageInfo 和 warnings 用于核对;
41
+ submittedPrompt 包含实际发送的参考图尺寸。实际结果比例不符时先核对,不把请求尺寸当成成功结果。
42
+
43
+ 有完整 UI 拆解用户模板时优先复用,在新画布替换原稿;没有时用现有图片和资源卡建立同样的流程。
44
+ 旧示例结果只供参考。换原稿后重做识别、布局、素材绑定与网格核对,不能只换首图就沿用旧结果。
45
+
46
+ 画布手动添加模板默认关闭识图;CLI 的 canvas run 游戏 UI 分组或图片步骤默认开启识图,
47
+ 保存开关,先完成去文字,再取得去文字图的清单后才继续下游,不依赖 Agent 额外开启。
48
+ 带当前 page-id、canvas-id、revision 和 target-dir 执行;只有用户明确要求无识图对照时,
49
+ 在本次及后续 run 的 input 中显式传 `"recognition":false`,例如
50
+ `{"id":"分组ID","recognition":false}`。仅提前关闭卡片开关不能覆盖 CLI run 的默认值。
51
+ 识图由当前对话 AI 自己完成,不要求配置 TAPTAP_MAKER_VISION_CONFIG 或另一个模型服务。
52
+ 沿用看图 → CLI 写入 → 继续流程:
53
+
54
+ 1. 先 run「去文字设计稿」卡片;分组 run 也会先完成去文字,然后提示当前 AI 识图。
55
+ inspect 确认去文字卡已完成,读取它的 assetPath 和 imageInfo,使用当前模型识别这张去文字图。
56
+ 原设计稿只作为去文字输入,以及美术字独立支线的参考;不能用原稿代替去文字图识别。
57
+ 不能以生图的标框图片代替清单;当前模型无法读取图片时,明确建议切换支持图片输入的模型。
58
+ 2. 逐项记录元素 id、name、category、rect(去文字图像素 x/y/宽/高)、parentId、zIndex、states、cutout。
59
+ category 取 icon/frame/tab/action/shortcut/close/title/panel/art_text/text;普通文字 cutout=false。
60
+ 重复按钮逐个记录,不能漏掉实例。坐标是 AI 识别估计,不能宣称精确测量。
61
+ 3. 用现有 canvas update-nodes 写去文字卡的 uiRecognition.result,自动显示便签并供标框/拆图引用。
62
+ input:`{"nodes":[{"id":"去文字卡ID","uiRecognition":{"enabled":true,"result":{...}}}]}`。
63
+ result 字段:id(新 UUID)、model(实际当前模型名,未知写 unknown)、prompt(本次识别要求)、
64
+ createdAt(ISO 时间)、durationMs(识别耗时,未计时写 0)、sourcePath(assetPath)、sourceSha256
65
+ (去文字图字节的 SHA-256)、width/height(真实像素)、elements(上述元素数组)。
66
+ 重新 inspect 取得 revision 后写入;系统校验去文字图路径、哈希、尺寸、坐标和编号,保存并选用清单。
67
+ 4. inspect 的 recognitionState=ready 且便签 text 有实际编号后,再 run 分组。
68
+ 换模型测试时读取同一去文字图,写入新的 result;历史清单保留,画布「对比」可查看和切换。
69
+ 报错时按具体原因修正,不自动关闭识图跳过。远端生图超时或 unknown 先查询原任务,不盲目重提。
70
+
71
+ 只执行已配置的画布模板时,确认输入和参数后使用分组 run(取得付费授权后传 --allow-paid)。
72
+ 队列按连线自动接续图片与资源卡,资源卡按已保存网格裁切并保存独立 PNG,不必逐张调用。
73
+ 最后一步是内容就绪的资源包卡片;入项目、meta、UI.json 和编辑器属于后续独立任务,
74
+ 仅在用户要求时继续。自动裁切不表示视觉复核通过;缺少网格或结果未知时处理原阻塞后再继续。
75
+
76
+ ## 执行
77
+
78
+ 布局字段、坐标依据、冗余资源和双重对位契约见 [workflow.md](references/workflow.md)。
79
+
80
+ 1. 先从原设计稿生成去文字稿;再由当前 AI 识别去文字稿,保存稳定元素 ID、该图像素位置、类型、父级及绘制顺序。
81
+ 相似按钮逐个记录,清单通过上述 CLI 写入便签,再用于标框和拆图。重新去文字后必须重新识别。
82
+ 2. 按去文字稿的清单分别标注按钮、图标;背景在去文字后再去除前景。
83
+ 美术字是独立支线:标注和提取始终引用未去文字的原设计稿,不能因去文字清单没有美术字而跳过。
84
+ 提取提示词分开写“参考与目标”“保留”“移除”“输出”。按钮默认/按下态分别生成、统一画布与锚点,
85
+ 图标与按钮底板分离;美术字只保留字形及字效,不带后方底框。
86
+ 后续组装需要的普通文字及原稿布局单独对照原稿补录,不混入去文字切图清单。
87
+ 3. 查看真实结果。透明处理、必要的重新排版要明确使用已有能力或可重复的本地处理,不能把人工修图冒充模板自动能力。
88
+ 用图集预览核对完整边界后确认,再导出独立 PNG;未知远端任务只查原任务,不自动重提。
89
+ 4. 正式素材按 assets/ui/<界面>/images/ 归档;备用图同目录 reserve/ 保留但不入布局。
90
+ 过程文件、layout.json、corrections.json 留在项目 .maker/ui-workflows/<界面>/,不混入正式 PNG。
91
+ 明确绑定资源 ID 与元素 ID、默认/按下态,记录图片尺寸与哈希;显式调用 generate_resource_meta。
92
+ 5. 使用本 Skill 的 scripts/assemble-ui.mjs 组装到新的目录,例如 assets/ui/<界面>/assembled-v1/。
93
+ 输出目录必须不存在,保护手工编辑;多轮用新目录。脚本验证绑定、哈希、尺寸与层级,不做视觉自动匹配。
94
+ 6. 在控制台「UI 编辑器」打开 assembled.ui.json,同名 assembled.reference.png 会自动作为设计稿。
95
+ 左右检查完整性、层级、资源选择,再重叠检查位置/尺寸;必要时按同一元素 ID 记录纠偏重新组装。
96
+ 用户已经手工编辑的文件继续在编辑器调整,不能无条件重新生成覆盖。
97
+
98
+ ## 组装和打开
99
+
100
+ 在已安装的 Skill 目录运行(正式分发的脚本已打包依赖,无需 npm install):
101
+
102
+ node scripts/assemble-ui.mjs <项目绝对路径> <layout.json> <新输出目录> [corrections.json]
103
+
104
+ 输出 assembled.ui.json、assembled.reference.png、assembly-map.json。将新资源纳入 meta 生成后,
105
+ 用当前分发的 CLI 执行 console open --target-dir <项目> --no-open --json,取得真实地址;
106
+ 保留其项目参数,追加 &page=ui-editor&ui=<URL编码的 assets/ 相对 UI 路径>,即可直达文档。
107
+ 控制台已打开时也可进入「UI 编辑器」并刷新文件列表。不要启动独立 UrhoxUIEditor 或 Python 服务。
108
+ 也可直接运行 taptap-maker ui open --target-dir <项目> --file <assets/相对UI路径> --no-open --json,
109
+ 取得含项目与 checkout 身份的直达地址;不要手工拼接另一个项目的 URL。
110
+
111
+ ## 完成检查
112
+
113
+ 检查正式文件和素材引用,查看真实左右/重叠效果,并确认保存后重新打开仍正确。
114
+ 保留冗余资源,报告缺件、形变、未验证项和实际修整;静态检查通过不代表像素级一致。
115
+ 交付目标是可在编辑器继续编辑的静态 UI;点击逻辑、动态列表和游戏运行时接入只有用户要求才做。
@@ -0,0 +1,85 @@
1
+ # Maker UI 设计稿到游戏素材工作流
2
+
3
+ ## 当前流程:保留位置、冗余切图、两次对位
4
+
5
+ 识别阶段先记录原设计稿中的元素身份和位置,再开始生图式切图。红框图只是可视化,
6
+ 不能替代机器可读的布局清单。所有坐标采用原始设计稿像素,不从生成图集的位置倒推。
7
+ 本流程复用现有画布图片和资源卡、UI 编辑器对照功能,不新增画布按钮或生成任务系统。
8
+
9
+ 1. **识别并保存布局**:原图尺寸、文件哈希,以及每个元素的稳定 ID、矩形、父元素、类型和
10
+ 同级绘制顺序写入布局 JSON。普通文字也保留为 Label;美术字记录为图片元素。
11
+ 图中相似元素逐个编号,素材相同不代表元素相同。修正框的位置时保留 ID,不因排序重新编号。
12
+ 2. **生成并绑定素材**:生成任务或图集槽位与元素/素材编号显式对应。图集网格坐标只用于裁图。
13
+ 导出后记录 PNG 的路径、哈希和尺寸;同一素材可以绑定多个元素,默认/按下状态绑定同一按钮。
14
+ 生图结果顺序仍需核对,不能只凭模型承诺或文件名猜测对应关系。
15
+ 3. **保留冗余**:允许同一对象的多种候选、备用状态和多切的底框,作为 reserve 素材保留。
16
+ 不因为没用于本次布局就删除,不把备用素材自动变成 UI 节点。原稿漏项仍应补识别,
17
+ 不能把“多切了素材”当成“原稿内容完整”。选择备用素材时显式改变绑定。
18
+ 4. **第一次组装**:程序按布局记录及绑定生成 UI JSON;父子相对坐标由全图坐标换算,
19
+ 同级层级按 elements 内的先后顺序,背景、图标、文字各自保留。缺少绑定则停止,禁止视觉猜配。
20
+ 5. **第二次对照纠偏**:Agent 在 UI 编辑器中打开组装结果,查看左右/重叠截图,对照同一份原稿,
21
+ 按已有 ID 检查偏移、尺寸、层级、遗漏和状态对齐。几何偏差写入独立 corrections JSON,
22
+ 保留 before、after、reason 和截图证据路径;重新组装并再次看图。层级或素材绑定错误需修正
23
+ 布局清单,再重新复核,不能用移动坐标掩盖。复核过程不重新匹配相似对象、不删除冗余资源。
24
+
25
+ “第二次对照”目前由 Agent 看图完成,工具不自动进行图像识别或判断视觉通过。
26
+ 纠偏记录绑定完整布局哈希、设计稿哈希及调整前坐标,旧版本记录不能套用到新布局。
27
+ 没有纠偏记录的输出明确为待视觉复核;有记录只表示已记录复核,不表示像素级自动验收通过。
28
+ 历史结果回填位置时,provenance 使用 reconstruction-backfill,不能把它说成切图时已记录。
29
+ 新设计稿在识别时记录则使用 recognition。
30
+
31
+ ### 布局文件与组装工具
32
+
33
+ 组装脚本 <本 Skill 目录>/scripts/assemble-ui.mjs 不调用付费模型、不写 meta、不修改已打开画布。
34
+ 随 Maker 的 npm 包和客户端插件分发;使用安装位置下的 Skill 脚本,不依赖开发仓库。
35
+ 布局文件放项目开发资源目录,UI 和正式 PNG 放 assets。命令输出目录必须不存在,避免覆盖手工编辑。
36
+
37
+ node <本 Skill 目录>/scripts/assemble-ui.mjs <项目根目录> <layout.json> <新输出目录> [corrections.json]
38
+
39
+ 输出 assembled.ui.json、assembled.reference.png 和 assembly-map.json。后者记录最终位置、
40
+ 原始位置、素材引用次数与备用清单。资源仍引用原项目 assets,不重复复制全部切图。
41
+ 把 UI 导入项目后显式调用 generate_resource_meta,再用 Maker 控制台「UI 编辑器」检查和对照。
42
+
43
+ 布局 JSON 的 version=1,coordinateSpace=design-pixels,rectBasis=asset-canvas。
44
+ design 包含 path(assets/ 相对路径)、sha256、width、height;assets 列表的每项具有这些
45
+ 图片字段及 id、role(bound 或 reserve)。素材可选 contentBounds 记录透明通道内容边界,
46
+ 只用于复核,不隐式改变放置坐标。elements 中每项包含:
47
+
48
+ - id、parentId(唯一根为 null)、type(Panel/Button/Label/Image)。
49
+ - render 区分 container、image、text;image 在切图绑定完成前不能组装,防止漏图静默变为空面板。
50
+ - rect=[x,y,width,height],全部是设计稿绝对像素坐标;根矩形与设计稿一致。
51
+ - props 存储颜色、文本等编辑器属性,不允许偷偷覆盖位置、尺寸、图片引用或添加整体变换。
52
+ - assetId 可绑定默认图片;Button 的 pressedAssetId 可绑定按下图片;Label 无需切图。
53
+
54
+ rect 表示整个 PNG 画布的放置范围,不能混用按钮主体边界与含阴影/透明边距的画布边界。
55
+ 先裁透明留白或统一状态画布,再记录资源尺寸和哈希;默认/按下态要检查主体锚点是否一致。
56
+ 切图若发生形变,坐标记录不会自动修复形变,应选择备用或在编辑器调整,不宣称完全无误差。
57
+ 当前工具只组装固定坐标的静态 UI,不处理旋转/缩放节点、动态列表、百分比和响应式布局。
58
+
59
+ 纠偏 JSON 的 version=1,layoutSha256 为解析后 layout 对象 JSON.stringify 的 SHA-256;
60
+ review 包含 designSha256 与 evidence(实际对照截图路径),adjustments 每项为
61
+ {id,before:[x,y,w,h],after:[x,y,w,h],reason}。没有偏差时可以记录空 adjustments。
62
+ 移动父节点时未单独纠偏的子节点一起移动;对子节点显式纠偏使用新的全图坐标。
63
+ 修改父节点宽高不会隐式缩放子节点。原始布局不被覆写,纠偏只作用于本次输出。
64
+
65
+ ## 复用已保存的 UI 拆解模板
66
+
67
+ 在画布的「添加模板 → 我的模板」中添加已保存流程,再替换实例的原设计稿。模板保存卡片、
68
+ 连线、提示词和示例结果,但不会把旧设计稿的元素清单、标框、网格和布局坐标自动适配到新图。
69
+ 旧结果只供参考,不能在替换首图后直接当作新设计稿的交付物。
70
+
71
+ 复用时由 Agent 跟随以下步骤,继续使用现有画布操作,不新增自动工作流引擎:
72
+
73
+ 1. 在新原稿上重新记录元素 ID、位置和状态。重复的奖励格保留不同实例 ID,可以共用素材;
74
+ 开关的开/关状态与按下反馈分别处理,不能仅把关闭底图当成开启按钮的按下态。
75
+ 2. 更新去文字、按钮标注、图标标注、背景准备和美术字的输入及清单。美术字识别仍引用原稿,
76
+ 不能只看已经去掉文字的图片。每条提取提示词分清保留、移除和输出要求。
77
+ 3. 查看真实生成结果,只返修缺件、图层混入或形状错误的组件。纯色底先处理为透明,再展示
78
+ 最终素材卡。清理几乎不可见的孤立像素后再确定透明边界,避免它们撑大尺寸、使主体显示偏小。
79
+ 4. 不假设模型严格遵守规则网格。主体跨格时先按完整边界重新排版,再查看网格预览、确认和导出。
80
+ 默认/按下态统一图片画布与锚点,备用资源保留但不自动放入 UI。
81
+ 5. 导出 PNG,按新布局记录组装 UI JSON,显式生成 meta,并在 UI 编辑器中做左右和重叠对照。
82
+ 保存画布后重新打开,确认展示的是新结果、资源可下载且文件引用有效。
83
+
84
+ 目前可以复用流程结构,再由 Agent 分阶段接续与复核;不能承诺只换首图、无人检查就自动生成
85
+ 全部可用素材和 UI。Agent 的透明处理、重新排版及视觉纠偏也不能表述成模板已有的一键能力。