| 416 | } |
| 417 | |
| 418 | Tree BehaviorTreeFactory::createTreeFromText(const std::string& text, |
| 419 | Blackboard::Ptr blackboard) |
| 420 | { |
| 421 | // Determine the main tree from the XML before loading into the shared parser. |
| 422 | tinyxml2::XMLDocument doc; |
| 423 | doc.Parse(text.c_str(), text.size()); |
| 424 | std::string main_tree_ID; |
| 425 | if(const auto* root = doc.RootElement()) |
| 426 | { |
| 427 | main_tree_ID = detectMainTreeId(root); |
| 428 | } |
| 429 | |
| 430 | const std::string resolved_ID = loadXmlAndResolveTreeId( |
| 431 | _p->parser.get(), main_tree_ID, [&] { _p->parser->loadFromText(text); }); |
| 432 | |
| 433 | // Set the polymorphic cast registry on the blackboard (Issue #943) |
| 434 | blackboard->setPolymorphicCastRegistry(_p->polymorphic_registry); |
| 435 | |
| 436 | Tree tree = resolved_ID.empty() ? _p->parser->instantiateTree(blackboard) : |
| 437 | _p->parser->instantiateTree(blackboard, resolved_ID); |
| 438 | tree.manifests = this->manifests(); |
| 439 | tree.remapManifestPointers(); |
| 440 | return tree; |
| 441 | } |
| 442 | |
| 443 | Tree BehaviorTreeFactory::createTreeFromFile(const std::filesystem::path& file_path, |
| 444 | Blackboard::Ptr blackboard) |