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

Method readItemsFromFile

src/mod_tools.cpp:886–1488  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

884}
885
886void ItemTooltips_t::readItemsFromFile()
887{
888 printlog("loading items...\n");
889 if ( !PHYSFS_getRealDir("items/items.json") )
890 {
891 printlog("[JSON]: Error: Could not find file: items/items.json");
892 return;
893 }
894
895 std::string inputPath = PHYSFS_getRealDir("/items/items.json");
896 inputPath.append("/items/items.json");
897
898 File* fp = FileIO::open(inputPath.c_str(), "rb");
899 if ( !fp )
900 {
901 printlog("[JSON]: Error: Could not open json file %s", inputPath.c_str());
902 return;
903 }
904
905 const int bufSize = 600000;
906 static char buf[bufSize];
907 int count = fp->read(buf, sizeof(buf[0]), sizeof(buf) - 1);
908 buf[count] = '\0';
909 //rapidjson::FileReadStream is(fp, buf, sizeof(buf)); - use this for large chunks.
910 rapidjson::StringStream is(buf);
911
912 rapidjson::Document d;
913 d.ParseStream(is);
914 FileIO::close(fp);
915 if ( !d.HasMember("version") || !d.HasMember("items") )
916 {
917 printlog("[JSON]: Error: No 'version' value in json file, or JSON syntax incorrect! %s", inputPath.c_str());
918 return;
919 }
920 int version = d["version"].GetInt();
921
922 int itemsRead = 0;
923
924 tmpItems.clear();
925
926 for ( rapidjson::Value::ConstMemberIterator item_itr = d["items"].MemberBegin();
927 item_itr != d["items"].MemberEnd(); ++item_itr )
928 {
929 tmpItem_t t;
930 t.internalName = item_itr->name.GetString();
931 t.itemId = item_itr->value["item_id"].GetInt();
932 t.fpIndex = item_itr->value["first_person_model_index"].GetInt();
933 t.tpIndex = item_itr->value["third_person_model_index"].GetInt();
934 if ( item_itr->value.HasMember("third_person_model_index_short") )
935 {
936 t.tpShortIndex = item_itr->value["third_person_model_index_short"].GetInt();
937 }
938 t.gold = item_itr->value["gold_value"].GetInt();
939 t.weight = item_itr->value["weight_value"].GetInt();
940 t.itemLevel = item_itr->value["item_level"].GetInt();
941 t.category = item_itr->value["item_category"].GetString();
942 t.equipSlot = item_itr->value["equip_slot"].GetString();
943

Callers 3

mainFunction · 0.80
initGameDatafilesFunction · 0.80
consolecommand.cppFile · 0.80

Calls 15

printlogFunction · 0.85
list_FreeAllFunction · 0.85
list_AddNodeLastFunction · 0.85
stringCopyFunction · 0.85
lowercaseStringFunction · 0.85
djb2HashFunction · 0.85
hashSpellPropFunction · 0.85
jsonVecToVecFunction · 0.85
findFunction · 0.85
appendMethod · 0.80
c_strMethod · 0.80
GetIntMethod · 0.80

Tested by

no test coverage detected