118 lines
3.3 KiB
Python
118 lines
3.3 KiB
Python
from abc import abstractmethod
|
|
from cliff.command import Command
|
|
import dcc.config
|
|
import io
|
|
import os
|
|
import tomlkit
|
|
|
|
class Wad(dcc.config.Base):
|
|
def get_parser(self, prog_name):
|
|
parser = super().get_parser(prog_name)
|
|
parser.add_argument('wad')
|
|
return parser
|
|
|
|
def wad_init(self, parsed_args):
|
|
self.init_base(parsed_args)
|
|
self._wad = parsed_args.wad
|
|
wcp = self.pwads.joinpath(self.wad).joinpath(self.config_name)
|
|
if wcp.exists():
|
|
self._wad_config = tomlkit.toml_file.TOMLFile(wcp).read()
|
|
for k,v in self._wad_config.value.items():
|
|
print(k,v)
|
|
self._config.add(k,v)
|
|
|
|
def run(self, parsed_args):
|
|
self.wad_init(self, parsed_args)
|
|
self.take_action(parsed_args)
|
|
|
|
@property
|
|
def wad(self):
|
|
return self._wad
|
|
|
|
|
|
class WadMap(Wad):
|
|
def get_parser(self, prog_name):
|
|
parser = super().get_parser(prog_name)
|
|
parser.add_argument('map')
|
|
parser.add_argument('-n','--name','--demo_name')
|
|
return parser
|
|
|
|
def run(self, parsed_args):
|
|
self._map = parsed_args.map
|
|
self._name = parsed_args.name
|
|
self.wad_init(parsed_args)
|
|
|
|
self.take_action(parsed_args)
|
|
|
|
@property
|
|
def map(self):
|
|
return self._map
|
|
|
|
@property
|
|
def name_string(self):
|
|
return "" if self._name is None else "_" + self._name
|
|
|
|
def dsda_preamble(self):
|
|
args = ["-iwad", self.iwad_path(self.wad)]
|
|
|
|
pwadpath = self.pwads.joinpath(self.wad)
|
|
wads = sorted(pwadpath.glob('*.wad', case_sensitive=False))
|
|
if len(wads) > 0:
|
|
args = args + ["-file"] + wads
|
|
|
|
dehs = sorted(pwadpath.glob('*.deh', case_sensitive=False))
|
|
if len(dehs) > 0:
|
|
args = args + ["-deh"] + dehs
|
|
|
|
args = args + ["-complevel", self.complevel()]
|
|
args = args + ["-skill", "4"]
|
|
args = args + ["-warp", self.map]
|
|
return args
|
|
|
|
def complevel(self):
|
|
complevel = self.pwads.joinpath(self.wad).joinpath("complevel")
|
|
if not complevel.exists():
|
|
raise Exception("No complevel set in PWAD dir {}.".format(pwadpath))
|
|
|
|
with io.open(complevel) as f:
|
|
return f.read().strip()
|
|
|
|
def demo_in_path(self):
|
|
candidates = [x for x in self.demos.joinpath(self.wad).glob(self._file_base("*.lmp"))]
|
|
if len(candidates) == 0:
|
|
raise Exception("no suitable demo candidates for WAD {} MAP {} name {}.".format(self.wad, self.map, self.name_string))
|
|
if len(candidates) == 1:
|
|
return candidates[0]
|
|
return sorted(filter(lambda s : re.search("-", str(s)), candidates))[-1]
|
|
|
|
def dsda_text_path(self):
|
|
return self._ensure(self.demos.joinpath(self.wad)).joinpath(self._file_base(".txt"))
|
|
|
|
def video_path(self):
|
|
return self._ensure(self.fabricate.joinpath(self.wad)).joinpath(self._file_base(".mp4"))
|
|
|
|
def demo_out_path(self):
|
|
return self._ensure(self.demos.joinpath(self.wad)).joinpath(self._file_base(".lmp"))
|
|
|
|
def target_bucket(self):
|
|
return "doom/" + self._file_base(".lmp")
|
|
|
|
def base_thumb_path(self):
|
|
return self._ensure(self.fabricate.joinpath(self.wad)).joinpath(self._file_base("_base.png"))
|
|
|
|
def m_doom_path(self):
|
|
return self._ensure(self.fabricate.joinpath(self.wad)).joinpath("M_DOOM_scaled.png")
|
|
|
|
def text_thumb_path(self):
|
|
return self._ensure(self.fabricate.joinpath(self.wad)).joinpath(self._file_base("_text.png"))
|
|
|
|
def thumb_path(self):
|
|
return self._ensure(self.fabricate.joinpath(self.wad)).joinpath(self._file_base("_thumb.png"))
|
|
|
|
def _file_base(self, ext):
|
|
return "{}_map{}{}{}".format(self.wad, self.map, self.name_string, ext)
|
|
|
|
def _ensure(self, path):
|
|
if not path.exists():
|
|
os.mkdir(path)
|
|
return path
|