Skip to content

Commit 1b81a0e

Browse files
author
Hiago Inacio
committed
improve scroll
1 parent 55a4b3b commit 1b81a0e

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

module/spaceScreen.py

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ def click_first(btns_pos, search_img):
255255

256256
ship_life = 50 + (life_index * scale_factor)
257257

258-
logger(f"{ship_life}%", end=" ", datetime=False)
258+
logger(f"{ship_life}%", end=" ", datetime=False)
259259

260260
if ship_life >= ship_work_percent:
261261
click_randomly_in_position(x,y,w,h)
@@ -264,7 +264,7 @@ def click_first(btns_pos, search_img):
264264
else:
265265
logger("💤;", datetime=False)
266266

267-
return False
267+
return False
268268

269269
logger(f"Sending ships to fight:")
270270

@@ -277,12 +277,7 @@ def click_first(btns_pos, search_img):
277277
buttons_position = Image.get_target_positions("button_fight_on", not_target="button_fight_off", screen_image=screen_img)
278278

279279
if not buttons_position:
280-
scroll(
281-
safe_scroll_target="ship_bar_vertical",
282-
distance=Config.get('screen','scroll', 'distance'),
283-
duration=Config.get('screen','scroll', 'duration'),
284-
wait=Config.get('screen','scroll', 'wait'),
285-
)
280+
Ship.scroll_ships()
286281
scroll_times += 1
287282
continue
288283

@@ -292,7 +287,7 @@ def click_first(btns_pos, search_img):
292287
final_x = inital_x + width_search_area
293288

294289
search_img = screen_img[:,inital_x:final_x, :]
295-
logger("↳", end=" ", datetime=False)
290+
296291

297292
ship_work_percent = Config.get('ship_work_percent')
298293

@@ -303,6 +298,11 @@ def click_first(btns_pos, search_img):
303298
if time.time() - start_time > 15:
304299
if not Ship.check_number_of_ships(Image.screen(), n_ships):
305300
raise Exception(f"Error trying to send {n_ships} ships to fight.")
301+
else:
302+
Ship.scroll_ships()
303+
scroll_times += 1
304+
continue
305+
306306

307307

308308
if n_ships < Config.get('n_minimum_ships_to_fight'):
@@ -327,6 +327,14 @@ def click_first(btns_pos, search_img):
327327
manager.set_refresh_timer("refresh_ships")
328328
return True
329329

330+
def scroll_ships():
331+
return scroll(
332+
safe_scroll_target=["button_fight_on", "button_fight_off"],
333+
distance=Config.get('screen','scroll', 'distance'),
334+
duration=Config.get('screen','scroll', 'duration'),
335+
wait=Config.get('screen','scroll', 'wait'),
336+
)
337+
330338
def check_number_of_ships(screen_img, n_ships):
331339
# CROP SCREEN FROM TEXT 'BATTLE':
332340
x, y, w, h = Image.get_one_target_position("identify_n_space_shipts_in_battle_start_area", screen_image=screen_img)

0 commit comments

Comments
 (0)