diff --git a/.gitignore b/.gitignore index 9f9fc87a..91b22ab9 100644 --- a/.gitignore +++ b/.gitignore @@ -16,10 +16,13 @@ README.html EnemizerCLI/ .mypy_cache/ RaceRom.py +upx/ weights/ settings.json working_dirs.json +*.exe + venv test diff --git a/CLI.py b/CLI.py index 9d1b8045..69a00b09 100644 --- a/CLI.py +++ b/CLI.py @@ -238,7 +238,7 @@ def parse_arguments(argv, no_defaults=False): parser.add_argument('--startinventory', default=defval(settings["startinventory"]), help='Specifies a list of items that will be in your starting inventory (separated by commas)') parser.add_argument('--usestartinventory', default=defval(settings["usestartinventory"] != 0), help='Not supported.') parser.add_argument('--custom', default=defval(settings["custom"] != 0), help='Not supported.') - parser.add_argument('--customitemarray', default=defval(settings["custom"] != 0), help='Not supported.') + parser.add_argument('--customitemarray', default={}, help='Not supported.') parser.add_argument('--accessibility', default=defval(settings["accessibility"]), const='items', nargs='?', choices=['items', 'locations', 'none'], help='''\ Select Item/Location Accessibility. (default: %(default)s) Items: You can reach all unique inventory items. No guarantees about @@ -492,11 +492,15 @@ def get_args_priority(settings_args, gui_args, cli_args): args["cli"] = {} cli = vars(parse_arguments(None)) for k,v in cli.items(): - if isinstance(v,dict): + if isinstance(v,dict) and 1 in v: args["cli"][k] = v[1] else: args["cli"][k] = v - if k not in args["load"] or args["load"][k] != args["cli"]: - args["load"][k] = args["cli"][k] + load_doesnt_have_key = k not in args["load"] + different_val = (k in args["load"] and k in args["cli"]) and (args["load"][k] != args["cli"][k]) + cli_has_empty_dict = k in args["cli"] and isinstance(args["cli"][k],dict) and len(args["cli"][k]) == 0 + if load_doesnt_have_key or different_val: + if not cli_has_empty_dict: + args["load"][k] = args["cli"][k] return args diff --git a/DungeonRandomizer.spec b/DungeonRandomizer.spec new file mode 100644 index 00000000..7b8de387 --- /dev/null +++ b/DungeonRandomizer.spec @@ -0,0 +1,59 @@ +# -*- mode: python -*- + +block_cipher = None +console = True + +def recurse_for_py_files(names_so_far): + returnvalue = [] + for name in os.listdir(os.path.join(*names_so_far)): + if name != "__pycache__": + subdir_name = os.path.join(*names_so_far, name) + if os.path.isdir(subdir_name): + new_name_list = names_so_far + [name] + for filename in os.listdir(os.path.join(*new_name_list)): + base_file,file_extension = os.path.splitext(filename) + if file_extension == ".py": + new_name = ".".join(new_name_list+[base_file]) + if not new_name in returnvalue: + returnvalue.append(new_name) + returnvalue.extend(recurse_for_py_files(new_name_list)) + returnvalue.append("PIL._tkinter_finder") #Linux needs this + return returnvalue + +hiddenimports = [] + +a = Analysis(['DungeonRandomizer.py'], + pathex=[], + binaries=[], + datas=[], + hiddenimports=hiddenimports, + hookspath=[], + runtime_hooks=[], + excludes=[], + win_no_prefer_redirects=False, + win_private_assemblies=False, + cipher=block_cipher, + noarchive=False) + +# https://stackoverflow.com/questions/17034434/how-to-remove-exclude-modules-and-files-from-pyinstaller +excluded_binaries = [ + 'VCRUNTIME140.dll', + 'msvcp140.dll', + 'mfc140u.dll'] +a.binaries = TOC([x for x in a.binaries if x[0] not in excluded_binaries]) + +pyz = PYZ(a.pure, a.zipped_data, + cipher=block_cipher) +exe = EXE(pyz, + a.scripts, + a.binaries, + a.zipfiles, + a.datas, + [], + name='DungeonRandomizer', + debug=False, + bootloader_ignore_signals=False, + strip=False, + upx=True, + runtime_tmpdir=None, + console=console ) # <--- change this to True to enable command prompt when the app runs diff --git a/Gui.spec b/Gui.spec new file mode 100644 index 00000000..cd6de67d --- /dev/null +++ b/Gui.spec @@ -0,0 +1,59 @@ +# -*- mode: python -*- + +block_cipher = None +console = True + +def recurse_for_py_files(names_so_far): + returnvalue = [] + for name in os.listdir(os.path.join(*names_so_far)): + if name != "__pycache__": + subdir_name = os.path.join(*names_so_far, name) + if os.path.isdir(subdir_name): + new_name_list = names_so_far + [name] + for filename in os.listdir(os.path.join(*new_name_list)): + base_file,file_extension = os.path.splitext(filename) + if file_extension == ".py": + new_name = ".".join(new_name_list+[base_file]) + if not new_name in returnvalue: + returnvalue.append(new_name) + returnvalue.extend(recurse_for_py_files(new_name_list)) + returnvalue.append("PIL._tkinter_finder") #Linux needs this + return returnvalue + +hiddenimports = [] + +a = Analysis(['Gui.py'], + pathex=[], + binaries=[], + datas=[], + hiddenimports=hiddenimports, + hookspath=[], + runtime_hooks=[], + excludes=[], + win_no_prefer_redirects=False, + win_private_assemblies=False, + cipher=block_cipher, + noarchive=False) + +# https://stackoverflow.com/questions/17034434/how-to-remove-exclude-modules-and-files-from-pyinstaller +excluded_binaries = [ + 'VCRUNTIME140.dll', + 'msvcp140.dll', + 'mfc140u.dll'] +a.binaries = TOC([x for x in a.binaries if x[0] not in excluded_binaries]) + +pyz = PYZ(a.pure, a.zipped_data, + cipher=block_cipher) +exe = EXE(pyz, + a.scripts, + a.binaries, + a.zipfiles, + a.datas, + [], + name='Gui', + debug=False, + bootloader_ignore_signals=False, + strip=False, + upx=True, + runtime_tmpdir=None, + console=console ) # <--- change this to True to enable command prompt when the app runs diff --git a/Utils.py b/Utils.py index a52e8616..d616ef22 100644 --- a/Utils.py +++ b/Utils.py @@ -34,6 +34,8 @@ def is_bundled(): return getattr(sys, 'frozen', False) def local_path(path): + return path + if local_path.cached_path is not None: return os.path.join(local_path.cached_path, path) diff --git a/build-dr.py b/build-dr.py new file mode 100644 index 00000000..120028d9 --- /dev/null +++ b/build-dr.py @@ -0,0 +1,21 @@ +import subprocess +import os +import shutil + +DEST_DIRECTORY = '.' + +if os.path.isdir("upx"): + upx_string = "--upx-dir=upx" +else: + upx_string = "" + +if os.path.isdir("build"): + shutil.rmtree("build") + +subprocess.run(" ".join(["pyinstaller DungeonRandomizer.spec ", + upx_string, + "-y ", + "--onefile ", + f"--distpath {DEST_DIRECTORY} ", + ]), + shell=True) diff --git a/build-gui.py b/build-gui.py new file mode 100644 index 00000000..3f63548d --- /dev/null +++ b/build-gui.py @@ -0,0 +1,21 @@ +import subprocess +import os +import shutil + +DEST_DIRECTORY = '.' + +if os.path.isdir("upx"): + upx_string = "--upx-dir=upx" +else: + upx_string = "" + +if os.path.isdir("build"): + shutil.rmtree("build") + +subprocess.run(" ".join(["pyinstaller Gui.spec ", + upx_string, + "-y ", + "--onefile ", + f"--distpath {DEST_DIRECTORY} ", + ]), + shell=True)