Skip to content

Commit

Permalink
feat: Make MaaDebugger Great Again (#24)
Browse files Browse the repository at this point in the history
- [x] 支持多资源配置
- [x] 支持pipeline_override
- [x] 启动前清除资源并按照顺序重新加载(自动刷新)
  • Loading branch information
overflow65537 authored Jan 7, 2025
1 parent ebe68a4 commit 6b6e135
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/MaaDebugger/maafw/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,10 @@ def connect_win32hwnd(
def load_resource(self, dir: Path) -> bool:
if not self.resource:
self.resource = Resource()
if not dir.exists():
return False

return self.resource.clear() and self.resource.post_path(dir).wait().succeeded()
return self.resource.post_path(dir).wait().succeeded()

@asyncify
def run_task(self, entry: str, pipeline_override: dict = {}) -> bool:
Expand Down Expand Up @@ -132,6 +134,7 @@ def get_reco_detail(self, reco_id: int) -> Optional[RecognitionDetail]:

return self.tasker.get_recognition_detail(reco_id)


# class Screenshotter(threading.Thread):
class Screenshotter:
def __init__(self, screencap_func: Callable):
Expand Down
53 changes: 51 additions & 2 deletions src/MaaDebugger/webpage/index_page/master_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,20 @@ async def load_resource_control():
on_click=lambda: on_click_load(),
)

loaded_directories_textarea = (
ui.textarea(
"Loaded Directories",
)
.props("size=60")
.props("readonly")
.bind_value(app.storage.general, "loaded_directories")
)

ui.button(
"Clear",
on_click=lambda: clear_textarea(),
)

async def on_click_load():
GlobalStatus.res_loading = Status.RUNNING

Expand All @@ -307,6 +321,17 @@ async def on_click_load():

GlobalStatus.res_loading = Status.SUCCEEDED

if dir_input.value not in loaded_directories_textarea.value.split("\n"):
if loaded_directories_textarea.value:
loaded_directories_textarea.value += "\n"

loaded_directories_textarea.value += dir_input.value

def clear_textarea():
if maafw.resource != None:
maafw.resource.clear()
loaded_directories_textarea.value = ""


async def run_task_control():
StatusIndicator(GlobalStatus, "task_running")
Expand All @@ -322,15 +347,39 @@ async def run_task_control():

ui.button("Start", on_click=lambda: on_click_start())
ui.button("Stop", on_click=lambda: on_click_stop())
pipeline_override_input = (
ui.input(
"Pipeline Override",
placeholder="eg: {}",
)
.props("size=60")
.bind_value(app.storage.general, "Pipeline_Override")
)

async def on_click_start():
GlobalStatus.task_running = Status.RUNNING

if not entry_input.value:
GlobalStatus.task_running = Status.FAILED
return

run = await maafw.run_task(entry_input.value)
pipeline_override = {}
if pipeline_override_input.value:
json_str = pipeline_override_input.value
try:
pipeline_override = json.loads(json_str) if json_str else None
except json.JSONDecodeError as e:
print("Error parsing pipeline_override:", e)
pipeline_override = {}
if maafw.resource:
maafw.resource.clear()

for resource_path in app.storage.general.get("loaded_directories").split("\n"):
loaded = await maafw.load_resource(Path(resource_path))
if not loaded:
GlobalStatus.res_loading = Status.FAILED
return

run = await maafw.run_task(entry_input.value, pipeline_override)
if not run:
GlobalStatus.task_running = Status.FAILED
return
Expand Down

0 comments on commit 6b6e135

Please sign in to comment.