Add json spoiler option

This commit is contained in:
2025-03-02 00:19:57 -06:00
parent 0d50f90c55
commit 62eb78e1ce
4 changed files with 14 additions and 6 deletions

1
.gitignore vendored
View File

@@ -4,6 +4,7 @@
*.bmbp *.bmbp
*.log *.log
*_Spoiler.json *_Spoiler.json
*_Meta.json
*_custom.yaml *_custom.yaml
*_meta.txt *_meta.txt
*.bps *.bps

View File

@@ -2944,7 +2944,7 @@ class Spoiler(object):
self.settings = {'settings'} self.settings = {'settings'}
elif world.spoiler_mode == 'semi': elif world.spoiler_mode == 'semi':
self.settings = {'settings', 'entrances', 'requirements', 'prizes'} self.settings = {'settings', 'entrances', 'requirements', 'prizes'}
elif world.spoiler_mode == 'full': elif world.spoiler_mode == 'full' or world.spoiler_mode == 'json':
self.settings = {'all'} self.settings = {'all'}
elif world.spoiler_mode == 'debug': elif world.spoiler_mode == 'debug':
self.settings = {'all', 'debug'} self.settings = {'all', 'debug'}

14
Main.py
View File

@@ -160,7 +160,8 @@ def main(args, seed=None, fish=None):
if world.spoiler_mode != 'none' and not args.jsonout: if world.spoiler_mode != 'none' and not args.jsonout:
logger.info(world.fish.translate("cli", "cli", "create.meta")) 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: if args.mystery and not args.suppress_meta:
world.spoiler.mystery_meta_to_file(output_path(f'{outfilebase}_meta.txt')) 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: if args.mystery and not args.suppress_meta:
world.spoiler.hashes_to_file(output_path(f'{outfilebase}_meta.txt')) 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')) 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")) logger.info(world.fish.translate("cli", "cli", "patching.spoiler"))
world.spoiler.to_file(output_path(f'{outfilebase}_Spoiler.txt')) world.spoiler.to_file(output_path(f'{outfilebase}_Spoiler.txt'))
if 'debug' in world.spoiler.settings: 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")) logger.info(world.fish.translate("cli","cli","patching.spoiler"))
if args.jsonout: if args.jsonout:
with open(output_path('%s_Spoiler.json' % outfilebase), 'w') as outfile: 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": elif world.players > 1 or world.logic[1] != "nologic":
world.spoiler.playthrough_to_file(output_path(f'{outfilebase}_Spoiler.txt')) world.spoiler.playthrough_to_file(output_path(f'{outfilebase}_Spoiler.txt'))

View File

@@ -10,7 +10,8 @@
"settings", "settings",
"semi", "semi",
"full", "full",
"debug" "debug",
"json"
] ]
}, },
"mystery": { "mystery": {