Skip to content

Commit

Permalink
Opt: move retry of input to input.py
Browse files Browse the repository at this point in the history
  • Loading branch information
guoh064 committed Apr 23, 2024
1 parent 405c207 commit 3407732
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 20 deletions.
13 changes: 11 additions & 2 deletions module/device/input.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
from module.device.method.uiautomator_2 import Uiautomator2
from module.logger import logger


class Input(Uiautomator2):
def text_input_and_confirm(self, text: str, clear: bool=False):
self.u2_send_keys(text=text, clear=clear)
self.u2_send_action(6)
for fail_count in range(3):
try:
self.u2_send_keys(text=text, clear=clear)
self.u2_send_action(6)
break
except EnvironmentError as e:
if fail_count >= 2:
raise e
logger.exception(str(e) + f'Retrying {fail_count + 1}/3')
23 changes: 5 additions & 18 deletions module/equipment/equipment_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@


def is_equip_code(string):
"""
Checks if current string is None or BASE64 string.
"""
if string is None:
return True
if not isinstance(string, str):
Expand Down Expand Up @@ -46,14 +49,12 @@ def __init__(self, config, key, ships):
self.config_key = key
self.coded_ships = ships
_config = config.cross_get(keys=key)
# print(_config)
codes = dict([(ship, None) for ship in self.coded_ships])
for line in _config.splitlines():
try:
codes.update(yaml.safe_load(line))
except Exception as e:
logger.error(f'Failed to parse current line of the config: "{line}", skipping')
# print(codes)
for ship in self.coded_ships:
code: str = codes.pop(ship, None)
self.__setattr__(ship, code)
Expand All @@ -66,7 +67,6 @@ def export_to_config(self):
for ship in self.coded_ships:
_config.update({ship: self.__getattribute__(ship)})
value = yaml.safe_dump(_config)
# print(value)
self.config.cross_set(keys=self.config_key, value=value)


Expand Down Expand Up @@ -193,7 +193,7 @@ def confirm_equip_preview(self, skip_first_screenshot=True):
if self.appear_then_click(EQUIPMENT_CODE_CONFIRM, interval=5):
continue

if self.handle_popup_confirm('GEAR_CODE'):
if self.handle_popup_confirm('EQUIPMENT_CODE'):
continue

# End
Expand Down Expand Up @@ -224,24 +224,11 @@ def apply_equip_code(self, code=None):
code = self.codes.__getattribute__(ship)
while 1:
self.enter_equip_code_input_mode()
try:
self.device.text_input_and_confirm(code, clear=True)
except EnvironmentError as e:
continue
self.device.text_input_and_confirm(code, clear=True)
self.confirm_equip_code()
success = self.confirm_equip_preview()
if success:
break
else:
self.handle_storage_full()
self.clear_equip_preview()


if __name__=="__main__":
config = AzurLaneConfig('alas')
key = "GemsFarming.GemsFarming.EquipmentCode"
ships = ['DD', 'bogue', 'hermes', 'langley', 'ranger']
self = EquipmentCodeHandler(config, key=key, ships=ships)
print(self.codes.hermes)
# self.codes.export_to_config(config)
# print(self.GemsFarming_EquipmentCode)

0 comments on commit 3407732

Please sign in to comment.