jsonout parameter now dumps to stdout instead of file.

This commit is contained in:
LLCoolDave 2017-07-16 23:20:54 +02:00
parent a6ab6cdcf1
commit 132a264d8a
2 changed files with 14 additions and 7 deletions

View File

@ -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]

View File

@ -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)