主要改动: - 切到 funplay-cocos-mcp v0.5.1 (用户级配置, 项目级 .mcp.json 删除) - 仓库文档/CLAUDE.md/.gitignore 等清理过时 cocos-mcp-server 引用 - memory 文件同步: cocos-mcp-setup/path/blocker/spriteframe-uuid/prefab-persist 等加 funplay 实测警告 - memory 新建 funplay-cocos-mcp-pending-verification.md (后已被实测覆盖) - spec/plan/data: - docs/superpowers/specs/2026-09-02-legacy-layer-migration-design.md - docs/superpowers/plans/2026-09-02-legacy-layer-migration.md - docs/superpowers/data/layer-spirit-summary.json - YouleNexus: profiles.ts / defaults.ts / PlayerInfoView.prefab / scene 改动 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
84 lines
3.2 KiB
JavaScript
84 lines
3.2 KiB
JavaScript
import { test } from 'node:test';
|
||
import assert from 'node:assert/strict';
|
||
import {
|
||
DESIGN_WIDTH, DESIGN_HEIGHT, CANVAS_WIDTH, CANVAS_HEIGHT,
|
||
toCocosPosition, inferWidget, stretchWidget, isFullScreen, isOffscreen,
|
||
} from '../ui-migration/coords.mjs';
|
||
|
||
test('内容区基准保持 1280x720(数据源事实,不随设计分辨率改变)', () => {
|
||
assert.equal(DESIGN_WIDTH, 1280);
|
||
assert.equal(DESIGN_HEIGHT, 720);
|
||
});
|
||
|
||
test('设计分辨率画布为 1600x720(20:9 主流移动端比例)', () => {
|
||
assert.equal(CANVAS_WIDTH, 1600);
|
||
assert.equal(CANVAS_HEIGHT, 720);
|
||
});
|
||
|
||
test('内容区基准与设计分辨率画布是两个独立常量', () => {
|
||
// 坐标/三区/满屏/越界用 DESIGN_WIDTH(1280);落地 Layer/Group 尺寸用 CANVAS_WIDTH(1600)。
|
||
assert.notEqual(DESIGN_WIDTH, CANVAS_WIDTH);
|
||
});
|
||
|
||
test('toCocosPosition 用 spec 的验算样例', () => {
|
||
// spec §1.2: Left=320 Top=200 150x70 → x=-245 y=125
|
||
assert.deepEqual(toCocosPosition(320, 200, 150, 70), { x: -245, y: 125 });
|
||
});
|
||
|
||
test('toCocosPosition 左上角对象落在画布左上', () => {
|
||
// 0,0 的 100x50 → 中心在 (50,25) → x=50-640=-590, y=360-25=335
|
||
assert.deepEqual(toCocosPosition(0, 0, 100, 50), { x: -590, y: 335 });
|
||
});
|
||
|
||
test('toCocosPosition 满屏对象落在原点', () => {
|
||
assert.deepEqual(toCocosPosition(0, 0, 1280, 720), { x: 0, y: 0 });
|
||
});
|
||
|
||
test('inferWidget 中心点在左区 → 锚左', () => {
|
||
// cx = 10+100/2 = 60 < 320
|
||
assert.deepEqual(inferWidget(10, 100), { horizontal: 'left', left: 10 });
|
||
});
|
||
|
||
test('inferWidget 中心点在右区 → 锚右', () => {
|
||
// cx = 1100+100/2 = 1150 > 960;right = 1280 - 1200 = 80
|
||
assert.deepEqual(inferWidget(1100, 100), { horizontal: 'right', right: 80 });
|
||
});
|
||
|
||
test('inferWidget 中心点在中区 → 水平居中', () => {
|
||
// cx = 320+150/2 = 395 ∈ [320,960];horizontalCenter = 395-640 = -245
|
||
assert.deepEqual(inferWidget(320, 150), { horizontal: 'center', horizontalCenter: -245 });
|
||
});
|
||
|
||
test('inferWidget 分界值 320 与 960 归入中区(非严格小于/大于才算边区)', () => {
|
||
// cx 恰为 320:不满足 < 320 → 中区
|
||
assert.equal(inferWidget(220, 200).horizontal, 'center');
|
||
// cx 恰为 960:不满足 > 960 → 中区
|
||
assert.equal(inferWidget(860, 200).horizontal, 'center');
|
||
});
|
||
|
||
test('inferWidget 屏外负坐标自然落入左区', () => {
|
||
// cx = -286+100/2 = -236 < 320
|
||
assert.equal(inferWidget(-286, 100).horizontal, 'left');
|
||
});
|
||
|
||
test('stretchWidget 四边全 0', () => {
|
||
assert.deepEqual(stretchWidget(), {
|
||
horizontal: 'stretch', vertical: 'stretch', left: 0, right: 0, top: 0, bottom: 0,
|
||
});
|
||
});
|
||
|
||
test('isFullScreen 只认 >= 设计分辨率', () => {
|
||
assert.equal(isFullScreen(1280, 720), true);
|
||
assert.equal(isFullScreen(1300, 800), true);
|
||
assert.equal(isFullScreen(1279, 720), false);
|
||
assert.equal(isFullScreen(1280, 719), false);
|
||
});
|
||
|
||
test('isOffscreen 识别越界对象', () => {
|
||
assert.equal(isOffscreen(0, 0, 1280, 720), false, '恰好满屏不算越界');
|
||
assert.equal(isOffscreen(-286, 100, 50, 50), true, '左越界');
|
||
assert.equal(isOffscreen(100, -318, 50, 50), true, '上越界');
|
||
assert.equal(isOffscreen(1260, 100, 50, 50), true, '右越界');
|
||
assert.equal(isOffscreen(100, 700, 50, 50), true, '下越界');
|
||
});
|