清理冗余代码及频繁日志输出
This commit is contained in:
@@ -559,26 +559,19 @@ export function useBehaviorTreeEditor() {
|
||||
|
||||
// 全局拖拽结束处理
|
||||
const handleGlobalDragEnd = (event: DragEvent) => {
|
||||
console.log('🔚 全局拖拽结束,是否正在拖拽条件:', conditionAttachment.dragState.isDraggingCondition);
|
||||
if (conditionAttachment.dragState.isDraggingCondition) {
|
||||
setTimeout(() => {
|
||||
console.log('⏰ 延迟重置拖拽状态');
|
||||
conditionAttachment.resetDragState();
|
||||
}, 100); // 延迟重置,确保drop事件先执行
|
||||
}, 100);
|
||||
}
|
||||
};
|
||||
|
||||
// 全局拖拽监听器用于调试
|
||||
const handleGlobalDragOver = (event: DragEvent) => {
|
||||
if (conditionAttachment.dragState.isDraggingCondition) {
|
||||
console.log('🌐 全局dragover,鼠标位置:', event.clientX, event.clientY, '目标:', event.target);
|
||||
}
|
||||
// 静默处理拖拽悬停
|
||||
};
|
||||
|
||||
const handleGlobalDrop = (event: DragEvent) => {
|
||||
if (conditionAttachment.dragState.isDraggingCondition) {
|
||||
console.log('🌐 全局drop事件,目标:', event.target, '位置:', event.clientX, event.clientY);
|
||||
}
|
||||
// 静默处理拖拽放置
|
||||
};
|
||||
|
||||
document.addEventListener('load-behavior-tree-file', handleLoadBehaviorTreeFile as EventListener);
|
||||
@@ -631,30 +624,21 @@ export function useBehaviorTreeEditor() {
|
||||
clearAllConnections,
|
||||
copyToClipboard,
|
||||
saveToFile,
|
||||
// 节点选择相关
|
||||
selectNode: (nodeId: string) => {
|
||||
// 选中普通节点时,取消条件节点的选中
|
||||
appState.selectedNodeId.value = nodeId;
|
||||
appState.selectedConditionNodeId.value = null;
|
||||
console.log('🎯 选中节点:', nodeId);
|
||||
},
|
||||
selectConditionNode: (decoratorNode: any) => {
|
||||
// 选中条件节点时,取消装饰器节点的选中
|
||||
appState.selectedNodeId.value = null;
|
||||
appState.selectedConditionNodeId.value = decoratorNode.id;
|
||||
console.log('📝 选中条件节点进行编辑:', decoratorNode.attachedCondition?.name);
|
||||
},
|
||||
// 统一的属性更新方法(支持普通节点和条件节点)
|
||||
updateNodeProperty: (path: string, value: any) => {
|
||||
// 如果选中的是条件节点,更新装饰器节点的属性
|
||||
if (appState.selectedConditionNodeId.value) {
|
||||
const decoratorNode = appState.getNodeByIdLocal(appState.selectedConditionNodeId.value);
|
||||
if (decoratorNode) {
|
||||
// 使用通用方法更新属性
|
||||
const keys = path.split('.');
|
||||
let current: any = decoratorNode;
|
||||
|
||||
// 导航到目标属性的父对象
|
||||
for (let i = 0; i < keys.length - 1; i++) {
|
||||
const key = keys[i];
|
||||
if (!(key in current) || typeof current[key] !== 'object' || current[key] === null) {
|
||||
@@ -663,18 +647,13 @@ export function useBehaviorTreeEditor() {
|
||||
current = current[key];
|
||||
}
|
||||
|
||||
// 设置最终值
|
||||
const finalKey = keys[keys.length - 1];
|
||||
current[finalKey] = value;
|
||||
|
||||
console.log('📝 更新条件属性:', path, '=', value);
|
||||
}
|
||||
} else {
|
||||
// 普通节点属性更新
|
||||
nodeOps.updateNodeProperty(path, value);
|
||||
}
|
||||
},
|
||||
// 条件吸附功能
|
||||
conditionDragState: conditionAttachment.dragState,
|
||||
startConditionDrag: conditionAttachment.startConditionDrag,
|
||||
handleDecoratorDragOver: conditionAttachment.handleDecoratorDragOver,
|
||||
@@ -684,48 +663,43 @@ export function useBehaviorTreeEditor() {
|
||||
removeConditionFromDecorator: conditionAttachment.removeConditionFromDecorator,
|
||||
canAcceptCondition: conditionAttachment.canAcceptCondition,
|
||||
resetDragState: conditionAttachment.resetDragState,
|
||||
// 合并的画布拖拽处理
|
||||
|
||||
handleCanvasDrop: (event: DragEvent) => {
|
||||
// 先尝试条件拖拽处理
|
||||
if (conditionAttachment.handleCanvasDrop(event)) {
|
||||
return; // 如果是条件拖拽,直接返回
|
||||
return;
|
||||
}
|
||||
// 否则使用正常的节点拖拽处理
|
||||
nodeOps.onCanvasDrop(event);
|
||||
},
|
||||
// 条件节点拖拽处理
|
||||
|
||||
handleConditionNodeDragStart: (event: DragEvent, template: any) => {
|
||||
console.log('🎯 条件节点拖拽事件:', template.name, template.isDraggableCondition);
|
||||
if (template.isDraggableCondition) {
|
||||
conditionAttachment.startConditionDrag(event, template);
|
||||
} else {
|
||||
nodeOps.onNodeDragStart(event, template);
|
||||
}
|
||||
},
|
||||
// 节点拖拽事件处理
|
||||
|
||||
handleNodeDrop: (event: DragEvent, node: any) => {
|
||||
console.log('📦 节点拖拽放置:', node.name, node.type, 'isDraggingCondition:', conditionAttachment.dragState.isDraggingCondition);
|
||||
if (node.type === 'conditional-decorator') {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
return conditionAttachment.attachConditionToDecorator(event, node);
|
||||
}
|
||||
},
|
||||
|
||||
handleNodeDragOver: (event: DragEvent, node: any) => {
|
||||
console.log('🔄 节点拖拽悬停:', node.name, node.type, 'isDraggingCondition:', conditionAttachment.dragState.isDraggingCondition);
|
||||
if (node.type === 'conditional-decorator') {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
return conditionAttachment.handleDecoratorDragOver(event, node);
|
||||
}
|
||||
},
|
||||
|
||||
handleNodeDragLeave: (event: DragEvent, node: any) => {
|
||||
console.log('🔙 节点拖拽离开:', node.name, node.type);
|
||||
if (node.type === 'conditional-decorator') {
|
||||
conditionAttachment.handleDecoratorDragLeave(node);
|
||||
}
|
||||
},
|
||||
// Blackboard拖拽相关功能
|
||||
isBlackboardDroppable,
|
||||
isBlackboardReference,
|
||||
handleBlackboardDrop,
|
||||
@@ -733,7 +707,6 @@ export function useBehaviorTreeEditor() {
|
||||
handleBlackboardDragLeave,
|
||||
clearBlackboardReference,
|
||||
|
||||
// Blackboard常驻侧边面板功能
|
||||
blackboardCollapsed: computed({
|
||||
get: () => blackboardSidebarState.collapsed,
|
||||
set: (value: boolean) => blackboardSidebarState.collapsed = value
|
||||
|
||||
@@ -51,30 +51,6 @@ export function useBlackboard() {
|
||||
allowedValuesText: ''
|
||||
});
|
||||
|
||||
const showAddVariableDialog = ref(false);
|
||||
const editingVariable = ref<BlackboardVariable | null>(null);
|
||||
const newVariable = reactive({
|
||||
name: '',
|
||||
type: 'string' as any,
|
||||
defaultValue: '' as any,
|
||||
defaultValueText: '',
|
||||
description: '',
|
||||
group: '',
|
||||
readonly: false,
|
||||
min: undefined as number | undefined,
|
||||
max: undefined as number | undefined,
|
||||
optionsText: ''
|
||||
});
|
||||
|
||||
const showImportExportDialog = ref(false);
|
||||
const activeTab = ref('export');
|
||||
const exportData = computed(() => {
|
||||
const data = Array.from(blackboardVariables.value.values());
|
||||
return JSON.stringify(data, null, 2);
|
||||
});
|
||||
const importData = ref('');
|
||||
const clearBeforeImport = ref(false);
|
||||
|
||||
const blackboardCollapsed = ref(false);
|
||||
const blackboardTransparent = ref(true);
|
||||
|
||||
@@ -108,18 +84,6 @@ export function useBlackboard() {
|
||||
return sortedGroups;
|
||||
});
|
||||
|
||||
const groups = computed(() => {
|
||||
const groupSet = new Set<string>();
|
||||
blackboardVariables.value.forEach(variable => {
|
||||
groupSet.add(variable.group || '未分组');
|
||||
});
|
||||
return Array.from(groupSet);
|
||||
});
|
||||
|
||||
const isValidVariable = computed(() => {
|
||||
return newVariable.name.trim().length > 0;
|
||||
});
|
||||
|
||||
const groupedBlackboardVariables = () => {
|
||||
return Object.entries(blackboardVariableGroups.value);
|
||||
};
|
||||
@@ -240,31 +204,6 @@ export function useBlackboard() {
|
||||
}
|
||||
};
|
||||
|
||||
const onTypeChange = () => {
|
||||
switch (newVariable.type) {
|
||||
case 'string':
|
||||
newVariable.defaultValue = '';
|
||||
break;
|
||||
case 'number':
|
||||
newVariable.defaultValue = 0;
|
||||
break;
|
||||
case 'boolean':
|
||||
newVariable.defaultValue = false;
|
||||
break;
|
||||
case 'vector2':
|
||||
newVariable.defaultValue = { x: 0, y: 0 };
|
||||
break;
|
||||
case 'vector3':
|
||||
newVariable.defaultValue = { x: 0, y: 0, z: 0 };
|
||||
break;
|
||||
case 'object':
|
||||
case 'array':
|
||||
newVariable.defaultValue = '';
|
||||
newVariable.defaultValueText = '';
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
const saveBlackboardVariable = () => {
|
||||
if (!blackboardModalData.name.trim()) {
|
||||
alert('请输入变量名称');
|
||||
@@ -273,7 +212,6 @@ export function useBlackboard() {
|
||||
|
||||
let finalValue = blackboardModalData.defaultValue;
|
||||
|
||||
// 处理对象和数组类型的JSON格式
|
||||
if (blackboardModalData.type === 'object' || blackboardModalData.type === 'array') {
|
||||
try {
|
||||
if (typeof blackboardModalData.defaultValue === 'string') {
|
||||
@@ -290,7 +228,6 @@ export function useBlackboard() {
|
||||
if (blackboardModalData.constraints.max !== undefined) constraints.max = blackboardModalData.constraints.max;
|
||||
if (blackboardModalData.constraints.step !== undefined) constraints.step = blackboardModalData.constraints.step;
|
||||
|
||||
// 处理字符串的可选值列表
|
||||
if (blackboardModalData.useAllowedValues && blackboardModalData.allowedValuesText.trim()) {
|
||||
constraints.allowedValues = blackboardModalData.allowedValuesText
|
||||
.split('\n')
|
||||
@@ -317,7 +254,6 @@ export function useBlackboard() {
|
||||
showBlackboardModal.value = false;
|
||||
editingBlackboardVariable.value = null;
|
||||
|
||||
// 重置模态框数据
|
||||
Object.assign(blackboardModalData, {
|
||||
name: '',
|
||||
type: 'string',
|
||||
@@ -421,10 +357,6 @@ export function useBlackboard() {
|
||||
event.dataTransfer.effectAllowed = 'copy';
|
||||
};
|
||||
|
||||
const removeBlackboardVariable = (variableName: string) => {
|
||||
deleteBlackboardVariable(variableName);
|
||||
};
|
||||
|
||||
const editVariable = (variable: BlackboardVariable) => {
|
||||
editingBlackboardVariable.value = variable;
|
||||
|
||||
@@ -447,71 +379,20 @@ export function useBlackboard() {
|
||||
showBlackboardModal.value = true;
|
||||
};
|
||||
|
||||
const onBlackboardDragStart = (event: DragEvent, variable: BlackboardVariable) => {
|
||||
onVariableDragStart(event, variable);
|
||||
};
|
||||
|
||||
const closeAddVariableDialog = () => {
|
||||
showAddVariableDialog.value = false;
|
||||
editingVariable.value = null;
|
||||
};
|
||||
|
||||
const saveVariable = () => {
|
||||
saveBlackboardVariable();
|
||||
};
|
||||
|
||||
const closeImportExportDialog = () => {
|
||||
showImportExportDialog.value = false;
|
||||
};
|
||||
|
||||
const copyExportData = () => {
|
||||
navigator.clipboard.writeText(exportData.value);
|
||||
alert('已复制到剪贴板');
|
||||
};
|
||||
|
||||
const importVariables = () => {
|
||||
try {
|
||||
const data = JSON.parse(importData.value);
|
||||
if (!Array.isArray(data)) {
|
||||
throw new Error('格式错误:期望数组格式');
|
||||
}
|
||||
|
||||
if (clearBeforeImport.value) {
|
||||
blackboardVariables.value.clear();
|
||||
}
|
||||
|
||||
let importCount = 0;
|
||||
data.forEach((varData: any) => {
|
||||
if (varData.name && varData.type) {
|
||||
blackboardVariables.value.set(varData.name, varData);
|
||||
importCount++;
|
||||
}
|
||||
});
|
||||
|
||||
alert(`成功导入 ${importCount} 个变量`);
|
||||
showImportExportDialog.value = false;
|
||||
importData.value = '';
|
||||
} catch (error) {
|
||||
alert('导入失败:' + (error as Error).message);
|
||||
}
|
||||
};
|
||||
|
||||
const addBlackboardVariable = () => {
|
||||
Object.assign(newVariable, {
|
||||
editingBlackboardVariable.value = null;
|
||||
Object.assign(blackboardModalData, {
|
||||
name: '',
|
||||
type: 'string',
|
||||
defaultValue: '',
|
||||
defaultValueText: '',
|
||||
description: '',
|
||||
group: '',
|
||||
readonly: false,
|
||||
min: undefined,
|
||||
max: undefined,
|
||||
optionsText: ''
|
||||
readOnly: false,
|
||||
constraints: {},
|
||||
useAllowedValues: false,
|
||||
allowedValuesText: ''
|
||||
});
|
||||
|
||||
editingVariable.value = null;
|
||||
showAddVariableDialog.value = true;
|
||||
showBlackboardModal.value = true;
|
||||
};
|
||||
|
||||
return {
|
||||
@@ -522,17 +403,6 @@ export function useBlackboard() {
|
||||
blackboardModalData,
|
||||
expandedGroups,
|
||||
blackboardVariableGroups,
|
||||
|
||||
showAddVariableDialog,
|
||||
editingVariable,
|
||||
newVariable,
|
||||
groups,
|
||||
showImportExportDialog,
|
||||
activeTab,
|
||||
exportData,
|
||||
importData,
|
||||
clearBeforeImport,
|
||||
isValidVariable,
|
||||
blackboardCollapsed,
|
||||
blackboardTransparent,
|
||||
|
||||
@@ -549,24 +419,15 @@ export function useBlackboard() {
|
||||
addBlackboardVariable,
|
||||
saveBlackboardVariable,
|
||||
deleteBlackboardVariable,
|
||||
removeBlackboardVariable,
|
||||
removeBlackboardVariable: deleteBlackboardVariable,
|
||||
updateBlackboardVariable,
|
||||
editVariable,
|
||||
selectVariable,
|
||||
clearBlackboard,
|
||||
|
||||
closeAddVariableDialog,
|
||||
saveVariable,
|
||||
onTypeChange,
|
||||
closeImportExportDialog,
|
||||
copyExportData,
|
||||
importVariables,
|
||||
|
||||
exportBlackboard,
|
||||
importBlackboard,
|
||||
|
||||
onBlackboardDragStart,
|
||||
|
||||
onBlackboardDragStart: onVariableDragStart,
|
||||
editBlackboardVariable: editVariable,
|
||||
onBlackboardValueChange: (variable: BlackboardVariable) => {
|
||||
updateBlackboardVariable(variable.name, variable.value);
|
||||
|
||||
@@ -21,7 +21,6 @@
|
||||
<button class="tool-btn" @click="exportConfig" title="导出配置">
|
||||
<span>⚡</span> 导出配置
|
||||
</button>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<div class="toolbar-right">
|
||||
@@ -348,7 +347,8 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- 输入端口 - 执行流入口 -->
|
||||
|
||||
<!-- 输入端口 -->
|
||||
<div
|
||||
v-if="node.canHaveParent"
|
||||
class="port port-input"
|
||||
@@ -361,12 +361,12 @@
|
||||
@mousedown.stop="startConnection($event, node.id, 'input')"
|
||||
@mouseenter="onPortHover(node.id, 'input')"
|
||||
@mouseleave="onPortLeave()"
|
||||
title="执行流入口(可从此开始连接)"
|
||||
title="执行流入口"
|
||||
>
|
||||
<div class="port-inner"></div>
|
||||
</div>
|
||||
|
||||
<!-- 输出端口 - 执行流出口 -->
|
||||
<!-- 输出端口 -->
|
||||
<div
|
||||
v-if="node.canHaveChildren"
|
||||
class="port port-output"
|
||||
@@ -379,25 +379,25 @@
|
||||
@mousedown.stop="startConnection($event, node.id, 'output')"
|
||||
@mouseenter="onPortHover(node.id, 'output')"
|
||||
@mouseleave="onPortLeave()"
|
||||
title="执行流出口(可从此开始连接)"
|
||||
title="执行流出口"
|
||||
>
|
||||
<div class="port-inner"></div>
|
||||
</div>
|
||||
<!-- 子节点指示器 -->
|
||||
|
||||
<div v-if="node.children && node.children.length > 0" class="children-indicator">
|
||||
{{ node.children.length }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 网格背景 -->
|
||||
|
||||
<div class="grid-background" :style="gridStyle()"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 右侧属性面板 -->
|
||||
|
||||
<div class="properties-panel-container">
|
||||
<!-- 属性面板 -->
|
||||
|
||||
<div class="properties-panel">
|
||||
<div class="panel-header">
|
||||
<h3>⚙️ 属性面板</h3>
|
||||
@@ -488,7 +488,6 @@
|
||||
</option>
|
||||
</select>
|
||||
|
||||
<!-- Blackboard引用指示器 -->
|
||||
<div v-if="isBlackboardReference(prop.value)" class="blackboard-reference">
|
||||
<span class="ref-icon">🔗</span>
|
||||
<span class="ref-text">{{ prop.value }}</span>
|
||||
@@ -513,7 +512,6 @@
|
||||
</div>
|
||||
|
||||
|
||||
<!-- 行为树结构面板 -->
|
||||
<div class="tree-structure-panel" v-if="rootNode()">
|
||||
<div class="panel-header">
|
||||
<h3>🌲 树结构</h3>
|
||||
@@ -528,13 +526,13 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 验证结果 -->
|
||||
|
||||
<div v-if="!validationResult().isValid" class="validation-error">
|
||||
<span class="error-icon">⚠️</span>
|
||||
<span>{{ validationResult().message }}</span>
|
||||
</div>
|
||||
|
||||
<!-- Blackboard变量编辑模态框 -->
|
||||
|
||||
<div v-if="showBlackboardModal" class="modal-overlay" @click="showBlackboardModal = false">
|
||||
<div class="modal-content blackboard-modal" @click.stop>
|
||||
<div class="modal-header">
|
||||
@@ -619,7 +617,6 @@
|
||||
>
|
||||
</div>
|
||||
|
||||
<!-- 约束设置 -->
|
||||
<div v-if="blackboardModalData.type === 'number'" class="form-group">
|
||||
<label>数值约束:</label>
|
||||
<div class="constraint-inputs">
|
||||
@@ -665,7 +662,7 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Blackboard常驻侧边面板 -->
|
||||
|
||||
<div class="blackboard-sidebar"
|
||||
:class="{
|
||||
'collapsed': blackboardCollapsed,
|
||||
@@ -674,7 +671,6 @@
|
||||
@mouseenter="blackboardTransparent = false"
|
||||
@mouseleave="blackboardTransparent = true">
|
||||
|
||||
<!-- 收缩/展开按钮 -->
|
||||
<button class="blackboard-toggle"
|
||||
@click="blackboardCollapsed = !blackboardCollapsed"
|
||||
:title="blackboardCollapsed ? '展开 Blackboard' : '收缩 Blackboard'">
|
||||
@@ -682,19 +678,16 @@
|
||||
<span v-else>◀</span>
|
||||
</button>
|
||||
|
||||
<!-- 面板内容 -->
|
||||
<div class="blackboard-content" v-show="!blackboardCollapsed">
|
||||
<div class="blackboard-header">
|
||||
<h3>📋 Blackboard</h3>
|
||||
</div>
|
||||
|
||||
<!-- Blackboard操作按钮 -->
|
||||
<div class="blackboard-actions">
|
||||
<button @click="showBlackboardModal = true" class="add-var-btn">+ 添加变量</button>
|
||||
<button @click="clearBlackboard" v-if="blackboardVariables.length > 0" class="clear-btn">清空</button>
|
||||
</div>
|
||||
|
||||
<!-- Blackboard变量列表 -->
|
||||
<div class="blackboard-scroll-area">
|
||||
<div v-if="blackboardVariables.length > 0" class="blackboard-groups">
|
||||
<div
|
||||
@@ -740,7 +733,6 @@
|
||||
<span v-else class="value-display">{{ getDisplayValue(variable) }}</span>
|
||||
</div>
|
||||
|
||||
<!-- 约束显示 -->
|
||||
<div v-if="variable.constraints && hasVisibleConstraints(variable)" class="variable-constraints">
|
||||
<small>{{ formatConstraints(variable.constraints) }}</small>
|
||||
</div>
|
||||
@@ -749,7 +741,6 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 空状态 -->
|
||||
<div v-else class="empty-blackboard">
|
||||
<div class="empty-icon">📋</div>
|
||||
<p>还没有定义任何变量</p>
|
||||
@@ -761,7 +752,6 @@
|
||||
|
||||
|
||||
|
||||
<!-- 导出模态框 -->
|
||||
<div v-if="showExportModal" class="modal-overlay" @click="showExportModal = false">
|
||||
<div class="modal-content" @click.stop>
|
||||
<div class="modal-header">
|
||||
|
||||
Reference in New Issue
Block a user