Skip to content

Commit

Permalink
Fix: empty code 0/0/0/0/0\0 and missing export
Browse files Browse the repository at this point in the history
  • Loading branch information
guoh064 committed Aug 28, 2024
1 parent aa2e985 commit 145ce00
Showing 1 changed file with 22 additions and 14 deletions.
36 changes: 22 additions & 14 deletions module/equipment/equipment_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@


BASE64_REGEX = re.compile('^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$')

EMPTY_GEAR_CODE = "MC8wLzAvMC8wXDA="

def is_equip_code(string):
"""
Expand Down Expand Up @@ -109,13 +109,8 @@ def current_ship(self):
# Will be overridden in subclasses.
pass

def export_equip_code(self, ship=None, skip_first_screenshot=True):
"""
Export current ship's gear code to config file.
This is done by first using "export" button
to export gear code to clipboard,
then update the config file using yaml.safe_dump().
"""
def click_export_button(self, skip_first_screenshot=True):
self.handle_info_bar()
while 1:
if skip_first_screenshot:
skip_first_screenshot = False
Expand All @@ -128,8 +123,17 @@ def export_equip_code(self, ship=None, skip_first_screenshot=True):

if self.appear_then_click(EQUIPMENT_CODE_EXPORT, interval=1):
continue


def export_equip_code(self, ship=None):
"""
Export current ship's gear code to config file.
This is done by first using "export" button
to export gear code to clipboard,
then update the config file using yaml.safe_dump().
"""
code = self.device.clipboard
if code == EMPTY_GEAR_CODE:
logger.info('Detect 0/0/0/0/0\\0 code, continue exporting.')
logger.attr("Gear code", code)
if not ship in self.codes.coded_ships:
ship = self.current_ship()
Expand Down Expand Up @@ -217,6 +221,7 @@ def confirm_equip_preview(self, skip_first_screenshot=True):
def clear_all_equip(self):
self.enter_equip_code_page()
ship = self.current_ship()
self.click_export_button()
if self.codes.__getattribute__(ship) is None:
self.export_equip_code(ship)
self.clear_equip_preview()
Expand All @@ -234,15 +239,18 @@ def apply_equip_code(self, code=None):
if code is None:
ship = self.current_ship()
code = self.codes.__getattribute__(ship)
if code is None:
code = self.device.clipboard # assuming clipboard is not modified
logger.info(f'Apply gear code {code} for {ship}')
else:
logger.info(f'Forcefully apply gear code {code} to current ship.')
while 1:
self.enter_equip_code_input_mode()
self.device.text_input_and_confirm(code, clear=True)
success = self.confirm_equip_code()
if not success:
continue
if code is not None and code != EMPTY_GEAR_CODE:
self.enter_equip_code_input_mode()
self.device.text_input_and_confirm(code, clear=True)
success = self.confirm_equip_code()
if not success:
continue
success = self.confirm_equip_preview()
if success:
logger.info("Gear code import complete.")
Expand Down

0 comments on commit 145ce00

Please sign in to comment.