Skip to content

Commit

Permalink
🐛 修复一些bug (#663) (#664)
Browse files Browse the repository at this point in the history
  • Loading branch information
KimigaiiWuyi committed Dec 23, 2024
1 parent 6ba0048 commit e4ea3c3
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 11 deletions.
7 changes: 5 additions & 2 deletions GenshinUID/genshinuid_enka/draw_char_rank.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import asyncio
from typing import Tuple, Union, Literal

import aiofiles
from PIL import Image, ImageDraw
from gsuid_core.models import Event

Expand Down Expand Up @@ -80,8 +81,10 @@ async def draw_cahrcard_list(
char_done_list = []
for char_name in char_list:
temp = {}
with open(uid_fold / f'{char_name}.json', 'r', encoding='UTF-8') as f:
raw_data = json.load(f)
async with aiofiles.open(
uid_fold / f'{char_name}.json', 'r', encoding='UTF-8'
) as f:
raw_data = json.loads(await f.read())

skill_list = raw_data['avatarSkill']

Expand Down
10 changes: 10 additions & 0 deletions GenshinUID/genshinuid_enka/etc/base_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,16 @@
'火': 'Pyro',
}

ELEMENT_TEXT_MAP = {
'Anemo': '风',
'Cryo': '冰',
'Dendro': '草',
'Electro': '雷',
'Geo': '岩',
'Hydro': '水',
'Pyro': '火',
}

ICON_ELEMENT = {
'风': 'Wind',
'冰': 'Ice',
Expand Down
19 changes: 16 additions & 3 deletions GenshinUID/genshinuid_enka/mono/Character.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
ELEMENT_MAP,
ICON_ELEMENT,
PERCENT_ATTR,
ELEMENT_TEXT_MAP,
baseFightProp,
baseWeaponInfo,
)
Expand Down Expand Up @@ -145,6 +146,7 @@ async def get_card_prop(
except ConnectTimeout:
weapon_raw_data = -1

weapon_raw_data = -1
if isinstance(weapon_raw_data, int) or isinstance(
weapon_raw_data, List
):
Expand All @@ -158,7 +160,13 @@ async def get_card_prop(
weapon_id = _weapon_id
break
else:
return {}
for _weapon_id in weaponId2Name_data:
_weapon_name = weaponId2Name_data[_weapon_id]
if weapon in _weapon_name:
weapon_id = _weapon_id
break
else:
return {}

if weapon_id == 0:
return {}
Expand Down Expand Up @@ -214,7 +222,7 @@ async def get_card_prop(
].format(
*weapon_raw_data[
'r{}'.format(str(weapon_info['weaponAffix']))
]
]['values']
)
weapon_info['weaponEffect'] = re.sub(
r'</?c[^\u4e00-\u9fa5/d]+>',
Expand Down Expand Up @@ -300,6 +308,8 @@ async def get_base_prop(self, char_name: str, char_level: int) -> Dict:
self.char_id = await name_to_avatar_id(char_name_covert)
if not self.char_id and char_name != '旅行者':
return {}
elif char_name == '旅行者':
self.char_id = '10000007'

'''
char_raw = await get_character_info(name=char_name_covert)
Expand All @@ -315,7 +325,10 @@ async def get_base_prop(self, char_name: str, char_level: int) -> Dict:
char_data = await get_character_stats(char_name_covert, char_level)
'''

char_raw = char_data = await convert_ambr_to_minigg(self.char_id)
char_raw = char_data = await convert_ambr_to_minigg(
self.char_id,
ELEMENT_TEXT_MAP[self.char_element],
)

if (
isinstance(char_data, List)
Expand Down
3 changes: 3 additions & 0 deletions GenshinUID/genshinuid_enka/start.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@

async def refresh_player_list(uid: str, is_force: bool = False) -> str:
player = PLAYER_PATH / uid
if not player.exists():
return f'该UID{uid}对应面板数据不存在, 请先进行 [刷新面板]!'

path = player / 'artifacts.json'
all_artifacts = deepcopy(ARTIFACT_DATA)
if not path.exists():
Expand Down
16 changes: 10 additions & 6 deletions GenshinUID/utils/ambr_to_minigg.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from typing import List, Union, Optional, TypedDict, cast

import aiofiles
from gsuid_core.logger import logger
from gsuid_core.utils.api.minigg.models import CharacterTalents
from gsuid_core.utils.api.ambr.request import (
get_ambr_char_data,
Expand Down Expand Up @@ -115,7 +116,7 @@ class ConvertCharacter(TypedDict):


async def convert_exist_data_to_char(
char_id: Union[str, int]
char_id: Union[str, int], element: Optional[str] = None
) -> ConvertCharacter:
path = CHAR_DATA_PATH / f'{char_id}.json'
if path.exists():
Expand All @@ -124,6 +125,7 @@ async def convert_exist_data_to_char(
else:
raw_data = await get_ambr_char_data(char_id)
if raw_data is None:
logger.error(f'[AmbrData] 未找到该角色{char_id}/数据无法下载!')
raise Exception('[AmbrData] 未找到该角色/数据无法下载!')
# 保存
async with aiofiles.open(path, 'w', encoding='utf-8') as f:
Expand All @@ -146,8 +148,10 @@ async def convert_exist_data_to_char(
'title': raw_data['fetter']['title'],
'rarity': raw_data['rank'],
'weapontype': WEAPON_TYPE[raw_data['weaponType']],
'elementText': ELEMENT_MAP[raw_data['element']],
'element': ELEMENT_MAP[raw_data['element']],
'elementText': (
element if element else ELEMENT_MAP[raw_data['element']]
),
'element': element if element else ELEMENT_MAP[raw_data['element']],
'images': {'namesideicon': raw_data['icon']}, # 暂时适配
'substatText': substatText,
'hp': raw_data['upgrade']['prop'][0]['initValue']
Expand Down Expand Up @@ -229,7 +233,7 @@ async def convert_ambr_to_weapon(
effect_up[affix],
)

result[f'r{index+1}'] = {'description': effect_desc}
result[f'r{index+1}'] = {'description': effect_desc, 'values': []}
else:
if index != 0:
result['effectTemplateRaw'] = result[f'r{index+1}']['description']
Expand All @@ -246,9 +250,9 @@ async def convert_ambr_to_weapon(


async def convert_ambr_to_minigg(
char_id: Union[str, int]
char_id: Union[str, int], element
) -> Optional[ConvertCharacter]:
return await convert_exist_data_to_char(char_id)
return await convert_exist_data_to_char(char_id, element)


async def convert_ambr_to_talent(
Expand Down

0 comments on commit e4ea3c3

Please sign in to comment.