22import time
33import win32gui
44import mouse , math
5+ from PIL import ImageChops
56from utils import captureWindow
67
78class GameInfo :
@@ -55,15 +56,15 @@ def interrupt(self):
5556 self .stopped = True
5657
5758
58- def waitSwitched (self , art_center_x , art_center_y , min_wait = 0.1 , max_wait = 3 ):
59+ def waitSwitched (self , art_center_x , art_center_y , min_wait = 0.1 , max_wait = 3 , condition = lambda pix : sum ( pix ) / 3 > 200 ):
5960 total_wait = 0
6061 while True :
6162 pix = captureWindow (self .game_info .hwnd , (
6263 art_center_x - self .game_info .art_width / 2 - self .game_info .art_expand ,
6364 art_center_y ,
6465 art_center_x - self .game_info .art_width / 2 - self .game_info .art_expand + 1.5 ,
6566 art_center_y + 1.5 ))
66- if sum (pix .getpixel ((0 ,0 )))/ 3 > 200 :
67+ if condition (pix .getpixel ((0 ,0 ))):
6768 return True
6869 else :
6970 time .sleep (min_wait )
@@ -149,8 +150,21 @@ def scrollToRow(self, target_row, max_scrolls=20, extra_scroll=0, interval=0.05)
149150 return rows_scrolled
150151 if lines_scrolled > max_scrolls :
151152 return rows_scrolled
153+ get_first_art = lambda : captureWindow (self .game_info .hwnd , (
154+ self .game_info .first_art_x + self .game_info .art_width / 2 - 1 ,
155+ self .game_info .first_art_y + self .game_info .art_height / 2 ,
156+ self .game_info .first_art_x + self .game_info .art_width / 2 + 1 ,
157+ self .game_info .first_art_y + self .game_info .art_height ))
158+ first_art = get_first_art ()
152159 for _ in range (7 if lines_scrolled == 0 and target_row > 0 else 1 ):
153160 mouse .wheel (- 1 )
154161 lines_scrolled += 1
155162 # print('翻一下')
156- time .sleep (interval )
163+ total_waited = 0
164+ while True :
165+ time .sleep (interval )
166+ total_waited += interval
167+ if total_waited > 5 :
168+ break
169+ if ImageChops .difference (get_first_art (), first_art ).getbbox ():
170+ break
0 commit comments