Files
Shuery 3f11426964 feat: TS 构建管线、Spine 抓取器与 wallpapers/ 唯一真相来源
把项目从「手写 dist/」改成「wallpapers/ 是唯一真相来源,dist/ 由 pnpm build 生成」,
并补上配套的类型、门禁与抓取器。一次提交落地整条管线,因为拆开会留下不能构建的中间态。

- src/:运行时与模拟器源码(TS,strict),编译到 build/ 再拷进各分发
- tools/:build / dev / check-{syntax,paths,dist},以及抓取器与回归门禁 tools/checks/
  (.scratch/ 下那批一次性脚本移入 tools/checks/ 并入库为长期门禁)
- wallpapers/:七档壁纸的源数据 + README.md(id/音频/预设的完整规范)
- docs/adr/0005-0008:构建管线与分发拓扑、模拟器契约、自包含 sim、每骨架资源布局
- .gitignore:排除 .scratch/ 的参考资料副本(上游 spine 整仓克隆 ~1.2 GB、
  抓取侦查数据 ~680 MB)与调试转储;这些是本地调查材料,补偿会让仓库无法克隆
- 归一化 .gitignore/CONTEXT.md 行尾(工作区 CRLF、索引 LF 造成的整文件假 diff)

同时修掉三档卡住构建的未完工壁纸:
- kv45 的 meta.json 里 id 还是抓取期场景名 scene_main,经 downloader promote 正名为 kv45
- shajin / zhigengniao_juheye 的 meta.json 误用了骨架描述文件(name/spine/animations/pages)、
  且都缺 preset.template.json;现按规范重建:骨架沉到 spines/<名>/(spine-ts 按 atlas 所在
  目录解析贴图页)、补上元数据与单骨架预设,并清掉 zhigengniao 骨架里指向作者机的绝对路径
- 顺带 promote 已在 sources.yml 里的 kv46(月升之前,与兽共舞)

pnpm check 五道门全绿:10 个分发 / 7 档壁纸 / 141 处引用自包含。
2026-10-02 01:27:02 +08:00

73 lines
3.0 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// 取景公式的离线验证:不依赖浏览器,直接对 viewport-fitter.js 求值。
// 两条硬约束:① 16:9 下必须与作者设定完全一致;② 立绘层缩放比必须等于背景 cover 缩放比。
import { readFileSync } from "node:fs";
const src = readFileSync(new URL("../../dist/releases/collection-all/scripts/viewport-fitter.js", import.meta.url), "utf8").replace(/^export\s+/gm, "");
const mod = new Function(
src + "\nreturn { contain, frameForAspect, coverScale, resolveViewport, toViewportConfig, REFERENCE_ASPECT };",
)();
const rect = (x, y, width, height) => ({ x, y, width, height });
const fmt = (r) =>
`x=${r.x.toFixed(2)} y=${r.y.toFixed(2)} w=${r.width.toFixed(2)} h=${r.height.toFixed(2)} 比例=${(r.width / r.height).toFixed(4)}`;
const cases = [
{
name: "xilian(昔涟立绘)",
R: rect(-2181.72, 1442.39, 4226.57, 3403.35),
imgW: 2048,
imgH: 1080,
},
{
name: "kv37(「成为昨日的明天」)",
R: rect(-1419.8, -512.4, 2457.6, 1228.8),
imgW: 2560,
imgH: 1440,
},
];
const canvases = [
[3440, 1440, "21:9"],
[1920, 1080, "16:9"],
[2560, 1600, "16:10"],
[1080, 1920, "9:16"],
];
// 背景走 CSS background-size:cover,它在画布上真实的像素缩放就是这两个候选里的较大者。
const bgScale = (w, h, imgW, imgH) => Math.max(w / imgW, h / imgH);
let failures = 0;
for (const c of cases) {
const imgAspect = c.imgW / c.imgH;
const V0 = mod.contain(c.R, mod.REFERENCE_ASPECT);
console.log(`\n=== ${c.name} 背景图 ${c.imgW}x${c.imgH}(比例 ${imgAspect.toFixed(4)}) ===`);
console.log(`作者视口 R : ${fmt(c.R)}`);
console.log(`参考取景 V0 : ${fmt(V0)}`);
// 基准取 16:9 1080p:立绘与背景都以此为准比较"被放大了多少倍"
const refCanvas = [1920, 1080];
const spinePx0 = refCanvas[1] / V0.height;
const bgPx0 = bgScale(refCanvas[0], refCanvas[1], c.imgW, c.imgH);
for (const [w, h, tag] of canvases) {
const aspect = w / h;
const V = mod.frameForAspect(V0, aspect, imgAspect);
const spineRatio = h / V.height / spinePx0;
const bgRatio = bgScale(w, h, c.imgW, c.imgH) / bgPx0;
const synced = Math.abs(spineRatio - bgRatio) < 1e-6;
if (!synced) failures++;
console.log(
` ${tag.padEnd(5)} ${String(w).padStart(4)}x${String(h).padEnd(4)} ${fmt(V)}` +
` 立绘 x${spineRatio.toFixed(4)} 背景 x${bgRatio.toFixed(4)} ${synced ? "同步 ✓" : "不同步 ✗"}`,
);
}
// 参考比例下必须与作者设定逐像素一致,且必须与拟合前的真实渲染值吻合
const Vref = mod.frameForAspect(V0, mod.REFERENCE_ASPECT, imgAspect);
const untouched = ["x", "y", "width", "height"].every((k) => Math.abs(Vref[k] - V0[k]) < 1e-9);
if (!untouched) failures++;
console.log(` 参考比例回归: ${untouched ? "与作者设定完全一致 ✓" : "被改动 ✗"}`);
}
console.log(`\n结论:${failures === 0 ? "全部通过 ✓" : `${failures} 项失败 ✗`}`);
process.exit(failures === 0 ? 0 : 1);