Move the remaining hardcoded constants into the configuration file.
This commit is contained in:
parent
4bbf57036d
commit
d778e281ba
4 changed files with 25 additions and 30 deletions
|
@ -6,12 +6,6 @@ import tomlkit
|
||||||
|
|
||||||
from cliff.command import Command
|
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
|
MIRROR = "https://youfailit.net/pub/idgames" # NYC
|
||||||
|
|
||||||
|
|
||||||
|
@ -34,15 +28,23 @@ 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_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):
|
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_path(self, what):
|
def _init_attr(self, what, default, fn=lambda x: x):
|
||||||
|
what = what.replace(".", "_")
|
||||||
setattr(
|
setattr(
|
||||||
self, f"_{what}", self.doom.joinpath(self._config.get(what, what)))
|
self, f"_{what}", fn(self._config.get(what, default)))
|
||||||
setattr(
|
setattr(
|
||||||
type(self), what, property(lambda self: getattr(self, f"_{what}")))
|
type(self), what, property(lambda self: getattr(self, f"_{what}")))
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,7 @@ class Fetch(dcc.config.Base):
|
||||||
) as response:
|
) as response:
|
||||||
reply = json.loads(response.read())
|
reply = json.loads(response.read())
|
||||||
rpath = "/".join([
|
rpath = "/".join([
|
||||||
dcc.config.MIRROR,
|
self.fetch_mirror,
|
||||||
reply["content"]["dir"],
|
reply["content"]["dir"],
|
||||||
reply["content"]["filename"]
|
reply["content"]["filename"]
|
||||||
])
|
])
|
||||||
|
|
23
dcc/ss.py
23
dcc/ss.py
|
@ -18,26 +18,19 @@ class SS(dcc.doom_base.WadMap):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def _try_screenshot(self, gravity, yolo):
|
def _try_screenshot(self, gravity, yolo):
|
||||||
with wand.image.Image(
|
width = self.thumbnail_width
|
||||||
width=dcc.config.THUMB_WIDTH,
|
height = self.thumbnail_height
|
||||||
height=dcc.config.THUMB_HEIGHT,
|
with wand.image.Image(width=width, height=height, pseudo="x:") as img:
|
||||||
pseudo="x:"
|
|
||||||
) as img:
|
|
||||||
img.reset_coords()
|
img.reset_coords()
|
||||||
if (
|
if (img.size[0] < width or img.size[1] < height):
|
||||||
img.size[0] < dcc.config.THUMB_WIDTH
|
|
||||||
or img.size[1] < dcc.config.THUMB_HEIGHT
|
|
||||||
):
|
|
||||||
if not messagebox.askretrycancel(
|
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.")
|
sys.exit("Gave up trying to select an image.")
|
||||||
return False
|
return False
|
||||||
img.crop(
|
img.crop(width=width, height=height, gravity=gravity)
|
||||||
width=dcc.config.THUMB_WIDTH,
|
|
||||||
height=dcc.config.THUMB_HEIGHT,
|
|
||||||
gravity=gravity
|
|
||||||
)
|
|
||||||
img.reset_coords()
|
img.reset_coords()
|
||||||
if not yolo:
|
if not yolo:
|
||||||
wand.display.display(img)
|
wand.display.display(img)
|
||||||
|
|
10
dcc/text.py
10
dcc/text.py
|
@ -6,10 +6,10 @@ import wand.image
|
||||||
|
|
||||||
def draw_text(img, text, font_size=64):
|
def draw_text(img, text, font_size=64):
|
||||||
with wand.drawing.Drawing() as draw:
|
with wand.drawing.Drawing() as draw:
|
||||||
draw.font = dcc.config.FONT
|
draw.font = self.thumbnail_font
|
||||||
draw.font_size = font_size
|
draw.font_size = font_size
|
||||||
draw.fill_color = wand.color.Color(dcc.config.TEXT_FILL_COLOR)
|
draw.fill_color = wand.color.Color(self.thumbnail_text_fill)
|
||||||
draw.stroke_color = wand.color.Color(dcc.config.TEXT_STROKE_COLOR)
|
draw.stroke_color = wand.color.Color(self.thumbnail_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)
|
||||||
|
@ -33,8 +33,8 @@ class Text(dcc.doom_base.WadMap):
|
||||||
text = "MAP{}: {}".format(parsed_args.map, text)
|
text = "MAP{}: {}".format(parsed_args.map, text)
|
||||||
text = "{}\n{}".format(text, parsed_args.demotype)
|
text = "{}\n{}".format(text, parsed_args.demotype)
|
||||||
with wand.image.Image(
|
with wand.image.Image(
|
||||||
height=dcc.config.THUMB_HEIGHT,
|
height=self.thumbnail_height,
|
||||||
width=dcc.config.THUMB_WIDTH
|
width=self.thumbnail_height
|
||||||
) as img:
|
) as img:
|
||||||
draw_text(img, text)
|
draw_text(img, text)
|
||||||
img.trim()
|
img.trim()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue