mirror of
https://github.com/PaiGramTeam/EnkaNetwork.py.git
synced 2024-11-16 03:45:28 +00:00
Support get character costumes image and Update traveler to see element
This commit is contained in:
parent
adea163945
commit
33c9e34402
@ -34,20 +34,39 @@ class Assets:
|
||||
def CHARACTERS_IDS(self) -> List[str]:
|
||||
return [x for x in self.DATA["characters"]]
|
||||
|
||||
@property
|
||||
def COSTUMES_IDS(self) -> List[str]:
|
||||
return [x for x in self.DATA["costumes"]]
|
||||
|
||||
@classmethod
|
||||
def character(cls, id: int) -> Union[assets.CharacterAsset, None]:
|
||||
def character(cls, id: Union[int, str]) -> Union[assets.CharacterAsset, None]: # noqa: E501
|
||||
LOGGER.debug(f"Getting character assets with id: {id}")
|
||||
|
||||
data = cls.DATA["characters"].get(str(id))
|
||||
if not data:
|
||||
LOGGER.error(f"Character not found with id: {id}")
|
||||
return
|
||||
|
||||
return assets.CharacterAsset.parse_obj({
|
||||
"id": id,
|
||||
"id": id if id.isdigit() else id.split("-")[0],
|
||||
"skill_id": str(id).split("-")[1] if not id.isdigit() else 0,
|
||||
"images": cls.create_character_icon(data["sideIconName"]),
|
||||
**data
|
||||
})
|
||||
|
||||
@classmethod
|
||||
def character_costume(cls, id: int): # noqa: E501
|
||||
LOGGER.debug(f"Getting costume assets with id: {id}")
|
||||
data = cls.DATA["costumes"].get(str(id))
|
||||
if not data:
|
||||
LOGGER.error(f"Costume not found with id: {id}")
|
||||
return
|
||||
|
||||
return assets.CharacterCostume.parse_obj({
|
||||
"id": id,
|
||||
"images": cls.create_chractar_costume_icon(data["sideIconName"])
|
||||
})
|
||||
|
||||
@classmethod
|
||||
def constellations(cls, id: int) -> Union[assets.CharacterConstellationsAsset, None]: # noqa: E501
|
||||
LOGGER.debug(f"Getting character constellations assets with id: {id}")
|
||||
@ -66,6 +85,7 @@ class Assets:
|
||||
def skills(cls, id: int) -> Union[assets.CharacterSkillAsset, None]:
|
||||
LOGGER.debug(f"Getting character skills assets with id: {id}")
|
||||
data = cls.DATA["skills"].get(str(id))
|
||||
|
||||
if not data:
|
||||
LOGGER.error(f"Character skills not found with id: {id}")
|
||||
return
|
||||
@ -120,6 +140,12 @@ class Assets:
|
||||
banner=create_ui_path(path.replace("AvatarIcon_Side", "Gacha_AvatarImg")) # noqa: E501
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def create_chractar_costume_icon(cls, path: str) -> assets.CharacterIconAsset: # noqa: E501
|
||||
_data = cls.create_character_icon(path)
|
||||
_data.banner = _data.banner.replace("Gacha_AvatarImg", "Costume")
|
||||
return _data
|
||||
|
||||
@staticmethod
|
||||
def create_icon_path(path: str) -> str:
|
||||
return create_ui_path(path)
|
||||
|
@ -30,11 +30,18 @@ class CharacterConstellationsAsset(BaseModel):
|
||||
icon: str = Field(None, alias="icon")
|
||||
|
||||
|
||||
class CharacterCostume(BaseModel):
|
||||
id: int = 0
|
||||
images: CharacterIconAsset = None
|
||||
|
||||
|
||||
class CharacterAsset(BaseModel):
|
||||
id: int = 0
|
||||
rarity: int = 0
|
||||
hash_id: str = Field("", alias="nameTextMapHash")
|
||||
element: ElementType = ElementType.Unknown
|
||||
images: CharacterIconAsset = None
|
||||
skill_id: int = 0
|
||||
skills: List[int] = []
|
||||
constellations: List[int] = Field([], alias="talents")
|
||||
|
||||
@ -44,4 +51,5 @@ class CharacterAsset(BaseModel):
|
||||
def __init__(__pydantic_self__, **data: Any) -> None:
|
||||
super().__init__(**data)
|
||||
|
||||
__pydantic_self__.element = ElementType(data["costElemType"]) if data["costElemType"] != "" else ElementType.Unknown.name # noqa: E501
|
||||
__pydantic_self__.element = ElementType(data["costElemType"]) if data["costElemType"] != "" else ElementType.Unknown # noqa: E501
|
||||
__pydantic_self__.rarity = 5 if data["qualityType"].endswith("_ORANGE") else 4 # noqa: E501
|
||||
|
@ -44,6 +44,7 @@ class CharacterInfo(BaseModel):
|
||||
name: str = "" # Get from name hash map
|
||||
friendship_level: int = 1
|
||||
element: ElementType = ElementType.Unknown
|
||||
rarity: int = 0
|
||||
image: CharacterIconAsset = CharacterIconAsset()
|
||||
skills: List[CharacterSkill] = []
|
||||
constellations: List[CharacterConstellations] = []
|
||||
@ -81,17 +82,29 @@ class CharacterInfo(BaseModel):
|
||||
|
||||
# Get character
|
||||
LOGGER.debug("=== Character Data ===")
|
||||
character = Assets.character(str(data["avatarId"]))
|
||||
avatarId = str(data["avatarId"])
|
||||
avatarId += f"-{data['skillDepotId']}" if data["avatarId"] in [10000005, 10000007] else "" # noqa: E501
|
||||
character = Assets.character(avatarId) # noqa: E501
|
||||
|
||||
# Check if character is founded
|
||||
if not character:
|
||||
return
|
||||
|
||||
# Load icon
|
||||
__pydantic_self__.image = character.images
|
||||
if "costumeId" in data:
|
||||
_data = Assets.character_costume(str(data["costumeId"]))
|
||||
if _data:
|
||||
__pydantic_self__.image = _data.images
|
||||
else:
|
||||
__pydantic_self__.image = character.images
|
||||
else:
|
||||
__pydantic_self__.image = character.images
|
||||
|
||||
# Get element
|
||||
__pydantic_self__.element = ElementType(character.element).name
|
||||
__pydantic_self__.element = ElementType(character.element)
|
||||
|
||||
# Check caulate rarity
|
||||
__pydantic_self__.rarity = character.rarity
|
||||
|
||||
# Load constellation
|
||||
LOGGER.debug("=== Constellation ===")
|
||||
|
@ -4,6 +4,7 @@ from pydantic import BaseModel, Field
|
||||
from typing import List, Any, Union
|
||||
|
||||
from ..assets import Assets
|
||||
from ..enum import ElementType
|
||||
|
||||
LOGGER = logging.getLogger(__name__)
|
||||
|
||||
@ -25,7 +26,11 @@ class ProfilePicture(BaseModel):
|
||||
# Get character
|
||||
LOGGER.debug("=== Avatar ===")
|
||||
if "avatarId" in data:
|
||||
icon = Assets.character_icon(str(data["avatarId"]))
|
||||
if "costumeId" in data:
|
||||
_data = Assets.character_costume(str(data["costumeId"]))
|
||||
icon = _data.images if _data is not None else _data
|
||||
else:
|
||||
icon = Assets.character_icon(str(data["avatarId"]))
|
||||
|
||||
if not icon:
|
||||
return
|
||||
@ -44,19 +49,29 @@ class showAvatar(BaseModel):
|
||||
Custom data
|
||||
"""
|
||||
name: str = ""
|
||||
icon: str = ""
|
||||
icon: str = ""
|
||||
element: ElementType = ElementType.Unknown
|
||||
|
||||
def __init__(__pydantic_self__, **data: Any) -> None:
|
||||
super().__init__(**data)
|
||||
|
||||
# Get character
|
||||
LOGGER.debug("=== Character preview ===")
|
||||
|
||||
# Find tarveler
|
||||
character_preview = Assets.character(str(data["avatarId"]))
|
||||
|
||||
if not character_preview:
|
||||
return
|
||||
|
||||
__pydantic_self__.icon = character_preview.images.icon
|
||||
__pydantic_self__.element = character_preview.element
|
||||
|
||||
if "costumeId" in data:
|
||||
_data = Assets.character_costume(str(data["costumeId"]))
|
||||
if _data:
|
||||
__pydantic_self__.icon = _data.images.icon
|
||||
else:
|
||||
__pydantic_self__.icon = character_preview.images.icon
|
||||
|
||||
# Get name hash map
|
||||
_name = Assets.get_hash_map(str(character_preview.hash_id))
|
||||
|
Loading…
Reference in New Issue
Block a user