def kill_popups_two(): ma.GS.im_app = ma.get_screen_shot() # get screan shot of app screen_cords = ma.screen_cords(ma.GS.click_bases) def do_action(so): """If the condiciton is med below, then do one of the following.""" da_msg = s_cord['msg'] if da_msg in ma.GS.popup_msgs: ma.GS.popup_msgs[da_msg] += 1 else: ma.GS.popup_msgs.update({da_msg: 1}) print(f"{da_msg}") if so['mv_to_click']: x = so['mv_to_click'][0] y = so['mv_to_click'][1] pag.moveTo(ma.GS.x + x, ma.GS.y + y, duration=.2) pag.click(ma.GS.x + x, ma.GS.y + y, clicks=1, button='left', interval=1) if so['mv_to_click_after_press']: sleep(so['sleap_after']) pag.press(so['mv_to_click_after_press'], interval=0) sleep(so['sleap_after']) else: pag.press(so['keys_press'], interval=0) sleep(so['sleap_after']) for s_cord in screen_cords: ### process cropped image needed_region = ma.cord_dict_to_tuple(s_cord['cords_dict']) im = ma.GS.im_app.crop(needed_region) im_gray = ma.get_img_gray(im) im_hash = ma.get_image_hash(im_gray) ### OCR process if s_cord['search_text']: im_text = ma.get_image_text(im, s_cord['text_color'])[0] else: im_text = '---' ### test each case if im_hash in s_cord['hashes']: do_action(s_cord) return 1 elif s_cord['search_text']: for s_text in s_cord['search_text']: if s_text in im_text: do_action(s_cord) print('\nsearch_text', s_cord['cords_dict'], im_hash, im_text) return 1 if ma.GS.debugging: # im.show() print('\nelse loop', s_cord['msg'], s_cord['cords_dict'], im_hash, im_text) return 0
def get_if_wasted(): sys_waste_hash='f01e8a71625e792d' sys_clean_cords=(1280,530,1400,580) ma.GS.im_app = ma.get_screen_shot() im_n = ma.GS.im_app.crop((sys_clean_cords)) im_n_hash = str(imagehash.phash(im_n)) if im_n_hash == sys_waste_hash: return True else: return False
def review_ship_builders(): """If any amount of ship building, then push almost all RD to ships.""" is_ship_building_hash='9887e638c1e4c6ee' is_ship_building_cords=(1050,390,1145,430) ma.GS.im_app = ma.get_screen_shot() im = ma.GS.im_app.crop((is_ship_building_cords)) im_hash = str(imagehash.phash(im)) if im_hash == is_ship_building_hash: pag.moveTo(ma.GS.x + 1170, ma.GS.y + 615, duration=.1) pag.click(ma.GS.x + 1170, ma.GS.y + 615, clicks=1, button='left',interval=.1) return True else: return False
def return_base_count(): base_hash_dict = ma.hashdata.bases() base_ct_cords=(1340,290,1420,340) base_ct_colors=[(255,218,76)] ma.GS.im_app = ma.get_screen_shot() base_im = ma.GS.im_app.crop((base_ct_cords)) im_t_img = ma.get_image_text(base_im, base_ct_colors)[1] base_hash = str(imagehash.phash(im_t_img)) if base_hash in base_hash_dict: return base_hash_dict[base_hash] else: im_t_img.save(f'.\\tmp\\{base_hash}.PNG') return 100
def get_idle_game_string(): """ Return a string of the game bar img hash and the mouse pointer. """ ma.GS.mouse_pos = str(pag.position()) ma.GS.im_app = ma.get_screen_shot() game_bar_hash = 'c88cafe3b7008a3f' game_bar_cords = (50,830,1100,910) game_bar_img = ma.GS.im_app.crop((game_bar_cords)) game_bar_current_hash = str(imagehash.phash(game_bar_img)) if game_bar_current_hash != game_bar_hash: return '---' else: return game_bar_current_hash + '-' + ma.GS.mouse_pos
def get_system_name(): ### name system_name_dict = ma.hashdata.sysnames() im_n_hash = '00000000000' while im_n_hash == '00000000000': ma.GS.im_app = ma.get_screen_shot() im_n = ma.GS.im_app.crop((sys_name_cords)) im_text, im_n_bw = ma.get_image_text(im_n, sys_name_colors) im_n_hash = str(imagehash.phash(im_n_bw)) if im_n_hash in system_name_dict: im_text = system_name_dict[im_n_hash] else: im_n_bw.save(f'.\\tmp\\{im_n_hash}.PNG') return im_n_hash, im_text