From a15a01fd408f34c7cd8f98878ceb384a62f6e0d6 Mon Sep 17 00:00:00 2001 From: qwerdvd <2450899274@qq.com> Date: Sat, 13 May 2023 17:21:03 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=A8=E4=BF=AE=E5=A4=8D=E5=A4=A7?= =?UTF-8?q?=E9=83=A8=E5=88=86=E5=B7=B2=E7=9F=A5=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../starrailuid_charinfo/draw_char_img.py | 61 ++++++++++++++----- StarRailUID/starrailuid_charinfo/to_data.py | 39 ++++++------ 2 files changed, 67 insertions(+), 33 deletions(-) diff --git a/StarRailUID/starrailuid_charinfo/draw_char_img.py b/StarRailUID/starrailuid_charinfo/draw_char_img.py index 664191c..a0da66a 100644 --- a/StarRailUID/starrailuid_charinfo/draw_char_img.py +++ b/StarRailUID/starrailuid_charinfo/draw_char_img.py @@ -99,12 +99,12 @@ async def draw_char_info_img(raw_mes: str, sr_uid: str, url: Optional[str]): # 放角色名 char_img_draw = ImageDraw.Draw(char_info) char_img_draw.text( - (690, 175), char.char_name, white_color, sr_font_38, 'mm' + (705, 175), char.char_name, white_color, sr_font_38, 'mm' ) # 放等级 char_img_draw.text( - (765, 183), f'LV.{str(char.char_level)}', white_color, sr_font_20, 'mm' + (790, 183), f'LV.{str(char.char_level)}', white_color, sr_font_20, 'mm' ) # 放星级 @@ -121,6 +121,11 @@ async def draw_char_info_img(raw_mes: str, sr_uid: str, url: Optional[str]): ) char_info.paste(rank_img, (772, 190), rank_img) + # # 放uid + # char_img_draw.text( + # (750, 290), f'UID: {sr_uid}', white_color, sr_font_23, 'mm' + # ) + # 放属性列表 attr_bg = Image.open(TEXT_PATH / 'attr_bg.png') attr_bg_draw = ImageDraw.Draw(attr_bg) @@ -136,7 +141,14 @@ async def draw_char_info_img(raw_mes: str, sr_uid: str, url: Optional[str]): hp = int(mp.floor(hp)) add_hp = int(mp.floor(add_hp)) attr_bg_draw.text( - (500, 31), f'{hp + add_hp} (+{add_hp})', white_color, sr_font_26, 'rm' + (415, 31), f'{hp + add_hp}', white_color, sr_font_26, 'rm' + ) + attr_bg_draw.text( + (430, 31), + f'(+{str(round(add_hp))})', + (95, 251, 80), + sr_font_26, + anchor='lm', ) # 攻击力 attack = mp.mpf(char.base_attributes['attack']) @@ -150,12 +162,19 @@ async def draw_char_info_img(raw_mes: str, sr_uid: str, url: Optional[str]): atk = int(mp.floor(attack)) add_attack = int(mp.floor(add_attack)) attr_bg_draw.text( - (500, 31 + 48), - f'{atk + add_attack} (+{add_attack})', + (415, 31 + 48), + f'{atk + add_attack}', white_color, sr_font_26, 'rm', ) + attr_bg_draw.text( + (430, 31 + 48), + f'(+{str(round(add_attack))})', + (95, 251, 80), + sr_font_26, + anchor='lm', + ) # 防御力 defence = mp.mpf(char.base_attributes['defence']) add_defence = mp.mpf( @@ -170,12 +189,19 @@ async def draw_char_info_img(raw_mes: str, sr_uid: str, url: Optional[str]): defence = int(mp.floor(defence)) add_defence = int(mp.floor(add_defence)) attr_bg_draw.text( - (500, 31 + 48 * 2), - f'{defence + add_defence} (+{add_defence})', + (415, 31 + 48 * 2), + f'{defence + add_defence}', white_color, sr_font_26, 'rm', ) + attr_bg_draw.text( + (430, 31 + 48 * 2), + f'(+{str(round(add_defence))})', + (95, 251, 80), + sr_font_26, + anchor='lm', + ) # 速度 speed = mp.mpf(char.base_attributes['speed']) add_speed = mp.mpf( @@ -184,12 +210,19 @@ async def draw_char_info_img(raw_mes: str, sr_uid: str, url: Optional[str]): speed = int(mp.floor(speed)) add_speed = int(mp.floor(add_speed)) attr_bg_draw.text( - (500, 31 + 48 * 3), - f'{speed + add_speed} (+{add_speed})', + (415, 31 + 48 * 3), + f'{speed + add_speed}', white_color, sr_font_26, 'rm', ) + attr_bg_draw.text( + (430, 31 + 48 * 3), + f'(+{str(round(add_speed))})', + (95, 251, 80), + sr_font_26, + anchor='lm', + ) # 暴击率 critical_chance = mp.mpf(char.base_attributes['CriticalChance']) critical_chance_base = mp.mpf( @@ -304,11 +337,11 @@ async def draw_char_info_img(raw_mes: str, sr_uid: str, url: Optional[str]): 'lm', ) skill_panel_img_draw.text( - (60, 88), + (75, 90), f'{skill["skillName"]}', (105, 105, 105), sr_font_20, - 'lm', + 'mm', ) skill_bg.paste(skill_panel_img, (50 + 187 * i, 35), skill_panel_img) i += 1 @@ -383,7 +416,7 @@ async def draw_char_info_img(raw_mes: str, sr_uid: str, url: Optional[str]): TEXT_PATH / f'LightCore_Rarity{RelicId2Rarity[str(relic["relicId"])]}.png' ).resize((200, 48)) - relic_img.paste(rarity_img, (-20, 80), rarity_img) + relic_img.paste(rarity_img, (-10, 80), rarity_img) relic_img_draw = ImageDraw.Draw(relic_img) if len(relic['relicName']) <= 5: main_name = relic['relicName'] @@ -405,7 +438,7 @@ async def draw_char_info_img(raw_mes: str, sr_uid: str, url: Optional[str]): if main_name in ['攻击力', '生命值', '防御力', '速度']: mainValueStr = nstr(main_value, 3) else: - mainValueStr = nstr(main_value * 100, 3) + '%' + mainValueStr = str(math.floor(main_value * 1000) / 10) + '%' mainNameNew = ( main_name.replace('百分比', '') @@ -428,7 +461,7 @@ async def draw_char_info_img(raw_mes: str, sr_uid: str, url: Optional[str]): anchor='lm', ) relic_img_draw.text( - (250, 60), + (180, 105), '+{}'.format(str(main_level)), (255, 255, 255), sr_font_23, diff --git a/StarRailUID/starrailuid_charinfo/to_data.py b/StarRailUID/starrailuid_charinfo/to_data.py index 61faf97..b8fe3eb 100644 --- a/StarRailUID/starrailuid_charinfo/to_data.py +++ b/StarRailUID/starrailuid_charinfo/to_data.py @@ -78,13 +78,13 @@ async def api_to_dict( char_dict_list = [] im = f'UID: {sr_uid} 的角色展柜刷新成功\n' - if PlayerDetailInfo['AssistAvatar']: + if PlayerDetailInfo.get('AssistAvatar'): char_dict, avatarName = await get_data( PlayerDetailInfo['AssistAvatar'], sr_data, sr_uid ) im += f'支援角色 {avatarName}\n' char_dict_list.append(char_dict) - if PlayerDetailInfo['IsDisplayAvatarList']: + if PlayerDetailInfo.get('DisplayAvatarList'): im += '星海同行' for char in PlayerDetailInfo['DisplayAvatarList']: char_dict, avatarName = await get_data(char, sr_data, sr_uid) @@ -199,23 +199,24 @@ async def get_data(char: dict, sr_data: dict, sr_uid: str): relic_temp['MainAffix']['Value'] = value relic_temp['SubAffixList'] = [] - for sub_affix in relic['RelicSubAffix']: - sub_affix_temp = {} - sub_affix_temp['SubAffixID'] = sub_affix['SubAffixID'] - sub_affix_property, value = await cal_relic_sub_affix( - relic_id=relic['ID'], - affix_id=sub_affix['SubAffixID'], - cnt=sub_affix['Cnt'], - step=sub_affix['Step'] if 'Step' in sub_affix else 0, - ) - sub_affix_temp['Property'] = sub_affix_property - sub_affix_temp['Name'] = Property2Name[sub_affix_property] - sub_affix_temp['Cnt'] = sub_affix['Cnt'] - sub_affix_temp['Step'] = ( - sub_affix['Step'] if 'Step' in sub_affix else 0 - ) - sub_affix_temp['Value'] = value - relic_temp['SubAffixList'].append(sub_affix_temp) + if relic.get('RelicSubAffix'): + for sub_affix in relic['RelicSubAffix']: + sub_affix_temp = {} + sub_affix_temp['SubAffixID'] = sub_affix['SubAffixID'] + sub_affix_property, value = await cal_relic_sub_affix( + relic_id=relic['ID'], + affix_id=sub_affix['SubAffixID'], + cnt=sub_affix['Cnt'], + step=sub_affix['Step'] if 'Step' in sub_affix else 0, + ) + sub_affix_temp['Property'] = sub_affix_property + sub_affix_temp['Name'] = Property2Name[sub_affix_property] + sub_affix_temp['Cnt'] = sub_affix['Cnt'] + sub_affix_temp['Step'] = ( + sub_affix['Step'] if 'Step' in sub_affix else 0 + ) + sub_affix_temp['Value'] = value + relic_temp['SubAffixList'].append(sub_affix_temp) char_data['RelicInfo'].append(relic_temp) # 处理命座