MCPcopy Create free account
hub / github.com/axmolengine/axmol / loadConfigFile

Method loadConfigFile

core/base/Configuration.cpp:337–413  ·  view source on GitHub ↗

load file

Source from the content-addressed store, hash-verified

335// load file
336//
337void Configuration::loadConfigFile(std::string_view filename)
338{
339 ValueMap dict = FileUtils::getInstance()->getValueMapFromFile(filename);
340 AXASSERT(!dict.empty(), "cannot create dictionary");
341
342 // search for metadata
343 bool validMetadata = false;
344 auto metadataIter = dict.find("metadata");
345 if (metadataIter != dict.cend() && metadataIter->second.getType() == Value::Type::MAP)
346 {
347
348 const auto& metadata = metadataIter->second.asValueMap();
349 auto formatIter = metadata.find("format");
350
351 if (formatIter != metadata.cend())
352 {
353 int format = formatIter->second.asInt();
354
355 // Support format: 1
356 if (format == 1)
357 {
358 validMetadata = true;
359 }
360 }
361 }
362
363 if (!validMetadata)
364 {
365 AXLOGW("Invalid config format for file: {}", filename);
366 return;
367 }
368
369 auto dataIter = dict.find("data");
370 if (dataIter == dict.cend() || dataIter->second.getType() != Value::Type::MAP)
371 {
372 AXLOGW("Expected 'data' dict, but not found. Config file: {}", filename);
373 return;
374 }
375
376 // Add all keys in the existing dictionary
377
378 const auto& dataMap = dataIter->second.asValueMap();
379 for (const auto& dataMapIter : dataMap)
380 {
381 if (_valueDict.find(dataMapIter.first) == _valueDict.cend())
382 _valueDict[dataMapIter.first] = dataMapIter.second;
383 else
384 AXLOGD("Key already present. Ignoring '{}'", dataMapIter.first);
385 }
386
387 // light info
388 std::string name = "axmol.3d.max_dir_light_in_shader";
389 if (_valueDict.find(name) != _valueDict.end())
390 _maxDirLightInShader = _valueDict[name].asInt();
391 else
392 _valueDict[name] = Value(_maxDirLightInShader);
393
394 name = "axmol.3d.max_point_light_in_shader";

Callers 3

initMethod · 0.80
onEnterMethod · 0.80

Calls 10

getInstanceFunction · 0.85
getValueMapFromFileMethod · 0.80
asIntMethod · 0.80
ValueClass · 0.70
emptyMethod · 0.45
findMethod · 0.45
cendMethod · 0.45
getTypeMethod · 0.45
endMethod · 0.45
dispatchEventMethod · 0.45

Tested by 2

initMethod · 0.64
onEnterMethod · 0.64