doomcc/dcc/dsda.py
yrriban e4c5c8b475 Skip the warp flag when generating the dsda text file.
This causes negative tics to work, for whatever reason.
2025-08-01 02:09:15 -04:00

62 lines
2.1 KiB
Python

import dcc.config
import dcc.doom_base
import os
import re
import shutil
import subprocess
import zipfile
class DSDA(dcc.doom_base.WadMap):
def get_parser(self, prog_name):
parser = super().get_parser(prog_name)
parser.add_argument("-s", "--single", action="store_true")
parser.add_argument("-a", "--abbreviation")
return parser
def take_action(self, parsed_args):
dip = self.demo_in_path()
dtp = self.dsda_text_path()
if not dtp.exists():
command = [self.dsda]
if shutil.which("xvfb-run") is not None:
command = ["xvfb-run"] + command
subprocess.run(
command + self.dsda_preamble(warp=False) + [
"-fastdemo", dip, "-nosound",
"-skiptic", "-1", "-export_text_file"
]
)
editor = "nano"
if "EDITOR" in os.environ:
editor = os.environ["EDITOR"]
subprocess.run([editor, dtp])
if parsed_args.abbreviation:
fh1 = parsed_args.abbreviation
if not parsed_args.single:
fh1 += self.map
else:
fh1 = self.wad[0:2] + self.map
if parsed_args.single:
fh1 = self.wad[0:min(len(self.wad), 4)]
fh2 = ""
with open(dtp, mode="r") as f:
for line in f:
if line[0:4] == "Time":
m = re.search("[^0-9]*([0-9]*):([0-9]*).[0-9]*", line)
if m is None:
continue
fh2 = m[1]+m[2]
if len(fh2) % 2 == 1:
fh2 = "0" + fh2
break
if not fh2:
sys.exit(f"Failed to match any line in {dtp} against Time regex.")
# TODO: demo names other than uv-max.
fnf = fh1 + "-" + fh2 + ".zip"
with zipfile.ZipFile(
self.demos.joinpath(self.wad).joinpath(fnf), mode="w"
) as zf:
zf.write(dip, arcname=dip.name)
zf.write(dtp, arcname=dtp.name)