Files
joywayerandClaude Opus 5 02dc5d51ca chore(spec): 综合清理 + legacy-layer 迁移 spec/plan/data
主要改动:
- 切到 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>
2026-09-02 07:36:54 +08:00

57 lines
2.3 KiB
JavaScript

/**
* 坐标换算与锚点推断。见 spec §2。
* 旧引擎:原点左上、Y 向下、精灵锚点左上。
* Cocos:原点在父节点中心、Y 向上、节点锚点 (0.5, 0.5)。
*/
// 旧 UI 内容区基准(数据源事实,不可变)。
// 991 个对象的 Left/Top 都是相对旧引擎 1280×720 画布给出的,坐标换算、三区锚点、
// 满屏/越界判断都据此判定。它与「设计分辨率画布宽度」是两回事,见 CANVAS_WIDTH。
export const DESIGN_WIDTH = 1280;
export const DESIGN_HEIGHT = 720;
// Cocos 设计分辨率画布(20:9 主流移动端比例)。落地时 Layer/Group 根节点据此设定
// UITransform 尺寸,运行时 Canvas 按 designResolution + fitHeight 对齐到屏幕。
// 对象坐标与 Widget 值仍以 DESIGN_WIDTH 为基准——靠左贴左、靠右贴右、居中在中心,
// 画布变宽由 Widget 弹性贴边消化,无需重算坐标。
export const CANVAS_WIDTH = 1600;
export const CANVAS_HEIGHT = 720;
const HALF_W = DESIGN_WIDTH / 2;
const HALF_H = DESIGN_HEIGHT / 2;
const LEFT_ZONE = DESIGN_WIDTH / 4; // 320
const RIGHT_ZONE = (DESIGN_WIDTH * 3) / 4; // 960
/** 左上坐标 → Cocos 中心锚点坐标。spec §2.2。 */
export function toCocosPosition(left, top, width, height) {
return {
x: left + width / 2 - HALF_W,
y: HALF_H - top - height / 2,
};
}
/**
* 水平锚点三区推断。spec §2.3。
* fitHeight 下垂直方向永远精确撑满,故不推断垂直锚点。
*/
export function inferWidget(left, width) {
const cx = left + width / 2;
if (cx < LEFT_ZONE) return { horizontal: 'left', left };
if (cx > RIGHT_ZONE) return { horizontal: 'right', right: DESIGN_WIDTH - (left + width) };
return { horizontal: 'center', horizontalCenter: cx - HALF_W };
}
/** 背景与遮罩:四边拉伸。spec §2.4。 */
export function stretchWidget() {
return { horizontal: 'stretch', vertical: 'stretch', left: 0, right: 0, top: 0, bottom: 0 };
}
export function isFullScreen(width, height) {
return width >= DESIGN_WIDTH && height >= DESIGN_HEIGHT;
}
/** 坐标超出画布。spec §2.5:不裁剪,只标记。 */
export function isOffscreen(left, top, width, height) {
return left < 0 || top < 0 || left + width > DESIGN_WIDTH || top + height > DESIGN_HEIGHT;
}