forked from MaaXYZ/MaaFramework
-
Notifications
You must be signed in to change notification settings - Fork 0
/
__main__.py
69 lines (48 loc) · 1.55 KB
/
__main__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
from typing import Tuple
# python -m pip install maafw
from maa.define import RectType
from maa.resource import Resource
from maa.controller import AdbController
from maa.instance import Instance
from maa.toolkit import Toolkit
from maa.custom_recognizer import CustomRecognizer
from maa.custom_action import CustomAction
import asyncio
async def main():
user_path = "./"
Toolkit.init_option(user_path)
resource = Resource()
await resource.load("sample/resource")
device_list = await Toolkit.adb_devices()
if not device_list:
print("No ADB device found.")
exit()
# for demo, we just use the first device
device = device_list[0]
controller = AdbController(
adb_path=device.adb_path,
address=device.address,
)
await controller.connect()
maa_inst = Instance()
maa_inst.bind(resource, controller)
if not maa_inst.inited:
print("Failed to init MAA.")
exit()
maa_inst.register_recognizer("MyRec", my_rec)
maa_inst.register_action("MyAct", my_act)
await maa_inst.run_task("StartUpAndClickButton")
class MyRecognizer(CustomRecognizer):
def analyze(
self, context, image, task_name, custom_param
) -> Tuple[bool, RectType, str]:
return True, (0, 0, 100, 100), "Hello World!"
class MyAction(CustomAction):
def run(self, context, task_name, custom_param, box, rec_detail) -> bool:
return True
def stop(self) -> None:
pass
my_rec = MyRecognizer()
my_act = MyAction()
if __name__ == "__main__":
asyncio.run(main())