Skip to content

Commit

Permalink
Change icon provider to Enka (#165)
Browse files Browse the repository at this point in the history
* fix: Use Enka as new icon provider

* Run nox

* feat: Add new gacha_art property

Add deprecation notice to image property
Change image property to return gacha_art instead
  • Loading branch information
seriaati authored Mar 15, 2024
1 parent dcbe321 commit 7b0af4e
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions genshin/models/genshin/character.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import re
import typing

from genshin.utility import deprecation

if typing.TYPE_CHECKING:
import pydantic.v1 as pydantic
else:
Expand All @@ -20,7 +22,7 @@

_LOGGER = logging.getLogger(__name__)

ICON_BASE = "https://upload-os-bbs.mihoyo.com/game_record/genshin/"
ICON_BASE = "https://enka.network/ui/"


def _parse_icon(icon: typing.Union[str, int]) -> str:
Expand Down Expand Up @@ -86,7 +88,14 @@ def _get_db_char(
constants.CHARACTER_NAMES[lang][char.id] = char
return char

return constants.DBChar(id or 0, icon_name, name or icon_name, element or "Anemo", rarity or 5, guessed=True)
return constants.DBChar(
id or 0,
icon_name,
name or icon_name,
element or "Anemo",
rarity or 5,
guessed=True,
)

if name:
for char in constants.CHARACTER_NAMES[lang].values():
Expand Down Expand Up @@ -115,7 +124,7 @@ def __autocomplete(cls, values: typing.Dict[str, typing.Any]) -> typing.Dict[str
id, name, icon, element, rarity = (values.get(x) for x in ("id", "name", "icon", "element", "rarity"))

char = _get_db_char(id, name, icon, element, rarity, lang=values["lang"])
icon = _create_icon(char.icon_name, "character_icon/UI_AvatarIcon_{}")
icon = _create_icon(char.icon_name, "UI_AvatarIcon_{}")

values["id"] = char.id
values["name"] = char.name
Expand Down Expand Up @@ -143,16 +152,21 @@ def __autocomplete(cls, values: typing.Dict[str, typing.Any]) -> typing.Dict[str
return values

@property
@deprecation.deprecated("gacha_art")
def image(self) -> str:
return _create_icon(self.icon, "character_image/UI_AvatarIcon_{}@2x")
return _create_icon(self.icon, "UI_Gacha_AvatarImg_{}")

@property
def gacha_art(self) -> str:
return _create_icon(self.icon, "UI_Gacha_AvatarImg_{}")

@property
def side_icon(self) -> str:
return _create_icon(self.icon, "character_side_icon/UI_AvatarIcon_Side_{}")
return _create_icon(self.icon, "UI_AvatarIcon_Side_{}")

@property
def card_icon(self) -> str:
return _create_icon(self.icon, "character_card_icon/UI_AvatarIcon_{}_Card")
return _create_icon(self.icon, "UI_AvatarIcon_{}_Card")

@property
def traveler_name(self) -> str:
Expand Down

0 comments on commit 7b0af4e

Please sign in to comment.