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

Method writeItemsSaveData

src/mod_tools.cpp:16956–17003  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

16954}
16955
16956void Compendium_t::Events_t::writeItemsSaveData()
16957{
16958 char path[PATH_MAX] = "";
16959 if ( *cvar_compendiumClientSave && multiplayer == CLIENT )
16960 {
16961 completePath(path, "savegames/compendium_items_mp.json", outputdir);
16962 }
16963 else
16964 {
16965 completePath(path, "savegames/compendium_items.json", outputdir);
16966 }
16967
16968 rapidjson::Document exportDocument;
16969 exportDocument.SetObject();
16970
16971 const int VERSION = 2;
16972
16973 CustomHelpers::addMemberToRoot(exportDocument, "version", rapidjson::Value(VERSION));
16974 rapidjson::Value itemsObj(rapidjson::kObjectType);
16975 for ( auto& pair : playerEvents )
16976 {
16977 const std::string& key = events[pair.first].name;
16978 rapidjson::Value namekey(key.c_str(), exportDocument.GetAllocator());
16979 itemsObj.AddMember(namekey, rapidjson::Value(rapidjson::kObjectType), exportDocument.GetAllocator());
16980 auto& obj = itemsObj[key.c_str()];
16981 for ( auto& itemsData : pair.second )
16982 {
16983 rapidjson::Value itemKey(std::to_string(itemsData.first).c_str(), exportDocument.GetAllocator());
16984 obj.AddMember(itemKey, itemsData.second.value, exportDocument.GetAllocator());
16985 }
16986 }
16987 CustomHelpers::addMemberToRoot(exportDocument, "items", itemsObj);
16988
16989 File* fp = FileIO::open(path, "wb");
16990 if ( !fp )
16991 {
16992 printlog("[JSON]: Error opening json file %s for write!", path);
16993 return;
16994 }
16995 rapidjson::StringBuffer os;
16996 rapidjson::Writer<rapidjson::StringBuffer> writer(os);
16997 exportDocument.Accept(writer);
16998 fp->write(os.GetString(), sizeof(char), os.GetSize());
16999 FileIO::close(fp);
17000
17001 printlog("[JSON]: Successfully wrote json file %s", path);
17002 return;
17003}
17004
17005bool Compendium_t::Events_t::EventVal_t::applyValue(const Sint32 val)
17006{

Callers

nothing calls this directly

Calls 5

completePathFunction · 0.85
printlogFunction · 0.85
c_strMethod · 0.80
writeMethod · 0.45
GetSizeMethod · 0.45

Tested by

no test coverage detected