48 lines
1.9 KiB
Python
48 lines
1.9 KiB
Python
|
#!/usr/bin/python
|
||
|
|
||
|
import logging
|
||
|
import re
|
||
|
|
||
|
|
||
|
def import_entrances(spoiler_log='/home/alice/Games/steam/steamapps/compatdata/553420/pfx/drive_c/users/steamuser/AppData/LocalLow/Andrew Shouldice/Secret Legend/Randomizer/Spoiler.log'):
|
||
|
"""A function to import the entrance mappings from the user's spoiler log.
|
||
|
|
||
|
Args:
|
||
|
spoiler_log (str, optional): The filepath of the spoiler log. Defaults to '/home/alice/Games/steam/steamapps/compatdata/553420/pfx/drive_c/users/steamuser/AppData/LocalLow/Andrew Shouldice/Secret Legend/Randomizer/Spoiler.log'.
|
||
|
"""
|
||
|
|
||
|
try:
|
||
|
with open(spoiler_log, 'r') as f:
|
||
|
spoiler_text = f.read()
|
||
|
entrances_map = re.findall('\s+- (.+) -- (.+)\n', spoiler_text)
|
||
|
# logging.debug(entrances_map)
|
||
|
except:
|
||
|
logging.error(f'Could not find spoiler log from path: {spoiler_log}')
|
||
|
return
|
||
|
|
||
|
return dict(entrances_map)
|
||
|
|
||
|
|
||
|
def log_entrances(e):
|
||
|
"""A debug function to ensure entrance parsing has been done successfully.
|
||
|
"""
|
||
|
|
||
|
for l in e:
|
||
|
logging.debug(f'{l[0]} <---> {l[1]}')
|
||
|
|
||
|
|
||
|
def check_mapped_entrances(new_entrances, entrances_map):
|
||
|
"""A function to check off when a new entrance pair has been visited and validate it with the spoiler log.
|
||
|
|
||
|
Args:
|
||
|
new_entrances (tuple): A pairing of two strings containing the entrance names.
|
||
|
entrances_map (dict): An imported dictionary mapping the entrances as listed in the spoiler log.
|
||
|
"""
|
||
|
if new_entrances[0] in entrances_map.keys():
|
||
|
logging.debug(f'Validated that {new_entrances[0]} connects to {new_entrances[1]}')
|
||
|
elif new_entrances[1] in entrances_map.keys():
|
||
|
logging.debug(f'Validated that {new_entrances[1]} connects to {new_entrances[0]}')
|
||
|
else:
|
||
|
logging.warn(f'No connection in spoiler log between {new_entrances[0]} and {new_entrances[1]}')
|
||
|
return False
|
||
|
return True
|