Skip to content

Commit

Permalink
feat: add MaaStatus to MaaTaskerGetTaskDetail
Browse files Browse the repository at this point in the history
@binding-developers
  • Loading branch information
MistEO committed Oct 22, 2024
1 parent ba7347f commit 642899c
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 27 deletions.
3 changes: 2 additions & 1 deletion include/MaaFramework/Instance/MaaTasker.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ extern "C"
MaaTaskId task_id,
/* out */ MaaStringBuffer* entry,
/* out */ MaaNodeId* node_id_list /**< array */,
/* in & out */ MaaSize* node_id_list_size);
/* in & out */ MaaSize* node_id_list_size,
/* out */ MaaStatus* status);

/**
* @param[out] latest_id
Expand Down
8 changes: 7 additions & 1 deletion source/MaaFramework/API/MaaTasker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,8 @@ MaaBool MaaTaskerGetTaskDetail(
MaaTaskId task_id,
MaaStringBuffer* entry,
MaaNodeId* node_id_list,
MaaSize* node_id_list_size)
MaaSize* node_id_list_size,
MaaStatus* status)
{
if (!tasker) {
LogError << "handle is null";
Expand Down Expand Up @@ -300,6 +301,11 @@ MaaBool MaaTaskerGetTaskDetail(
return false;
}

CheckNullAndWarn(status)
{
*status = tasker->status(task_id);
}

return true;
}

Expand Down
23 changes: 23 additions & 0 deletions source/binding/Python/maa/define.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,28 @@ class MaaCustomControllerCallbacks(ctypes.Structure):
]


class Status:
_status: MaaStatusEnum

def __init__(self, status: Union[MaaStatus, MaaStatusEnum]):
self._status = MaaStatusEnum(status)

def done(self) -> bool:
return self._status in [MaaStatusEnum.succeeded, MaaStatusEnum.failed]

def succeeded(self) -> bool:
return self._status == MaaStatusEnum.succeeded

def failed(self) -> bool:
return self._status == MaaStatusEnum.failed

def pending(self) -> bool:
return self._status == MaaStatusEnum.pending

def running(self) -> bool:
return self._status == MaaStatusEnum.running


@dataclass
class Rect:
x: int = 0
Expand Down Expand Up @@ -487,6 +509,7 @@ class TaskDetail:
task_id: int
entry: str
nodes: List[NodeDetail]
status: Status


class LoggingLevelEnum(IntEnum):
Expand Down
24 changes: 0 additions & 24 deletions source/binding/Python/maa/job.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,6 @@
from typing import Union

from .define import *


class Status:
_status: MaaStatusEnum

def __init__(self, status: Union[MaaStatus, MaaStatusEnum]):
self._status = MaaStatusEnum(status)

def done(self) -> bool:
return self._status in [MaaStatusEnum.succeeded, MaaStatusEnum.failed]

def succeeded(self) -> bool:
return self._status == MaaStatusEnum.succeeded

def failed(self) -> bool:
return self._status == MaaStatusEnum.failed

def pending(self) -> bool:
return self._status == MaaStatusEnum.pending

def running(self) -> bool:
return self._status == MaaStatusEnum.running


class Job:
job_id: MaaId

Expand Down
6 changes: 5 additions & 1 deletion source/binding/Python/maa/tasker.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,13 +283,15 @@ def get_node_detail(self, node_id: int) -> Optional[NodeDetail]:
def get_task_detail(self, task_id: int) -> Optional[TaskDetail]:
size = MaaSize()
entry = StringBuffer()
status = MaaStatus()
ret = bool(
Library.framework.MaaTaskerGetTaskDetail(
self._handle,
MaaTaskId(task_id),
entry._handle,
None,
ctypes.pointer(size),
ctypes.pointer(status),
)
)
if not ret:
Expand All @@ -303,6 +305,7 @@ def get_task_detail(self, task_id: int) -> Optional[TaskDetail]:
entry._handle,
c_node_id_list,
ctypes.pointer(size),
ctypes.pointer(status),
)
)
if not ret:
Expand All @@ -313,7 +316,7 @@ def get_task_detail(self, task_id: int) -> Optional[TaskDetail]:
detail = self.get_node_detail(int(c_node_id_list[i]))
nodes.append(detail)

return TaskDetail(task_id=task_id, entry=entry.get(), nodes=nodes)
return TaskDetail(task_id=task_id, entry=entry.get(), nodes=nodes, status=Status(status))

_api_properties_initialized: bool = False

Expand Down Expand Up @@ -433,6 +436,7 @@ def _set_api_properties():
MaaStringBufferHandle,
ctypes.POINTER(MaaRecoId),
ctypes.POINTER(MaaSize),
ctypes.POINTER(MaaStatus),
]

Library.framework.MaaTaskerGetLatestNode.restype = MaaBool
Expand Down

1 comment on commit 642899c

@MistEO
Copy link
Member Author

@MistEO MistEO commented on 642899c Oct 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MaaXYZ/binding-developers

Please sign in to comment.