Skip to content

Commit

Permalink
✨ 支持在任务结束后提示接到的悬赏封印数量
Browse files Browse the repository at this point in the history
  • Loading branch information
AquamarineCyan committed Jan 19, 2025
1 parent 63a1258 commit c757e99
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.MD
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
### 新功能

- 完善后台交互,包括截图、点击、键盘事件
- 支持在任务结束后提示接到的悬赏封印数量

### 优化

Expand Down
17 changes: 17 additions & 0 deletions src/package/global_parameter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class GlobalParameter:
"""全局参数"""

count: int = 0

def add(self):
self.count += 1

def reset(self):
self.count = 0

def get(self):
return self.count


xuanshangfengyin_count = GlobalParameter()
"""悬赏封印数量"""
19 changes: 13 additions & 6 deletions src/package/utils.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import time
from pathlib import Path
from typing import Literal

from ..utils.adapter import Mouse
from ..utils.application import RESOURCE_GLOBAL_PATH, SCREENSHOT_DIR_PATH
from ..utils.application import SCREENSHOT_DIR_PATH
from ..utils.assets import AssetOcr
from ..utils.decorator import log_function_call, run_in_thread
from ..utils.event import event_thread
Expand All @@ -15,9 +14,11 @@
from ..utils.paddleocr import RuleOcr
from ..utils.screenshot import ScreenShot
from ..utils.toast import toast
from .global_parameter import xuanshangfengyin_count

__all__ = ["Package", "GlobalResource"]


def load_asset(resource_path, type: str = Literal["image", "ocr"]) -> dict:
assets_file, data = get_asset_data(resource_path)
if data.get(f"{type}_data") is None:
Expand Down Expand Up @@ -303,14 +304,13 @@ def start(self, *args, **kwargs) -> None:
self.check_click(self.IMAGE_START, *args, **kwargs)

def screenshot(self) -> None:
"""截图,保存在当前功能的名称截图目录"""
screenshot_path = "cache" if self.resource_path is None else self.resource_path
screenshot_path = SCREENSHOT_DIR_PATH / screenshot_path
if not screenshot_path.exists():
screenshot_path.mkdir(parents=True)

screenshot_file = (
screenshot_path / f"screenshot-{time.strftime('%Y%m%d%H%M%S')}.png"
)
screenshot_file = screenshot_path / f"screenshot-{time.strftime('%Y%m%d%H%M%S')}.png"
ScreenShot().save(str(screenshot_file))
logger.info(f"screenshot: {screenshot_file}")

Expand Down Expand Up @@ -394,16 +394,19 @@ def finish_info(self):
@run_in_thread
def task_start(self):
"""任务开始"""

# 禁用按钮
ms.main.is_fighting_update.emit(True)
_start = time.perf_counter()
if self.max:
logger.num(f"0/{self.max}")

xuanshangfengyin_count.reset()

try:
self.run()
except Exception as e:
logger.error(e)
logger.ui_error(f"任务出错: {e}")

_end = time.perf_counter()
_cost = _end - _start
Expand All @@ -414,7 +417,11 @@ def task_start(self):
logger.ui(f"耗时{int(_cost)}秒")
except Exception:
logger.error("耗时统计计算失败")

self.finish_info()
if xuanshangfengyin_count.get():
logger.ui_warn(f"接到 {xuanshangfengyin_count.get()} 个悬赏封印")
xuanshangfengyin_count.reset()

# 启用按钮
ms.main.is_fighting_update.emit(False)
Expand Down
3 changes: 3 additions & 0 deletions src/package/xuanshangfengyin.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from ..utils.myschedule import global_scheduler
from ..utils.screenshot import ScreenShot
from ..utils.toast import toast
from .global_parameter import xuanshangfengyin_count
from .utils import Package


Expand Down Expand Up @@ -72,6 +73,8 @@ def scheduler_check(self):
event_xuanshang.set()
self.check_click(_asset, 5, "center")

xuanshangfengyin_count.add()

@run_in_thread
def task_start(self):
if config.user.xuanshangfengyin == "关闭":
Expand Down

0 comments on commit c757e99

Please sign in to comment.