diff --git a/NTEUID/nte_gacha/gacha_card.py b/NTEUID/nte_gacha/gacha_card.py index edbba4f..78f9e1c 100644 --- a/NTEUID/nte_gacha/gacha_card.py +++ b/NTEUID/nte_gacha/gacha_card.py @@ -1,5 +1,6 @@ from __future__ import annotations +import random from pathlib import Path from datetime import datetime @@ -133,6 +134,13 @@ def _truncate(draw: ImageDraw.ImageDraw, text: str, font, max_w: int, suffix: st return text + suffix if text else suffix +def _pick_card_long_id(summary: NTEGachaSummary) -> str | None: + candidates = {item.item_id for section in summary.sections for item in section.items if item.item_id.isdigit()} + if not candidates: + return None + return random.choice(tuple(candidates)) + + async def _load_gacha_icon(item_id: str) -> Image.Image | None: if item_id.startswith("fork_"): return await get_weapon_img(item_id) @@ -261,7 +269,7 @@ async def draw_gacha_summary_img( canvas = get_nte_bg(_PAGE_W, total_h, "bg2") canvas.alpha_composite( - make_nte_role_title(await get_event_avatar(ev), role_name, role_id), + make_nte_role_title(await get_event_avatar(ev), role_name, role_id, card_long_id=_pick_card_long_id(summary)), (0, _TITLE_Y), ) diff --git a/NTEUID/utils/image.py b/NTEUID/utils/image.py index 47be647..2efd100 100644 --- a/NTEUID/utils/image.py +++ b/NTEUID/utils/image.py @@ -337,8 +337,9 @@ def get_nte_title_bg(width: int, height: int, *, game: str = "yihuan") -> Image. def _load_card_long(card_long_id: str | None = None) -> Image.Image: if card_long_id: path = CARD_LONG_PATH / f"{card_long_id}.png" - else: - path = random.choice(list(CARD_LONG_PATH.glob("*.png"))) + if path.exists(): + return Image.open(path).convert("RGBA") + path = random.choice(list(CARD_LONG_PATH.glob("*.png"))) return Image.open(path).convert("RGBA")