Skip to content

Commit

Permalink
Feat: support 2.1 instance
Browse files Browse the repository at this point in the history
  • Loading branch information
moesnow committed Mar 27, 2024
1 parent 4635c1c commit bfebf59
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 77 deletions.
4 changes: 2 additions & 2 deletions app/card/messagebox_custom.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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():
Expand Down
24 changes: 13 additions & 11 deletions assets/config/instance_names.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,17 @@
},
"拟造花萼(赤)": {
"无": "跳过",
"毁灭之蕾": "收容舱段",
"存护之蕾": "支援舱段",
"巡猎之蕾": "城郊雪原",
"丰饶之蕾": "边缘通路",
"智识之蕾": "铆钉镇",
"同谐之蕾": "机械聚落",
"虚无之蕾": "大矿区",
"毁灭之蕾2": "鳞渊境",
"虚无之蕾2": "丹鼎司",
"同谐之蕾2": "「白日梦」酒店-梦境"
"收容舱段": "毁灭之蕾",
"支援舱段": "存护之蕾",
"城郊雪原": "巡猎之蕾",
"边缘通路": "丰饶之蕾",
"铆钉镇": "智识之蕾",
"机械聚落": "同谐之蕾",
"大矿区": "虚无之蕾",
"鳞渊境": "毁灭之蕾",
"丹鼎司": "虚无之蕾",
"「白日梦」酒店-梦境": "同谐之蕾",
"绥园": "丰饶之蕾"
},
"凝滞虚影": {
"无": "跳过",
Expand All @@ -35,7 +36,8 @@
"幽府之形": "银枝 / 寒鸦",
"燔灼之形": "托帕&账账 / 桂乃芬",
"冰酿之形": "米沙",
"焦炙之形": "花火"
"焦炙之形": "花火",
"嗔怒之形": "加拉赫"
},
"侵蚀隧洞": {
"无": "跳过",
Expand Down
35 changes: 35 additions & 0 deletions assets/config/ocr_replacements.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"direct": {
"翼风之形": "巽风之形",
"嘎偶之形": "偃偶之形",
"優偶之形": "偃偶之形",
"厦偶之形": "偃偶之形",
"潘灼之形": "燔灼之形",
"熠灼之形": "燔灼之形",
"幽寞之径": "幽冥之径",
"幽幂之径": "幽冥之径",
"焦灸之形": "焦炙之形",
"集多之形": "焦炙之形",
"蛀星的旧履": "蛀星的旧靥",
"蛀星的旧膚": "蛀星的旧靥",
"蛀星的旧魔": "蛀星的旧靥",
"“异器盈界": "异器盈界",
"“花藏繁生": "花藏繁生",
"“位面分裂": "位面分裂",
"拟造花萼 (赤)": "拟造花萼(赤)",
"拟造花萼 (金)": "拟造花萼(金)",
"拟造花萼 (赤)": "拟造花萼(赤)",
"拟造花萼 (金)": "拟造花萼(金)"
},
"conditional": {
"风之形": "巽风之形",
"芒之形": "锋芒之形",
"偶之形": "偃偶之形",
"兽之形": "孽兽之形",
"灼之形": "燔灼之形",
"幽之径": "幽冥之径",
"冥之径": "幽冥之径",
"怒之形": "嗔怒之形",
"蛀星的旧": "蛀星的旧靥"
}
}
6 changes: 6 additions & 0 deletions assets/docs/Changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# 更新日志

## v2.1.0

### 新功能
- 支持2.1新增副本
- “拟造花萼(赤)”改为通过地点进行查找

## v2.0.7

### 新功能
Expand Down
14 changes: 12 additions & 2 deletions module/ocr/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from utils.logger.logger import Logger
from typing import Optional
import cpufeature
import json


class OCRInstaller:
Expand All @@ -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}")
Expand Down Expand Up @@ -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)
57 changes: 16 additions & 41 deletions module/ocr/ocr.py
Original file line number Diff line number Diff line change
Expand Up @@ -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实例未创建,则创建之"""
Expand Down Expand Up @@ -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"]]
Expand Down
32 changes: 11 additions & 21 deletions tasks/power/instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from .character import Character
from .relicset import Relicset
import time
import json


class Instance:
Expand All @@ -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)

Expand Down Expand Up @@ -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")

Expand All @@ -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)
# 等待界面完全停止
Expand Down Expand Up @@ -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("进入战斗")
Expand Down

0 comments on commit bfebf59

Please sign in to comment.