From 2df263f67eaad7b2fb9ca3bca703b0cd5bf449d7 Mon Sep 17 00:00:00 2001 From: wootguy Date: Sat, 4 Jan 2025 23:00:50 -0800 Subject: [PATCH] map conversion script updates 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. --- scripts/convert_angelscript.py | 6 +++- scripts/convert_map.py | 24 ++++++++++++- scripts/hud_create.py | 64 ++++++++++++++++++++++++++++++++++ sevenkewp | 2 +- 4 files changed, 93 insertions(+), 3 deletions(-) create mode 100644 scripts/hud_create.py diff --git a/scripts/convert_angelscript.py b/scripts/convert_angelscript.py index 5e25b037..5573a7fd 100644 --- a/scripts/convert_angelscript.py +++ b/scripts/convert_angelscript.py @@ -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'), @@ -73,6 +74,9 @@ ('& in ', '&'), ('& out ', '&'), ('& inout ', '&'), + ('EHandle ', 'EHANDLE'), + ('this.', 'this->'), + ('RemoveEntity', 'UTIL_Remove'), ] def convert_script(fpath): @@ -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) \ No newline at end of file diff --git a/scripts/convert_map.py b/scripts/convert_map.py index 28ac507e..ccbdb047 100644 --- a/scripts/convert_map.py +++ b/scripts/convert_map.py @@ -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"] @@ -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 @@ -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) @@ -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) @@ -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...") diff --git a/scripts/hud_create.py b/scripts/hud_create.py new file mode 100644 index 00000000..36040a6b --- /dev/null +++ b/scripts/hud_create.py @@ -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") diff --git a/sevenkewp b/sevenkewp index acdce8f4..1ec6a716 160000 --- a/sevenkewp +++ b/sevenkewp @@ -1 +1 @@ -Subproject commit acdce8f4d5124857893501ffe1e114a8a65d07a1 +Subproject commit 1ec6a71618d109e53b00d018a4c789d629b59ccb