Skip to content

Commit

Permalink
feat: add python api: get_image
Browse files Browse the repository at this point in the history
  • Loading branch information
MistEO committed Mar 27, 2024
1 parent cbfd75c commit e14937f
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions source/binding/Python/maa/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@ def __del__(self):

async def connect(self) -> bool:
"""
Async connect to the controller.
Async connect.
:return: True if the connection was successful, False otherwise.
"""
return await self.post_connection().wait()

def post_connection(self) -> Future:
"""
Post a connection to the controller. (connect in backgroud)
Post a connection. (connect in backgroud)
:return: The connection ID.
"""
Expand All @@ -76,13 +76,21 @@ def connected(self) -> bool:

async def screencap(self) -> Optional[numpy.ndarray]:
"""
Async get the screencap of the controller.
Async capture the screenshot.
:return: image
"""
if not await self.post_screencap().wait():
return None

return self.get_image()

def get_image(self) -> Optional[numpy.ndarray]:
"""
Get latest screenshot. (without capture)
:return: image
"""
image_buffer = ImageBuffer()
ret = Library.framework.MaaControllerGetImage(
self._handle, image_buffer.c_handle
Expand All @@ -93,7 +101,7 @@ async def screencap(self) -> Optional[numpy.ndarray]:

def post_screencap(self) -> Future:
"""
Post a screencap to the controller. (get screencap in backgroud)
Post a screencap. (get screencap in backgroud)
:return: The screencap ID.
"""
Expand All @@ -114,7 +122,7 @@ async def click(self, x: int, y: int) -> bool:

def post_click(self, x: int, y: int) -> Future:
"""
Post a click to the controller. (click in backgroud)
Post a click. (click in backgroud)
:param x: The x coordinate.
:param y: The y coordinate.
Expand Down Expand Up @@ -251,8 +259,8 @@ def __init__(
:param adb_path: The path to the ADB executable.
:param address: The address of the device.
:param type: The type of the controller.
:param config: The configuration of the controller.
:param type: The type.
:param config: The configuration.
:param callback: The callback function.
:param callback_arg: The callback argument.
"""
Expand Down

0 comments on commit e14937f

Please sign in to comment.