commit c941ceee6c50e3cd29be1bc361453ce32255734a Author: Adrian Malacoda Date: Sun Sep 22 05:08:11 2024 -0500 Initial split of nukage tools into own repo diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..0364f59 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "omgifol"] + path = omgifol + url = https://github.com/devinacker/omgifol diff --git a/edit.py b/edit.py new file mode 100644 index 0000000..1b6b011 --- /dev/null +++ b/edit.py @@ -0,0 +1,35 @@ +#!/usr/bin/env python +import sys +import os +import subprocess + +BUILDER = "Builder" +GAME_CFG = "GZDoom_DoomUDMF.cfg" +IPK3 = "nukage.ipk3" +RESOURCES = [".", "graphics"] + +def edit(map, resources=[]): + command = [BUILDER, os.path.join(f"maps", f"{map}.wad"), "-map", map, "-cfg", GAME_CFG] + for resource in resources: + command.append("-resource") + extension = os.path.splitext(resource)[1] + if os.path.isdir(resource): + command.append("dir") + elif extension == ".pk3" or extension == ".ipk3": + command.append("pk3") + command.append(resource) + + print(command) + subprocess.call(command) + +if __name__ == "__main__": + MAP = sys.argv[1] + resources = list(RESOURCES) + + if os.path.isfile(IPK3): + resources.insert(0, os.path.abspath(IPK3)) + + if os.path.isfile(MAP): + MAP = os.path.splitext(os.path.basename(MAP))[0] + + edit(MAP, resources) diff --git a/omgifol b/omgifol new file mode 160000 index 0000000..4ca9e99 --- /dev/null +++ b/omgifol @@ -0,0 +1 @@ +Subproject commit 4ca9e99f6ba2fd5c1c5b1ecd785e2f40faf99aea diff --git a/unmake.py b/unmake.py new file mode 100644 index 0000000..cc13dc2 --- /dev/null +++ b/unmake.py @@ -0,0 +1,87 @@ +#!/usr/bin/env python3 +import os +import sys +import shutil + +from urllib.request import urlopen +from zipfile import ZipFile + +sys.path.append("omgifol") +import omg + +def unmake(source, target=".", overwritedirs=True): + print(source) + ipk3 = ZipFile(source) + for entry in ipk3.infolist(): + local_path = os.path.join(target, entry.filename).replace("/", os.sep) + if entry.is_dir(): + if overwritedirs and os.path.isdir(local_path): + shutil.rmtree(local_path) + print(f">> Removing existing content of directory {local_path}") + os.makedirs(local_path, exist_ok=True) + print(f">> Creating directory {local_path}") + else: + with ipk3.open(entry) as source_file: + with open(local_path, "wb") as target_file: + print(f">> Writing file {local_path}") + shutil.copyfileobj(source_file, target_file) + +def unmerge(source, target="maps"): + source_wad = omg.WadIO(source) + target_wad = None + current_map = None + in_maps = False + os.makedirs(target, exist_ok=True) + for i, entry in enumerate(source_wad.entries): + if entry.name == "P_START": + break + + if entry.name.startswith("E"): + in_maps = True + + if not in_maps: + continue + + if current_map is None: + current_map = entry.name + target_path = os.path.join(target, f"{current_map}.wad") + if os.path.exists(target_path): + os.remove(target_path) + target_wad = omg.WadIO(target_path) + + if target_wad is not None: + print(f">> Processing entry {entry.name}") + target_wad.insert(entry.name, source_wad.read(i)) + + if entry.name == "ENDMAP": + print(f">> Writing map {current_map}") + target_wad.save() + current_map = None + target_wad = None + +if __name__ == "__main__": + SOURCE = None + OVERWRITE = False + UNMERGE = False + + for arg in sys.argv[1:]: + if arg == "-f": + OVERWRITE = True + elif arg == "-u": + UNMERGE = True + else: + SOURCE = arg + + if SOURCE.startswith("https://"): + with urlopen(SOURCE) as remote_file: + unmake(remote_file, overwritedirs=OVERWRITE) + else: + with open(SOURCE, "rb") as local_file: + unmake(local_file, overwritedirs=OVERWRITE) + + if UNMERGE: + for item in os.listdir("."): + if item.endswith(".wad"): + print(f">> Unmerging maps wad {item}") + unmerge(item) + os.remove(item)