Skip to content

Commit

Permalink
map conversion script updates
Browse files Browse the repository at this point in the history
added a script that can create a single weapon HUD sprite from individual icons, for all resolutions, using a standard layout. Map converter downscales skybox images that are too large. fixed model texture downscaling not always working.
  • Loading branch information
wootguy committed Jan 5, 2025
1 parent ff4885d commit 2df263f
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 3 deletions.
6 changes: 5 additions & 1 deletion scripts/convert_angelscript.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
('g_Game.PrecacheModel', 'PRECACHE_MODEL'),
('g_SoundSystem.PrecacheSound', 'PRECACHE_SOUND'),
('self.', ''),
('self->', ''),
('g_ItemRegistry.RegisterWeapon', 'UTIL_RegisterWeapon'),
('g_EntityFuncs.SetModel(self', 'SET_MODEL(edict()'),
('g_EntityFuncs.SetModel', 'SET_MODEL'),
Expand All @@ -73,6 +74,9 @@
('& in ', '&'),
('& out ', '&'),
('& inout ', '&'),
('EHandle ', 'EHANDLE'),
('this.', 'this->'),
('RemoveEntity', 'UTIL_Remove'),
]

def convert_script(fpath):
Expand All @@ -91,6 +95,6 @@ def convert_script(fpath):
if os.path.isdir(path):
for filename in os.listdir(path):
if filename.endswith('.as'):
convert_script(fpath)
convert_script(os.path.join(path, filename))
else:
convert_script(path)
24 changes: 23 additions & 1 deletion scripts/convert_map.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import struct, os, subprocess, wave, time, sys, copy, codecs, json, shutil, copy
from collections import OrderedDict
from PIL import Image

nonstandard_audio_formats = ["aiff", "asf", "asx", "au", "dls", "flac", "fsb", "it", "m3u", "mid", "midi", "mod", "mp2", "ogg", "pls", "s3m", "vag", "wax", "wma", "xm", "xma"]

Expand Down Expand Up @@ -111,6 +112,14 @@ def get_all_cfgs(maps_dir):

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

def get_all_skies(skies_dir):
sky_files = []
for file in os.listdir(skies_dir):
if file.endswith('.tga') or file.endswith('.bmp'):
sky_files.append(os.path.join(skies_dir, file))

return sky_files

def convert_audio(file, out_format, samp_rate):
global converted_files

Expand Down Expand Up @@ -872,6 +881,7 @@ def ents_match(d1, d2, path=""):
all_maps = get_all_maps(maps_dir)
all_cfgs = get_all_cfgs(maps_dir)
all_models = get_all_models(models_dir)
all_skies = get_all_skies('gfx/env')
all_skill_cvar_names = get_all_skill_cvar_names(skill_path)
all_titles = parse_titles(titles_path)
#sentences_hl = parse_sentences(sent_path_hl)
Expand Down Expand Up @@ -926,7 +936,7 @@ def ents_match(d1, d2, path=""):
newHeight = int((newHeight + 4) / 8) * 8

print("Resizing invalid texture in %s (%s %dx%d -> %dx%d)" % (mdl, tex["name"], tex["width"], tex["height"], newWidth, newHeight))
mdlguy_command = [modelguy_path, 'resize', tex["name"], "%d" % newWidth, "%d" % newHeight, mdl, json_path]
mdlguy_command = [modelguy_path, 'resize', tex["name"], "%dx%d" % (newWidth, newHeight), mdl]
#print(' '.join(mdlguy_command))
subprocess.run(mdlguy_command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)

Expand All @@ -947,6 +957,18 @@ def ents_match(d1, d2, path=""):
print(' '.join(mdlguy_command))
subprocess.run(mdlguy_command)
os.remove(json_path)

print ("Converting skies")
for sky in all_skies:
with Image.open(sky) as image:
width, height = image.size

if width > 256:
x = 256
y = 256
print("Resizing invalid sky texture: %s (%dx%d -> %dx%d)" % (sky, width, height, x, y))
image = image.resize((x, y), Image.ANTIALIAS)
image.save(sky)

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

Expand Down
64 changes: 64 additions & 0 deletions scripts/hud_create.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
from PIL import Image
import os, sys

# creates a weapon HUD file for HL25 for all resolutions, packed into a single 512x512 image

# Prepare the following input icons:
# weapon.bmp = deselected weapon icon (170x45)
# weapon_s.bmp = selected weapon icon (170x45)

# Optional icons:
# ammo.bmp = ammo icon (24x24)
# crosshair.bmp = weapon crosshair (24x24)
# autoaim.bmp = autoaim crosshair (24x24)

if not os.path.exists("weapon.bmp"):
print("weapon.bmp does not exist. Cannot create a HUD file without the weapon icon.")
sys.exit()
if not os.path.exists("weapon_s.bmp"):
print("weapon_s.bmp does not exist. Cannot create a HUD file without the highlighted weapon icon.")
sys.exit()

new_img = Image.new("RGB", (512, 512), "blue")

# weapon icons
weapon = Image.open('weapon.bmp')
weapon_s = Image.open('weapon_s.bmp')
new_img.paste(weapon.resize((int(170 * 3), int(45 * 3)), Image.NEAREST), (0, 0))
new_img.paste(weapon_s.resize((int(170 * 3), int(45 * 3)), Image.NEAREST), (0, 135))
new_img.paste(weapon.resize((int(170 * 2), int(45 * 2)), Image.NEAREST), (0, 270))
new_img.paste(weapon_s.resize((int(170 * 2), int(45 * 2)), Image.NEAREST), (0, 360))
new_img.paste(weapon, (0, 450))
new_img.paste(weapon_s, (170, 450))

# ammo icons
if os.path.exists("ammo.bmp"):
ammo = Image.open('ammo.bmp')
new_img.paste(ammo.resize((int(24 * 3), int(24 * 3)), Image.NEAREST), (340, 270))
new_img.paste(ammo.resize((int(24 * 2), int(24 * 2)), Image.NEAREST), (412, 270))
new_img.paste(ammo, (460, 270))
else:
print("ammo.bmp does not exist. Ammo icons will not be added to the HUD.")

# crosshair icons
if os.path.exists("crosshair.bmp"):
crosshair = Image.open('crosshair.bmp')
new_img.paste(crosshair.resize((int(24 * 3), int(24 * 3)), Image.NEAREST), (340, 342))
new_img.paste(crosshair.resize((int(24 * 2), int(24 * 2)), Image.NEAREST), (412, 342))
new_img.paste(crosshair, (460, 342))
else:
print("crosshair.bmp does not exist. Crosshairs will not be added to the HUD.")

# autoaim icons
if os.path.exists("autoaim.bmp"):
autoaim = Image.open('autoaim.bmp')
new_img.paste(autoaim.resize((int(24 * 3), int(24 * 3)), Image.NEAREST), (340, 414))
new_img.paste(autoaim.resize((int(24 * 2), int(24 * 2)), Image.NEAREST), (412, 414))
new_img.paste(autoaim, (460, 414))
else:
print("autoaim.bmp does not exist. Autoaim crosshairs will not be added to the HUD.")

# save the new image
new_img.quantize(colors=256, method=2).save("hud_output.bmp")

print("Created HUD file: hud_output.bmp")
2 changes: 1 addition & 1 deletion sevenkewp

0 comments on commit 2df263f

Please sign in to comment.