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

Method BehaviorDatabase

source/game/StarBehaviorDatabase.cpp:151–197  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

149 : name(name), scripts(scripts), parameters(parameters) { }
150
151BehaviorDatabase::BehaviorDatabase() {
152 auto assets = Root::singleton().assets();
153
154 auto& nodeFiles = assets->scanExtension("nodes");
155 assets->queueJsons(nodeFiles);
156 for (String const& file : nodeFiles) {
157 try {
158 Json nodes = assets->json(file);
159 for (auto& node : nodes.toObject()) {
160 StringMap<NodeParameter> parameters;
161 for (auto p : node.second.getObject("properties", {}))
162 parameters.set(p.first, jsonToNodeParameter(p.second));
163
164 m_nodeParameters.set(node.first, parameters);
165
166 StringMap<NodeOutput> output;
167 for (auto p : node.second.getObject("output", {}))
168 output.set(p.first, jsonToNodeOutput(p.second));
169
170 m_nodeOutput.set(node.first, output);
171 }
172 } catch (StarException const& e) {
173 throw StarException(strf("Could not load nodes file \'{}\'", file), e);
174 }
175 }
176
177 auto& behaviorFiles = assets->scanExtension("behavior");
178 assets->queueJsons(behaviorFiles);
179 for (auto const& file : behaviorFiles) {
180 try {
181 auto config = assets->json(file);
182 auto name = config.getString("name");
183
184 if (m_configs.contains(name))
185 throw StarException(strf("Duplicate behavior tree \'{}\'", name));
186
187 m_configs[name] = config;
188 } catch (StarException const& e) {
189 throw StarException(strf("Could not load behavior file \'{}\'", file), e);
190 }
191 }
192
193 for (auto& pair : m_configs) {
194 if (!m_behaviors.contains(pair.first))
195 loadTree(pair.first);
196 }
197}
198
199BehaviorTreeConstPtr BehaviorDatabase::behaviorTree(String const& name) const {
200 if (!m_behaviors.contains(name))

Callers

nothing calls this directly

Calls 13

singletonClass · 0.85
jsonToNodeParameterFunction · 0.85
jsonToNodeOutputFunction · 0.85
StarExceptionClass · 0.85
strfFunction · 0.85
assetsMethod · 0.80
queueJsonsMethod · 0.80
jsonMethod · 0.80
toObjectMethod · 0.80
getStringMethod · 0.80
getObjectMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected