MaaFw 4.4.0b1__py3-none-manylinux2014_x86_64.whl → 5.4.0__py3-none-manylinux2014_x86_64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of MaaFw might be problematic. Click here for more details.

maa/custom_action.py CHANGED
@@ -8,6 +8,20 @@ from .define import *
8
8
 
9
9
 
10
10
  class CustomAction(ABC):
11
+ """自定义动作基类 / Custom action base class
12
+
13
+ 用于实现自定义的 Pipeline 动作。继承此类并实现 run 方法,
14
+ 然后通过 Resource.register_custom_action 或 AgentServer.register_custom_action 注册。
15
+ Used to implement custom Pipeline actions. Inherit this class and implement the run method,
16
+ then register via Resource.register_custom_action or AgentServer.register_custom_action.
17
+
18
+ Example:
19
+ class MyAction(CustomAction):
20
+ def run(self, context, argv):
21
+ context.tasker.controller.post_click(100, 100).wait()
22
+ return True
23
+ """
24
+
11
25
  _handle: MaaCustomActionCallback
12
26
 
13
27
  def __init__(self):
@@ -15,6 +29,17 @@ class CustomAction(ABC):
15
29
 
16
30
  @dataclass
17
31
  class RunArg:
32
+ """run 方法的参数 / Arguments for run method
33
+
34
+ Attributes:
35
+ task_detail: 当前任务详情 / Current task detail
36
+ node_name: 当前节点名 / Current node name
37
+ custom_action_name: 自定义动作名 / Custom action name
38
+ custom_action_param: 自定义动作参数 (JSON 字符串) / Custom action parameter (JSON string)
39
+ reco_detail: 前序识别详情 / Previous recognition detail
40
+ box: 前序识别位置 / Previous recognition box
41
+ """
42
+
18
43
  task_detail: TaskDetail
19
44
  node_name: str
20
45
  custom_action_name: str
@@ -24,6 +49,12 @@ class CustomAction(ABC):
24
49
 
25
50
  @dataclass
26
51
  class RunResult:
52
+ """run 方法的返回结果 / Return result of run method
53
+
54
+ Attributes:
55
+ success: 动作是否执行成功 / Whether the action executed successfully
56
+ """
57
+
27
58
  success: bool
28
59
 
29
60
  @abstractmethod
@@ -32,6 +63,15 @@ class CustomAction(ABC):
32
63
  context: Context,
33
64
  argv: RunArg,
34
65
  ) -> Union[RunResult, bool]:
66
+ """执行自定义动作 / Execute custom action
67
+
68
+ Args:
69
+ context: 任务上下文,可用于执行其他操作 / Task context, can be used to execute other operations
70
+ argv: 动作参数 / Action arguments
71
+
72
+ Returns:
73
+ Union[RunResult, bool]: 执行结果,可返回 RunResult 或 bool / Execution result, can return RunResult or bool
74
+ """
35
75
  raise NotImplementedError
36
76
 
37
77
  @property
@@ -88,5 +128,8 @@ class CustomAction(ABC):
88
128
  elif isinstance(result, bool):
89
129
  return int(result)
90
130
 
131
+ elif result is None:
132
+ return int(True)
133
+
91
134
  else:
92
135
  raise TypeError(f"Invalid return type: {result!r}")
maa/custom_recognition.py CHANGED
@@ -1,7 +1,7 @@
1
1
  import ctypes
2
+ import json
2
3
  from dataclasses import dataclass
3
4
  from abc import ABC, abstractmethod
4
- from typing import Tuple
5
5
 
6
6
  import numpy
7
7
 
@@ -11,6 +11,20 @@ from .define import *
11
11
 
12
12
 
13
13
  class CustomRecognition(ABC):
14
+ """自定义识别器基类 / Custom recognition base class
15
+
16
+ 用于实现自定义的 Pipeline 识别算法。继承此类并实现 analyze 方法,
17
+ 然后通过 Resource.register_custom_recognition 或 AgentServer.register_custom_recognition 注册。
18
+ Used to implement custom Pipeline recognition algorithms. Inherit this class and implement the analyze method,
19
+ then register via Resource.register_custom_recognition or AgentServer.register_custom_recognition.
20
+
21
+ Example:
22
+ class MyRecognition(CustomRecognition):
23
+ def analyze(self, context, argv):
24
+ # 返回识别到的位置,或 None 表示未识别到
25
+ return (100, 100, 50, 50)
26
+ """
27
+
14
28
  _handle: MaaCustomRecognitionCallback
