MCPcopy Create free account
hub / github.com/OpenStarbound/OpenStarbound / behaviorNode

Method behaviorNode

source/game/StarBehaviorDatabase.cpp:252–296  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

250}
251
252BehaviorNodeConstPtr BehaviorDatabase::behaviorNode(Json const& json, StringMap<NodeParameterValue> const& treeParameters, BehaviorTree& tree) const {
253 BehaviorNodeType type = BehaviorNodeTypeNames.getLeft(json.getString("type"));
254
255 auto name = json.getString("name");
256 auto parameterConfig = json.getObject("parameters", {});
257
258 if (type == BehaviorNodeType::Module) {
259 // merge in module parameters to a copy of the treeParameters to propagate
260 // tree parameters into the sub-tree, but allow modules to override
261 auto moduleParameters = treeParameters;
262 for (auto p : parameterConfig)
263 moduleParameters.set(p.first, replaceBehaviorTag(nodeParameterValueFromJson(p.second), treeParameters));
264
265 BehaviorTree module = *buildTree(m_configs.get(name), moduleParameters);
266 tree.scripts.addAll(module.scripts);
267 tree.functions.addAll(module.functions);
268
269 return module.root;
270 }
271
272 StringMap<NodeParameter> parameters = m_nodeParameters.get(name);
273 for (auto& p : parameters)
274 p.second.second = parameterConfig.maybe(p.first).apply(nodeParameterValueFromJson).value(p.second.second);
275 applyTreeParameters(parameters, treeParameters);
276
277 if (type == BehaviorNodeType::Action) {
278 tree.functions.add(name);
279
280 Json outputConfig = json.getObject("output", {});
281 StringMap<NodeOutput> output = m_nodeOutput.get(name);
282 for (auto& p : output)
283 p.second.second.first = replaceOutputBehaviorTag(outputConfig.optString(p.first).orMaybe(p.second.second.first), treeParameters);
284
285 return make_shared<BehaviorNode>(ActionNode(name, parameters, output));
286 } else if (type == BehaviorNodeType::Decorator) {
287 tree.functions.add(name);
288 BehaviorNodeConstPtr child = behaviorNode(json.get("child"), treeParameters, tree);
289 return make_shared<BehaviorNode>(DecoratorNode(name, parameters, child));
290 } else if (type == BehaviorNodeType::Composite) {
291 return make_shared<BehaviorNode>(compositeNode(json, parameters, treeParameters, tree));
292 }
293
294 // above statement must be exhaustive
295 throw StarException(strf("Behavior node type '{}' could not be created from JSON", BehaviorNodeTypeNames.getRight(type)));
296}
297
298}

Callers

nothing calls this directly

Calls 15

replaceBehaviorTagFunction · 0.85
applyTreeParametersFunction · 0.85
replaceOutputBehaviorTagFunction · 0.85
ActionNodeClass · 0.85
DecoratorNodeClass · 0.85
StarExceptionClass · 0.85
strfFunction · 0.85
getStringMethod · 0.80
orMaybeMethod · 0.80
optStringMethod · 0.80
getObjectMethod · 0.45

Tested by

no test coverage detected