@@ -535,14 +535,26 @@ def select_suitable_ship(self):
535535 logger .info ('Dock is empty or favorite ships is empty' )
536536 return False
537537
538- level_grids = CARD_LEVEL_GRIDS
539- card_grids = CARD_GRIDS
538+ # Ship cards may slow to show, like:
539+ # [0, 0, 120, 120, 120, 120, 0, 0, 0, 0, 0, 0, 0, 0]
540+ # [12, 0, 0, 120, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
541+ # Wait until they turn into
542+ # [120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120]
543+ level_ocr = LevelOcr (CARD_LEVEL_GRIDS .buttons , name = 'DOCK_LEVEL_OCR' , threshold = 64 )
544+ timeout = Timer (1 , count = 1 ).start ()
545+ while 1 :
546+ list_level = level_ocr .ocr (self .device .image )
547+ first_ship = next ((i for i , x in enumerate (list_level ) if x > 0 ), len (list_level ))
548+ first_empty = next ((i for i , x in enumerate (list_level ) if x == 0 ), len (list_level ))
549+ if timeout .reached ():
550+ logger .warning ('Wait ship cards timeout' )
551+ break
552+ if first_empty >= first_ship :
553+ break
554+ self .device .screenshot ()
540555
541- level_ocr = LevelOcr (level_grids .buttons ,
542- name = 'DOCK_LEVEL_OCR' , threshold = 64 )
543- list_level = level_ocr .ocr (self .device .image )
544556 should_select_button = None
545- for button , level in list (zip (card_grids .buttons , list_level ))[self .dock_select_index :]:
557+ for button , level in list (zip (CARD_GRIDS .buttons , list_level ))[self .dock_select_index :]:
546558 # Select ship LV > 1 only
547559 if level > 1 :
548560 should_select_button = button
0 commit comments