|
|
@@ -892,20 +892,22 @@ export class BlockManager extends Component {
|
|
|
// 检查根节点是否有B1子节点,如果有,则B1是实际的形状根节点
|
|
|
const b1Node = block.getChildByName('B1');
|
|
|
if (b1Node) {
|
|
|
- // B1节点作为(0,0)位置
|
|
|
+ // B1节点作为形状的根节点和坐标原点(0,0)
|
|
|
+ // 将B1节点本身添加为第一个部分
|
|
|
parts.push({ node: b1Node, x: 0, y: 0 });
|
|
|
- this.findBlockParts(b1Node, parts, 0, 0);
|
|
|
+ // 然后递归查找B1的子节点,但要避免重复添加B1本身
|
|
|
+ this.findBlockParts(b1Node, parts, 0, 0, true);
|
|
|
} else {
|
|
|
- // 没有B1节点,使用根节点
|
|
|
+ // 没有B1节点,使用根节点作为形状根节点
|
|
|
parts.push({ node: block, x: 0, y: 0 });
|
|
|
- this.findBlockParts(block, parts, 0, 0);
|
|
|
+ this.findBlockParts(block, parts, 0, 0, false);
|
|
|
}
|
|
|
|
|
|
return parts;
|
|
|
}
|
|
|
|
|
|
// 递归查找方块的所有部分
|
|
|
- findBlockParts(node: Node, result: { node: Node, x: number, y: number }[], parentX: number, parentY: number) {
|
|
|
+ findBlockParts(node: Node, result: { node: Node, x: number, y: number }[], parentX: number, parentY: number, skipRoot: boolean = false) {
|
|
|
for (let i = 0; i < node.children.length; i++) {
|
|
|
const child = node.children[i];
|
|
|
|
|
|
@@ -928,10 +930,14 @@ export class BlockManager extends Component {
|
|
|
x = parentX + relativeX;
|
|
|
y = parentY + relativeY;
|
|
|
|
|
|
- result.push({ node: child, x, y });
|
|
|
+ // 避免重复添加已经在result中的节点
|
|
|
+ const existingPart = result.find(part => part.node === child);
|
|
|
+ if (!existingPart) {
|
|
|
+ result.push({ node: child, x, y });
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- this.findBlockParts(child, result, x, y);
|
|
|
+ this.findBlockParts(child, result, x, y, false);
|
|
|
}
|
|
|
}
|
|
|
|