feat(scripts): computeLpos / computeContentSize - 锚点转换公式(实测验证)
This commit is contained in:
+50
@@ -0,0 +1,50 @@
|
||||
import { test } from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { computeLpos, computeContentSize } from '../../scripts/legacy-layer-to-cocos-prefab.mjs';
|
||||
|
||||
test('computeLpos 锚点转换(实测验证:渠道logo)', () => {
|
||||
const spirit = { x: '734', y: '143', w: '59', h: '148' };
|
||||
const lpos = computeLpos(spirit);
|
||||
// x = 734 + 59/2 - 640 = 123.5
|
||||
// y = 360 - (143 + 148/2) = 143
|
||||
assert.equal(lpos.x, 123.5);
|
||||
assert.equal(lpos.y, 143);
|
||||
assert.equal(lpos.z, 0);
|
||||
});
|
||||
|
||||
test('computeLpos 锚点转换(实测验证:游客登录)', () => {
|
||||
const spirit = { x: '540', y: '388', w: '320', h: '95' };
|
||||
const lpos = computeLpos(spirit);
|
||||
// x = 540 + 160 - 640 = 60
|
||||
// y = 360 - (388 + 47.5) = -75.5
|
||||
assert.equal(lpos.x, 60);
|
||||
assert.equal(lpos.y, -75.5);
|
||||
});
|
||||
|
||||
test('computeLpos 字符串转数字(X/Y 为字符串 "0"/"-100")', () => {
|
||||
const spirit = { x: '0', y: '-100', w: '100', h: '100' };
|
||||
const lpos = computeLpos(spirit);
|
||||
// x = 0 + 50 - 640 = -590
|
||||
// y = 360 - (-100 + 50) = 410
|
||||
assert.equal(lpos.x, -590);
|
||||
assert.equal(lpos.y, 410);
|
||||
});
|
||||
|
||||
test('computeContentSize 直接读 Width/Height(SizeCalcMode=0 路径)', () => {
|
||||
const spirit = { w: '320', h: '95', sizeCalcMode: '0' };
|
||||
const size = computeContentSize(spirit);
|
||||
assert.equal(size.width, 320);
|
||||
assert.equal(size.height, 95);
|
||||
});
|
||||
|
||||
test('computeContentSize 默认 SizeCalcMode=0(字段缺失视作 0)', () => {
|
||||
const spirit = { w: '100', h: '50' }; // no sizeCalcMode
|
||||
const size = computeContentSize(spirit);
|
||||
assert.equal(size.width, 100);
|
||||
assert.equal(size.height, 50);
|
||||
});
|
||||
|
||||
test('computeContentSize SizeCalcMode=1 → throw(不静默)', () => {
|
||||
const spirit = { w: '100', h: '50', sizeCalcMode: '1' };
|
||||
assert.throws(() => computeContentSize(spirit), /SizeCalcMode=1.*reverse gameabc\.min\.js/);
|
||||
});
|
||||
Reference in New Issue
Block a user