From d778e281ba085567fe52a19c695e156c12fd4897 Mon Sep 17 00:00:00 2001 From: yrriban Date: Thu, 3 Jul 2025 18:04:19 -0400 Subject: [PATCH 1/5] Move the remaining hardcoded constants into the configuration file. --- dcc/config.py | 20 +++++++++++--------- dcc/fetch.py | 2 +- dcc/ss.py | 23 ++++++++--------------- dcc/text.py | 10 +++++----- 4 files changed, 25 insertions(+), 30 deletions(-) diff --git a/dcc/config.py b/dcc/config.py index cac1f0a..a0edeb2 100644 --- a/dcc/config.py +++ b/dcc/config.py @@ -6,12 +6,6 @@ import tomlkit from cliff.command import Command -THUMB_WIDTH = 1280 -THUMB_HEIGHT = 720 -FONT = "League-Spartan-Bold" -TEXT_FILL_COLOR = "white" -TEXT_STROKE_COLOR = "srgb(176,0,0)" - MIRROR = "https://youfailit.net/pub/idgames" # NYC @@ -34,15 +28,23 @@ class Base(Command): "required key 'dsda' not set in config " + f"{self.doom.joinpath(self.config_name)}.") for d in ("iwads", "pwads", "demos", "fabricate"): - self._init_path(d) + self._init_attr(d, d, fn=self.doom.joinpath) + + self._init_attr("thumbnail.height", 1280) + self._init_attr("thumbnail.width", 720) + self._init_attr("thumbnail.font", None) + self._init_attr("thumbnail.text_fill", "white") + self._init_attr("thumbnail.text_stroke", "red") + self._init_attr("fetch.mirror", "https://youfailit.net/pub/idgames") def run(self, parsed_args): self.init_base(parsed_args) self.take_action(parsed_args) - def _init_path(self, what): + def _init_attr(self, what, default, fn=lambda x: x): + what = what.replace(".", "_") setattr( - self, f"_{what}", self.doom.joinpath(self._config.get(what, what))) + self, f"_{what}", fn(self._config.get(what, default))) setattr( type(self), what, property(lambda self: getattr(self, f"_{what}"))) diff --git a/dcc/fetch.py b/dcc/fetch.py index 00121f5..27f9f11 100644 --- a/dcc/fetch.py +++ b/dcc/fetch.py @@ -23,7 +23,7 @@ class Fetch(dcc.config.Base): ) as response: reply = json.loads(response.read()) rpath = "/".join([ - dcc.config.MIRROR, + self.fetch_mirror, reply["content"]["dir"], reply["content"]["filename"] ]) diff --git a/dcc/ss.py b/dcc/ss.py index 6d5dc2e..9ec2f54 100644 --- a/dcc/ss.py +++ b/dcc/ss.py @@ -18,26 +18,19 @@ class SS(dcc.doom_base.WadMap): pass def _try_screenshot(self, gravity, yolo): - with wand.image.Image( - width=dcc.config.THUMB_WIDTH, - height=dcc.config.THUMB_HEIGHT, - pseudo="x:" - ) as img: + width = self.thumbnail_width + height = self.thumbnail_height + with wand.image.Image(width=width, height=height, pseudo="x:") as img: img.reset_coords() - if ( - img.size[0] < dcc.config.THUMB_WIDTH - or img.size[1] < dcc.config.THUMB_HEIGHT - ): + if (img.size[0] < width or img.size[1] < height): if not messagebox.askretrycancel( - title="DCC", message="Image too small. Try again?" + title="DCC", + message=f"Image too small ({img.width}x{img.height})." + + "Try again?" ): sys.exit("Gave up trying to select an image.") return False - img.crop( - width=dcc.config.THUMB_WIDTH, - height=dcc.config.THUMB_HEIGHT, - gravity=gravity - ) + img.crop(width=width, height=height, gravity=gravity) img.reset_coords() if not yolo: wand.display.display(img) diff --git a/dcc/text.py b/dcc/text.py index 4a9aa61..5df6ed4 100644 --- a/dcc/text.py +++ b/dcc/text.py @@ -6,10 +6,10 @@ import wand.image def draw_text(img, text, font_size=64): with wand.drawing.Drawing() as draw: - draw.font = dcc.config.FONT + draw.font = self.thumbnail_font draw.font_size = font_size - draw.fill_color = wand.color.Color(dcc.config.TEXT_FILL_COLOR) - draw.stroke_color = wand.color.Color(dcc.config.TEXT_STROKE_COLOR) + draw.fill_color = wand.color.Color(self.thumbnail_text_fill) + draw.stroke_color = wand.color.Color(self.thumbnail_text_stroke) draw.stroke_width = font_size * 5 / 32 draw.text_interline_spacing = -font_size / 4 draw.text(5, int(draw.font_size) + 5, text) @@ -33,8 +33,8 @@ class Text(dcc.doom_base.WadMap): text = "MAP{}: {}".format(parsed_args.map, text) text = "{}\n{}".format(text, parsed_args.demotype) with wand.image.Image( - height=dcc.config.THUMB_HEIGHT, - width=dcc.config.THUMB_WIDTH + height=self.thumbnail_height, + width=self.thumbnail_height ) as img: draw_text(img, text) img.trim() From e4d978149b74f5bd3ed571cca2b2be1706235ed7 Mon Sep 17 00:00:00 2001 From: yrriban Date: Thu, 3 Jul 2025 18:05:12 -0400 Subject: [PATCH 2/5] PEP 8 compliance. --- dcc/__main__.py | 2 +- dcc/concat.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dcc/__main__.py b/dcc/__main__.py index 6383388..dbb5b19 100644 --- a/dcc/__main__.py +++ b/dcc/__main__.py @@ -2,4 +2,4 @@ import sys from dcc.main import main if __name__ == '__main__': - sys.exit(main(sys.argv[1:])) + sys.exit(main(sys.argv[1:])) diff --git a/dcc/concat.py b/dcc/concat.py index 1f28199..33a3a8b 100644 --- a/dcc/concat.py +++ b/dcc/concat.py @@ -61,7 +61,7 @@ class Concat(dcc.doom_base.Wad): output.close() for line in summary: - summary_file.write(f"{line}\n") + summary_file.write(f"{line}\n") summary_file.close() def _add_chunk(self, v, output, overlay): From 673e649e87853cc41632dde69d6477073149c3e6 Mon Sep 17 00:00:00 2001 From: yrriban Date: Thu, 3 Jul 2025 18:06:00 -0400 Subject: [PATCH 3/5] Remove last unneeded constant. --- dcc/config.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/dcc/config.py b/dcc/config.py index a0edeb2..3b47181 100644 --- a/dcc/config.py +++ b/dcc/config.py @@ -6,8 +6,6 @@ import tomlkit from cliff.command import Command -MIRROR = "https://youfailit.net/pub/idgames" # NYC - class Base(Command): def get_parser(self, prog_name): From 5881c94c112e908666a9127f485c4fbafd9a77a5 Mon Sep 17 00:00:00 2001 From: yrriban Date: Thu, 3 Jul 2025 18:18:19 -0400 Subject: [PATCH 4/5] Add a configure command for initial wad setup. Reshuffle a couple things that depend on it. --- dcc/config.py | 8 -------- dcc/configure.py | 24 ++++++++++++++++++++++++ dcc/doom_base.py | 10 +++++++++- dcc/eureka.py | 2 +- 4 files changed, 34 insertions(+), 10 deletions(-) create mode 100644 dcc/configure.py diff --git a/dcc/config.py b/dcc/config.py index 3b47181..6d1c4b3 100644 --- a/dcc/config.py +++ b/dcc/config.py @@ -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 diff --git a/dcc/configure.py b/dcc/configure.py new file mode 100644 index 0000000..c5b2304 --- /dev/null +++ b/dcc/configure.py @@ -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) diff --git a/dcc/doom_base.py b/dcc/doom_base.py index 48d411a..3833bd8 100644 --- a/dcc/doom_base.py +++ b/dcc/doom_base.py @@ -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)) diff --git a/dcc/eureka.py b/dcc/eureka.py index d147879..1e49500 100644 --- a/dcc/eureka.py +++ b/dcc/eureka.py @@ -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) From b14c12c609f7b6af4d0f7a76f0283e90f4311d4b Mon Sep 17 00:00:00 2001 From: yrriban Date: Thu, 3 Jul 2025 18:21:24 -0400 Subject: [PATCH 5/5] Add a pwad_path property and also convert the iwad_path method to a property. --- dcc/configure.py | 3 ++- dcc/doom_base.py | 14 +++++++++----- dcc/eureka.py | 2 +- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/dcc/configure.py b/dcc/configure.py index c5b2304..e5a6c6a 100644 --- a/dcc/configure.py +++ b/dcc/configure.py @@ -2,6 +2,7 @@ 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) @@ -11,7 +12,7 @@ class Configure(dcc.config.Base): return parser def take_action(self, parsed_args): - new_config = self.pwads.joinpath(parsed_args.wad).joinpath(self.config_name) + new_config = self.pwad_path.joinpath(self.config_name) if new_config.exists(): raise Exception("Config %s already exists.".format(new_config)) diff --git a/dcc/doom_base.py b/dcc/doom_base.py index 3833bd8..7ef5f5b 100644 --- a/dcc/doom_base.py +++ b/dcc/doom_base.py @@ -29,9 +29,14 @@ class Wad(dcc.config.Base): def wad(self): return self._wad + @property + def pwad_path(self): + return self.pwads.joinpath(self.wad) + + @property def iwad_path(self): iwad = self.iwads.joinpath(self._config.get("iwad")) - iwadpath = self.pwads.joinpath(self.wad).joinpath("iwad") + iwadpath = self.pwad_path.joinpath("iwad") if iwadpath.exists(): with io.open(iwadpath) as f: iwad = self.iwads.joinpath(f.read().strip() + ".WAD") @@ -61,14 +66,13 @@ class WadMap(Wad): return "" if self._name is None else "_" + self._name def dsda_preamble(self): - args = ["-iwad", self.iwad_path()] + args = ["-iwad", self.iwad_path] - pwadpath = self.pwads.joinpath(self.wad) - wads = sorted(pwadpath.glob('*.wad', case_sensitive=False)) + wads = sorted(self.pwad_path.glob('*.wad', case_sensitive=False)) if len(wads) > 0: args = args + ["-file"] + wads - dehs = sorted(pwadpath.glob('*.deh', case_sensitive=False)) + dehs = sorted(self.pwad_path.glob('*.deh', case_sensitive=False)) if len(dehs) > 0: args = args + ["-deh"] + dehs diff --git a/dcc/eureka.py b/dcc/eureka.py index 1e49500..5aa2c56 100644 --- a/dcc/eureka.py +++ b/dcc/eureka.py @@ -10,7 +10,7 @@ class Eureka(dcc.doom_base.WadMap): return parser def take_action(self, parsed_args): - iwad = self.iwad_path() + iwad = self.iwad_path pwadpath = self.pwads.joinpath(parsed_args.wad) if parsed_args.main is not None: mw = pwadpath.joinpath(parsed_args.main)