33import win32gui
44import mouse , math
55from PIL import ImageChops
6+ import numpy as np
67from utils import captureWindow
78
89class GameInfo :
@@ -51,20 +52,25 @@ class ArtScannerLogic:
5152 def __init__ (self , game_info ):
5253 self .game_info = game_info
5354 self .stopped = False
55+ self .avg_response_time = 1 / 60
5456
5557 def interrupt (self ):
5658 self .stopped = True
5759
5860
5961 def waitSwitched (self , art_center_x , art_center_y , min_wait = 0.1 , max_wait = 3 , condition = lambda pix :sum (pix )/ 3 > 200 ):
62+ start = time .time ()
6063 total_wait = 0
6164 while True :
65+ mouse .move (self .game_info .left + art_center_x , self .game_info .top + art_center_y )
66+ mouse .click ()
6267 pix = captureWindow (self .game_info .hwnd , (
6368 art_center_x - self .game_info .art_width / 2 - self .game_info .art_expand ,
6469 art_center_y ,
6570 art_center_x - self .game_info .art_width / 2 - self .game_info .art_expand + 1.5 ,
6671 art_center_y + 1.5 ))
6772 if condition (pix .getpixel ((0 ,0 ))):
73+ self .avg_response_time = 0.5 * self .avg_response_time + 0.5 * (time .time ()- start )
6874 return True
6975 else :
7076 time .sleep (min_wait )
@@ -113,12 +119,13 @@ def scanRows(self, rows, callback):
113119
114120 def alignFirstRow (self ):
115121 mouse .move (self .game_info .left + self .game_info .first_art_x , self .game_info .top + self .game_info .first_art_y )
122+ mouse .click ()
116123 pix = captureWindow (self .game_info .hwnd , (
117124 self .game_info .scroll_fin_keypt_x ,
118125 self .game_info .scroll_fin_keypt_y ,
119126 self .game_info .scroll_fin_keypt_x + 1.5 ,
120127 self .game_info .scroll_fin_keypt_y + 1.5 ))
121- if pix .getpixel ((0 ,0 ))[0 ]!= 233 or pix .getpixel ((0 ,0 ))[1 ]!= 229 or pix .getpixel ((0 ,0 ))[2 ]!= 220 :
128+ if abs ( pix .getpixel ((0 ,0 ))[0 ]- 233 ) > 5 or abs ( pix .getpixel ((0 ,0 ))[1 ]- 229 ) > 5 or abs ( pix .getpixel ((0 ,0 ))[2 ]- 220 ) > 5 :
122129 for _ in range (3 ):
123130 mouse .wheel (1 )
124131 time .sleep (0.1 )
@@ -135,7 +142,7 @@ def scrollToRow(self, target_row, max_scrolls=20, extra_scroll=0, interval=0.05)
135142 self .game_info .scroll_fin_keypt_y ,
136143 self .game_info .scroll_fin_keypt_x + 1.5 ,
137144 self .game_info .scroll_fin_keypt_y + 1.5 ))
138- if pix .getpixel ((0 ,0 ))[0 ]!= 233 or pix .getpixel ((0 ,0 ))[1 ]!= 229 or pix .getpixel ((0 ,0 ))[2 ]!= 220 :
145+ if abs ( pix .getpixel ((0 ,0 ))[0 ]- 233 ) > 5 or abs ( pix .getpixel ((0 ,0 ))[1 ]- 229 ) > 5 or abs ( pix .getpixel ((0 ,0 ))[2 ]- 220 ) > 5 :
139146 # if in_between_row==False:
140147 # print('到行之间了')
141148 in_between_row = True
@@ -150,21 +157,22 @@ def scrollToRow(self, target_row, max_scrolls=20, extra_scroll=0, interval=0.05)
150157 return rows_scrolled
151158 if lines_scrolled > max_scrolls :
152159 return rows_scrolled
153- get_first_art = lambda : captureWindow (self .game_info .hwnd , (
160+ get_first_art = lambda : np . array ( captureWindow (self .game_info .hwnd , (
154161 self .game_info .first_art_x + self .game_info .art_width / 2 - 1 ,
155162 self .game_info .first_art_y + self .game_info .art_height / 2 ,
156163 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 ))
164+ self .game_info .first_art_y + self .game_info .art_height )))
158165 first_art = get_first_art ()
159166 for _ in range (7 if lines_scrolled == 0 and target_row > 0 else 1 ):
160167 mouse .wheel (- 1 )
161168 lines_scrolled += 1
162169 # print('翻一下')
170+ time .sleep (self .avg_response_time )
163171 total_waited = 0
164172 while True :
165- time .sleep (interval )
166- total_waited += interval
167173 if total_waited > 5 :
168174 break
169- if ImageChops . difference ( get_first_art (), first_art ). getbbox () :
175+ if np . max ( np . abs ( get_first_art ()- first_art )) > 5 :
170176 break
177+ time .sleep (interval )
178+ total_waited += interval
0 commit comments