static std::string GenerateItemInfo(const Item &item, const std::string &key, bool fancy) { std::vector<std::string> sections; std::string properties_text = GenerateProperties(item); if (properties_text.size() > 0) sections.push_back(properties_text); std::string requirements_text = GenerateRequirements(item); if (requirements_text.size() > 0) sections.push_back("Requires " + requirements_text); std::vector<std::string> mods = GenerateMods(item); sections.insert(sections.end(), mods.begin(), mods.end()); std::string unmet; if (!item.identified()) unmet += "Unidentified"; if (item.corrupted()) unmet += (unmet.empty() ? "" : "<br>") + std::string("Corrupted"); if (!unmet.empty()) sections.push_back(ColorPropertyValue(ItemPropertyValue{ unmet, 2 })); std::string text; bool first = true; for (auto &s : sections) { if (!first) { text += "<br>"; if (fancy) text += "<img src=':/tooltip/Separator" + key + ".png'><br>"; else text += "<hr>"; } first = false; text += s; } if (!fancy) text = ColorPropertyValue(ItemPropertyValue{ item.PrettyName(), 0 }) + "<hr>" + text; return "<center>" + text + "</center>"; }
Item::Item(const rapidjson::Value &json) : name_(fixup_name(json["name"].GetString())), location_(ItemLocation(json)), typeLine_(fixup_name(json["typeLine"].GetString())), corrupted_(json["corrupted"].GetBool()), identified_(json["identified"].GetBool()), w_(json["w"].GetInt()), h_(json["h"].GetInt()), frameType_(json["frameType"].GetInt()), icon_(json["icon"].GetString()), sockets_cnt_(0), links_cnt_(0), sockets_({ 0, 0, 0, 0 }), json_(Util::RapidjsonSerialize(json)), has_mtx_(false), ilvl_(0) { for (auto &mod_type : ITEM_MOD_TYPES) { text_mods_[mod_type] = std::vector<std::string>(); if (json.HasMember(mod_type.c_str())) { auto &mods = text_mods_[mod_type]; for (auto &mod : json[mod_type.c_str()]) mods.push_back(mod.GetString()); } } if (json.HasMember("note")) { note_ = json["note"].GetString(); } if (json.HasMember("properties")) { for (auto prop_it = json["properties"].Begin(); prop_it != json["properties"].End(); ++prop_it) { auto &prop = *prop_it; std::string name = prop["name"].GetString(); if (name == "Map Level") name = "Level"; if (name == "Elemental Damage") { for (auto value_it = prop["values"].Begin(); value_it != prop["values"].End(); ++value_it) elemental_damage_.push_back(std::make_pair((*value_it)[0].GetString(), (*value_it)[1].GetInt())); } else { if (prop["values"].Size()) properties_[name] = prop["values"][0][0].GetString(); } ItemProperty property; property.name = name; property.display_mode = prop["displayMode"].GetInt(); for (auto &value : prop["values"]) { ItemPropertyValue v; v.str = value[0].GetString(); v.type = value[1].GetInt(); property.values.push_back(v); } text_properties_.push_back(property); } } if (json.HasMember("requirements")) { for (auto &req : json["requirements"]) { std::string name = req["name"].GetString(); std::string value = req["values"][0][0].GetString(); requirements_[name] = std::atoi(value.c_str()); ItemPropertyValue v; v.str = value; v.type = req["values"][0][1].GetInt(); text_requirements_.push_back({ name, v }); } } if (json.HasMember("sockets")) { ItemSocketGroup current_group = { 0, 0, 0, 0 }; sockets_cnt_ = json["sockets"].Size(); int counter = 0, prev_group = -1; for (auto &socket : json["sockets"]) { ItemSocket current_socket = { static_cast<unsigned char>(socket["group"].GetInt()), socket["attr"].GetString()[0] }; text_sockets_.push_back(current_socket); if (prev_group != current_socket.group) { counter = 0; socket_groups_.push_back(current_group); current_group = { 0, 0, 0, 0 }; } prev_group = current_socket.group; ++counter; links_cnt_ = std::max(links_cnt_, counter); switch (current_socket.attr) { case 'S': sockets_.r++; current_group.r++; break; case 'D': sockets_.g++; current_group.g++; break; case 'I': sockets_.b++; current_group.b++; break; case 'G': sockets_.w++; current_group.w++; break; } } socket_groups_.push_back(current_group); } CalculateHash(json); count_ = 1; if (properties_.find("Stack Size") != properties_.end()) { std::string size = properties_["Stack Size"]; if (size.find("/") != std::string::npos) { size = size.substr(0, size.find("/")); count_ = std::stoi(size); } } has_mtx_ = json.HasMember("cosmeticMods"); if (json.HasMember("ilvl")) ilvl_ = json["ilvl"].GetInt(); GenerateMods(json); }
Item::Item(const rapidjson::Value &json) : location_(ItemLocation(json)), name_(correct_name(json["name"].GetString())), typeLine_(correct_name(json["typeLine"].GetString())), corrupted_(json["corrupted"].GetBool()), w_(json["w"].GetInt()), h_(json["h"].GetInt()), frameType_(json["frameType"].GetInt()), icon_(json["icon"].GetString()), sockets_cnt_(0), links_cnt_(0), sockets_({ 0, 0, 0, 0 }), has_mtx_(false) { for (auto &mod_type : ITEM_MOD_TYPES) { text_mods_[mod_type] = std::vector<std::string>(); if (json.HasMember(mod_type.c_str())) { auto &mods = text_mods_[mod_type]; for (auto &mod : json[mod_type.c_str()]) mods.push_back(mod.GetString()); } } if (json.HasMember("properties")) { for (auto prop_it = json["properties"].Begin(); prop_it != json["properties"].End(); ++prop_it) { auto &prop = *prop_it; std::string name = prop["name"].GetString(); if (name == "Уровень карты") name = "Уровень"; if (name == "Урон от стихий") { for (auto value_it = prop["values"].Begin(); value_it != prop["values"].End(); ++value_it) elemental_damage_.push_back(std::make_pair((*value_it)[0].GetString(), (*value_it)[1].GetInt())); } else { if (prop["values"].Size()) properties_[name] = prop["values"][0][0].GetString(); } ItemProperty property; property.name = name; property.display_mode = prop["displayMode"].GetInt(); for (auto &value : prop["values"]) property.values.push_back(value[0].GetString()); text_properties_.push_back(property); } } if (json.HasMember("requirements")) { for (auto &req : json["requirements"]) { std::string name = req["name"].GetString(); std::string value = req["values"][0][0].GetString(); requirements_[name] = std::atoi(value.c_str()); text_requirements_.push_back({ name, value }); } } if (json.HasMember("sockets")) { ItemSocketGroup current_group = { 0, 0, 0, 0 }; sockets_cnt_ = json["sockets"].Size(); int counter = 0, prev_group = -1; for (auto &socket : json["sockets"]) { ItemSocket current_socket = { static_cast<unsigned char>(socket["group"].GetInt()), socket["attr"].GetString()[0] }; text_sockets_.push_back(current_socket); if (prev_group != current_socket.group) { counter = 0; socket_groups_.push_back(current_group); current_group = { 0, 0, 0, 0 }; } prev_group = current_socket.group; ++counter; links_cnt_ = std::max(links_cnt_, counter); switch (current_socket.attr) { case 'S': sockets_.r++; current_group.r++; break; case 'D': sockets_.g++; current_group.g++; break; case 'I': sockets_.b++; current_group.b++; break; case 'G': sockets_.w++; current_group.w++; break; } } socket_groups_.push_back(current_group); } std::string hashes[3]; for (int i = 0; i < 3; i++) { std::string unique(name_ + "~" + typeLine_ + "~"); if (i == 2) { // Strip off last "~" (a mistake from 0.3) unique = unique.substr(0, unique.length() - 1); } if (json.HasMember("explicitMods")) for (auto mod_it = json["explicitMods"].Begin(); mod_it != json["explicitMods"].End(); ++mod_it) unique += std::string(mod_it->GetString()) + "~"; if (json.HasMember("implicitMods")) for (auto mod_it = json["implicitMods"].Begin(); mod_it != json["implicitMods"].End(); ++mod_it) unique += std::string(mod_it->GetString()) + "~"; unique += item_unique_properties(json, "properties") + "~"; unique += item_unique_properties(json, "additionalProperties") + "~"; if (json.HasMember("sockets")) for (auto socket_it = json["sockets"].Begin(); socket_it != json["sockets"].End(); ++socket_it) unique += std::to_string((*socket_it)["group"].GetInt()) + "~" + (*socket_it)["attr"].GetString() + "~"; // This will only effect corrupted item's new hashes... if (i == 1 && corrupted()) unique += "corrupted"; hashes[i] = Util::Md5(unique); } old_hash_ = hashes[0]; hash_ = hashes[1]; broken_hash_ = hashes[2]; count_ = 1; if (properties_.find("Размер стопки") != properties_.end()) { std::string size = properties_["Размер стопки"]; if (size.find("/") != std::string::npos) { size = size.substr(0, size.find("/")); count_ = std::stoi(size); } } has_mtx_ = json.HasMember("cosmeticMods"); GenerateMods(json); }
Item::Item(const rapidjson::Value &json) : location_(ItemLocation(json)), name_(json["name"].GetString()), typeLine_(json["typeLine"].GetString()), corrupted_(json["corrupted"].GetBool()), w_(json["w"].GetInt()), h_(json["h"].GetInt()), frameType_(json["frameType"].GetInt()), icon_(json["icon"].GetString()), sockets_cnt_(0), links_cnt_(0), sockets_({ 0, 0, 0, 0 }), has_mtx_(false) { // Fix for 2.0.2 QString name = QString::fromStdString(name_); name.remove(QRegularExpression("<(.*)>")); name_ = name.toStdString(); QString typeLine = QString::fromStdString(typeLine_); typeLine.remove(QRegularExpression("<(.*)>")); typeLine_ = typeLine.toStdString(); for (auto &mod_type : ITEM_MOD_TYPES) { text_mods_[mod_type] = std::vector<std::string>(); if (json.HasMember(mod_type.c_str())) { auto &mods = text_mods_[mod_type]; for (auto &mod : json[mod_type.c_str()]) mods.push_back(mod.GetString()); } } if (json.HasMember("properties")) { for (auto prop_it = json["properties"].Begin(); prop_it != json["properties"].End(); ++prop_it) { auto &prop = *prop_it; std::string name = prop["name"].GetString(); if (name == "Map Level") name = "Level"; if (name == "Elemental Damage") { for (auto value_it = prop["values"].Begin(); value_it != prop["values"].End(); ++value_it) elemental_damage_.push_back(std::make_pair((*value_it)[0].GetString(), (*value_it)[1].GetInt())); } else { if (prop["values"].Size()) properties_[name] = prop["values"][0][0].GetString(); } ItemProperty property; property.name = name; property.display_mode = prop["displayMode"].GetInt(); for (auto &value : prop["values"]) property.values.push_back(value[0].GetString()); text_properties_.push_back(property); } } if (json.HasMember("requirements")) { for (auto &req : json["requirements"]) { std::string name = req["name"].GetString(); std::string value = req["values"][0][0].GetString(); requirements_[name] = std::atoi(value.c_str()); text_requirements_.push_back({ name, value }); } } if (json.HasMember("sockets")) { ItemSocketGroup current_group = { 0, 0, 0, 0 }; sockets_cnt_ = json["sockets"].Size(); int counter = 0, prev_group = -1; for (auto &socket : json["sockets"]) { ItemSocket current_socket = { static_cast<unsigned char>(socket["group"].GetInt()), socket["attr"].GetString()[0] }; text_sockets_.push_back(current_socket); if (prev_group != current_socket.group) { counter = 0; socket_groups_.push_back(current_group); current_group = { 0, 0, 0, 0 }; } prev_group = current_socket.group; ++counter; links_cnt_ = std::max(links_cnt_, counter); switch (current_socket.attr) { case 'S': sockets_.r++; current_group.r++; break; case 'D': sockets_.g++; current_group.g++; break; case 'I': sockets_.b++; current_group.b++; break; case 'G': sockets_.w++; current_group.w++; break; } } socket_groups_.push_back(current_group); } std::string unique(std::string(json["name"].GetString()) + "~" + json["typeLine"].GetString() + "~"); if (json.HasMember("explicitMods")) for (auto mod_it = json["explicitMods"].Begin(); mod_it != json["explicitMods"].End(); ++mod_it) unique += std::string(mod_it->GetString()) + "~"; if (json.HasMember("implicitMods")) for (auto mod_it = json["implicitMods"].Begin(); mod_it != json["implicitMods"].End(); ++mod_it) unique += std::string(mod_it->GetString()) + "~"; unique += item_unique_properties(json, "properties") + "~"; unique += item_unique_properties(json, "additionalProperties") + "~"; if (json.HasMember("sockets")) for (auto socket_it = json["sockets"].Begin(); socket_it != json["sockets"].End(); ++socket_it) unique += std::to_string((*socket_it)["group"].GetInt()) + "~" + (*socket_it)["attr"].GetString() + "~"; hash_ = Util::Md5(unique); count_ = 1; if (properties_.find("Stack Size") != properties_.end()) { std::string size = properties_["Stack Size"]; if (size.find("/") != std::string::npos) { size = size.substr(0, size.find("/")); count_ = std::stoi(size); } } has_mtx_ = json.HasMember("cosmeticMods"); GenerateMods(json); }