/
genScripts.py
executable file
·72 lines (62 loc) · 2.15 KB
/
genScripts.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/env python3
import shlex, PKSMScript, sys, glob, shutil, os
games = ["USUM", "SM", "ORAS", "XY", "B2W2", "BW", "HGSS", "PT", "DP"]
def main(args):
print("Generating scripts...")
shutil.rmtree("scripts", True)
shutil.rmtree("build", True)
os.mkdir("scripts")
if os.path.exists("src/universal"):
# shutil.copytree("src/universal", "scripts/universal")
os.mkdir("scripts/universal")
for path, _, files in os.walk("src/universal"):
for fullname in files:
data = ""
with open(os.path.join(path, fullname), 'r') as f:
data = f.read()
data = data.replace("\r\n", "\n")
# Get rid of all comments
commentIndex = data.find("/*")
while commentIndex != -1:
data = data[:commentIndex] + data[data.find("*/")+2:]
commentIndex = data.find("/*")
commentIndex = data.find("//")
while commentIndex != -1:
data = data[:commentIndex] + data[data[commentIndex+2:].find("\n")+1 + commentIndex+2:]
commentIndex = data.find("//")
lines = data.split("\n")
out = ""
for line in lines:
line = line.strip()
# preprocessor directives
if "#" in line:
out += line + "\n"
# just in case there are multiline strings/macros
elif line[len(line) - 1:] == "\\":
out += line + "\n"
# all other cases
else:
out += line
with open(os.path.join(path.replace("src/", "scripts/"), fullname), 'w') as f:
f.write(out)
for game in games:
generate(game)
if os.path.exists("src/" + game.lower()):
shutil.copytree("src/" + game.lower(), "scripts/" + game.lower())
else:
os.mkdir("scripts/" + game.lower())
if os.path.exists("build"):
for f in os.listdir("build"):
shutil.move("build/" + f, "scripts/" + game.lower())
scriptFiles = glob.glob("*.pksm")
for pksmFile in scriptFiles:
shutil.move(pksmFile,"scripts/" + game.lower())
def generate(game):
with open(os.path.join("src", "scripts%s.txt" % game)) as pksmArgFile:
for line in pksmArgFile:
if (not line.startswith('#')):
line.replace('\\', '/')
pksmArgs = PKSMScript.parser.parse_args(shlex.split(line))
PKSMScript.main(pksmArgs)
if __name__ == '__main__':
main(sys.argv)