-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d09bd87
commit 86a4169
Showing
10 changed files
with
391 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,222 @@ | ||
import re | ||
from pathlib import Path | ||
from datetime import datetime | ||
|
||
from PIL import Image, ImageDraw | ||
from gsuid_core.utils.error_reply import get_error | ||
from gsuid_core.utils.image.convert import convert_img | ||
|
||
from ..utils.image.image_tools import add_footer | ||
from ..utils.api.hakush.request import hakush_api | ||
from ..utils.map.name_covert import avatar_id_to_name | ||
from ..utils.resource.RESOURCE_PATH import CHAR_CARD_PATH, MONSTER_ICON_PATH | ||
from ..utils.fonts.genshin_fonts import ( | ||
gs_font_20, | ||
gs_font_22, | ||
gs_font_26, | ||
gs_font_28, | ||
gs_font_30, | ||
gs_font_38, | ||
) | ||
|
||
TEXT_PATH = Path(__file__).parent / 'texture2d2' | ||
|
||
|
||
def remove_angle_brackets(text: str) -> str: | ||
cleaned_text = re.sub(r'<.*?>', '', text) | ||
return cleaned_text | ||
|
||
|
||
def is_current_time_in_range(start_time: str, end_time: str) -> bool: | ||
start_datetime = datetime.strptime(start_time, "%Y-%m-%d %H:%M:%S") | ||
end_datetime = datetime.strptime(end_time, "%Y-%m-%d %H:%M:%S") | ||
|
||
current_datetime = datetime.now() | ||
|
||
return start_datetime <= current_datetime <= end_datetime | ||
|
||
|
||
async def draw_poetry_abyss_image(): | ||
data = await hakush_api.get_hakush_rolecombats() | ||
if isinstance(data, int): | ||
return get_error(data) | ||
|
||
poetry_id = 0 | ||
for _id in data: | ||
item = data[_id] | ||
begin = item['begin'] | ||
end = item['end'] | ||
if is_current_time_in_range(begin, end): | ||
poetry_id = _id | ||
break | ||
else: | ||
return '没有找到当前的活动!' | ||
|
||
pdata = await hakush_api.get_hakush_rolecombat(poetry_id) | ||
if isinstance(pdata, int): | ||
return get_error(pdata) | ||
|
||
w, h = 1000, 1270 + 50 | ||
|
||
monster_list = list(pdata['DifficultyConfig'].values())[-1] | ||
monster_room = monster_list['Room'] | ||
|
||
for room_id in monster_room: | ||
monster = monster_room[room_id] | ||
if 'Title' in monster: | ||
h += 301 | ||
else: | ||
h += 145 | ||
|
||
time = f"{pdata['BeginTime']} ~ {pdata['EndTime']}" | ||
img = Image.new('RGBA', (w, h), (22, 18, 20, 255)) | ||
|
||
title = Image.open(TEXT_PATH / 'title.png') | ||
title_draw = ImageDraw.Draw(title) | ||
title_draw.text( | ||
(500, 473), | ||
f'剧诗ID:{poetry_id} 详细信息', | ||
(255, 255, 255), | ||
font=gs_font_38, | ||
anchor='mm', | ||
) | ||
img.paste(title, (0, 0), title) | ||
|
||
avatar_bg = Image.open(TEXT_PATH / 'avatar_bg.png') | ||
avatar_draw = ImageDraw.Draw(avatar_bg) | ||
|
||
avatar_draw.text( | ||
(500, 184), | ||
time, | ||
(139, 137, 133), | ||
font=gs_font_22, | ||
anchor='mm', | ||
) | ||
|
||
avatar_draw.text( | ||
(500, 474), | ||
pdata['AvatarConfig']['BuffAvatarList'][0]['Desc'][16:-9], | ||
(139, 137, 133), | ||
font=gs_font_26, | ||
anchor='mm', | ||
) | ||
|
||
for cindex, char in enumerate(pdata['AvatarConfig']['BuffAvatarList']): | ||
char_id = str(char['Id']) | ||
char_img = Image.open(CHAR_CARD_PATH / f'{char_id}.png') | ||
char_img = char_img.resize((102, 124)) | ||
char_name = await avatar_id_to_name(char_id) | ||
char_draw = ImageDraw.Draw(char_img) | ||
char_draw.text( | ||
(51, 111), | ||
char_name, | ||
(10, 10, 10), | ||
font=gs_font_20, | ||
anchor='mm', | ||
) | ||
avatar_bg.paste(char_img, (121 + cindex * 130, 302), char_img) | ||
|
||
for iindex, char_id in enumerate( | ||
pdata['AvatarConfig']['InviteAvatarList'] | ||
): | ||
char_id = str(char_id) | ||
char_img = Image.open(CHAR_CARD_PATH / f'{char_id}.png') | ||
char_img = char_img.resize((102, 124)) | ||
char_name = await avatar_id_to_name(char_id) | ||
char_draw = ImageDraw.Draw(char_img) | ||
char_draw.text( | ||
(51, 111), | ||
char_name, | ||
(10, 10, 10), | ||
font=gs_font_20, | ||
anchor='mm', | ||
) | ||
avatar_bg.paste(char_img, (252 + iindex * 130, 576), char_img) | ||
|
||
img.paste(avatar_bg, (0, 482), avatar_bg) | ||
|
||
point = 1270 | ||
for room_id in monster_room: | ||
monster = monster_room[room_id] | ||
if 'Title' in monster: | ||
monster_bg = Image.open(TEXT_PATH / 'long_monster_bg.png') | ||
monster_draw = ImageDraw.Draw(monster_bg) | ||
desc = remove_angle_brackets(monster['Desc']) | ||
desc = desc[:26] + '...' | ||
monster_draw.text( | ||
(245, 69), | ||
f'{monster["Title"]}', | ||
'black', | ||
font=gs_font_30, | ||
anchor='lm', | ||
) | ||
for mindex, m in enumerate(monster['MonsterPreviewList']): | ||
monster_icon = m['Icon'] | ||
monster_img = await hakush_api.get_hakush_ui( | ||
monster_icon, MONSTER_ICON_PATH | ||
) | ||
monster_img = monster_img.resize((90, 90)) | ||
monster_name = m['Name'] | ||
if '·' in monster_name: | ||
monster_name = monster_name.split('·')[-1] | ||
|
||
monster_name = monster_name[:6] | ||
|
||
monster_hp = int(m['Hp']) | ||
mimg = Image.new( | ||
'RGBA', | ||
(250, 90), | ||
(219, 209, 203), | ||
) | ||
ming_draw = ImageDraw.Draw(mimg) | ||
|
||
mimg.paste(monster_img, (0, 0), monster_img) | ||
ming_draw.text( | ||
(100, 30), | ||
f'{monster_name}', | ||
(36, 36, 36), | ||
font=gs_font_22, | ||
anchor='lm', | ||
) | ||
|
||
ming_draw.text( | ||
(100, 57), | ||
f'HP {monster_hp}', | ||
(90, 90, 90), | ||
font=gs_font_22, | ||
anchor='lm', | ||
) | ||
monster_bg.paste(mimg, (126 + mindex * 257, 158), mimg) | ||
else: | ||
monster_bg = Image.open(TEXT_PATH / 'short_monster_bg.png') | ||
monster_draw = ImageDraw.Draw(monster_bg) | ||
desc = f'怪物等级 Lv{monster["MonsterLevel"]}' | ||
|
||
monster_draw.text( | ||
(131, 69), | ||
f'第{room_id}幕', | ||
'black', | ||
font=gs_font_30, | ||
anchor='lm', | ||
) | ||
|
||
monster_draw.text( | ||
(131, 114), | ||
desc, | ||
(99, 99, 99), | ||
font=gs_font_28, | ||
anchor='lm', | ||
) | ||
|
||
if 'Title' not in monster: | ||
point -= 12 | ||
|
||
img.paste(monster_bg, (0, point), monster_bg) | ||
if 'Title' not in monster: | ||
point += 145 | ||
else: | ||
point += 301 | ||
|
||
img = add_footer(img, 1000) | ||
res = await convert_img(img) | ||
return res |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
HAKUSH_D_API = 'https://api.hakush.in/gi/data' | ||
HAKUSH_U_API = 'https://api.hakush.in/gi/UI' | ||
|
||
HAKUSH_ROLECOMBATS_API = f'{HAKUSH_D_API}/rolecombat.json' | ||
HAKUSH_ROLECOMBAT_API = f'{HAKUSH_D_API}/zh/rolecombat/' + '{}.json' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
from typing import Dict, List, TypedDict | ||
|
||
|
||
class RoleCombatEvent(TypedDict): | ||
begin: str | ||
end: str | ||
element: List[int] | ||
invite: List[int] | ||
buff: List[int] | ||
live_begin: str | ||
live_end: str | ||
|
||
|
||
class BuffAvatar(TypedDict): | ||
Id: int | ||
Desc: str | ||
|
||
|
||
class MonsterPreview(TypedDict): | ||
Id: int | ||
Hp: float | ||
Name: str | ||
Icon: str | ||
|
||
|
||
class RoomConfig(TypedDict): | ||
MonsterLevel: int | ||
Title: str | ||
Desc: str | ||
MonsterPreviewList: List[MonsterPreview] | ||
|
||
|
||
class DifficultyLevel(TypedDict): | ||
CanInvitePool: int | ||
BossMaxRoomNumber: int | ||
MinimumAvatarLevel: int | ||
Room: Dict[str, RoomConfig] | ||
CanInvitePoolAdd: int | ||
|
||
|
||
class AvatarConfig(TypedDict): | ||
ElementList: List[int] | ||
InviteAvatarList: List[int] | ||
BuffAvatarList: List[BuffAvatar] | ||
|
||
|
||
class ShopItem(TypedDict): | ||
Id: int | ||
Name: str | ||
Desc: str | ||
|
||
|
||
class RoleCombatData(TypedDict): | ||
BeginTime: str | ||
EndTime: str | ||
AvatarConfig: AvatarConfig | ||
DifficultyConfig: Dict[str, DifficultyLevel] | ||
ShopConfig: List[ShopItem] |
Oops, something went wrong.