Actually load the values for screenshot text, etc. correctly from the config. Pass them into draw_text which doesn't have them readily available.

This commit is contained in:
yrriban 2025-07-04 11:50:10 -04:00
parent b14c12c609
commit 1ac3851065
4 changed files with 42 additions and 19 deletions

View file

@ -85,7 +85,14 @@ class Concat(dcc.doom_base.Wad):
) )
mapstring = v.name[-6:-4] mapstring = v.name[-6:-4]
text = self._config["map_names"][f"map{mapstring}"] text = self._config["map_names"][f"map{mapstring}"]
dcc.text.draw_text(img, f"MAP{mapstring}: {text}", font_size=120) dcc.text.draw_text(
img,
f"MAP{mapstring}: {text}",
self.thumbnail_font,
self.thumbnail_text_fill,
self.thumbnail_text_stroke,
font_size=120
)
img.trim(reset_coords=True) img.trim(reset_coords=True)
img.border("graya(25%, 25%)", 10, 10) img.border("graya(25%, 25%)", 10, 10)
img.border(dcc.config.TEXT_STROKE_COLOR, 16, 16) img.border(dcc.config.TEXT_STROKE_COLOR, 16, 16)

View file

@ -26,25 +26,36 @@ class Base(Command):
"required key 'dsda' not set in config " "required key 'dsda' not set in config "
+ f"{self.doom.joinpath(self.config_name)}.") + f"{self.doom.joinpath(self.config_name)}.")
for d in ("iwads", "pwads", "demos", "fabricate"): for d in ("iwads", "pwads", "demos", "fabricate"):
self._init_attr(d, d, fn=self.doom.joinpath) self._init_attr([d], d, fn=self.doom.joinpath)
self._init_attr("thumbnail.height", 1280) self._init_attr(["thumbnail", "height"], 720)
self._init_attr("thumbnail.width", 720) self._init_attr(["thumbnail", "width"], 1280)
self._init_attr("thumbnail.font", None) self._init_attr(["thumbnail", "font"], None)
self._init_attr("thumbnail.text_fill", "white") self._init_attr(["thumbnail", "text_fill"], "white")
self._init_attr("thumbnail.text_stroke", "red") self._init_attr(["thumbnail", "text_stroke"], "red")
self._init_attr("fetch.mirror", "https://youfailit.net/pub/idgames") self._init_attr(
["fetch", "mirror"],
"https://youfailit.net/pub/idgames"
)
def run(self, parsed_args): def run(self, parsed_args):
self.init_base(parsed_args) self.init_base(parsed_args)
self.take_action(parsed_args) self.take_action(parsed_args)
def _init_attr(self, what, default, fn=lambda x: x): def _init_attr(self, what, default, fn=lambda x: x):
what = what.replace(".", "_") propname = "_".join(what)
val = self._config
for w in what:
val = val[w]
if val is None:
val = default
break
setattr(self, f"_{propname}", fn(val))
setattr( setattr(
self, f"_{what}", fn(self._config.get(what, default))) type(self), propname,
setattr( property(lambda self: getattr(self, f"_{propname}"))
type(self), what, property(lambda self: getattr(self, f"_{what}"))) )
@property @property
def doom(self): def doom(self):

View file

@ -22,7 +22,7 @@ class SS(dcc.doom_base.WadMap):
height = self.thumbnail_height height = self.thumbnail_height
with wand.image.Image(width=width, height=height, pseudo="x:") as img: with wand.image.Image(width=width, height=height, pseudo="x:") as img:
img.reset_coords() img.reset_coords()
if (img.size[0] < width or img.size[1] < height): if (img.width < width or img.height < height):
if not messagebox.askretrycancel( if not messagebox.askretrycancel(
title="DCC", title="DCC",
message=f"Image too small ({img.width}x{img.height})." + message=f"Image too small ({img.width}x{img.height})." +

View file

@ -4,12 +4,12 @@ import wand.drawing
import wand.image import wand.image
def draw_text(img, text, font_size=64): def draw_text(img, text, font, text_fill, text_stroke, font_size=64):
with wand.drawing.Drawing() as draw: with wand.drawing.Drawing() as draw:
draw.font = self.thumbnail_font draw.font = font
draw.font_size = font_size draw.font_size = font_size
draw.fill_color = wand.color.Color(self.thumbnail_text_fill) draw.fill_color = wand.color.Color(text_fill)
draw.stroke_color = wand.color.Color(self.thumbnail_text_stroke) draw.stroke_color = wand.color.Color(text_stroke)
draw.stroke_width = font_size * 5 / 32 draw.stroke_width = font_size * 5 / 32
draw.text_interline_spacing = -font_size / 4 draw.text_interline_spacing = -font_size / 4
draw.text(5, int(draw.font_size) + 5, text) draw.text(5, int(draw.font_size) + 5, text)
@ -34,9 +34,14 @@ class Text(dcc.doom_base.WadMap):
text = "{}\n{}".format(text, parsed_args.demotype) text = "{}\n{}".format(text, parsed_args.demotype)
with wand.image.Image( with wand.image.Image(
height=self.thumbnail_height, height=self.thumbnail_height,
width=self.thumbnail_height width=self.thumbnail_width
) as img: ) as img:
draw_text(img, text) draw_text(
img, text,
self.thumbnail_font,
self.thumbnail_text_fill,
self.thumbnail_text_stroke
)
img.trim() img.trim()
img.reset_coords() img.reset_coords()
img.save(filename=self.text_thumb_path()) img.save(filename=self.text_thumb_path())