feat(ui-migration): 帧矩形与命名(1 基 + 行优先)

帧序经实证: 读 00014.png 网格内容与 11 个按钮的 FrameIndex 对照, 六项精确命中。
用例直接锚定该实证样例(通知=10/设置=11/战绩=4)。
命名保持 1 基并补零, 使字典序等于帧序、且文件名与 FrameIndex 直接对齐。

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-08-28 00:47:51 +08:00
co-authored by Claude Opus 5
parent f2e766a89a
commit f1ab6e7fd9
2 changed files with 109 additions and 0 deletions
@@ -0,0 +1,39 @@
/**
* 帧矩形与命名。见 spec §0.3、§3。
* 帧号 1 基、行优先——已由读取 00014.png 的网格内容与 11 个按钮的 FrameIndex 对照实证。
*/
/** 帧号 → 源矩形。FrameIndex=0 按帧 1 处理(实测仅 2 个对象如此)。 */
export function frameRect(image, frameIndex) {
const idx = (frameIndex || 1) - 1;
if (idx < 0 || idx >= image.frame_all) {
throw new RangeError(
`帧号越界: ${image.bmp} frameIndex=${frameIndex}(有效范围 1..${image.frame_all})`,
);
}
return {
x: (idx % image.w) * image.w1,
y: Math.floor(idx / image.w) * image.h1,
width: image.w1,
height: image.h1,
};
}
/** 补零位数:保证字典序 = 帧序。 */
export function padWidth(frameCount) {
return String(frameCount).length;
}
/** 00014.png + 帧 5/共 12 → 00014_05.png;单帧图原样返回。 */
export function frameFileName(bmp, frameIndex, frameCount) {
if (frameCount <= 1) return bmp;
const base = bmp.replace(/\.png$/i, '');
const n = String(frameIndex || 1).padStart(padWidth(frameCount), '0');
return `${base}_${n}.png`;
}
/** 该图全部帧的文件名,下标 0 对应帧 1。 */
export function frameNames(image) {
return Array.from({ length: image.frame_all }, (_, i) =>
frameFileName(image.bmp, i + 1, image.frame_all));
}