Skip to content

Commit

Permalink
fix: Fix costume gacha art
Browse files Browse the repository at this point in the history
  • Loading branch information
seriaati committed Feb 2, 2024
1 parent 245e8ca commit 73c3cb3
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 16 deletions.
2 changes: 1 addition & 1 deletion enka/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def _post_process_showcase_character(
costume_data = self._assets.character_data[str(showcase_character.id)]["Costumes"]
if costume_data is not None:
showcase_character.costuime_icon = Icon(
costume_data[str(showcase_character.costume_id)]["sideIconName"]
costume_data[str(showcase_character.costume_id)]["sideIconName"], is_costume=True
)

return showcase_character
Expand Down
7 changes: 5 additions & 2 deletions enka/models/icon.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
class Icon:
def __init__(self, side_icon_ui_path: str) -> None:
def __init__(self, side_icon_ui_path: str, *, is_costume: bool = False) -> None:
self._side_icon_ui_path = side_icon_ui_path
self._side_icon = f"https://enka.network/ui/{side_icon_ui_path}.png"
self._is_costume = is_costume

@property
def icon_ui_path(self) -> str:
Expand Down Expand Up @@ -33,7 +34,9 @@ def gacha(self) -> str:
The gacha art of the character.
e.g. https://enka.network/ui/UI_Gacha_AvatarImg_Ambor.png
"""
return self._side_icon.replace("AvatarIcon_Side", "Gacha_AvatarImg")
return self._side_icon.replace(
"AvatarIcon_Side", "Costume" if self._is_costume else "Gacha_AvatarImg"
)

@property
def front(self) -> str:
Expand Down
32 changes: 19 additions & 13 deletions example.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
async def main() -> None:
async with enka.EnkaAPI() as api:
try:
response = await api.fetch_showcase(901211014)
response = await api.fetch_showcase(738081787)
except enka.exceptions.PlayerDoesNotExistError:
return print("Player does not exist.")
except enka.exceptions.GameMaintenanceError:
Expand All @@ -17,19 +17,25 @@ async def main() -> None:
print("Achievements:", response.player.achievements)
print("Namecard:", response.player.namecard.full)

for character in response.characters:
for showcase_character in response.player.showcase_characters:
print("\n==================\n")
print(character.name)
print("Level:", character.level)
print("Element:", character.element.name)
print("Constellation:", len(character.constellations))
print("Weapon:", character.weapon.name)
print("Weapon level:", character.weapon.level)
print("Weapon refinement:", character.weapon.refinement)
print("Side icon:", character.icon.side)
print("Circle icon:", character.icon.circle)
print("Gacha art:", character.icon.gacha)
print("Front icon:", character.icon.front)
print("Level:", showcase_character.level)
if showcase_character.costuime_icon:
print("Costume icon:", showcase_character.costuime_icon.gacha)

# for character in response.characters:
# print("\n==================\n")
# print(character.name)
# print("Level:", character.level)
# print("Element:", character.element.name)
# print("Constellation:", len(character.constellations))
# print("Weapon:", character.weapon.name)
# print("Weapon level:", character.weapon.level)
# print("Weapon refinement:", character.weapon.refinement)
# print("Side icon:", character.icon.side)
# print("Circle icon:", character.icon.circle)
# print("Gacha art:", character.icon.gacha)
# print("Front icon:", character.icon.front)


asyncio.run(main())

0 comments on commit 73c3cb3

Please sign in to comment.