From 88224a5aca58aefadf027d410f79a6c34614a59f Mon Sep 17 00:00:00 2001 From: Kara Alexandra Date: Wed, 5 Mar 2025 19:06:19 -0600 Subject: [PATCH] Add spoiler json output option --- .gitignore | 2 ++ EntranceRandomizer.py | 1 + Main.py | 6 ++++++ 3 files changed, 9 insertions(+) diff --git a/.gitignore b/.gitignore index 6812cac0..31f6bb1e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,8 @@ .idea .vscode *_Spoiler.txt +*_Spoiler.json +*_Meta.json *.pyc *.sfc *.wixobj diff --git a/EntranceRandomizer.py b/EntranceRandomizer.py index 7ec65b0e..937bfb2d 100755 --- a/EntranceRandomizer.py +++ b/EntranceRandomizer.py @@ -19,6 +19,7 @@ class ArgumentDefaultsHelpFormatter(argparse.RawTextHelpFormatter): def start(): parser = argparse.ArgumentParser(formatter_class=ArgumentDefaultsHelpFormatter) parser.add_argument('--create_spoiler', help='Output a Spoiler File', action='store_true') + parser.add_argument('--json_spoiler', help='Output a JSON Spoiler File', action='store_true') parser.add_argument('--logic', default='noglitches', const='noglitches', nargs='?', choices=['noglitches', 'minorglitches', 'nologic'], help='''\ Select Enforcement of Item Requirements. (default: %(default)s) diff --git a/Main.py b/Main.py index 1681ad72..e98955e1 100644 --- a/Main.py +++ b/Main.py @@ -144,6 +144,12 @@ def main(args, seed=None): if args.create_spoiler and not args.jsonout: world.spoiler.to_file(output_path('%s_Spoiler.txt' % outfilebase)) + if args.json_spoiler: + with open(output_path('%s_Spoiler.json' % outfilebase), 'w') as outfile: + outfile.write(world.spoiler.to_json()) + with open(output_path('%s_Meta.json' % outfilebase), 'w') as outfile: + outfile.write(json.dumps(world.spoiler.metadata)) + if not args.skip_playthrough: logger.info('Calculating playthrough.') create_playthrough(world)