#include "ModifierName.h" #include using namespace nejlika; nejlika::ModifierName::ModifierName(const nlohmann::json & json) { name = json["name"].get(); if (json.contains("type")) { type = magic_enum::enum_cast(json["type"].get()).value_or(ModifierNameType::Prefix); } else { type = ModifierNameType::Prefix; } if (json.contains("rarity")) { rarity = magic_enum::enum_cast(json["rarity"].get()).value_or(ModifierRarity::Common); } else { rarity = ModifierRarity::Common; } } nejlika::ModifierName::ModifierName(const ModifierNameTemplate& templateData) { name = templateData.GetName(); type = templateData.GetType(); rarity = templateData.GetRarity(); } nlohmann::json nejlika::ModifierName::ToJson() const { nlohmann::json json; json["name"] = name; json["type"] = magic_enum::enum_name(type); json["rarity"] = magic_enum::enum_name(rarity); return json; } std::string nejlika::ModifierName::GenerateHtmlString() const { const auto& rarityColor = ModifierRarityHelper::GetModifierRarityColor(rarity); std::stringstream ss; ss << "" << name << ""; return ss.str(); } std::string nejlika::ModifierName::GenerateHtmlString(const std::vector& names) { std::stringstream ss; for (const auto& name : names) { if (name.GetType() == ModifierNameType::Prefix && !name.name.empty()) { ss << name.GenerateHtmlString() << "\n"; } } ss << "NAME"; for (const auto& name : names) { if (name.GetType() == ModifierNameType::Suffix && !name.name.empty()) { ss << "\n" << name.GenerateHtmlString(); } } // Remove the last newline auto str = ss.str(); if (!str.empty() && str.back() == '\n') { str.pop_back(); } return str; }