Extract the main tree ID from an XML root element. Checks main_tree_to_execute attribute first, then falls back to the single BehaviorTree ID if only one is defined.
| 30 | // Checks main_tree_to_execute attribute first, then falls back to the |
| 31 | // single BehaviorTree ID if only one is defined. |
| 32 | std::string detectMainTreeId(const tinyxml2::XMLElement* xml_root) |
| 33 | { |
| 34 | if(const auto* attr = xml_root->Attribute("main_tree_to_execute")) |
| 35 | { |
| 36 | return attr; |
| 37 | } |
| 38 | int bt_count = 0; |
| 39 | std::string single_id; |
| 40 | for(const auto* bt_elem = xml_root->FirstChildElement("BehaviorTree"); |
| 41 | bt_elem != nullptr; bt_elem = bt_elem->NextSiblingElement("BehaviorTree")) |
| 42 | { |
| 43 | bt_count++; |
| 44 | if(const auto* tree_id = bt_elem->Attribute("ID")) |
| 45 | { |
| 46 | single_id = tree_id; |
| 47 | } |
| 48 | } |
| 49 | if(bt_count == 1 && !single_id.empty()) |
| 50 | { |
| 51 | return single_id; |
| 52 | } |
| 53 | return {}; |
| 54 | } |
| 55 | |
| 56 | // Load XML into parser and resolve which tree to instantiate. |
| 57 | // Returns the resolved tree ID (may be empty if parser should use default). |
no test coverage detected