Skip to content

Commit

Permalink
fix: Fix font missing in item list card
Browse files Browse the repository at this point in the history
  • Loading branch information
seriaati committed Mar 5, 2024
1 parent 70def3d commit bdb1e84
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
14 changes: 10 additions & 4 deletions src/draw/item_list.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from io import BytesIO
from typing import TYPE_CHECKING

from cachetools import LRUCache, cached
from PIL import Image, ImageDraw
Expand All @@ -13,18 +14,23 @@
Drawer,
)

if TYPE_CHECKING:
from discord import Locale

def cache_key(items: list[ItemWithDescription] | list[ItemWithTrailing], dark_mode: bool) -> str:

def cache_key(
items: list[ItemWithDescription] | list[ItemWithTrailing], dark_mode: bool, locale: "Locale"
) -> str:
items_key = "_".join(
f"{item.title}_{item.description if isinstance(item, ItemWithDescription) else item.trailing}"
for item in items
)
return f"{items_key}_{dark_mode}"
return f"{items_key}_{dark_mode}_{locale.value}"


@cached(cache=LRUCache(maxsize=100), key=cache_key)
def draw_item_list(
items: list[ItemWithDescription] | list[ItemWithTrailing], dark_mode: bool
items: list[ItemWithDescription] | list[ItemWithTrailing], dark_mode: bool, locale: "Locale"
) -> BytesIO:
is_trailing = any(isinstance(item, ItemWithTrailing) for item in items)

Expand All @@ -49,7 +55,7 @@ def draw_item_list(
color=DARK_SURFACE if dark_mode else LIGHT_SURFACE,
)
draw = ImageDraw.Draw(im)
drawer = Drawer(draw, folder="draw-list", dark_mode=dark_mode)
drawer = Drawer(draw, folder="draw-list", dark_mode=dark_mode, locale=locale)

for index, item in enumerate(items):
pos = (
Expand Down
4 changes: 3 additions & 1 deletion src/ui/hoyo/genshin/abyss.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ async def update(self, i: "INTERACTION") -> None:
await download_and_save_static_images(
[item.icon for item in items[0] + items[1]], "draw-list", i.client.session
)
buffer = await asyncio.to_thread(draw_item_list, items[self._wave_index], self._dark_mode)
buffer = await asyncio.to_thread(
draw_item_list, items[self._wave_index], self._dark_mode, self.locale
)
buffer.seek(0)
file_ = File(buffer, filename="enemies.webp")

Expand Down

0 comments on commit bdb1e84

Please sign in to comment.