From 62eb78e1ce43a767fd1edfdec96a5f198aa1ec00 Mon Sep 17 00:00:00 2001 From: Kara Alexandra Date: Sun, 2 Mar 2025 00:19:57 -0600 Subject: [PATCH] Add json spoiler option --- .gitignore | 1 + BaseClasses.py | 2 +- Main.py | 14 ++++++++++---- resources/app/cli/args.json | 3 ++- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index f731841f..f9ac15fa 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ *.bmbp *.log *_Spoiler.json +*_Meta.json *_custom.yaml *_meta.txt *.bps diff --git a/BaseClasses.py b/BaseClasses.py index 19725779..138f8bae 100644 --- a/BaseClasses.py +++ b/BaseClasses.py @@ -2944,7 +2944,7 @@ class Spoiler(object): self.settings = {'settings'} elif world.spoiler_mode == 'semi': self.settings = {'settings', 'entrances', 'requirements', 'prizes'} - elif world.spoiler_mode == 'full': + elif world.spoiler_mode == 'full' or world.spoiler_mode == 'json': self.settings = {'all'} elif world.spoiler_mode == 'debug': self.settings = {'all', 'debug'} diff --git a/Main.py b/Main.py index e1af57b1..10333981 100644 --- a/Main.py +++ b/Main.py @@ -160,7 +160,8 @@ def main(args, seed=None, fish=None): if world.spoiler_mode != 'none' and not args.jsonout: logger.info(world.fish.translate("cli", "cli", "create.meta")) - world.spoiler.meta_to_file(output_path(f'{outfilebase}_Spoiler.txt')) + if world.spoiler_mode != 'json': + world.spoiler.meta_to_file(output_path(f'{outfilebase}_Spoiler.txt')) if args.mystery and not args.suppress_meta: world.spoiler.mystery_meta_to_file(output_path(f'{outfilebase}_meta.txt')) @@ -363,9 +364,9 @@ def main(args, seed=None, fish=None): if args.mystery and not args.suppress_meta: world.spoiler.hashes_to_file(output_path(f'{outfilebase}_meta.txt')) - elif world.spoiler_mode != 'none' and not args.jsonout: + elif world.spoiler_mode != 'none' and world.spoiler_mode != 'json' and not args.jsonout: world.spoiler.hashes_to_file(output_path(f'{outfilebase}_Spoiler.txt')) - if world.spoiler_mode != 'none' and not args.jsonout: + if world.spoiler_mode != 'none' and world.spoiler_mode != 'json' and not args.jsonout: logger.info(world.fish.translate("cli", "cli", "patching.spoiler")) world.spoiler.to_file(output_path(f'{outfilebase}_Spoiler.txt')) if 'debug' in world.spoiler.settings: @@ -385,7 +386,12 @@ def main(args, seed=None, fish=None): logger.info(world.fish.translate("cli","cli","patching.spoiler")) if args.jsonout: with open(output_path('%s_Spoiler.json' % outfilebase), 'w') as outfile: - outfile.write(world.spoiler.to_json()) + outfile.write(world.spoiler.to_json()) + elif world.spoiler_mode == 'json': + 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)) elif world.players > 1 or world.logic[1] != "nologic": world.spoiler.playthrough_to_file(output_path(f'{outfilebase}_Spoiler.txt')) diff --git a/resources/app/cli/args.json b/resources/app/cli/args.json index 54fea6cb..62159299 100644 --- a/resources/app/cli/args.json +++ b/resources/app/cli/args.json @@ -10,7 +10,8 @@ "settings", "semi", "full", - "debug" + "debug", + "json" ] }, "mystery": {