Skip to content

Commit

Permalink
fix: Fix cached character card generation error
Browse files Browse the repository at this point in the history
  • Loading branch information
seriaati committed Mar 1, 2024
1 parent 1590701 commit b756f7c
Showing 1 changed file with 31 additions and 19 deletions.
50 changes: 31 additions & 19 deletions hoyo_buddy/ui/hoyo/hsr_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,11 @@ async def draw_card(self, i: "INTERACTION") -> "io.BytesIO":
)
self._card_settings = card_settings

# Force change the template to hb1 if is cached data
if not character.live:
self._card_settings.template = "hb1"
await self._card_settings.save()

if "hb" in self._card_settings.template:
bytes_obj = await self._draw_hb_character_card(character, i.client.session)
else:
Expand Down Expand Up @@ -340,7 +345,12 @@ async def callback(self, i: "INTERACTION") -> None:
self.view._card_settings.custom_images,
)
)
self.view.add_item(CardTemplateSelect(self.view._card_settings.template))
self.view.add_item(
CardTemplateSelect(
self.view._card_settings.template,
self.view.character_id in self.view.live_data_character_ids,
)
)
self.view.add_item(
PrimaryColorButton(
self.view._card_settings.custom_primary_color,
Expand Down Expand Up @@ -664,7 +674,7 @@ async def callback(self, i: "INTERACTION") -> None:


class CardTemplateSelect(Select[HSRProfileView]):
def __init__(self, current_template: str) -> None:
def __init__(self, current_template: str, is_live: bool) -> None:
hb_templates = (1,)
src_templates = (1, 2, 3)

Expand All @@ -687,23 +697,24 @@ def __init__(self, current_template: str) -> None:
default=value == current_template,
),
)
for template_num in src_templates:
value = f"src{template_num}"
options.append(
SelectOption(
label=LocaleStr(
"StarRailCard Template {num}",
key="profile.card_template_select.src.label",
num=template_num,
if is_live:
for template_num in src_templates:
value = f"src{template_num}"
options.append(
SelectOption(
label=LocaleStr(
"StarRailCard Template {num}",
key="profile.card_template_select.src.label",
num=template_num,
),
description=LocaleStr(
"Designed and programmed by @korzzex",
key="profile.card_template_select.src.description",
),
value=value,
default=value == current_template,
),
description=LocaleStr(
"Designed and programmed by @korzzex",
key="profile.card_template_select.src.description",
),
value=value,
default=value == current_template,
),
)
)

super().__init__(
options=options,
Expand Down Expand Up @@ -779,7 +790,8 @@ async def callback(self, i: "INTERACTION") -> None:
value=LocaleStr(
"- Hoyo Buddy has its own template made by me, but I also added templates made by other developers.\n"
"- Code of 3rd party templates are not maintained by me, so I cannot guarantee their quality; I am also not responsible for any issues with them.\n"
"- 3rd party templates may have feature limitations compared to Hoyo Buddy's.\n",
"- 3rd party templates may have feature limitations compared to Hoyo Buddy's.\n"
"- Cached data characters can only use Hoyo Buddy's template.",
key="profile.info.embed.templates.value",
),
inline=False,
Expand Down

0 comments on commit b756f7c

Please sign in to comment.