fix(scripts): final review Critical+Important fixes (Widget alignment, full readLayerXml, Label _string, atlas selection, hard-coded paths, exit code, dead code removal)
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
import { test } from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { readFileSync } from 'node:fs';
|
||||
import { join } from 'node:path';
|
||||
import { readLayerXml, emitPrefabJson } from '../../scripts/legacy-layer-to-cocos-prefab.mjs';
|
||||
import { ROOT, HOST_PROJECT } from '../../scripts/lib/paths.mjs';
|
||||
|
||||
// PoC 阶段 3 端到端: Layer00002.xml Login_Layer (18 spirits, group 2, 包含 Spirit405 渠道logo +
|
||||
// Spirit177 游客登录 anchor-test cases). 验证生成 prefab 与 fixtures/Login_Layer.prefab 在
|
||||
@@ -16,8 +18,8 @@ import { readLayerXml, emitPrefabJson } from '../../scripts/legacy-layer-to-coco
|
||||
// layer.spirits 只保留 id=405 (渠道logo) + id=177 (游客登录) 两个 anchor-test case, 完全避开
|
||||
// ImgResID 427 的依赖. 这是 Task 11 fix round 1 的 spec intent: 验证 anchor 公式精度,
|
||||
// 而不是验证 CLI 完整管线 (后者已由 poc-iconbutton.test.mjs / poc-protocol.test.mjs 覆盖).
|
||||
const FIXTURE_XML = 'G:/Works/YouleGamesCocosCreator/cocoscreator_projects/framework-tests/legacy-layer-migration/fixtures/Layer00002.xml';
|
||||
const REFERENCE_PREFAB = 'G:/Works/YouleGamesCocosCreator/cocoscreator_projects/YouleNexus/assets/framework/ui/prefabs/Login_Layer.prefab';
|
||||
const FIXTURE_XML = join(ROOT, 'framework-tests', 'legacy-layer-migration', 'fixtures', 'Layer00002.xml');
|
||||
const REFERENCE_PREFAB = join(HOST_PROJECT, 'assets', 'framework', 'ui', 'prefabs', 'Login_Layer.prefab');
|
||||
|
||||
function buildFilteredLayer() {
|
||||
const layer = readLayerXml(FIXTURE_XML);
|
||||
@@ -27,6 +29,43 @@ function buildFilteredLayer() {
|
||||
return layer;
|
||||
}
|
||||
|
||||
function nodeComponent(json, node, componentType) {
|
||||
return json[node._components.map(ref => ref.__id__).find(index => json[index]?.__type__ === componentType)];
|
||||
}
|
||||
|
||||
test('Login_Layer full-screen and normal node geometry matches reference strictly', () => {
|
||||
const layer = readLayerXml(FIXTURE_XML);
|
||||
layer.spirits = layer.spirits.filter(s => s.id === '2' || s.id === '405');
|
||||
const generated = emitPrefabJson(layer);
|
||||
const expected = JSON.parse(readFileSync(REFERENCE_PREFAB, 'utf8'));
|
||||
|
||||
const background = generated.find(o => o.__type__ === 'cc.Node' && o._name === '微信登录背景');
|
||||
const backgroundExpected = expected.find(o => o.__type__ === 'cc.Node' && o._name === '微信登录背景');
|
||||
assert.ok(background);
|
||||
assert.ok(backgroundExpected);
|
||||
assert.equal(background._lpos.x, backgroundExpected._lpos.x);
|
||||
assert.equal(background._lpos.y, backgroundExpected._lpos.y);
|
||||
assert.equal(nodeComponent(generated, background, 'cc.Widget')._alignFlags, 45);
|
||||
assert.equal(nodeComponent(generated, background, 'cc.Widget')._originalWidth, 100);
|
||||
assert.equal(nodeComponent(generated, background, 'cc.Widget')._originalHeight, 100);
|
||||
assert.equal(nodeComponent(generated, background, 'cc.UITransform')._contentSize.width, 1600);
|
||||
assert.equal(nodeComponent(generated, background, 'cc.UITransform')._contentSize.height, 720);
|
||||
|
||||
const normal = generated.find(o => o.__type__ === 'cc.Node' && o._name === 'Spirit405');
|
||||
const normalExpected = expected.find(o => o.__type__ === 'cc.Node' && o._name === '渠道logo');
|
||||
assert.ok(normal);
|
||||
assert.ok(normalExpected);
|
||||
assert.equal(normal._lpos.x, normalExpected._lpos.x);
|
||||
assert.equal(normal._lpos.y, normalExpected._lpos.y);
|
||||
assert.equal(nodeComponent(generated, normal, 'cc.Widget')._alignFlags, 16);
|
||||
assert.equal(nodeComponent(generated, normal, 'cc.Widget')._horizontalCenter, 123.5);
|
||||
assert.equal(nodeComponent(generated, normal, 'cc.Widget')._verticalCenter, 0);
|
||||
assert.equal(nodeComponent(generated, normal, 'cc.Widget')._left, undefined);
|
||||
assert.equal(nodeComponent(generated, normal, 'cc.Widget')._top, undefined);
|
||||
assert.equal(nodeComponent(generated, normal, 'cc.UITransform')._contentSize.width, 59);
|
||||
assert.equal(nodeComponent(generated, normal, 'cc.UITransform')._contentSize.height, 148);
|
||||
});
|
||||
|
||||
test('PoC 阶段 3 - 渠道logo _lpos 误差 < 0.001 (bypass CLI to avoid sprite atlas dep)', () => {
|
||||
const layer = buildFilteredLayer();
|
||||
const json = emitPrefabJson(layer);
|
||||
|
||||
Reference in New Issue
Block a user