From 09b9c63c0bef00f28db517ff3a00c24a7824c9f9 Mon Sep 17 00:00:00 2001 From: baiqwerdvd <158065462+baiqwerdvd@users.noreply.github.com> Date: Tue, 17 Sep 2024 23:19:48 +0800 Subject: [PATCH] update --- py.typed | 0 starrail_damage_cal/excel/model.py | 4 ++-- starrail_damage_cal/mihomo/requests.py | 2 +- starrail_damage_cal/to_data.py | 20 ++++++++++++-------- test.py | 5 ++--- 5 files changed, 17 insertions(+), 14 deletions(-) create mode 100644 py.typed diff --git a/py.typed b/py.typed new file mode 100644 index 0000000..e69de29 diff --git a/starrail_damage_cal/excel/model.py b/starrail_damage_cal/excel/model.py index c54e84d..ed8b50b 100644 --- a/starrail_damage_cal/excel/model.py +++ b/starrail_damage_cal/excel/model.py @@ -21,7 +21,6 @@ class PromotionAttr(Struct): class SingleAvatarPromotion(Struct): AvatarID: int - # Promotion: int PromotionCostList: List[PromotionCost] MaxLevel: int # WorldLevelRequire: Union[int, None] @@ -35,12 +34,12 @@ class SingleAvatarPromotion(Struct): CriticalChance: PromotionAttr CriticalDamage: PromotionAttr BaseAggro: PromotionAttr + Promotion: Union[int, None] = None PlayerLevelRequire: Union[int, None] = None class SingleEquipmentPromotion(Struct): EquipmentID: int - # Promotion: int PromotionCostList: List[PromotionCost] MaxLevel: int # WorldLevelRequire: Union[int, None] @@ -50,6 +49,7 @@ class SingleEquipmentPromotion(Struct): BaseAttackAdd: PromotionAttr BaseDefence: PromotionAttr BaseDefenceAdd: PromotionAttr + Promotion: Union[int, None] = None PlayerLevelRequire: Union[int, None] = None diff --git a/starrail_damage_cal/mihomo/requests.py b/starrail_damage_cal/mihomo/requests.py index 2824a07..da2d924 100644 --- a/starrail_damage_cal/mihomo/requests.py +++ b/starrail_damage_cal/mihomo/requests.py @@ -31,7 +31,7 @@ async def get_char_card_info( path = save_path / str(uid) path.mkdir(parents=True, exist_ok=True) with Path.open(path / f"{uid!s}.json", "w") as file: - file.write(req.text) + _= file.write(req.text) try: return convert(req.json(), type=MihomoData) except msgspec.ValidationError as e: diff --git a/starrail_damage_cal/to_data.py b/starrail_damage_cal/to_data.py index 685acb3..10217cf 100644 --- a/starrail_damage_cal/to_data.py +++ b/starrail_damage_cal/to_data.py @@ -34,6 +34,14 @@ from starrail_damage_cal.mihomo.models import Avatar, MihomoData from starrail_damage_cal.mihomo.requests import get_char_card_info +async def api_to_model( + uid: Union[str, None] = None, + mihomo_raw: Union[MihomoData, None] = None, + save_path: Union[Path, None] = None, +) -> Tuple[List[str], List[Dict[str, Any]]]: + pass + + async def api_to_dict( uid: Union[str, None] = None, mihomo_raw: Union[MihomoData, None] = None, @@ -52,15 +60,12 @@ async def api_to_dict( path = save_path / uid path.mkdir(parents=True, exist_ok=True) with Path.open(path / f"{uid!s}.json", "wb") as file: - file.write(msgjson.format(msgjson.encode(PlayerDetailInfo), indent=4)) + _ = file.write(msgjson.format(msgjson.encode(PlayerDetailInfo), indent=4)) with Path.open(path / "rawData.json", "wb") as file: - file.write(msgjson.format(msgjson.encode(sr_data), indent=4)) + _ = file.write(msgjson.format(msgjson.encode(sr_data), indent=4)) player_uid = str(PlayerDetailInfo.uid) - if sr_data.detailInfo is None: - raise CharacterShowcaseNotOpenError(player_uid) - char_name_list: List[str] = [] char_id_list: List[str] = [] char_data_list: Dict[str, Dict] = {} @@ -222,7 +227,7 @@ async def get_data( base_attributes = {} avatar_promotion_base = None for avatar in AvatarPromotionConfig: - if avatar.AvatarID == char.avatarId: + if avatar.AvatarID == char.avatarId and avatar.Promotion == char.promotion: avatar_promotion_base = avatar break if not avatar_promotion_base: @@ -256,7 +261,6 @@ async def get_data( char_data["baseAttributes"] = base_attributes # 处理武器 - equipment_info = {} if char.equipment and char.equipment.tid is not None: equipment_info["equipmentID"] = char.equipment.tid @@ -269,7 +273,7 @@ async def get_data( equipment_base_attributes = {} equipment_promotion_base = None for equipment in EquipmentPromotionConfig: - if equipment.EquipmentID == char.equipment.tid: + if equipment.EquipmentID == char.equipment.tid and equipment.Promotion == char.equipment.promotion: equipment_promotion_base = equipment break if not equipment_promotion_base: diff --git a/test.py b/test.py index a37698b..49e84c5 100644 --- a/test.py +++ b/test.py @@ -8,9 +8,8 @@ from starrail_damage_cal.to_data import api_to_dict async def test_get_damage_data_by_uid() -> None: # print(await api_to_dict("108069476")) - char_data = await get_char_data(uid="108069476", avatar_name="流萤") - if isinstance(char_data, Union[List, dict]): - print(json.dumps(char_data, ensure_ascii=False, indent=4)) + char_data = await get_char_data(uid="100086290", avatar_name="希儿") + print(json.dumps(char_data, ensure_ascii=False, indent=4)) char = await cal_char_info(char_data) avatar = AvatarInstance(char)