Add a configure command for initial wad setup. Reshuffle a couple things that depend on it.

This commit is contained in:
yrriban 2025-07-03 18:18:19 -04:00
parent 673e649e87
commit 5881c94c11
4 changed files with 34 additions and 10 deletions

View file

@ -57,11 +57,3 @@ class Base(Command):
@property
def dsda(self):
return self._doom.joinpath(self._dsda)
def iwad_path(self, wad):
iwad = self.iwads.joinpath(self._config.get("default_iwad"))
iwadpath = self.pwads.joinpath(wad).joinpath("iwad")
if iwadpath.exists():
with io.open(iwadpath) as f:
iwad = self.iwads.joinpath(f.read().strip() + ".WAD")
return iwad

24
dcc/configure.py Normal file
View file

@ -0,0 +1,24 @@
import dcc.config
import tomlkit
from tomlkit.toml_file import TOMLFile
class Configure(dcc.config.Base):
def get_parser(self, prog_name):
parser = super().get_parser(prog_name)
parser.add_argument("wad")
parser.add_argument("complevel")
parser.add_argument("--iwad")
return parser
def take_action(self, parsed_args):
new_config = self.pwads.joinpath(parsed_args.wad).joinpath(self.config_name)
if new_config.exists():
raise Exception("Config %s already exists.".format(new_config))
doc = tomlkit.document()
doc.add("complevel", parsed_args.complevel)
if parsed_args.iwad is not None:
doc.add("iwad", parsed_args.iwad)
f = TOMLFile(new_config)
f.write(doc)

View file

@ -29,6 +29,14 @@ class Wad(dcc.config.Base):
def wad(self):
return self._wad
def iwad_path(self):
iwad = self.iwads.joinpath(self._config.get("iwad"))
iwadpath = self.pwads.joinpath(self.wad).joinpath("iwad")
if iwadpath.exists():
with io.open(iwadpath) as f:
iwad = self.iwads.joinpath(f.read().strip() + ".WAD")
return iwad
class WadMap(Wad):
def get_parser(self, prog_name):
@ -53,7 +61,7 @@ class WadMap(Wad):
return "" if self._name is None else "_" + self._name
def dsda_preamble(self):
args = ["-iwad", self.iwad_path(self.wad)]
args = ["-iwad", self.iwad_path()]
pwadpath = self.pwads.joinpath(self.wad)
wads = sorted(pwadpath.glob('*.wad', case_sensitive=False))

View file

@ -10,7 +10,7 @@ class Eureka(dcc.doom_base.WadMap):
return parser
def take_action(self, parsed_args):
iwad = self.iwad_path(parsed_args.wad)
iwad = self.iwad_path()
pwadpath = self.pwads.joinpath(parsed_args.wad)
if parsed_args.main is not None:
mw = pwadpath.joinpath(parsed_args.main)