keep MultiMystery.py console open in case of crash, as users typically don't know how to keep a console open
This commit is contained in:
		
							parent
							
								
									1c736f8afe
								
							
						
					
					
						commit
						2ff2b5b30c
					
				
							
								
								
									
										133
									
								
								MultiMystery.py
								
								
								
								
							
							
						
						
									
										133
									
								
								MultiMystery.py
								
								
								
								
							| 
						 | 
				
			
			@ -55,70 +55,75 @@ def feedback(text:str):
 | 
			
		|||
 | 
			
		||||
 | 
			
		||||
if __name__ == "__main__":
 | 
			
		||||
    print(f"{__author__}'s MultiMystery Launcher V{__version__}")
 | 
			
		||||
    if not os.path.exists(enemizer_location):
 | 
			
		||||
        feedback(f"Enemizer not found at {enemizer_location}, please adjust the path in MultiMystery.py's config or put Enemizer in the default location.")
 | 
			
		||||
    if not os.path.exists("Zelda no Densetsu - Kamigami no Triforce (Japan).sfc"):
 | 
			
		||||
        feedback("Base rom is expected as Zelda no Densetsu - Kamigami no Triforce (Japan).sfc in the Multiworld root folder please place/rename it there.")
 | 
			
		||||
    player_files = []
 | 
			
		||||
    os.makedirs(player_files_folder, exist_ok=True)
 | 
			
		||||
    for file in os.listdir(player_files_folder):
 | 
			
		||||
        if file.lower().endswith(".yaml"):
 | 
			
		||||
            player_files.append(file)
 | 
			
		||||
            print(f"Player {file[:-5]} found.")
 | 
			
		||||
    player_count = len(player_files)
 | 
			
		||||
    if player_count == 0:
 | 
			
		||||
        feedback(f"No player files found. Please put them in a {player_files_folder} folder.")
 | 
			
		||||
    else:
 | 
			
		||||
        print(player_count, "Players found.")
 | 
			
		||||
 | 
			
		||||
    player_string = ""
 | 
			
		||||
    for i,file in enumerate(player_files):
 | 
			
		||||
        player_string += f"--p{i+1} {os.path.join(player_files_folder, file)} "
 | 
			
		||||
 | 
			
		||||
    player_names = list(file[:-5] for file in player_files)
 | 
			
		||||
 | 
			
		||||
    command = f"py -{py_version} Mystery.py --multi {len(player_files)} {player_string} " \
 | 
			
		||||
              f"--names {','.join(player_names)} --enemizercli {enemizer_location} " \
 | 
			
		||||
              f"--outputpath {outputpath}" + " --create_spoiler" if create_spoiler else "" + " --race" if race else ""
 | 
			
		||||
    print(command)
 | 
			
		||||
    import time
 | 
			
		||||
    start = time.perf_counter()
 | 
			
		||||
    text = subprocess.check_output(command, shell=True).decode()
 | 
			
		||||
    print(f"Took {time.perf_counter()-start:.3f} seconds to generate seed.")
 | 
			
		||||
    seedname = ""
 | 
			
		||||
 | 
			
		||||
    for segment in text.split():
 | 
			
		||||
        if segment.startswith("M"):
 | 
			
		||||
            seedname = segment
 | 
			
		||||
            break
 | 
			
		||||
 | 
			
		||||
    multidataname = f"ER_{seedname}_multidata"
 | 
			
		||||
 | 
			
		||||
    romfilename = ""
 | 
			
		||||
    if player_name:
 | 
			
		||||
        try:
 | 
			
		||||
            index = player_names.index(player_name)
 | 
			
		||||
        except IndexError:
 | 
			
		||||
            print(f"Could not find Player {player_name}")
 | 
			
		||||
    try:
 | 
			
		||||
        print(f"{__author__}'s MultiMystery Launcher V{__version__}")
 | 
			
		||||
        if not os.path.exists(enemizer_location):
 | 
			
		||||
            feedback(f"Enemizer not found at {enemizer_location}, please adjust the path in MultiMystery.py's config or put Enemizer in the default location.")
 | 
			
		||||
        if not os.path.exists("Zelda no Densetsu - Kamigami no Triforce (Japan).sfc"):
 | 
			
		||||
            feedback("Base rom is expected as Zelda no Densetsu - Kamigami no Triforce (Japan).sfc in the Multiworld root folder please place/rename it there.")
 | 
			
		||||
        player_files = []
 | 
			
		||||
        os.makedirs(player_files_folder, exist_ok=True)
 | 
			
		||||
        for file in os.listdir(player_files_folder):
 | 
			
		||||
            if file.lower().endswith(".yaml"):
 | 
			
		||||
                player_files.append(file)
 | 
			
		||||
                print(f"Player {file[:-5]} found.")
 | 
			
		||||
        player_count = len(player_files)
 | 
			
		||||
        if player_count == 0:
 | 
			
		||||
            feedback(f"No player files found. Please put them in a {player_files_folder} folder.")
 | 
			
		||||
        else:
 | 
			
		||||
            romfilename = os.path.join(outputpath, f"ER_{seedname}_P{index+1}_{player_name}.sfc")
 | 
			
		||||
            import webbrowser
 | 
			
		||||
            if os.path.exists(romfilename):
 | 
			
		||||
                print(f"Launching ROM file {romfilename}")
 | 
			
		||||
                webbrowser.open(romfilename)
 | 
			
		||||
            print(player_count, "Players found.")
 | 
			
		||||
 | 
			
		||||
    if zip_roms:
 | 
			
		||||
        zipname = os.path.join(outputpath, f"ER_{seedname}.zip")
 | 
			
		||||
        print(f"Creating zipfile {zipname}")
 | 
			
		||||
        import zipfile
 | 
			
		||||
        with zipfile.ZipFile(zipname, "w", compression=zipfile.ZIP_DEFLATED, compresslevel=9) as zf:
 | 
			
		||||
            for file in os.listdir(outputpath):
 | 
			
		||||
                if file.endswith(".sfc") and seedname in file:
 | 
			
		||||
                    zf.write(os.path.join(outputpath, file), file)
 | 
			
		||||
                    print(f"Packed {file} into zipfile {zipname}")
 | 
			
		||||
                    if zip_roms == 2 and player_name.lower() not in file.lower():
 | 
			
		||||
                        os.remove(file)
 | 
			
		||||
                        print(f"Removed file {file} that is now present in the zipfile")
 | 
			
		||||
        player_string = ""
 | 
			
		||||
        for i,file in enumerate(player_files):
 | 
			
		||||
            player_string += f"--p{i+1} {os.path.join(player_files_folder, file)} "
 | 
			
		||||
 | 
			
		||||
    subprocess.call(f"py -{py_version} MultiServer.py --multidata {os.path.join(outputpath, multidataname)}")
 | 
			
		||||
        player_names = list(file[:-5] for file in player_files)
 | 
			
		||||
 | 
			
		||||
        command = f"py -{py_version} Mystery.py --multi {len(player_files)} {player_string} " \
 | 
			
		||||
                  f"--names {','.join(player_names)} --enemizercli {enemizer_location} " \
 | 
			
		||||
                  f"--outputpath {outputpath}" + " --create_spoiler" if create_spoiler else "" + " --race" if race else ""
 | 
			
		||||
        print(command)
 | 
			
		||||
        import time
 | 
			
		||||
        start = time.perf_counter()
 | 
			
		||||
        text = subprocess.check_output(command, shell=True).decode()
 | 
			
		||||
        print(f"Took {time.perf_counter()-start:.3f} seconds to generate seed.")
 | 
			
		||||
        seedname = ""
 | 
			
		||||
 | 
			
		||||
        for segment in text.split():
 | 
			
		||||
            if segment.startswith("M"):
 | 
			
		||||
                seedname = segment
 | 
			
		||||
                break
 | 
			
		||||
 | 
			
		||||
        multidataname = f"ER_{seedname}_multidata"
 | 
			
		||||
 | 
			
		||||
        romfilename = ""
 | 
			
		||||
        if player_name:
 | 
			
		||||
            try:
 | 
			
		||||
                index = player_names.index(player_name)
 | 
			
		||||
            except IndexError:
 | 
			
		||||
                print(f"Could not find Player {player_name}")
 | 
			
		||||
            else:
 | 
			
		||||
                romfilename = os.path.join(outputpath, f"ER_{seedname}_P{index+1}_{player_name}.sfc")
 | 
			
		||||
                import webbrowser
 | 
			
		||||
                if os.path.exists(romfilename):
 | 
			
		||||
                    print(f"Launching ROM file {romfilename}")
 | 
			
		||||
                    webbrowser.open(romfilename)
 | 
			
		||||
 | 
			
		||||
        if zip_roms:
 | 
			
		||||
            zipname = os.path.join(outputpath, f"ER_{seedname}.zip")
 | 
			
		||||
            print(f"Creating zipfile {zipname}")
 | 
			
		||||
            import zipfile
 | 
			
		||||
            with zipfile.ZipFile(zipname, "w", compression=zipfile.ZIP_DEFLATED, compresslevel=9) as zf:
 | 
			
		||||
                for file in os.listdir(outputpath):
 | 
			
		||||
                    if file.endswith(".sfc") and seedname in file:
 | 
			
		||||
                        zf.write(os.path.join(outputpath, file), file)
 | 
			
		||||
                        print(f"Packed {file} into zipfile {zipname}")
 | 
			
		||||
                        if zip_roms == 2 and player_name.lower() not in file.lower():
 | 
			
		||||
                            os.remove(file)
 | 
			
		||||
                            print(f"Removed file {file} that is now present in the zipfile")
 | 
			
		||||
 | 
			
		||||
        subprocess.call(f"py -{py_version} MultiServer.py --multidata {os.path.join(outputpath, multidataname)}")
 | 
			
		||||
    except:
 | 
			
		||||
        import traceback
 | 
			
		||||
        traceback.print_exc()
 | 
			
		||||
        input("Press enter to close")
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue