Files
MaaAssistantArknights/src/MeoAssistant/RecruitConfiger.cpp

53 lines
1.5 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#include "RecruitConfiger.h"
#include <algorithm>
#include <meojson/json.hpp>
#include "Logger.hpp"
bool asst::RecruitConfiger::parse(const json::value& json)
{
LogTraceFunction;
clear();
for (const json::value& oper : json.as_array()) {
RecruitOperInfo oper_temp;
oper_temp.name = oper.at("name").as_string();
oper_temp.type = oper.at("type").as_string();
m_all_types.emplace(oper_temp.type);
// 职业类型也作为tag之一加上"干员"两个字
std::string type_as_tag = oper_temp.type + "干员";
oper_temp.tags.emplace(type_as_tag);
m_all_tags.emplace(std::move(type_as_tag));
oper_temp.level = oper.at("level").as_integer();
oper_temp.sex = oper.get("sex", "unknown");
for (const json::value& tag_value : oper.at("tags").as_array()) {
std::string tag = tag_value.as_string();
oper_temp.tags.emplace(tag);
m_all_tags.emplace(std::move(tag));
}
oper_temp.hidden = oper.get("hidden", false);
oper_temp.name_en = oper.get("name-en", "unknown");
m_all_opers.emplace_back(std::move(oper_temp));
}
// 按干员等级排个序
std::sort(m_all_opers.begin(), m_all_opers.end(), [](const auto& lhs, const auto& rhs) -> bool {
return lhs.level > rhs.level;
});
return true;
}
void asst::RecruitConfiger::clear()
{
LogTraceFunction;
m_all_opers.clear();
m_all_tags.clear();
m_all_types.clear();
}