#!/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); }