-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMenuMusicMod-Creator.py
More file actions
175 lines (145 loc) · 6.54 KB
/
MenuMusicMod-Creator.py
File metadata and controls
175 lines (145 loc) · 6.54 KB
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
import os
import sys
import shutil
import re
from appJar import gui
#set working directory for appJar icon
if getattr( sys, 'frozen', False ):
os.chdir(sys._MEIPASS)
dir_path = os.path.dirname(os.path.abspath(sys.executable))
else:
os.chdir(os.path.dirname(os.path.abspath(__file__)))
dir_path = os.path.dirname(os.path.abspath(__file__))
# return object class for create_folders()
class modloc(object):
def __init__(self, modroot, name):
self.modroot = modroot
self.loc = '{0}/Loc'.format(modroot)
self.music = '{0}\Assets\music\{1}'.format(modroot, name)
# this function creates every folder needed for the mod
def create_folders(root, name):
modroot = '{0}\{1}'.format(root, name)
os.makedirs('{0}\Assets\music\{1}'.format(modroot, name))
os.mkdir('{0}\Loc'.format(modroot))
return modloc(modroot, name)
def move_file(modloc, musicfile):
# move music.movie to modroot/Assets/music/musicname/
shutil.copy2(musicfile, modloc.music)
return
def create_main(modloc, filename, super):
# create main.xml in modroot/
if super:
with open('{0}/main.xml'.format(modloc.modroot), 'w') as outfile:
outfile.write(
'<table name="{0}">\n <Localization directory="Loc" default="EN.txt"/>\n <MenuMusic id="{0}" source="music/{0}.ogg"/>\n</table>'.format(filename))
return
else:
with open('{0}/main.xml'.format(modloc.modroot), 'w') as outfile:
outfile.write('<table name="{0}">\n <Localization directory="Loc" default="EN.txt"/>\n <Music id="{0}" directory="music/{0}" source="{0}" menu="true" heist="false"/>\n</table>'.format(filename))
return
def create_locale(modloc, filename, musicname):
# create EN.txt in modroot/Loc/
with open('{0}/EN.txt'.format(modloc.loc), 'w') as outfile:
outfile.write('{{\n "menu_jukebox_{0}" : "{1}",\n "menu_jukebox_screen_{0}" : "{1}"\n}}'.format(filename, musicname))
return
# -----------------Main function-----------------
# Function to be called at gui button press.
def makeithappen(button_name):
modname = app.getEntry('modname')
moddir = app.getEntry('moddir')
musicname = app.getEntry('musicname')
musicfile = app.getEntry('musicfile')
try:
musicfile_name = re.search('.*/(.*?)\.movie', musicfile).group(1)
except:
app.infoBox('ERROR', 'Music file has the wrong format!')
return
# check if names are ok
if modname == '' or re.match('^[a-zA-Z0-9_-]*$', modname) is None:
app.infoBox('ERROR', 'Invalid mod name!')
return
elif musicname == '' or re.match('^[ a-zA-Z0-9_-]*$', musicname) is None:
app.infoBox('ERROR', 'Invalid music name!')
return
# check if mod folder already exists
if os.path.exists('{0}\{1}'.format(moddir, modname)):
app.infoBox('ERROR', 'Mod folder already exists!')
return
# check if music file exists and is a ".movie" file.
# also check if music file name contains only alphanumeric characters, underscores and hyphens
if not os.path.isfile(musicfile):
app.infoBox('ERROR', 'Music file does not exist!')
return
elif musicfile_name == '' or re.match('^[a-zA-Z0-9_-]*$', musicfile_name) is None:
app.infoBox('ERROR', 'Invalid music file name!')
return
# if all checks pass, these functions are called to make the mod
modfiles = create_folders(moddir, modname)
move_file(modfiles, musicfile)
create_main(modfiles, musicfile_name, False)
create_locale(modfiles, musicfile_name, musicname)
# display 'Done' message
app.infoBox('Success!',
'Your MenuMusicMod has been created.\nYou can find it here:\n{0}\{1}'.format(moddir, modname))
def makeithappen_super(button_name):
modname = app.getEntry('modname')
moddir = app.getEntry('moddir')
musicname = app.getEntry('musicname')
musicfile = app.getEntry('musicfile')
try:
musicfile_name = re.search('.*/(.*?)\.ogg', musicfile).group(1)
except:
app.infoBox('ERROR', 'Music file has the wrong format!')
return
# check if names are ok
if modname == '' or re.match('^[a-zA-Z0-9_-]*$', modname) is None:
app.infoBox('ERROR', 'Invalid mod name!')
return
elif musicname == '' or re.match('^[ a-zA-Z0-9_-]*$', musicname) is None:
app.infoBox('ERROR', 'Invalid music name!')
return
# check if mod folder already exists
if os.path.exists('{0}\{1}'.format(moddir, modname)):
app.infoBox('ERROR', 'Mod folder already exists!')
return
# check if music file exists and is a ".movie" file.
# also check if music file name contains only alphanumeric characters, underscores and hyphens
if not os.path.isfile(musicfile):
app.infoBox('ERROR', 'Music file does not exist!')
return
elif musicfile_name == '' or re.match('^[a-zA-Z0-9_-]*$', musicfile_name) is None:
app.infoBox('ERROR', 'Invalid music file name!')
return
# if all checks pass, these functions are called to make the mod
modfiles = create_folders(moddir, modname)
move_file(modfiles, musicfile)
create_main(modfiles, musicfile_name, True)
create_locale(modfiles, musicfile_name, musicname)
# display 'Done' message
app.infoBox('Success!',
'Your MenuMusicMod has been created.\nYou can find it here:\n{0}\{1}'.format(moddir, modname))
# -----------------GUI-----------------
# create gui and set title
app = gui('MenuMusicMod Creator', '650x150')
app.setIcon('mmmc.gif')
app.setFont('10', font='Verdana')
# add labels and entries to gui
# mod name
app.addLabel('modname_lab', 'Mod name:', 0, 0)
app.addEntry('modname', 0, 1)
# music name
app.addLabel('musicname_lab', 'Music name (shown in-game):', 1, 0)
app.addEntry('musicname', 1, 1)
# music to use
app.addLabel('musicfile_lab', 'Music to use (already in .movie/.ogg format): ', 2, 0)
app.addFileEntry('musicfile', 2, 1)
# mod directory
app.addLabel('moddir_lab', 'Mod folder output directory: ', 3, 0)
app.addDirectoryEntry('moddir', 3, 1)
app.setEntry('moddir', '{0}'.format(dir_path))
# "start" button
app.addButtons(['makeithappen','makeithappen_super'], [makeithappen, makeithappen_super], colspan=2)
app.setButton('makeithappen', 'Create MenuMusicMod\n(Normal BLT .movie)')
app.setButton('makeithappen_super', 'Create MenuMusicMod\n(Super BLT .ogg)')
# run gui
app.go()