按 LayerID 段位 + 显式名单判定; 命名笼统的 7 个层标 unassigned 交人工归位, 不猜。 图按引用它的对象所在层归属, 跨 bucket 归 common, 无引用归 unassigned。 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
83 lines
3.3 KiB
JavaScript
83 lines
3.3 KiB
JavaScript
import { test } from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import { join } from 'node:path';
|
|
import { layerBucket, imageBuckets } from '../ui-migration/buckets.mjs';
|
|
import { loadSource } from '../ui-migration/gameabc-source.mjs';
|
|
import { ROOT } from '../lib/paths.mjs';
|
|
|
|
const REAL_SOURCE = join(ROOT, '..', 'projects', 'Game_Surface_3', 'output');
|
|
|
|
test('layerBucket 按名单判 login', () => {
|
|
assert.equal(layerBucket(1, 'Logo_Layer'), 'login');
|
|
assert.equal(layerBucket(2, 'Login_Layer'), 'login');
|
|
assert.equal(layerBucket(18, 'Auth_layer'), 'login');
|
|
assert.equal(layerBucket(16, 'Bind_Layer'), 'login');
|
|
assert.equal(layerBucket(29, 'phoneInfo'), 'login');
|
|
});
|
|
|
|
test('layerBucket 按 ID 段位判 hall / room / common', () => {
|
|
assert.equal(layerBucket(4, 'MainMenu_Layer'), 'hall');
|
|
assert.equal(layerBucket(26, 'Task_Layer'), 'hall');
|
|
assert.equal(layerBucket(50, 'MainScene_Layer'), 'room');
|
|
assert.equal(layerBucket(202, 'Player_Head_Score_Layer'), 'room');
|
|
assert.equal(layerBucket(418, 'ChatPannel_Layer'), 'room');
|
|
assert.equal(layerBucket(602, 'inputPannel'), 'common');
|
|
assert.equal(layerBucket(614, 'Loading_Layer'), 'common');
|
|
});
|
|
|
|
test('layerBucket 对命名笼统的层返回 unassigned(不猜)', () => {
|
|
for (const [id, name] of [[6, 'Layer6'], [13, 'Layer13'], [403, 'Layer403'],
|
|
[411, 'Layer411'], [601, 'Layer601'], [603, 'Layer603'], [618, 'Layer618']]) {
|
|
assert.equal(layerBucket(id, name), 'unassigned', `${name} 应为 unassigned`);
|
|
}
|
|
});
|
|
|
|
test('layerBucket 的 unassigned 优先于段位规则', () => {
|
|
// Layer601 若只按段位会判成 common,但名字笼统 → 必须 unassigned
|
|
assert.equal(layerBucket(601, 'Layer601'), 'unassigned');
|
|
});
|
|
|
|
test('imageBuckets 单一 bucket 的图归该 bucket', () => {
|
|
const source = {
|
|
objects: new Map([[1, { ObjectID: 1, ImageFileID: 7, BelongLayerID: 2 }]]),
|
|
layers: [{ layerId: 2, name: 'Login_Layer', objectIds: [1] }],
|
|
images: new Map([[7, { id: 7, bmp: 'a.png', frame_all: 1 }]]),
|
|
groups: [],
|
|
};
|
|
assert.equal(imageBuckets(source).get(7), 'login');
|
|
});
|
|
|
|
test('imageBuckets 跨 bucket 的图归 common', () => {
|
|
const source = {
|
|
objects: new Map([
|
|
[1, { ObjectID: 1, ImageFileID: 7, BelongLayerID: 2 }],
|
|
[2, { ObjectID: 2, ImageFileID: 7, BelongLayerID: 4 }],
|
|
]),
|
|
layers: [
|
|
{ layerId: 2, name: 'Login_Layer', objectIds: [1] },
|
|
{ layerId: 4, name: 'MainMenu_Layer', objectIds: [2] },
|
|
],
|
|
images: new Map([[7, { id: 7, bmp: 'a.png', frame_all: 1 }]]),
|
|
groups: [],
|
|
};
|
|
assert.equal(imageBuckets(source).get(7), 'common');
|
|
});
|
|
|
|
test('imageBuckets 无对象引用的图归 unassigned', () => {
|
|
const source = {
|
|
objects: new Map(),
|
|
layers: [],
|
|
images: new Map([[7, { id: 7, bmp: 'orphan.png', frame_all: 1 }]]),
|
|
groups: [],
|
|
};
|
|
assert.equal(imageBuckets(source).get(7), 'unassigned');
|
|
});
|
|
|
|
test('imageBuckets 在真实数据上给每张图一个归属(回归护栏)', () => {
|
|
const source = loadSource(REAL_SOURCE);
|
|
const m = imageBuckets(source);
|
|
assert.equal(m.size, source.images.size, '每张图都要有归属');
|
|
const valid = new Set(['login', 'hall', 'room', 'common', 'unassigned']);
|
|
for (const [id, b] of m) assert.ok(valid.has(b), `图 ${id} 的 bucket 非法: ${b}`);
|
|
});
|