Skip to content

Commit

Permalink
convert audio files referenced in GSR files
Browse files Browse the repository at this point in the history
  • Loading branch information
wootguy committed Sep 10, 2024
1 parent 713cee8 commit 12f16c8
Showing 1 changed file with 70 additions and 4 deletions.
74 changes: 70 additions & 4 deletions convert_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,17 @@ def get_all_models(models_dir):
mdl_files.append(os.path.join(root, file))

return mdl_files

def get_all_cfgs(maps_dir):
all_cfgs = []

for file in os.listdir(maps_dir):
if not file.lower().endswith('.cfg'):
continue

all_cfgs.append(file)

return sorted(all_cfgs, key=lambda v: v.upper())

def convert_audio(file, out_format, samp_rate):
global converted_files
Expand Down Expand Up @@ -534,6 +545,7 @@ def ents_match(d1, d2, path=""):
models_dir = "models"

all_maps = get_all_maps(maps_dir)
all_cfgs = get_all_cfgs(maps_dir)
all_models = get_all_models(models_dir)

fix_problems = True
Expand Down Expand Up @@ -585,13 +597,11 @@ def ents_match(d1, d2, path=""):
print(' '.join(mdlguy_command))
subprocess.run(mdlguy_command)
os.remove(json_path)



sys.exit()

print("\nSearching for incompatible entity settings...")

gsr_files = []

last_progress_str = ''
for idx, map_name in enumerate(all_maps):
map_path = os.path.join(maps_dir, map_name)
Expand All @@ -608,6 +618,13 @@ def ents_match(d1, d2, path=""):

special_map_logic = False

for ent in all_ents:
if ent.get('classname', '') == 'worldspawn' and ent.get('globalsoundlist', ''):
# keep classname last
path = os.path.normpath("sound/%s/%s" % (map_name.replace(".bsp", ""), ent['globalsoundlist']))
gsr_files.append(path)
break

if check_map_problems(all_ents, False) or special_map_logic:
print()
if not fix_problems:
Expand Down Expand Up @@ -657,5 +674,54 @@ def ents_match(d1, d2, path=""):

print()

print("Converting GSR audio")
for cfg in all_cfgs:
with open("maps/%s" % cfg, 'r') as file:
for line in file:
line = line.strip().lower()
parts = line.split()
if len(parts) < 2:
continue

if parts[0] == 'globalsoundlist':
mapname = os.path.splitext(cfg)[0]
path = os.path.normpath("sound/%s/%s" % (mapname, parts[1]))
gsr_files.append(path)

for gsr in gsr_files:
if not os.path.exists(gsr):
print("Missing GSR: %s" % gsr)
continue

new_lines = []
with open(gsr, 'r') as file:
for line in file:
line = line.strip()
parts = line.split()

if len(parts) < 2:
new_lines.append(line)
continue

needsReplace = False
for fmt in nonstandard_audio_formats:
if (".%s" % fmt) in parts[1]:
needsReplace = True

if needsReplace:
oldpath = parts[1].replace('"', '')
newpath = '"' + os.path.splitext(parts[1])[0].replace('"', '') + '.wav"'

convert_audio(oldpath, 'wav', 22050)

line = '%s %s' % (parts[0], newpath)
new_lines.append(line)

with open(gsr, 'w') as file:
for line in new_lines:
file.write(line + "\n")



print()
os.system('pause')

0 comments on commit 12f16c8

Please sign in to comment.