Initial split of nukage tools into own repo
This commit is contained in:
3
.gitmodules
vendored
Normal file
3
.gitmodules
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
[submodule "omgifol"]
|
||||
path = omgifol
|
||||
url = https://github.com/devinacker/omgifol
|
||||
35
edit.py
Normal file
35
edit.py
Normal file
@@ -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)
|
||||
1
omgifol
Submodule
1
omgifol
Submodule
Submodule omgifol added at 4ca9e99f6b
87
unmake.py
Normal file
87
unmake.py
Normal file
@@ -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)
|
||||
Reference in New Issue
Block a user