From 215a4d039f26233c4213e668ffbd670e9ce89424 Mon Sep 17 00:00:00 2001 From: "Mike A. Trethewey" Date: Sun, 22 Mar 2020 16:32:15 -0700 Subject: [PATCH] Pull in fixes from Multiworld --- Fill.py | 2 +- Main.py | 4 +++ Rom.py | 2 +- resources/app/cli/lang/en.json | 2 +- source/gui/bottom.py | 64 ++++++++++++++++++++++++---------- source/gui/loadcliargs.py | 2 +- 6 files changed, 54 insertions(+), 22 deletions(-) diff --git a/Fill.py b/Fill.py index 69a774bb..014db619 100644 --- a/Fill.py +++ b/Fill.py @@ -392,7 +392,7 @@ def balance_multiworld_progression(world): threshold = max(reachable_locations_count.values()) - 20 balancing_players = [player for player, reachables in reachable_locations_count.items() if reachables < threshold] - if balancing_players: + if balancing_players is not None and len(balancing_players) > 0: balancing_state = state.copy() balancing_unchecked_locations = unchecked_locations.copy() balancing_reachables = reachable_locations_count.copy() diff --git a/Main.py b/Main.py index 407af108..35300de9 100644 --- a/Main.py +++ b/Main.py @@ -191,6 +191,7 @@ def main(args, seed=None, fish=None): for team in range(world.teams): for player in range(1, world.players + 1): sprite_random_on_hit = type(args.sprite[player]) is str and args.sprite[player].lower() == 'randomonhit' + enemized = False use_enemizer = (world.boss_shuffle[player] != 'none' or world.enemy_shuffle[player] != 'none' or world.enemy_health[player] != 'default' or world.enemy_damage[player] != 'default' or args.shufflepots[player] or sprite_random_on_hit) @@ -204,6 +205,7 @@ def main(args, seed=None, fish=None): raise RuntimeError("Could not find valid base rom for enemizing at expected path %s." % args.rom) if os.path.exists(args.enemizercli): patch_enemizer(world, player, rom, args.rom, args.enemizercli, args.shufflepots[player], sprite_random_on_hit) + enemized = True if not args.jsonout: rom = LocalRom.fromJsonRom(rom, args.rom, 0x400000) else: @@ -212,6 +214,8 @@ def main(args, seed=None, fish=None): logging.warning(enemizerMsg) raise EnemizerError(enemizerMsg) + patch_rom(world, rom, player, team, enemized) + if args.race: patch_race_rom(rom) diff --git a/Rom.py b/Rom.py index b2344e7f..db84aefd 100644 --- a/Rom.py +++ b/Rom.py @@ -79,7 +79,7 @@ class LocalRom(object): self.hash = hash self.orig_buffer = None if not os.path.isfile(file): - raise RuntimeError("Could not find valid local base rom for patching at expected path %s." % args.rom) + raise RuntimeError("Could not find valid local base rom for patching at expected path %s." % file) with open(file, 'rb') as stream: self.buffer = read_rom(stream) if patch: diff --git a/resources/app/cli/lang/en.json b/resources/app/cli/lang/en.json index 9c6519a4..6edf5496 100644 --- a/resources/app/cli/lang/en.json +++ b/resources/app/cli/lang/en.json @@ -36,7 +36,7 @@ "cannot.reach.required": "Not all required items reachable. Something went terribly wrong here.", "patching.rom": "Patching ROM", "patching.spoiler": "Creating Spoiler", - "calc.playthrough": "Calculating playthrough", + "calc.playthrough": "Calculating Playthrough", "made.rom": "Patched ROM: %s", "made.playthrough": "Printed Playthrough: %s", "made.spoiler": "Printed Spoiler: %s", diff --git a/source/gui/bottom.py b/source/gui/bottom.py index cb01b471..6daa4e30 100644 --- a/source/gui/bottom.py +++ b/source/gui/bottom.py @@ -3,6 +3,7 @@ from argparse import Namespace import logging import os import random +import re from CLI import parse_cli from Fill import FillError from Main import main, EnemizerError @@ -74,26 +75,53 @@ def bottom_frame(self, parent, args=None): setattr(guiargs, k, v) elif type(v) is dict: # use same settings for every player setattr(guiargs, k, {player: getattr(guiargs, k) for player in range(1, guiargs.multi + 1)}) - try: - if guiargs.count is not None: - seed = guiargs.seed - for _ in range(guiargs.count): - main(seed=seed, args=guiargs, fish=parent.fish) - seed = random.randint(0, 999999999) + argsDump = vars(guiargs) + hasEnemizer = "enemizercli" in argsDump and os.path.isfile(argsDump["enemizercli"]) + needEnemizer = False + if not hasEnemizer: + falsey = [ "none", "default", "vanilla", False, 0 ] + for enemizerOption in [ "shufflepots", "shuffleenemies", "enemy_damage", "shufflebosses", "enemy_health" ]: + if enemizerOption in argsDump: + if isinstance(argsDump[enemizerOption], dict): + for playerID,playerSetting in argsDump[enemizerOption].items(): + if not playerSetting in falsey: + needEnemizer = True + elif not argsDump[enemizerOption] in falsey: + needEnemizer = True + seeds = [] + if not needEnemizer or (needEnemizer and hasEnemizer): + try: + if guiargs.count is not None: + seed = guiargs.seed + for _ in range(guiargs.count): + seeds.append(seed) + main(seed=seed, args=guiargs, fish=parent.fish) + seed = random.randint(0, 999999999) + else: + seeds.append(guiargs.seed) + main(seed=guiargs.seed, args=guiargs, fish=parent.fish) + except (FillError, EnemizerError, Exception, RuntimeError) as e: + logging.exception(e) + messagebox.showerror(title="Error while creating seed", message=str(e)) else: - main(seed=guiargs.seed, args=guiargs, fish=parent.fish) - except (FillError, EnemizerError, Exception, RuntimeError) as e: - logging.exception(e) - messagebox.showerror(title="Error while creating seed", message=str(e)) - else: - YES = parent.fish.translate("cli","cli","yes") - NO = parent.fish.translate("cli","cli","no") - successMsg = "" - successMsg += (parent.fish.translate("cli","cli","made.rom").strip() % (YES if (guiargs.create_rom) else NO)) + "\n" - successMsg += (parent.fish.translate("cli","cli","made.playthrough").strip() % (YES if (guiargs.calc_playthrough) else NO)) + "\n" - successMsg += (parent.fish.translate("cli","cli","made.spoiler").strip() % (YES if (not guiargs.jsonout and guiargs.create_spoiler) else NO)) + YES = parent.fish.translate("cli","cli","yes") + NO = parent.fish.translate("cli","cli","no") + successMsg = "" + made = {} + for k in [ "rom", "playthrough", "spoiler" ]: + made[k] = parent.fish.translate("cli","cli","made." + k) + for k in made: + v = made[k] + pattern = "([\w]+)(:)([\s]+)(.*)" + m = re.search(pattern,made[k]) + made[k] = m.group(1) + m.group(2) + ' ' + m.group(4) + successMsg += (made["rom"] % (YES if (guiargs.create_rom) else NO)) + "\n" + successMsg += (made["playthrough"] % (YES if (guiargs.calc_playthrough) else NO)) + "\n" + successMsg += (made["spoiler"] % (YES if (not guiargs.jsonout and guiargs.create_spoiler) else NO)) + "\n" + # FIXME: English + successMsg += ("Seed%s: %s" % ('s' if len(seeds) > 1 else "", ','.join(seeds))) - messagebox.showinfo(title="Success", message=successMsg) + messagebox.showinfo(title="Success", message=successMsg) ## Generate Button # widget ID diff --git a/source/gui/loadcliargs.py b/source/gui/loadcliargs.py index 83342892..31658549 100644 --- a/source/gui/loadcliargs.py +++ b/source/gui/loadcliargs.py @@ -124,7 +124,7 @@ def loadcliargs(gui, args, settings=None): widget = "seed" setting = "seed" if args[setting]: - gui.pages[mainpage].widgets[widget].storageVar.set(args[setting]) + gui.pages[mainpage].pages[subpage].widgets[widget].storageVar.set(args[setting]) # set textbox/frame label label = fish.translate("gui","gui",mainpage + '.' + subpage + '.' + widget) gui.pages[mainpage].pages[subpage].widgets[widget].pieces["frame"].label.configure(text=label)