From 132a264d8a2df3c59060267007ac9aa1363a9d99 Mon Sep 17 00:00:00 2001 From: LLCoolDave Date: Sun, 16 Jul 2017 23:20:54 +0200 Subject: [PATCH] jsonout parameter now dumps to stdout instead of file. --- EntranceRandomizer.py | 13 ++++++++----- Main.py | 8 ++++++-- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/EntranceRandomizer.py b/EntranceRandomizer.py index 8240454c..61c63bf8 100644 --- a/EntranceRandomizer.py +++ b/EntranceRandomizer.py @@ -144,8 +144,8 @@ if __name__ == '__main__': ''') parser.add_argument('--suppress_rom', help='Do not create an output rom file.', action='store_true') parser.add_argument('--gui', help='Launch the GUI', action='store_true') - parser.add_argument('--jsonout', help='''\ - Output .json patch file instead of a patched rom. Used + parser.add_argument('--jsonout', action='store_true', help='''\ + Output .json patch to stdout instead of a patched rom. Used for VT site integration, do not use otherwise. ''') args = parser.parse_args() @@ -154,9 +154,12 @@ if __name__ == '__main__': if not args.jsonout and not os.path.isfile(args.rom): input('Could not find valid base rom for patching at expected path %s. Please run with -h to see help for further information. \nPress Enter to exit.' % args.rom) exit(1) - if args.sprite is not None and not os.path.isfile(args.rom): - input('Could not find link sprite sheet at given location. \nPress Enter to exit.' % args.sprite) - exit(1) + if args.sprite is not None and not os.path.isfile(args.sprite): + if not args.jsonout: + input('Could not find link sprite sheet at given location. \nPress Enter to exit.' % args.sprite) + exit(1) + else: + raise IOError('Cannot find sprite file at %s' % args.sprite) # set up logger loglevel = {'error': logging.ERROR, 'info': logging.INFO, 'warning': logging.WARNING, 'debug': logging.DEBUG}[args.loglevel] diff --git a/Main.py b/Main.py index f8d5382f..d0ea3b05 100644 --- a/Main.py +++ b/Main.py @@ -8,6 +8,7 @@ from Items import ItemFactory import random import time import logging +import json __version__ = '0.4.2-dev' @@ -92,9 +93,12 @@ def main(args, seed=None): else: rom = LocalRom(args.rom) patch_rom(world, rom, bytearray(logic_hash), args.quickswap, args.heartbeep, sprite) - rom.write_to_file(args.jsonout or '%s.sfc' % outfilebase) + if args.jsonout: + print(json.dumps({'patch': rom.patches, 'spoiler': world.spoiler})) + else: + rom.write_to_file(args.jsonout or '%s.sfc' % outfilebase) - if args.create_spoiler: + if args.create_spoiler and not args.jsonout: with open('%s_Spoiler.txt' % outfilebase, 'w') as outfile: outfile.write(world.spoiler)