Skip to content

Commit

Permalink
#15 点击星球时分两次点击
Browse files Browse the repository at this point in the history
  • Loading branch information
DoctorReid committed Oct 25, 2023
1 parent a7dfed4 commit fe85568
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/basic/win_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def screenshot(left, top, width, height) -> MatLike:
return cv2.cvtColor(np.array(img), cv2.COLOR_RGB2BGR)


def click(x: int = None, y: int = None, press_time: int = 0):
def click(x: int = None, y: int = None, press_time: float = 0):
"""
点击鼠标
:param x: 屏幕坐标
Expand Down
2 changes: 1 addition & 1 deletion src/sr/control/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def click_ocr(self, screen: MatLike, word: str, threshold: float = 0.5, rect: tu
log.debug('OCR识别 %s 成功 准备点击 (%d, %d)', word, x, y)
return self.click((x, y), press_time=press_time)

def click(self, pos: tuple = None, press_time: int = 0) -> bool:
def click(self, pos: tuple = None, press_time: float = 0) -> bool:
"""
点击位置
:param pos: 点击位置 (x,y) 默认分辨率下的游戏窗口里的坐标
Expand Down
2 changes: 1 addition & 1 deletion src/sr/control/pc_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def open_map(self) -> bool:
pyautogui.press('m')
return True

def click(self, pos: tuple = None, press_time: int = 0) -> bool:
def click(self, pos: tuple = None, press_time: float = 0) -> bool:
"""
点击位置
:param pos: 游戏中的位置 (x,y)
Expand Down
9 changes: 8 additions & 1 deletion src/sr/operation/unit/choose_planet.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,11 @@ def choose_planet(self, screen) -> bool:
# 二值化后更方便识别字体
gray = cv2.cvtColor(screen, cv2.COLOR_RGB2GRAY)
_, mask = cv2.threshold(gray, 200, 255, cv2.THRESH_BINARY)
return self.ctx.controller.click_ocr(mask, gt(self.planet.ocr_str), click_offset=(0, -100), press_time=1.5)
km = self.ctx.ocr.match_words(mask, words=[gt(self.planet.ocr_str)])
if len(km) == 0:
return False
for v in km.values():
x, y = v.max.cx, v.max.cy - 100
self.ctx.controller.click((x, y))
self.ctx.controller.click((x, y), press_time=1.5)
return True

0 comments on commit fe85568

Please sign in to comment.