Compare commits
No commits in common. "b14c12c609f7b6af4d0f7a76f0283e90f4311d4b" and "4bbf57036d755c1e2538b4b8ea897914579e8461" have entirely different histories.
b14c12c609
...
4bbf57036d
9 changed files with 47 additions and 69 deletions
|
@ -6,6 +6,14 @@ 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
|
||||||
|
|
||||||
|
|
||||||
class Base(Command):
|
class Base(Command):
|
||||||
def get_parser(self, prog_name):
|
def get_parser(self, prog_name):
|
||||||
|
@ -26,23 +34,15 @@ 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_path(d)
|
||||||
|
|
||||||
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_attr(self, what, default, fn=lambda x: x):
|
def _init_path(self, what):
|
||||||
what = what.replace(".", "_")
|
|
||||||
setattr(
|
setattr(
|
||||||
self, f"_{what}", fn(self._config.get(what, default)))
|
self, f"_{what}", self.doom.joinpath(self._config.get(what, what)))
|
||||||
setattr(
|
setattr(
|
||||||
type(self), what, property(lambda self: getattr(self, f"_{what}")))
|
type(self), what, property(lambda self: getattr(self, f"_{what}")))
|
||||||
|
|
||||||
|
@ -57,3 +57,11 @@ class Base(Command):
|
||||||
@property
|
@property
|
||||||
def dsda(self):
|
def dsda(self):
|
||||||
return self._doom.joinpath(self._dsda)
|
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
|
||||||
|
|
|
@ -1,25 +0,0 @@
|
||||||
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.pwad_path.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)
|
|
|
@ -29,19 +29,6 @@ class Wad(dcc.config.Base):
|
||||||
def wad(self):
|
def wad(self):
|
||||||
return self._wad
|
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.pwad_path.joinpath("iwad")
|
|
||||||
if iwadpath.exists():
|
|
||||||
with io.open(iwadpath) as f:
|
|
||||||
iwad = self.iwads.joinpath(f.read().strip() + ".WAD")
|
|
||||||
return iwad
|
|
||||||
|
|
||||||
|
|
||||||
class WadMap(Wad):
|
class WadMap(Wad):
|
||||||
def get_parser(self, prog_name):
|
def get_parser(self, prog_name):
|
||||||
|
@ -66,13 +53,14 @@ class WadMap(Wad):
|
||||||
return "" if self._name is None else "_" + self._name
|
return "" if self._name is None else "_" + self._name
|
||||||
|
|
||||||
def dsda_preamble(self):
|
def dsda_preamble(self):
|
||||||
args = ["-iwad", self.iwad_path]
|
args = ["-iwad", self.iwad_path(self.wad)]
|
||||||
|
|
||||||
wads = sorted(self.pwad_path.glob('*.wad', case_sensitive=False))
|
pwadpath = self.pwads.joinpath(self.wad)
|
||||||
|
wads = sorted(pwadpath.glob('*.wad', case_sensitive=False))
|
||||||
if len(wads) > 0:
|
if len(wads) > 0:
|
||||||
args = args + ["-file"] + wads
|
args = args + ["-file"] + wads
|
||||||
|
|
||||||
dehs = sorted(self.pwad_path.glob('*.deh', case_sensitive=False))
|
dehs = sorted(pwadpath.glob('*.deh', case_sensitive=False))
|
||||||
if len(dehs) > 0:
|
if len(dehs) > 0:
|
||||||
args = args + ["-deh"] + dehs
|
args = args + ["-deh"] + dehs
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@ class Eureka(dcc.doom_base.WadMap):
|
||||||
return parser
|
return parser
|
||||||
|
|
||||||
def take_action(self, parsed_args):
|
def take_action(self, parsed_args):
|
||||||
iwad = self.iwad_path
|
iwad = self.iwad_path(parsed_args.wad)
|
||||||
pwadpath = self.pwads.joinpath(parsed_args.wad)
|
pwadpath = self.pwads.joinpath(parsed_args.wad)
|
||||||
if parsed_args.main is not None:
|
if parsed_args.main is not None:
|
||||||
mw = pwadpath.joinpath(parsed_args.main)
|
mw = pwadpath.joinpath(parsed_args.main)
|
||||||
|
|
|
@ -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([
|
||||||
self.fetch_mirror,
|
dcc.config.MIRROR,
|
||||||
reply["content"]["dir"],
|
reply["content"]["dir"],
|
||||||
reply["content"]["filename"]
|
reply["content"]["filename"]
|
||||||
])
|
])
|
||||||
|
|
23
dcc/ss.py
23
dcc/ss.py
|
@ -18,19 +18,26 @@ class SS(dcc.doom_base.WadMap):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def _try_screenshot(self, gravity, yolo):
|
def _try_screenshot(self, gravity, yolo):
|
||||||
width = self.thumbnail_width
|
with wand.image.Image(
|
||||||
height = self.thumbnail_height
|
width=dcc.config.THUMB_WIDTH,
|
||||||
with wand.image.Image(width=width, height=height, pseudo="x:") as img:
|
height=dcc.config.THUMB_HEIGHT,
|
||||||
|
pseudo="x:"
|
||||||
|
) as img:
|
||||||
img.reset_coords()
|
img.reset_coords()
|
||||||
if (img.size[0] < width or img.size[1] < height):
|
if (
|
||||||
|
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",
|
title="DCC", message="Image too small. Try again?"
|
||||||
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(width=width, height=height, gravity=gravity)
|
img.crop(
|
||||||
|
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 = self.thumbnail_font
|
draw.font = dcc.config.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(dcc.config.TEXT_FILL_COLOR)
|
||||||
draw.stroke_color = wand.color.Color(self.thumbnail_text_stroke)
|
draw.stroke_color = wand.color.Color(dcc.config.TEXT_STROKE_COLOR)
|
||||||
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=self.thumbnail_height,
|
height=dcc.config.THUMB_HEIGHT,
|
||||||
width=self.thumbnail_height
|
width=dcc.config.THUMB_WIDTH
|
||||||
) 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