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

Function convert_single_node

convert_v3_to_v4.py:35–90  ·  view source on GitHub ↗

converts a leaf node from V3 to V4. Args: node (ET.Element): the node to convert.

(node: ET.Element)

Source from the content-addressed store, hash-verified

33
34
35def convert_single_node(node: ET.Element) -> None:
36 """converts a leaf node from V3 to V4.
37 Args:
38 node (ET.Element): the node to convert.
39 """
40 if node.tag == "root":
41 node.attrib["BTCPP_format"] = "4"
42
43 def convert_no_warn(node_type: str, v3_name: str, v4_name: str):
44 if node.tag == v3_name:
45 node.tag = v4_name
46 elif (
47 (node.tag == node_type)
48 and ("ID" in node.attrib)
49 and (node.attrib["ID"] == v3_name)
50 ):
51 node.attrib["ID"] = v3_name
52
53 original_attrib = copy.copy(node.attrib)
54 convert_no_warn("Control", "SequenceStar", "SequenceWithMemory")
55
56 if node.tag == "SubTree":
57 logger.info(
58 "SubTree is now deprecated, auto converting to V4 SubTree"
59 " (formerly known as SubTreePlus)"
60 )
61 for key, val in original_attrib.items():
62 if key == "__shared_blackboard" and strtobool(val):
63 logger.warning(
64 "__shared_blackboard for subtree is deprecated"
65 ", using _autoremap instead."
66 " Some behavior may change!"
67 )
68 node.attrib.pop(key)
69 node.attrib["_autoremap"] = "1"
70 elif key == "ID":
71 pass
72 else:
73 node.attrib[key] = f"{{{val}}}"
74
75 elif node.tag == "SubTreePlus":
76 node.tag = "SubTree"
77 for key, val in original_attrib.items():
78 if key == "__autoremap":
79 node.attrib.pop(key)
80 node.attrib["_autoremap"] = val
81
82 for key in node.attrib:
83 if key in SCRIPT_DIRECTIVES:
84 logging.error(
85 "node %s%s has port %s, this is reserved for scripts in V4."
86 " Please edit the node before converting to V4.",
87 node.tag,
88 f" with ID {node.attrib['ID']}" if "ID" in node.attrib else "",
89 key,
90 )
91
92

Callers 1

recurseFunction · 0.85

Calls 4

convert_no_warnFunction · 0.85
strtoboolFunction · 0.85
popMethod · 0.80
copyMethod · 0.45

Tested by

no test coverage detected