🎨 优化角色深渊的版本显示 (#499)

This commit is contained in:
Wuyi无疑 2023-05-05 00:24:08 +08:00
parent 637bb821b8
commit a019ea1610
2 changed files with 34 additions and 6 deletions

View File

@ -5,9 +5,9 @@ from PIL import Image, ImageDraw
from ..utils.image.convert import convert_img
from ..utils.map.GS_MAP_PATH import artifact2attr
from .get_all_char_data import get_akasha_char_data
from ..utils.image.image_tools import get_color_bg, draw_pic_with_ring
from ..utils.resource.generate_char_card import create_single_item_card
from .get_all_char_data import get_abyssinfo_data, get_akasha_char_data
from ..utils.map.name_covert import name_to_avatar_id, alias_to_char_name
from ..utils.resource.RESOURCE_PATH import REL_PATH, CHAR_PATH, WEAPON_PATH
from ..utils.fonts.genshin_fonts import (
@ -31,13 +31,15 @@ rank_dict = {
60: (95, 64, 189),
40: (64, 140, 189),
20: (64, 189, 125),
0: (200, 200, 200),
0: (134, 107, 71),
}
async def draw_char_abyss_info(char_name: str) -> Union[bytes, str]:
char_name = await alias_to_char_name(char_name)
char_id = await name_to_avatar_id(char_name)
abyss_info = await get_abyssinfo_data()
# _char_id = char_id[1:].lstrip('0')
char_useage_rank = []
char_img = Image.open(CHAR_PATH / f'{char_id}.png')
@ -122,10 +124,18 @@ async def draw_char_abyss_info(char_name: str) -> Union[bytes, str]:
img_draw.rounded_rectangle((108, y1, 108 + _pixel, y2), r, fill)
value = f'{rank["d"]}% / {rank["r"]}'
img_draw.text(
(37, 16 + _intent), f'版本{rank["v"]}', 'Black', gs_font_20, 'lm'
)
img_draw.text((730, 16 + _intent), value, 'Black', gs_font_20, 'lm')
if rank['v'] in abyss_info:
version = abyss_info[rank['v']]['version']
else:
version = f'版本{rank["v"]}'
if version == '版本0':
version = '平均'
version = version.replace('-', ' - ')
img_draw.text((95, 16 + _intent), version, 'Black', gs_font_20, 'rm')
img_draw.text((726, 16 + _intent), value, 'Black', gs_font_20, 'lm')
img.paste(_img, (0, 0), _img)

View File

@ -1,4 +1,6 @@
import json
import random
import asyncio
from typing import Dict, List, Tuple, Optional
import aiofiles
@ -17,6 +19,7 @@ from ..utils.map.name_covert import name_to_avatar_id, alias_to_char_name
all_char_info_path = DATA_PATH / 'all_char_info.json'
abyss_rank_path = DATA_PATH / 'abyss_rank.json'
abyss_info_path = DATA_PATH / 'abyss_info.json'
async def save_all_char_info():
@ -27,9 +30,24 @@ async def save_all_char_info():
async def save_all_abyss_rank():
abyss_rank = await get_akasha_abyss_rank()
await asyncio.sleep(random.randint(0, 3))
abyss_info = await get_akasha_abyss_rank(True)
async with aiofiles.open(abyss_rank_path, 'w') as f:
await f.write(json.dumps(abyss_rank))
async with aiofiles.open(abyss_info_path, 'w') as f:
await f.write(json.dumps(abyss_info))
async def get_abyssinfo_data():
if not abyss_info_path.exists():
await save_all_abyss_rank()
async with aiofiles.open(abyss_info_path, 'r') as f:
abyss_info: Dict[str, Dict[str, str]] = json.loads(await f.read())
return abyss_info
async def get_akasha_char_data(
char_name: str,