rft: 使用RecruitData代替ocrReplace的外服适配 (#11879)

* rft: use RecruitData instead of ocrReplace

* chore: tasks.json

* docs: 注释

* i18n: txwy tweak

* perf: 加载资源时缓存客户端对应语言的招募tag集

---------

Co-authored-by: momomochi987 <as99us301@gmail.com>
This commit is contained in:
status102
2025-02-17 09:14:27 +08:00
committed by GitHub
parent 6ead3db018
commit 76bb116e5d
7 changed files with 59 additions and 128 deletions

View File

@@ -1065,35 +1065,9 @@
},
"RecruitTags": {
"ocrReplace": [
["Starter", "新手"],
["Top Operato.?", "高级资深干员"],
["Senior Operato.?", "资深干员"],
["Melee", "近战位"],
["Ranged", "远程位"],
["Guard", "近卫干员"],
["Medic", "医疗干员"],
["Vanguard", "先锋干员"],
["Caster", "术师干员"],
["Sniper", "狙击干员"],
["Defender", "重装干员"],
["Supporter", "辅助干员"],
["Specialist", "特种干员"],
["Healing", "治疗"],
["Support$", "支援"],
["DPS", "输出"],
["AoE", "群攻"],
["Slow", "减速"],
["Survival", "生存"],
["Defense", "防护"],
["Debuff", "削弱"],
["Shift", "位移"],
["Crowd-Control", "控场"],
["Nuker", "爆发"],
["Summon", "召唤"],
["Fast-Redeploy", "快速复活"],
["DP-Recovery", "费用回复"],
["Robot", "支援机械"],
["Elemental", "元素"]
["Top Operato.?", "Top Operator"],
["Senior Operato.?", "Senior Operator"],
["Support$", "Support"]
]
},
"RecruitContinue": {

View File

@@ -1043,34 +1043,17 @@
},
"RecruitTags": {
"ocrReplace": [
["初期", "新手"],
["上級エリ.*", "高级资深干员"],
["^エリ.*", "资深干员"],
["近距離", "近战位"],
["遠距離", "远程位"],
["前衛.*イ.*", "近卫干员"],
["医療.*イ.*", "医疗干员"],
["先鋒.*イ.*", "先锋干员"],
["術師.*イ.*", "术师干员"],
["狙撃.*イ.*", "狙击干员"],
["重装.*イ.*", "重装干员"],
["補助.*イ.*", "辅助干员"],
["特殊.*イ.*", "特种干员"],
["治療", "治疗"],
["支援", "支援"],
["火力", "输出"],
["範囲攻撃", "群攻"],
["減速", "减速"],
["生存", "生存"],
["防御", "防护"],
["弱化", "削弱"],
["強制移動", "位移"],
["牽制", "控场"],
["爆発力", "爆发"],
["召喚", "召唤"],
["高速再配置", "快速复活"],
["C.+ST回復", "费用回复"],
["ロボット", "支援机械"]
["上級エリ.*", "上級エリート"],
["^エリ.*", "エリート"],
["前衛.*イ.*", "前衛タイプ"],
["医療.*イ.*", "医療タイプ"],
["先鋒.*イ.*", "先鋒タイプ"],
["術師.*イ.*", "術師タイプ"],
["狙撃.*イ.*", "狙撃タイプ"],
["重装.*イ.*", "重装タイプ"],
["補助.*イ.*", "補助タイプ"],
["特殊.*イ.*", "特殊タイプ"],
["C.+ST回復", "COST回復"]
]
},
"RecruitContinue": {

View File

@@ -1051,35 +1051,16 @@
"RecruitTags": {
"ocrReplace": [
["(\\s|\\$|\\(|\\)|\\.|\"|/|'| | |—|_|-|=|,|^4)", ""],
["신입", "新手"],
["고급특별채용", "高级资深干员"],
["^특별채용$", "资深干员"],
["근거리", "近战位"],
["원거리", "远程位"],
["^가(드|도|든)$", "近卫干员"],
["메(딕|달|딜|닉)", "医疗干员"],
["뱅가(드|도|든)", "先锋干员"],
["캐스터", "术师干员"],
["스(나|냐)이퍼", "狙击干员"],
["디(펜|핀)더", "重装干员"],
["서포터", "辅助干员"],
["스페(셜|설|솔)리스트", "特种干员"],
["힐링", "治疗"],
["지원", "支援"],
["딜러", "输出"],
["범위공격", "群攻"],
["감속", "减速"],
["생존형", "生存"],
["방어형", "防护"],
["디버프", "削弱"],
["강제이동", "位移"],
["제어형", "控场"],
["누커", "爆发"],
["소환", "召唤"],
["쾌속부활", "快速复活"],
["코스트\\+?", "费用回复"],
["로(봇|못|뭇)", "支援机械"],
["원소", "元素"]
["고급특별채용", "고급 특별 채용"],
["^특별채용$", "특별 채용"],
["^가(드|도|든)$", "가드"],
["메(딕|달|딜|닉)", "메딕"],
["뱅가(드|도|든)", "뱅가드"],
["스(나|냐)이퍼", "스나이퍼"],
["디(펜|핀)더", "디펜더"],
["스페(셜|설|솔)리스트", "스페셜리스트"],
["코스트\\+?", "코스트+"],
["로(봇|못|뭇)", "로봇"]
]
},
"RecruitContinue": {

View File

@@ -808,42 +808,11 @@
},
"RecruitTags": {
"ocrReplace": [
["初期", "新手"],
["乾員", "干员"],
["幹員", "干员"],
["翰員", "干员"],
["高級資深", "高级资深"],
["資深", "资深"],
["近戰位", "近战位"],
["遠程位", "远程位"],
["近衛", "近卫"],
["醫療", "医疗"],
["先鋒", "先锋"],
["術師", "术师"],
["衛師", "术师"],
["狙擎", "狙击"],
["狙搫", "狙击"],
["狙犟", "狙击"],
["狙擊", "狙击"],
["重裝", "重装"],
["輔.*助", "辅助"],
["特種", "特种"],
["治療", "治疗"],
["支援", "支援"],
["輸出", "输出"],
["群攻", "群攻"],
["減速", "减速"],
["生存", "生存"],
["防護", "防护"],
["削弱", "削弱"],
["位移", "位移"],
["控場", "控场"],
["爆發", "爆发"],
["召喚", "召唤"],
["快速復活", "快速复活"],
["回復", "回复"],
["費用回.+", "费用回复"],
["支援機械", "支援机械"]
["(乾|翰)員", "幹員"],
["衛師", "術師"],
["狙(擎|犟|搫)", "狙擊"],
["輔.*助", "輔助"],
["費用回.+", "費用回復"]
]
},
"RecruitContinue": {

View File

@@ -15,12 +15,27 @@ std::string asst::RecruitConfig::get_tag_name(const TagId& id) const noexcept
return iter->second;
}
std::string asst::RecruitConfig::find_tag_id(const std::string& name) const noexcept
{
for (const auto& [id, tag_name] : m_all_tags_name) {
if (tag_name == name) {
return id;
}
}
return "Unknown tag";
}
bool asst::RecruitConfig::parse(const json::value& json)
{
LogTraceFunction;
clear();
for (const auto& [id, name] : json.at("tags").as_object()) {
m_all_tags_name.emplace(id, name);
}
// tags的列表里有些tag可能是多余的不出现在operators的tags里
for (const json::value& oper : json.at("operators").as_array()) {
Recruitment oper_temp;
oper_temp.name = oper.at("name").as_string();
@@ -30,13 +45,11 @@ bool asst::RecruitConfig::parse(const json::value& json)
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_displayed.emplace(get_tag_name(tag));
m_all_tags.emplace(std::move(tag));
}
m_all_opers.emplace_back(std::move(oper_temp));
}
for (const auto& [id, name] : json.at("tags").as_object()) {
m_all_tags_name.emplace(id, name);
}
// 按干员等级排个序
ranges::sort(m_all_opers, std::greater {}, std::mem_fn(&Recruitment::level));
@@ -50,5 +63,6 @@ void asst::RecruitConfig::clear()
m_all_opers.clear();
m_all_tags.clear();
m_all_tags_displayed.clear();
m_all_tags_name.clear();
}

