From 950ba4581cb87b99019cf3081792492bd843a60c Mon Sep 17 00:00:00 2001 From: Joywayer Date: Wed, 2 Sep 2026 08:36:51 +0800 Subject: [PATCH] =?UTF-8?q?fix(scripts):=20emitPrefabJson=20rootNode.=5Fch?= =?UTF-8?q?ildren=20=E5=BF=85=E9=A1=BB=E5=8C=85=E5=90=AB=20group-X=20?= =?UTF-8?q?=E8=8A=82=E7=82=B9=20(Task=209=20fix=20round=201)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../legacy-layer-migration/poc-iconbutton.test.mjs | 13 +++++++++++++ .../scripts/legacy-layer-to-cocos-prefab.mjs | 4 +++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/cocoscreator_projects/framework-tests/legacy-layer-migration/poc-iconbutton.test.mjs b/cocoscreator_projects/framework-tests/legacy-layer-migration/poc-iconbutton.test.mjs index 2af0c8b..1391949 100644 --- a/cocoscreator_projects/framework-tests/legacy-layer-migration/poc-iconbutton.test.mjs +++ b/cocoscreator_projects/framework-tests/legacy-layer-migration/poc-iconbutton.test.mjs @@ -28,4 +28,17 @@ test('Layer00619 端到端生成 + 校验关键字段', () => { // 校验含 group-55 父节点 (BackHall_Layer.xml Spirit BelongGroupID=55). const groupNode = json.find(o => o.__type__ === 'cc.Node' && o._name === 'group-55'); assert.ok(groupNode, '应有 group-55 父节点'); +}); + +test('Layer00619 端到端 - root._children 包含 group-55', () => { + execSync(`${CLI} ${INPUT} ${TARGET} ${OUTPUT_DIR}`, { stdio: 'pipe' }); + const json = JSON.parse(readFileSync(OUTPUT, 'utf8')); + const rootNode = json.find(o => o.__type__ === 'cc.Node' && o._name === 'BackHall_Layer'); + const groupNode = json.find(o => o.__type__ === 'cc.Node' && o._name === 'group-55'); + assert.ok(rootNode, '应有 root node'); + assert.ok(groupNode, '应有 group-55 node'); + // The fix: root._children must reference group-55 + const childIds = (rootNode._children || []).map(c => c.__id__); + assert.ok(childIds.includes(json.indexOf(groupNode)), + `root._children must include group-55 reference; got [${childIds.join(', ')}]`); }); \ No newline at end of file diff --git a/cocoscreator_projects/scripts/legacy-layer-to-cocos-prefab.mjs b/cocoscreator_projects/scripts/legacy-layer-to-cocos-prefab.mjs index 25c940d..2e0cf0a 100644 --- a/cocoscreator_projects/scripts/legacy-layer-to-cocos-prefab.mjs +++ b/cocoscreator_projects/scripts/legacy-layer-to-cocos-prefab.mjs @@ -614,7 +614,9 @@ export function emitPrefabJson(layer) { for (const g of groupParents) { const node = makeNode(g.name, { __id__: rootId }); out.push(node); - groupInfo.push({ group: g, node, nodeId: out.length - 1 }); + const nodeId = out.length - 1; + rootNode._children.push({ __id__: nodeId }); // wire group node into root._children (Task 9 fix round 1) + groupInfo.push({ group: g, node, nodeId }); } // ── 4. Spirit 子节点 + 组件 ────────────────────────────────────