Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion NTEUID/nte_gacha/gacha_card.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import random
from pathlib import Path
from datetime import datetime

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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),
)

Expand Down
5 changes: 3 additions & 2 deletions NTEUID/utils/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")


Expand Down