View File

@@ -74,9 +74,13 @@ public:
const std::unordered_set<std::string>& get_all_tags() const noexcept { return m_all_tags; }
const std::unordered_set<std::string>& get_all_tags_displayed() const noexcept { return m_all_tags_displayed; }
const std::vector<Recruitment>& get_all_opers() const noexcept { return m_all_opers; }
std::string get_tag_name(const TagId& id) const noexcept;
// 根据 外文/中文tag 名称查找 中文tag id
std::string find_tag_id(const std::string& name) const noexcept;
protected:
virtual bool parse(const json::value& json) override;
@@ -84,8 +88,9 @@ protected:
void clear();
std::unordered_set<std::string> m_all_tags;
std::unordered_set<std::string> m_all_tags_displayed;
std::vector<Recruitment> m_all_opers;
std::unordered_map<TagId, std::string> m_all_tags_name;
std::unordered_map<TagId, std::string> m_all_tags_name; // <中文tag, 中文/外文tag>
};
// 公开招募的干员组合

View File

@@ -27,7 +27,7 @@ bool asst::RecruitImageAnalyzer::tags_analyze()
static OCRer tags_analyzer;
if (!analyzer_inited) {
tags_analyzer.set_task_info("RecruitTags");
auto& all_tags_set = RecruitData.get_all_tags();
auto& all_tags_set = RecruitData.get_all_tags_displayed();
// 已经 fullMatch不会再把 `支援机械` 匹配成 `支援`、`高级资深干员` 匹配成 `资深干员` 了,因此不必再排序。
tags_analyzer.set_required(std::vector(all_tags_set.begin(), all_tags_set.end()));
@@ -37,7 +37,12 @@ bool asst::RecruitImageAnalyzer::tags_analyze()
tags_analyzer.set_image(m_image);
if (tags_analyzer.analyze()) {
m_tags_result = tags_analyzer.get_result();
std::vector<asst::TextRect> result = tags_analyzer.get_result();
for (auto& tag : result) {
tag.text = RecruitData.find_tag_id(tag.text);
}
m_tags_result = std::move(result);
return true;
// if (m_tags_result.size() == RecruitData.CorrectNumberOfTags) {
// return true;