Compare commits

...

4 commits

5 changed files with 42 additions and 23 deletions

View file

@ -85,7 +85,11 @@ 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) self.draw_text(
img,
f"MAP{mapstring}: {text}",
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

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

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

@ -1,10 +1,11 @@
import dcc.config
import dcc.doom_base import dcc.doom_base
import sys import sys
import wand.drawing import wand.drawing
import wand.image import wand.image
def draw_text(img, text, font_size=64): def draw_text(self, img, text, font_size=64):
with wand.drawing.Drawing() as draw: with wand.drawing.Drawing() as draw:
draw.font = self.thumbnail_font draw.font = self.thumbnail_font
draw.font_size = font_size draw.font_size = font_size
@ -20,6 +21,9 @@ def draw_text(img, text, font_size=64):
draw(img) draw(img)
dcc.config.Base.draw_text = draw_text
class Text(dcc.doom_base.WadMap): class Text(dcc.doom_base.WadMap):
def get_parser(self, prog_name): def get_parser(self, prog_name):
parser = super().get_parser(prog_name) parser = super().get_parser(prog_name)
@ -34,9 +38,11 @@ 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) self.draw_text(
img, text,
)
img.trim() img.trim()
img.reset_coords() img.reset_coords()
img.save(filename=self.text_thumb_path()) img.save(filename=self.text_thumb_path())