MCPcopy Create free account
hub / github.com/TurningWheel/Barony / readCodexFromFile

Method readCodexFromFile

src/mod_tools.cpp:14375–14598  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

14373}
14374
14375void Compendium_t::readCodexFromFile(bool forceLoadBaseDirectory)
14376{
14377 const std::string filename = "data/compendium/codex.json";
14378 if ( !PHYSFS_getRealDir(filename.c_str()) )
14379 {
14380 printlog("[JSON]: Error: Could not locate json file %s", filename.c_str());
14381 return;
14382 }
14383
14384 std::string inputPath = PHYSFS_getRealDir(filename.c_str());
14385 if ( forceLoadBaseDirectory )
14386 {
14387 inputPath = BASE_DATA_DIR;
14388 }
14389 else
14390 {
14391 if ( inputPath != BASE_DATA_DIR )
14392 {
14393 readCodexFromFile(true); // force load the base directory first, then modded paths later.
14394 }
14395 else
14396 {
14397 forceLoadBaseDirectory = true;
14398 }
14399 }
14400
14401 inputPath.append(PHYSFS_getDirSeparator());
14402 inputPath.append(filename.c_str());
14403
14404 File* fp = FileIO::open(inputPath.c_str(), "rb");
14405 if ( !fp )
14406 {
14407 printlog("[JSON]: Error: Could not locate json file %s", inputPath.c_str());
14408 return;
14409 }
14410
14411 char buf[120000];
14412 int count = fp->read(buf, sizeof(buf[0]), sizeof(buf) - 1);
14413 buf[count] = '\0';
14414 rapidjson::StringStream is(buf);
14415 FileIO::close(fp);
14416
14417 rapidjson::Document d;
14418 d.ParseStream(is);
14419 if ( !d.IsObject() || !d.HasMember("version") || !d.HasMember("codex") )
14420 {
14421 printlog("[JSON]: Error: No 'version' value in json file, or JSON syntax incorrect! %s", inputPath.c_str());
14422 return;
14423 }
14424
14425 codex.clear();
14426
14427 Compendium_t::Events_t::eventCodexIDLookup.clear();
14428 Compendium_t::Events_t::eventCodexLookup.clear();
14429 Compendium_t::Events_t::codexIDToString.clear();
14430 Compendium_t::CompendiumCodex_t::readContentsLang();
14431
14432 auto& entries = d["codex"];

Callers 2

initGameDatafilesFunction · 0.80
consolecommand.cppFile · 0.80

Calls 15

printlogFunction · 0.85
jsonVecToVecFunction · 0.85
makeColorRGBFunction · 0.85
findFunction · 0.85
c_strMethod · 0.80
appendMethod · 0.80
GetIntMethod · 0.80
GetBoolMethod · 0.80
BeginMethod · 0.80
EndMethod · 0.80
readMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected