feat(ui-migration): PNG 切分/重组与全量重组校验
切分可逆, 故「重组(切分(原图)) 的像素 === 原图像素」是对全部 1006 帧的完全验证, 成本近零。比较解码后的像素缓冲而非文件字节(编码参数不同会让同像素图字节不同)。 verify-frames CLI 对全部 139 张多帧图跑该校验, 任一失败退出码 1。 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
#!/usr/bin/env node
|
||||
import { readFileSync, existsSync } from 'node:fs';
|
||||
import { join } from 'node:path';
|
||||
import { pathToFileURL } from 'node:url';
|
||||
import { loadSource } from './ui-migration/gameabc-source.mjs';
|
||||
import { verifySheet } from './ui-migration/frame-io.mjs';
|
||||
import { ROOT } from './lib/paths.mjs';
|
||||
|
||||
const DEFAULT_SOURCE = join(ROOT, '..', 'projects', 'Game_Surface_3');
|
||||
|
||||
/** 对全部多帧图跑重组校验。返回 { checked, failures: [{bmp, reason}] }。 */
|
||||
export function verifyAllFrames(projectDir = DEFAULT_SOURCE) {
|
||||
const { images } = loadSource(join(projectDir, 'output'));
|
||||
const failures = [];
|
||||
let checked = 0;
|
||||
for (const image of images.values()) {
|
||||
if (image.frame_all <= 1) continue;
|
||||
const p = join(projectDir, 'assets', 'bmp', image.bmp);
|
||||
if (!existsSync(p)) {
|
||||
failures.push({ bmp: image.bmp, reason: `图片文件不存在: ${p}` });
|
||||
continue;
|
||||
}
|
||||
checked++;
|
||||
const r = verifySheet(readFileSync(p), image);
|
||||
if (!r.ok) failures.push({ bmp: image.bmp, reason: r.reason });
|
||||
}
|
||||
return { checked, failures };
|
||||
}
|
||||
|
||||
if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
|
||||
const { checked, failures } = verifyAllFrames(process.argv[2] ?? DEFAULT_SOURCE);
|
||||
console.log(`重组校验:${checked} 张多帧图`);
|
||||
if (failures.length === 0) {
|
||||
console.log('OK: 全部通过(切分对全部帧完全可逆)。');
|
||||
process.exit(0);
|
||||
}
|
||||
console.error(`\n${failures.length} 张失败:`);
|
||||
for (const f of failures) console.error(` ${f.bmp}\n ${f.reason}`);
|
||||
process.exit(1);
|
||||
}
|
||||
Reference in New Issue
Block a user