Last active
April 30, 2023 22:00
-
-
Save uyjulian/eb60829b9703b88ef5ec409155fc5e67 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# NScripter ONScripter scenario file splitter tool. | |
# Be careful with the arguments as you can overwrite your work | |
import re | |
import sys | |
x = re.compile('^\\*s([\\d]*)$') | |
lns = [] | |
idn = None | |
skipjump = False | |
if len(sys.argv) > 2: | |
with open(sys.argv[2], 'w') as out_file: | |
out_file.write('') | |
with open(sys.argv[1]) as in_file: | |
for line in in_file: | |
ln = line.rstrip() | |
if idn is None: | |
matc = x.match(ln) | |
if matc is not None: | |
idn = matc.group(1) | |
if len(lns) > 0: | |
if len(sys.argv) > 2: | |
with open(sys.argv[2], 'a') as out_file: | |
out_file.write(('\n').join(lns) + '\n') | |
lns = [] | |
lns.append(ln) | |
else: | |
lns.append(ln) | |
elif ln == 'skip %yesno': | |
skipjump = True | |
lns.append(ln) | |
elif ln == 'return' and skipjump == False and idn is not None: | |
lns.append(ln) | |
if len(sys.argv) > 2: | |
with open('s' + str(idn) + '.txt') as in_snip_file: | |
with open(sys.argv[2], 'a') as out_file: | |
out_file.write(in_snip_file.read()) | |
else: | |
with open('s' + str(idn) + '.txt', 'w') as out_file: | |
out_file.write(('\n').join(lns) + '\n') | |
idn = None | |
lns = [] | |
else: | |
skipjump = False | |
lns.append(ln) | |
if len(lns) > 0: | |
if len(sys.argv) > 2: | |
with open(sys.argv[2], 'a') as out_file: | |
out_file.write(('\n').join(lns) + '\n') | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment