From ea4a1d293e78e5485c8dd0a17a71aa27172b1ebe Mon Sep 17 00:00:00 2001 From: Faraphel Date: Thu, 14 Jul 2022 15:49:03 +0200 Subject: [PATCH] fixed an issue where ImageFont couldn't read directly from a Path object, and set CT_ICON_SIZE constant to 128 instead of hardcoding 128 --- source/mkw/Cup.py | 9 ++++++--- source/mkw/ModConfig.py | 12 +++++++----- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/source/mkw/Cup.py b/source/mkw/Cup.py index 07a4864..2d787f3 100644 --- a/source/mkw/Cup.py +++ b/source/mkw/Cup.py @@ -21,14 +21,17 @@ class Cup: Get the default cticon for this cup :return: the default cticon """ - ct_icon = Image.new("RGBA", (128, 128)) + from source.mkw.ModConfig import CT_ICON_SIZE + + ct_icon = Image.new("RGBA", (CT_ICON_SIZE, CT_ICON_SIZE)) + default_font_path = str(mod_config.get_default_font().resolve()) draw = ImageDraw.Draw(ct_icon) draw.text( (4, 4), "CT", (255, 165, 0), - font=ImageFont.truetype(mod_config.get_default_font(), 90), + font=ImageFont.truetype(default_font_path, 90), stroke_width=2, stroke_fill=(0, 0, 0) ) @@ -36,7 +39,7 @@ class Cup: (5, 80), f"{self.cup_id:03}", (255, 165, 0), - font=ImageFont.truetype(mod_config.get_default_font(), 60), + font=ImageFont.truetype(default_font_path, 60), stroke_width=2, stroke_fill=(0, 0, 0) ) diff --git a/source/mkw/ModConfig.py b/source/mkw/ModConfig.py index ad0a5a1..113ddfa 100644 --- a/source/mkw/ModConfig.py +++ b/source/mkw/ModConfig.py @@ -9,6 +9,9 @@ from source.mkw.Track import Track import json +CT_ICON_SIZE: int = 128 + + # representation of the configuration of a mod class ModConfig: __slots__ = ("name", "path", "nickname", "variant", "region", "tags_prefix", "tags_suffix", @@ -203,7 +206,7 @@ class ModConfig: if self.enable_random_cup: icon_names.append("random") for icon_name in icon_names: - yield Image.open(self.get_mod_directory() / f"{icon_name}.png").resize((128, 128)) + yield Image.open(self.get_mod_directory() / f"_CUPS/{icon_name}.png").resize((CT_ICON_SIZE, CT_ICON_SIZE)) def get_custom_cticons(self) -> Generator[Image.Image, None, None]: """ @@ -211,7 +214,7 @@ class ModConfig: :return: """ for cup in self.get_cups(): - yield cup.get_cticon(mod_config=self).resize((128, 128)) + yield cup.get_cticon(mod_config=self).resize((CT_ICON_SIZE, CT_ICON_SIZE)) def get_cticons(self) -> Generator[Image.Image, None, None]: """ @@ -227,7 +230,6 @@ class ModConfig: Return the default font for creating ct_icons :return: the path to the default font file """ - # TODO: make it customizable return Path("./assets/SuperMario256.ttf") def get_full_cticon(self) -> Image.Image: @@ -237,7 +239,7 @@ class ModConfig: """ cticons = list(self.get_cticons()) - full_cticon = Image.new("RGBA", (128 * len(cticons), 128)) - for i, cticon in enumerate(cticons): full_cticon.paste(cticon, (i * 128, 0)) + full_cticon = Image.new("RGBA", (CT_ICON_SIZE * len(cticons), CT_ICON_SIZE)) + for i, cticon in enumerate(cticons): full_cticon.paste(cticon, (i * CT_ICON_SIZE, 0)) return full_cticon