15
29
 
16
30
  def __init__(self):
@@ -18,6 +32,17 @@ class CustomRecognition(ABC):
18
32
 
19
33
  @dataclass
20
34
  class AnalyzeArg:
35
+ """analyze 方法的参数 / Arguments for analyze method
36
+
37
+ Attributes:
38
+ task_detail: 当前任务详情 / Current task detail
39
+ node_name: 当前节点名 / Current node name
40
+ custom_recognition_name: 自定义识别器名 / Custom recognition name
41
+ custom_recognition_param: 自定义识别器参数 (JSON 字符串) / Custom recognition parameter (JSON string)
42
+ image: 待识别的图像 (BGR 格式) / Image to recognize (BGR format)
43
+ roi: 识别区域 / Recognition region of interest
44
+ """
45
+
21
46
  task_detail: TaskDetail
22
47
  node_name: str
23
48
  custom_recognition_name: str
@@ -27,8 +52,15 @@ class CustomRecognition(ABC):
27
52
 
28
53
  @dataclass
29
54
  class AnalyzeResult:
55
+ """analyze 方法的返回结果 / Return result of analyze method
56
+
57
+ Attributes:
58
+ box: 识别到的位置,None 表示未识别到 / Recognized position, None means not recognized
59
+ detail: 识别详情,会被记录到识别结果中 / Recognition details, will be recorded in recognition result
60
+ """
61
+
30
62
  box: Optional[RectType]
31
- detail: str
63
+ detail: dict
32
64
 
33
65
  @abstractmethod
34
66
  def analyze(
@@ -36,6 +68,18 @@ class CustomRecognition(ABC):
36
68
  context: Context,
37
69
  argv: AnalyzeArg,
38
70
  ) -> Union[AnalyzeResult, Optional[RectType]]:
71
+ """执行自定义识别 / Execute custom recognition
72
+
73
+ Args:
74
+ context: 任务上下文,可用于执行其他操作 / Task context, can be used to execute other operations
75
+ argv: 识别参数 / Recognition arguments
76
+
77
+ Returns:
78
+ Union[AnalyzeResult, Optional[RectType]]: 识别结果。可返回 AnalyzeResult、RectType 或 None。
79
+ 返回 None 表示未识别到。
80
+ Recognition result. Can return AnalyzeResult, RectType, or None.
81
+ Return None means not recognized.
82
+ """
39
83
  raise NotImplementedError
40
84
 
41
85
  @property
@@ -92,21 +136,29 @@ class CustomRecognition(ABC):
92
136
  if isinstance(result, CustomRecognition.AnalyzeResult):
93
137
  if result.box:
94
138
  rect_buffer.set(result.box)
95
- detail_buffer.set(result.detail)
139
+ detail_buffer.set(json.dumps(result.detail, ensure_ascii=False))
96
140
  return int(result.box is not None)
97
141
 
98
- elif result is None:
99
- return int(False)
100
-
101
142
  # RectType
102
143
  elif (
103
144
  isinstance(result, Rect)
104
- or (isinstance(result, list) and len(result) == 4 and all(isinstance(x, int) for x in result))
145
+ or (
146
+ isinstance(result, list)
147
+ and len(result) == 4
148
+ and all(isinstance(x, int) for x in result)
149
+ )
105
150
  or (isinstance(result, numpy.ndarray) and result.size == 4)
106
- or (isinstance(result, tuple) and len(result) == 4 and all(isinstance(x, int) for x in result))
151
+ or (
152
+ isinstance(result, tuple)
153
+ and len(result) == 4
154
+ and all(isinstance(x, int) for x in result)
155
+ )
107
156
  ):
108
157
  rect_buffer.set(result)
109
158
  return int(True)
110
159
 
160
+ elif result is None:
161
+ return int(False)
162
+
111
163
  else:
112
- raise ValueError("Invalid return type")
164
+ raise TypeError(f"Invalid return type: {result!r}")