forked from abyssonym/terrorwave
-
Notifications
You must be signed in to change notification settings - Fork 0
/
import_export_event_dump.py
43 lines (37 loc) · 1.42 KB
/
import_export_event_dump.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
from randomizer import (dump_events, patch_events, ALL_OBJECTS,
MapEventObject, MapMetaObject)
from randomtools.interface import run_interface
from os import remove, rename, path
from sys import argv
from time import time
if __name__ == '__main__':
try:
mode, sourcefile, script_dump = argv[1:]
assert mode in ['import', 'export']
except:
print('USAGE:\n'
'python3 import_export_event_dump.py import ROM_FILENAME EVENT_DUMP_TXT\n'
'python3 import_export_event_dump.py export ROM_FILENAME EVENT_DUMP_TXT')
exit(1)
outfile = '_temp.smc'
flags = ''
seed = '0'
args = [None, sourcefile, flags, seed]
run_interface(ALL_OBJECTS, snes=False, args=args, setup_only=True,
override_outfile=outfile)
for meo in MapEventObject.every:
meo.preprocess()
if mode == 'import':
patch_events(script_dump, warn_double_import=True)
MapEventObject.full_cleanup()
MapMetaObject.full_cleanup()
MapEventObject.write_all(outfile)
MapMetaObject.write_all(outfile)
backup_name = '{0}.backup'.format(sourcefile)
if path.exists(backup_name):
backup_name = '{0}.{1}'.format(backup_name, int(time()))
rename(sourcefile, backup_name)
rename(outfile, sourcefile)
elif mode == 'export':
dump_events(script_dump)
remove(outfile)