fix: support multi-tree BehaviorTree XML imports

This commit is contained in:
TuxMonkey
2026-07-21 22:16:29 +08:00
parent 5cc4c73e47
commit 82374aabd2
10 changed files with 431 additions and 127 deletions

View File

@@ -11,7 +11,7 @@ import {
Zap,
type LucideIcon,
} from 'lucide-react'
import type { BehaviorNode, NodeCategory, NodeType } from '../types'
import type { BehaviorNode, CustomNodeModel, NodeCategory, NodeType } from '../types'
export interface NodeDefinition {
type: NodeType
@@ -70,6 +70,19 @@ export function createNode(type: NodeType, position = { x: 80, y: 80 }): Behavio
}
}
export function createNodeFromModel(model: CustomNodeModel, position = { x: 80, y: 80 }): BehaviorNode {
const node = createNode(model.nodeType, position)
node.data = {
...node.data,
label: model.id,
category: model.category,
registrationName: model.id,
xmlTag: model.id,
ports: Object.fromEntries(model.ports.map((port) => [port.name, port.defaultValue || ''])),
}
return node
}
export function canHaveChildren(type: NodeType) {
return !['Action', 'Condition', 'SubTree', 'AlwaysSuccess', 'AlwaysFailure'].includes(type)
}