| 884 | } |
| 885 | |
| 886 | void 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 |
no test coverage detected