From 883a75165b21948ccf97a241078a5caec6f10ab2 Mon Sep 17 00:00:00 2001 From: MistEO Date: Fri, 20 Sep 2024 15:53:30 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E9=80=82=E9=85=8D=E6=96=B0=E7=89=88maaf?= =?UTF-8?q?w=20v2.0.0b4=EF=BC=8C=E4=BF=AE=E5=A4=8D=E4=B8=80=E4=BA=9B?= =?UTF-8?q?=E5=B0=8F=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/MaaDebugger/maafw/__init__.py | 41 +++++++------------ .../webpage/index_page/master_control.py | 3 +- src/MaaDebugger/webpage/reco_page/__init__.py | 10 +++-- 3 files changed, 22 insertions(+), 32 deletions(-) diff --git a/src/MaaDebugger/maafw/__init__.py b/src/MaaDebugger/maafw/__init__.py index e28b9b5..168fecf 100644 --- a/src/MaaDebugger/maafw/__init__.py +++ b/src/MaaDebugger/maafw/__init__.py @@ -4,7 +4,7 @@ from typing import Callable, List, Optional from maa.controller import AdbController, Win32Controller -from maa.tasker import Tasker, RecognitionDetail +from maa.tasker import Tasker, RecognitionDetail, NotificationHandler from maa.resource import Resource from maa.toolkit import Toolkit, AdbDevice, DesktopWindow from PIL import Image @@ -14,7 +14,10 @@ class MaaFW: - tasker: Tasker + resource: Resource | None + controller: AdbController | Win32Controller | None + tasker: Tasker | None + notification_handler: NotificationHandler | None def __init__(self): Toolkit.init_option("./") @@ -84,12 +87,16 @@ def run_task(self, entry: str, pipeline_override: dict = {}) -> bool: if not self.tasker: self.tasker = Tasker(notification_handler=self.notification_handler) + if not self.resource or not self.controller: + print("Resource or Controller not initialized") + return False + self.tasker.bind(self.resource, self.controller) if not self.tasker.inited: print("Failed to init MaaFramework instance") return False - return self.tasker.post_pipeline(entry, pipeline_override).wait() + return self.tasker.post_pipeline(entry, pipeline_override).wait().succeeded() @asyncify def stop_task(self): @@ -112,38 +119,18 @@ def screencap(self, capture: bool = True) -> Optional[Image.Image]: return cvmat_to_image(im) @asyncify - def click(self, x, y) -> None: + def click(self, x, y) -> bool: if not self.controller: - return None + return False - self.controller.post_click(x, y).wait() + return self.controller.post_click(x, y).wait().succeeded() @asyncify def get_reco_detail(self, reco_id: int) -> Optional[RecognitionDetail]: if not self.tasker: return None - return self.tasker._get_recognition_detail(reco_id) - - def _tasker_callback(self, msg: str, detail: dict, arg): - if msg == "Task.Debug.ListToRecognize": - self.screenshotter.refresh(False) - if self.on_next_list_starting: - self.on_next_list_starting(detail["current"], detail["list"]) - - elif msg == "Task.Debug.MissAll": - if self.on_miss_all: - self.on_miss_all(detail["current"], detail["list"]) - - elif msg == "Task.Debug.RecognitionResult": - reco = detail["recognition"] - reco_id = reco["reco_id"] - name = reco["name"] - hit = reco["box"] is not None - - if self.on_recognition_succeeded: - self.on_recognition_succeeded(reco_id, name, hit) - + return self.tasker.get_recognition_detail(reco_id) # class Screenshotter(threading.Thread): class Screenshotter: diff --git a/src/MaaDebugger/webpage/index_page/master_control.py b/src/MaaDebugger/webpage/index_page/master_control.py index d22198a..ee55ec6 100644 --- a/src/MaaDebugger/webpage/index_page/master_control.py +++ b/src/MaaDebugger/webpage/index_page/master_control.py @@ -140,6 +140,7 @@ async def on_click_detect(): return devices_select.value = next(iter(options)) + on_change_devices_select(devices_select.value) GlobalStatus.ctrl_detecting = Status.SUCCEEDED def on_change_devices_select(e): @@ -223,7 +224,7 @@ async def on_click_connect(): async def on_click_detect(): GlobalStatus.ctrl_detecting = Status.RUNNING - windows = await maafw.detect_win32hwnd("", window_name_input.value) + windows = await maafw.detect_win32hwnd(window_name_input.value) options = {} for w in windows: options[hex(w.hwnd)] = hex(w.hwnd) + " " + w.window_name diff --git a/src/MaaDebugger/webpage/reco_page/__init__.py b/src/MaaDebugger/webpage/reco_page/__init__.py index 38312e6..534491f 100644 --- a/src/MaaDebugger/webpage/reco_page/__init__.py +++ b/src/MaaDebugger/webpage/reco_page/__init__.py @@ -24,14 +24,16 @@ async def reco_page(reco_id: int): ui.separator() - details: RecognitionDetail = await maafw.get_reco_detail(reco_id) + details: RecognitionDetail | None = await maafw.get_reco_detail(reco_id) if not details: ui.markdown("## Not Found") return - ui.markdown(f"#### Hit: {str(details.box)}") + ui.markdown(f"#### {details.algorithm}") + # ui.markdown(f"#### Box: {str(details.box)}") + ui.markdown(f"#### {details.best_result}") - for draw in details.draws: + for draw in details.draw_images: ui.image(cvmat_to_image(draw)).props("fit=scale-down") - ui.json_editor({"content": {"json": details.detail}, "readOnly": True}) + ui.json_editor({"content": {"json": details.raw_detail}, "readOnly": True})