From 41b3cc63ff6314f2eed7b199660a12ac7c76d1b5 Mon Sep 17 00:00:00 2001 From: CMHopeSunshine <277073121@qq.com> Date: Wed, 24 May 2023 17:00:14 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20=E4=BF=AE=E5=A4=8D=E5=9B=BE?= =?UTF-8?q?=E6=A0=87=E8=B5=84=E6=BA=90=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LittlePaimon/database/models/character.py | 8 ++++---- LittlePaimon/utils/alias.py | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/LittlePaimon/database/models/character.py b/LittlePaimon/database/models/character.py index 78127b9..4c33f34 100644 --- a/LittlePaimon/database/models/character.py +++ b/LittlePaimon/database/models/character.py @@ -6,7 +6,7 @@ from tortoise import fields from tortoise.models import Model from LittlePaimon.utils.path import JSON_DATA -from LittlePaimon.utils.alias import get_name_by_id +from LittlePaimon.utils.alias import get_name_by_id, get_weapon_icon, get_artifact_icon, get_constellation_icon from LittlePaimon.utils.files import load_json from LittlePaimon.utils.typing import * @@ -429,7 +429,7 @@ class Character(Model): character.promote_level = 0 if character.level < 20 else 1 if character.level < 40 else 2 if character.level < 50 else 3 if character.level < 60 else 4 if character.level < 70 else 5 if character.level < 80 else 6 character.constellation = Constellations(constellation_list=[ Constellation(name=data['constellations'][i]['name'], - icon=data['constellations'][i]['icon'].split('/')[-1].replace('.png', '')) for i in + icon=get_constellation_icon(data['constellations'][i]['name'])) for i in range(data['actived_constellation_num']) ]) if character.name in ['荧', '空']: @@ -460,7 +460,7 @@ class Character(Model): character.weapon = Weapon( name=data['weapon']['name'], type=data['weapon']['type_name'], - icon=data['weapon']['icon'].split('/')[-1].replace('.png', ''), + icon=get_weapon_icon(data['weapon']['name']), level=data['weapon']['level'], rarity=data['weapon']['rarity'], affix_level=data['weapon']['affix_level'], @@ -468,7 +468,7 @@ class Character(Model): if 'reliquaries' in data: character.artifacts = Artifacts(artifact_list=[Artifact( name=a['name'], - icon=a['icon'].split('/')[-1].replace('.png', ''), + icon=get_artifact_icon(a['name']), level=a['level'], rarity=a['rarity'], suit=a['set']['name'], diff --git a/LittlePaimon/utils/alias.py b/LittlePaimon/utils/alias.py index a9511c4..356d5dd 100644 --- a/LittlePaimon/utils/alias.py +++ b/LittlePaimon/utils/alias.py @@ -151,3 +151,18 @@ def get_chara_icon(name: Optional[str] = None, chara_id: Optional[int] = None, def get_weapon_icon(name: str) -> Optional[str]: icon_list = load_json(JSON_DATA / 'weapon.json')['Icon'] return icon_list.get(name) + + +def get_artifact_icon(name: str) -> Optional[str]: + icon_list = load_json(JSON_DATA / 'artifact.json')['Icon'] + for k, v in icon_list['Name'].items(): + if name == v: + return k + + + +def get_constellation_icon(name: str) -> Optional[str]: + icon_list = load_json(JSON_DATA / 'role_talent.json') + for k, v in icon_list['Name'].items(): + if name == v: + return icon_list['Icon'].get(k)