feat: add page map recognition and grouped task planning
This commit is contained in:
1 parent
386198e8e0
commit
f7628ab41e
76 files changed
+12437
-49
No files matched your search
@@ -0,0 +1,45 @@
|
||||
"""Identify an open game page or plan a route, without clicking anything."""
|
||||
import argparse
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
import numpy as np
|
||||
from PIL import Image
|
||||
|
||||
from automation.offers import MacGameDesktop
|
||||
from automation.pages import PageMap
|
||||
|
||||
ROOT = Path(__file__).resolve().parent
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description='只读识别当前游戏页面或规划导航路径')
|
||||
parser.add_argument('--image', type=Path, help='已裁剪的游戏内容截图;不能包含标题栏或桌面')
|
||||
parser.add_argument('--from-page', dest='start', help='导航起点页面 ID')
|
||||
parser.add_argument('--to-page', dest='target', help='导航终点页面 ID')
|
||||
parser.add_argument('--previous-page', help='已确认的进入前页面;用于区分外观相同的弹框')
|
||||
args = parser.parse_args()
|
||||
page_map = PageMap(ROOT)
|
||||
if args.start or args.target:
|
||||
if not (args.start and args.target):
|
||||
parser.error('--from-page 与 --to-page 必须同时提供')
|
||||
print(json.dumps(page_map.route(args.start, args.target), ensure_ascii=False, indent=2))
|
||||
return 0
|
||||
if args.image:
|
||||
with Image.open(args.image) as image:
|
||||
if abs(image.width / image.height - 562 / 1002) > .035:
|
||||
parser.error('图片必须仅包含竖屏游戏内容。')
|
||||
frame = np.asarray(image.convert('RGB').resize((562, 1002), Image.Resampling.LANCZOS))
|
||||
else:
|
||||
desktop = MacGameDesktop()
|
||||
shot = desktop.screenshot()
|
||||
frame = page_map.matcher.frame(shot, desktop.region_for(shot))
|
||||
if args.previous_page and args.previous_page not in page_map.pages:
|
||||
parser.error('未知的进入前页面 ID。')
|
||||
result = page_map.identify(frame, previous_page=args.previous_page)
|
||||
print(json.dumps(result, ensure_ascii=False, indent=2))
|
||||
return 0 if result['status'] == 'identified' else 1
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
raise SystemExit(main())
|
||||
Reference in new issue
Block a user