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

Method readWorldFromFile

src/mod_tools.cpp:14725–15010  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

14723}
14724
14725void Compendium_t::readWorldFromFile(bool forceLoadBaseDirectory)
14726{
14727 const std::string filename = "data/compendium/world.json";
14728 if ( !PHYSFS_getRealDir(filename.c_str()) )
14729 {
14730 printlog("[JSON]: Error: Could not locate json file %s", filename.c_str());
14731 return;
14732 }
14733
14734 std::string inputPath = PHYSFS_getRealDir(filename.c_str());
14735 if ( forceLoadBaseDirectory )
14736 {
14737 inputPath = BASE_DATA_DIR;
14738 }
14739 else
14740 {
14741 if ( inputPath != BASE_DATA_DIR )
14742 {
14743 readWorldFromFile(true); // force load the base directory first, then modded paths later.
14744 }
14745 else
14746 {
14747 forceLoadBaseDirectory = true;
14748 }
14749 }
14750
14751 inputPath.append(PHYSFS_getDirSeparator());
14752 inputPath.append(filename.c_str());
14753
14754 File* fp = FileIO::open(inputPath.c_str(), "rb");
14755 if ( !fp )
14756 {
14757 printlog("[JSON]: Error: Could not locate json file %s", inputPath.c_str());
14758 return;
14759 }
14760
14761 char buf[120000];
14762 int count = fp->read(buf, sizeof(buf[0]), sizeof(buf) - 1);
14763 buf[count] = '\0';
14764 rapidjson::StringStream is(buf);
14765 FileIO::close(fp);
14766
14767 rapidjson::Document d;
14768 d.ParseStream(is);
14769 if ( !d.IsObject() || !d.HasMember("version") || !d.HasMember("world") )
14770 {
14771 printlog("[JSON]: Error: No 'version' value in json file, or JSON syntax incorrect! %s", inputPath.c_str());
14772 return;
14773 }
14774
14775 worldObjects.clear();
14776 Compendium_t::Events_t::eventWorldIDLookup.clear();
14777 Compendium_t::Events_t::eventWorldLookup.clear();
14778 Compendium_t::Events_t::worldIDToString.clear();
14779 Compendium_t::CompendiumWorld_t::readContentsLang();
14780
14781 auto& entries = d["world"];
14782 for ( auto itr = entries.MemberBegin(); itr != entries.MemberEnd(); ++itr )

Callers 2

initGameDatafilesFunction · 0.80
consolecommand.cppFile · 0.80

Calls 14

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

Tested by

no test coverage detected