支持在通信节点右键菜单中挂载行为树

This commit is contained in:
2026-04-14 15:09:50 +08:00
parent 835bb56851
commit 2b2a11831d
3 changed files with 173 additions and 4 deletions

View File

@@ -64,7 +64,7 @@ import { createGraphScenarioElement, createGraphTaskElementFromScenario } from '
import PlatformCard from './platform-card.vue';
import NodesCard from './nodes-card.vue';
import { findOneScenarioById, saveScenario } from './api';
import { findOneScenarioById, saveScenario, getAllBehaviorTreesBySceneId } from './api';
import { resolveConnectionRelation } from './relation';
const TeleportContainer = defineComponent(getTeleport());
@@ -211,7 +211,7 @@ export default defineComponent({
}
};
const handleSelect = (scenario: Scenario) => {
const handleSelect = async (scenario: Scenario) => {
let nodeGraph: GraphContainer | null = null;
try {
nodeGraph = JSON.parse(scenario.communicationGraph as unknown as string) as unknown as GraphContainer;
@@ -230,6 +230,27 @@ export default defineComponent({
relations: []
};
currentScenarioEditing.value = true;
// 将场景ID存储到graph对象中,供子组件访问
if (graph.value) {
(graph.value as any).currentScenario = currentScenario.value;
// 加载该场景下的行为树列表
try {
const response = await getAllBehaviorTreesBySceneId(scenario.id);
if (response.code === 200 && response.data) {
(graph.value as any).behaviorTrees = response.data;
console.log(`加载场景${scenario.id}的行为树列表:`, response.data.length, '个');
} else {
(graph.value as any).behaviorTrees = [];
console.warn('获取行为树列表失败:', response.msg);
}
} catch (error) {
console.error('获取行为树列表失败:', error);
(graph.value as any).behaviorTrees = [];
}
}
createElements();
};
@@ -277,6 +298,12 @@ export default defineComponent({
nodes: [],
},
};
// 清空graph中的场景信息
if (graph.value) {
(graph.value as any).currentScenario = null;
}
currentGraph.value = {
edges: [],
nodes: [],