fix: debug 工具改用 query-node-tree 替换不存在的 query-hierarchy
This commit is contained in:
100
dist/tools/debug-tools.js
vendored
100
dist/tools/debug-tools.js
vendored
File diff suppressed because one or more lines are too long
@@ -268,52 +268,69 @@ export class DebugTools implements ToolExecutor {
|
||||
|
||||
private async getNodeTree(rootUuid?: string, maxDepth: number = 10): Promise<ToolResponse> {
|
||||
return new Promise((resolve) => {
|
||||
const buildTree = async (nodeUuid: string, depth: number = 0): Promise<any> => {
|
||||
const mapTree = (node: any, depth: number = 0): any => {
|
||||
if (depth >= maxDepth) {
|
||||
return { truncated: true };
|
||||
}
|
||||
|
||||
try {
|
||||
const nodeData = await Editor.Message.request('scene', 'query-node', nodeUuid);
|
||||
|
||||
const tree = {
|
||||
uuid: nodeData.uuid,
|
||||
name: nodeData.name,
|
||||
active: nodeData.active,
|
||||
components: (nodeData as any).components ? (nodeData as any).components.map((c: any) => c.__type__) : [],
|
||||
childCount: nodeData.children ? nodeData.children.length : 0,
|
||||
children: [] as any[]
|
||||
};
|
||||
|
||||
if (nodeData.children && nodeData.children.length > 0) {
|
||||
for (const childId of nodeData.children) {
|
||||
const childTree = await buildTree(childId, depth + 1);
|
||||
tree.children.push(childTree);
|
||||
}
|
||||
}
|
||||
|
||||
return tree;
|
||||
} catch (err: any) {
|
||||
return { error: err.message };
|
||||
if (!node) {
|
||||
return null;
|
||||
}
|
||||
const children = Array.isArray(node.children) ? node.children : [];
|
||||
return {
|
||||
uuid: node.uuid,
|
||||
name: node.name,
|
||||
active: node.active,
|
||||
components: Array.isArray(node.components)
|
||||
? node.components.map((c: any) => c.__type__ || c.type || c.cid).filter((x: any) => x)
|
||||
: [],
|
||||
childCount: children.length,
|
||||
children: children.map((c: any) => mapTree(c, depth + 1))
|
||||
};
|
||||
};
|
||||
|
||||
if (rootUuid) {
|
||||
buildTree(rootUuid).then(tree => {
|
||||
resolve({ success: true, data: tree });
|
||||
});
|
||||
} else {
|
||||
Editor.Message.request('scene', 'query-hierarchy').then(async (hierarchy: any) => {
|
||||
const trees = [];
|
||||
for (const rootNode of hierarchy.children) {
|
||||
const tree = await buildTree(rootNode.uuid);
|
||||
trees.push(tree);
|
||||
const findInTree = (node: any, uuid: string): any => {
|
||||
if (!node) {
|
||||
return null;
|
||||
}
|
||||
if (node.uuid === uuid) {
|
||||
return node;
|
||||
}
|
||||
const children = Array.isArray(node.children) ? node.children : [];
|
||||
for (const child of children) {
|
||||
const found = findInTree(child, uuid);
|
||||
if (found) {
|
||||
return found;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
// 'query-hierarchy' 在 3.8.x 不存在,统一使用已验证可用的 'query-node-tree'
|
||||
Editor.Message.request('scene', 'query-node-tree').then((tree: any) => {
|
||||
if (rootUuid) {
|
||||
const roots = Array.isArray(tree) ? tree : [tree];
|
||||
let target: any = null;
|
||||
for (const root of roots) {
|
||||
target = findInTree(root, rootUuid);
|
||||
if (target) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!target) {
|
||||
resolve({ success: false, error: `Node not found: ${rootUuid}` });
|
||||
return;
|
||||
}
|
||||
resolve({ success: true, data: mapTree(target, 0) });
|
||||
} else {
|
||||
const roots = Array.isArray(tree)
|
||||
? tree
|
||||
: (tree && Array.isArray(tree.children) ? tree.children : (tree ? [tree] : []));
|
||||
const trees = roots.map((root: any) => mapTree(root, 0));
|
||||
resolve({ success: true, data: trees });
|
||||
}).catch((err: Error) => {
|
||||
resolve({ success: false, error: err.message });
|
||||
});
|
||||
}
|
||||
}
|
||||
}).catch((err: Error) => {
|
||||
resolve({ success: false, error: err.message });
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -359,8 +376,11 @@ export class DebugTools implements ToolExecutor {
|
||||
|
||||
// Check for performance issues
|
||||
if (options.checkPerformance) {
|
||||
const hierarchy = await Editor.Message.request('scene', 'query-hierarchy');
|
||||
const nodeCount = this.countNodes(hierarchy.children);
|
||||
const hierarchy: any = await Editor.Message.request('scene', 'query-node-tree');
|
||||
const roots = Array.isArray(hierarchy)
|
||||
? hierarchy
|
||||
: (hierarchy && Array.isArray(hierarchy.children) ? hierarchy.children : []);
|
||||
const nodeCount = this.countNodes(roots);
|
||||
|
||||
if (nodeCount > 1000) {
|
||||
issues.push({
|
||||
|
||||
Reference in New Issue
Block a user