diff --git a/app/card/messagebox_custom.py b/app/card/messagebox_custom.py index bedcfac5..fc289d51 100644 --- a/app/card/messagebox_custom.py +++ b/app/card/messagebox_custom.py @@ -1,7 +1,7 @@ from PyQt5.QtCore import Qt, QUrl from PyQt5.QtWidgets import QLabel, QHBoxLayout from PyQt5.QtGui import QPixmap, QDesktopServices, QFont -from qfluentwidgets import MessageBox, LineEdit, ComboBox, EditableComboBox, DateTimeEdit, BodyLabel, FluentStyleSheet +from qfluentwidgets import MessageBox, LineEdit, ComboBox, DateTimeEdit, BodyLabel, FluentStyleSheet from typing import Optional import datetime import json @@ -148,7 +148,7 @@ def __init__(self, title: str, content: dict, configtemplate: str, parent=None): titleLabel.setFont(font) self.textLayout.addWidget(titleLabel, 0, Qt.AlignTop) - comboBox = EditableComboBox() + comboBox = ComboBox() has_default = False for name, info in names.items(): diff --git a/assets/config/instance_names.json b/assets/config/instance_names.json index 1076381e..46941154 100644 --- a/assets/config/instance_names.json +++ b/assets/config/instance_names.json @@ -7,16 +7,17 @@ }, "拟造花萼(赤)": { "无": "跳过", - "毁灭之蕾": "收容舱段", - "存护之蕾": "支援舱段", - "巡猎之蕾": "城郊雪原", - "丰饶之蕾": "边缘通路", - "智识之蕾": "铆钉镇", - "同谐之蕾": "机械聚落", - "虚无之蕾": "大矿区", - "毁灭之蕾2": "鳞渊境", - "虚无之蕾2": "丹鼎司", - "同谐之蕾2": "「白日梦」酒店-梦境" + "收容舱段": "毁灭之蕾", + "支援舱段": "存护之蕾", + "城郊雪原": "巡猎之蕾", + "边缘通路": "丰饶之蕾", + "铆钉镇": "智识之蕾", + "机械聚落": "同谐之蕾", + "大矿区": "虚无之蕾", + "鳞渊境": "毁灭之蕾", + "丹鼎司": "虚无之蕾", + "「白日梦」酒店-梦境": "同谐之蕾", + "绥园": "丰饶之蕾" }, "凝滞虚影": { "无": "跳过", @@ -35,7 +36,8 @@ "幽府之形": "银枝 / 寒鸦", "燔灼之形": "托帕&账账 / 桂乃芬", "冰酿之形": "米沙", - "焦炙之形": "花火" + "焦炙之形": "花火", + "嗔怒之形": "加拉赫" }, "侵蚀隧洞": { "无": "跳过", diff --git a/assets/config/ocr_replacements.json b/assets/config/ocr_replacements.json new file mode 100644 index 00000000..eaba5f6d --- /dev/null +++ b/assets/config/ocr_replacements.json @@ -0,0 +1,35 @@ +{ + "direct": { + "翼风之形": "巽风之形", + "嘎偶之形": "偃偶之形", + "優偶之形": "偃偶之形", + "厦偶之形": "偃偶之形", + "潘灼之形": "燔灼之形", + "熠灼之形": "燔灼之形", + "幽寞之径": "幽冥之径", + "幽幂之径": "幽冥之径", + "焦灸之形": "焦炙之形", + "集多之形": "焦炙之形", + "蛀星的旧履": "蛀星的旧靥", + "蛀星的旧膚": "蛀星的旧靥", + "蛀星的旧魔": "蛀星的旧靥", + "“异器盈界": "异器盈界", + "“花藏繁生": "花藏繁生", + "“位面分裂": "位面分裂", + "拟造花萼 (赤)": "拟造花萼(赤)", + "拟造花萼 (金)": "拟造花萼(金)", + "拟造花萼 (赤)": "拟造花萼(赤)", + "拟造花萼 (金)": "拟造花萼(金)" + }, + "conditional": { + "风之形": "巽风之形", + "芒之形": "锋芒之形", + "偶之形": "偃偶之形", + "兽之形": "孽兽之形", + "灼之形": "燔灼之形", + "幽之径": "幽冥之径", + "冥之径": "幽冥之径", + "怒之形": "嗔怒之形", + "蛀星的旧": "蛀星的旧靥" + } +} \ No newline at end of file diff --git a/assets/docs/Changelog.md b/assets/docs/Changelog.md index 1a0cf422..beb70a0a 100644 --- a/assets/docs/Changelog.md +++ b/assets/docs/Changelog.md @@ -1,5 +1,11 @@ # 更新日志 +## v2.1.0 + +### 新功能 +- 支持2.1新增副本 +- “拟造花萼(赤)”改为通过地点进行查找 + ## v2.0.7 ### 新功能 diff --git a/module/ocr/__init__.py b/module/ocr/__init__.py index 2ce93c7d..977e795f 100644 --- a/module/ocr/__init__.py +++ b/module/ocr/__init__.py @@ -4,6 +4,7 @@ from utils.logger.logger import Logger from typing import Optional import cpufeature +import json class OCRInstaller: @@ -15,11 +16,17 @@ def __init__(self, logger: Optional[Logger] = None): self.logger = logger self.ocr_name, self.ocr_path = self._determine_ocr() + def _cpu_support_avx2(self): + """ + 判断 CPU 是否支持 AVX2 指令集。 + """ + return cpufeature.CPUFeature["AVX2"] + def _determine_ocr(self): """ 根据 CPU 是否支持 AVX2 指令集来决定使用的 OCR 工具。 """ - if cpufeature.CPUFeature["AVX2"]: + if self._cpu_support_avx2(): ocr_name = "PaddleOCR-json" ocr_path = r".\3rdparty\PaddleOCR-json_v.1.3.1\PaddleOCR-json.exe" self.logger.debug(f"CPU 支持 AVX2 指令集,使用 {ocr_name}") @@ -60,5 +67,8 @@ def check_and_install(self): ocr_installer = OCRInstaller(log) # 检查并安装 OCR ocr_installer.check_and_install() +# 读取 OCR 替换配置 +with open("./assets/config/ocr_replacements.json", 'r', encoding='utf-8') as file: + replacements = json.load(file) # 初始化 OCR 对象 -ocr = OCR(ocr_installer.ocr_path, log) +ocr = OCR(ocr_installer.ocr_path, log, replacements) diff --git a/module/ocr/ocr.py b/module/ocr/ocr.py index 445003c5..e369b6d0 100644 --- a/module/ocr/ocr.py +++ b/module/ocr/ocr.py @@ -8,11 +8,12 @@ class OCR: - def __init__(self, exePath, logger: Optional[Logger] = None): - """初始化OCR类,设置执行路径和ocr实例为None""" + def __init__(self, exePath, logger: Optional[Logger] = None, replacements=None): + """初始化OCR类""" self.exePath = exePath self.ocr = None self.logger = logger + self.replacements = replacements def instance_ocr(self): """实例化OCR,若ocr实例未创建,则创建之""" @@ -58,48 +59,22 @@ def run(self, image): self.logger.error(e) return "{}" - def replace_strings(self, original_dict): + def replace_strings(self, results): """替换OCR结果中的错误字符串""" - replacements = { - # 替换字符串的字典 - "'翼风之形": "'巽风之形", - "'风之形": "'巽风之形", - "'芒之形": "'锋芒之形", - "'嘎偶之形": "'偃偶之形", - "'優偶之形": "'偃偶之形", - "'厦偶之形": "'偃偶之形", - "'偶之形": "'偃偶之形", - "'兽之形": "'孽兽之形", - "'潘灼之形": "'燔灼之形", - "'熠灼之形": "'燔灼之形", - "'灼之形": "'燔灼之形", - "'幽寞之径": "'幽冥之径", - "'幽幂之径": "'幽冥之径", - "'幽之径": "'幽冥之径", - "'冥之径": "'幽冥之径", - "'蛀星的旧履": "'蛀星的旧靥", - "'蛀星的旧膚": "'蛀星的旧靥", - "'蛀星的旧魔": "'蛀星的旧靥", - "'蛀星的旧": "'蛀星的旧靥", - "“异器盈界": "异器盈界", - "“花藏繁生": "花藏繁生", - "“位面分裂": "位面分裂", - "拟造花萼 (赤)": "拟造花萼(赤)", - "拟造花萼 (金)": "拟造花萼(金)", - "拟造花萼 (赤)": "拟造花萼(赤)", - "拟造花萼 (金)": "拟造花萼(金)", - "焦灸之形": "焦炙之形", - "集多之形": "焦炙之形" - } - original_str = str(original_dict) - for old_str, new_str in replacements.items(): - original_str = original_str.replace(old_str, new_str) + if "data" not in results or "text" not in results["data"][0] or self.replacements is None: + return results - modified_dict = eval(original_str) - self.log_ocr_results(modified_dict) - return modified_dict + for item in results["data"]: + for old_str, new_str in self.replacements["direct"].items(): + item["text"] = item["text"].replace(old_str, new_str) + for old_str, new_str in self.replacements["conditional"].items(): + if new_str not in item["text"]: + item["text"] = item["text"].replace(old_str, new_str) - def log_ocr_results(self, modified_dict): + self.log_results(results) + return results + + def log_results(self, modified_dict): """记录OCR识别结果""" if "data" in modified_dict and "text" in modified_dict["data"][0]: print_list = [item["text"] for item in modified_dict["data"]] diff --git a/tasks/power/instance.py b/tasks/power/instance.py index d7d00493..d28cc7d3 100644 --- a/tasks/power/instance.py +++ b/tasks/power/instance.py @@ -7,6 +7,7 @@ from .character import Character from .relicset import Relicset import time +import json class Instance: @@ -17,8 +18,6 @@ def run(instance_type, instance_name, power_need, runs): log.hr(f"开始刷{instance_type} - {instance_name},总计{runs}次", 2) - instance_name = Instance.process_instance_name(instance_name) - if cfg.instance_team_enable: Team.change_to(cfg.instance_team_number) @@ -83,7 +82,11 @@ def prepare_instance(instance_type, instance_name): "虚无之蕾2": "./assets/images/share/calyx/crimson/nihility2.png", "同谐之蕾2": "./assets/images/share/calyx/crimson/harmony2.png", } - def func(): return auto.click_element(("传送", "进入", "追踪"), "min_distance_text", crop=instance_name_crop, include=True, source=crimson_images[instance_name], source_type="image") + # 临时解决方案 + if instance_name in crimson_images: + def func(): return auto.click_element(("传送", "进入", "追踪"), "min_distance_text", crop=instance_name_crop, include=True, source=crimson_images[instance_name], source_type="image") + else: + def func(): return auto.click_element(("传送", "进入", "追踪"), "min_distance_text", crop=instance_name_crop, include=True, source=instance_name, source_type="text") else: def func(): return auto.click_element(("传送", "进入", "追踪"), "min_distance_text", crop=instance_name_crop, include=True, source=instance_name, source_type="text") @@ -97,6 +100,11 @@ def func(): return auto.click_element(("传送", "进入", "追踪"), "min_dista screen.wait_for_screen_change('guide3') return False Flag = True + # 临时解决方案 + if "拟造花萼(赤)" in instance_type: + with open("./assets/config/instance_names.json", 'r', encoding='utf-8') as file: + template = json.load(file) + instance_name = template[instance_type][instance_name] break auto.mouse_scroll(12, -1) # 等待界面完全停止 @@ -161,24 +169,6 @@ def complete_run(instance_type): if ("侵蚀隧洞" or "历战余响") in instance_type and cfg.break_down_level_four_relicset: Relicset.run() - @staticmethod - def process_instance_name(instance_name): - replacements = { - "巽风之形": "风之形", - "翼风之形": "风之形", - "偃偶之形": "偶之形", - "孽兽之形": "兽之形", - "燔灼之形": "灼之形", - "潘灼之形": "灼之形", - "熠灼之形": "灼之形", - "蛀星的旧靥": "蛀星的旧" - } - - for key, value in replacements.items(): - instance_name = instance_name.replace(key, value) - - return instance_name - @staticmethod def wait_fight(num, timeout=1800): log.info("进入战斗")