From ac46d4d8aafdc2c6cef6fee16495a596cd0ba75c Mon Sep 17 00:00:00 2001 From: StructuralMike <66819228+StructuralMike@users.noreply.github.com> Date: Sat, 27 Mar 2021 12:43:00 +0100 Subject: [PATCH 1/2] Update mystery yaml parser to a maintained package module Tested on both local files and url-files and works great. --- Mystery.py | 35 +++---------------- .../app/meta/manifests/pip_requirements.txt | 3 +- 2 files changed, 7 insertions(+), 31 deletions(-) diff --git a/Mystery.py b/Mystery.py index 2d827747..f7d360bf 100644 --- a/Mystery.py +++ b/Mystery.py @@ -4,33 +4,12 @@ import random import urllib.request import urllib.parse import re +import yaml from DungeonRandomizer import parse_cli from Main import main as DRMain from source.classes.BabelFish import BabelFish -def parse_yaml(txt): - def strip(s): - s = s.strip() - return '' if not s else s.strip('"') if s[0] == '"' else s.strip("'") if s[0] == "'" else s - ret = {} - indents = {len(txt) - len(txt.lstrip(' ')): ret} - for line in txt.splitlines(): - line = re.sub(r'#.*', '', line) - if not line: - continue - name, val = line.split(':', 1) - val = strip(val) - spaces = len(name) - len(name.lstrip(' ')) - name = strip(name) - if val: - indents[spaces][name] = val - else: - newdict = {} - indents[spaces][name] = newdict - indents[spaces+2] = newdict - return ret - def main(): parser = argparse.ArgumentParser(add_help=False) parser.add_argument('--multi', default=1, type=lambda value: min(max(int(value), 1), 255)) @@ -106,15 +85,11 @@ def main(): def get_weights(path): try: if urllib.parse.urlparse(path).scheme: - yaml = str(urllib.request.urlopen(path).read(), "utf-8") - else: - with open(path, 'rb') as f: - yaml = str(f.read(), "utf-8") + return yaml.load(urllib.request.urlopen(path), Loader=yaml.FullLoader) + with open(path, 'r', encoding='utf-8') as f: + return yaml.load(f, Loader=yaml.FullLoader) except Exception as e: - print('Failed to read weights (%s)' % e) - return - - return parse_yaml(yaml) + raise Exception(f'Failed to read weights file: {e}') def roll_settings(weights): def get_choice(option, root=weights): diff --git a/resources/app/meta/manifests/pip_requirements.txt b/resources/app/meta/manifests/pip_requirements.txt index 595691d2..faa3c48f 100644 --- a/resources/app/meta/manifests/pip_requirements.txt +++ b/resources/app/meta/manifests/pip_requirements.txt @@ -3,4 +3,5 @@ fast-enum python-bps-continued colorama aioconsole -websockets \ No newline at end of file +websockets +pyyaml \ No newline at end of file From b42e4db472d2187da2e8757c5087e95369fdb333 Mon Sep 17 00:00:00 2001 From: StructuralMike <66819228+StructuralMike@users.noreply.github.com> Date: Tue, 13 Apr 2021 16:58:08 +0200 Subject: [PATCH 2/2] potential retro-fix --- Rom.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Rom.py b/Rom.py index 392efbb7..b4cb3da5 100644 --- a/Rom.py +++ b/Rom.py @@ -1571,8 +1571,9 @@ def write_custom_shops(rom, world, player): break if world.shopsanity[player] or shop.type == ShopType.TakeAny: rom.write_byte(0x186560 + shop.sram_address + index, 1) - loc_item = world.get_location(shop_to_location_table[shop.region.name][index], player).item - if not loc_item: + if world.shopsanity[player] and shop.region.name in shop_to_location_table: + loc_item = world.get_location(shop_to_location_table[shop.region.name][index], player).item + else: loc_item = ItemFactory(item['item'], player) item_id = loc_item.code price = int16_as_bytes(item['price'])