MCPcopy Create free account
hub / github.com/BehaviorTree/BehaviorTree.CPP / loadSubstitutionRuleFromJSON

Method loadSubstitutionRuleFromJSON

src/bt_factory.cpp:520–571  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

518}
519
520void BehaviorTreeFactory::loadSubstitutionRuleFromJSON(const std::string& json_text)
521{
522 auto const json = nlohmann::json::parse(json_text);
523
524 std::unordered_map<std::string, TestNodeConfig> configs;
525
526 // TestNodeConfigs is optional: users may only have string-based
527 // substitution rules that map to already-registered node types.
528 if(json.contains("TestNodeConfigs"))
529 {
530 auto test_configs = json.at("TestNodeConfigs");
531 for(auto const& [name, test_config] : test_configs.items())
532 {
533 auto& config = configs[name];
534
535 auto return_status = test_config.at("return_status").get<std::string>();
536 config.return_status = convertFromString<NodeStatus>(return_status);
537 if(test_config.contains("async_delay"))
538 {
539 config.async_delay =
540 std::chrono::milliseconds(test_config["async_delay"].get<int>());
541 }
542 if(test_config.contains("post_script"))
543 {
544 config.post_script = test_config["post_script"].get<std::string>();
545 }
546 if(test_config.contains("success_script"))
547 {
548 config.success_script = test_config["success_script"].get<std::string>();
549 }
550 if(test_config.contains("failure_script"))
551 {
552 config.failure_script = test_config["failure_script"].get<std::string>();
553 }
554 }
555 }
556
557 auto substitutions = json.at("SubstitutionRules");
558 for(auto const& [node_name, test] : substitutions.items())
559 {
560 auto test_name = test.get<std::string>();
561 auto it = configs.find(test_name);
562 if(it == configs.end())
563 {
564 addSubstitutionRule(node_name, test_name);
565 }
566 else
567 {
568 addSubstitutionRule(node_name, it->second);
569 }
570 }
571}
572
573const std::unordered_map<std::string, BehaviorTreeFactory::SubstitutionRule>&
574BehaviorTreeFactory::substitutionRules() const

Callers 2

TESTFunction · 0.80
mainFunction · 0.80

Calls 2

parseFunction · 0.85
endMethod · 0.45

Tested by 1

TESTFunction · 0.64