From cfead16f87f62f572c9786da0d3ef561dcd80f50 Mon Sep 17 00:00:00 2001 From: xtaodada Date: Fri, 16 Aug 2024 11:39:47 +0800 Subject: [PATCH] :bug: Fix challenge avatar icon --- core/dependence/assets.py | 19 +++++++++++++++++-- modules/wiki/models/avatar.py | 10 +++++++--- modules/wiki/models/buddy.py | 2 ++ modules/wiki/models/enums.py | 5 +++++ plugins/zzz/challenge.py | 16 ++++++++++++++-- resources/zzz/abyss/floor.html | 4 ++-- 6 files changed, 47 insertions(+), 9 deletions(-) diff --git a/core/dependence/assets.py b/core/dependence/assets.py index a476a10..3d3a929 100644 --- a/core/dependence/assets.py +++ b/core/dependence/assets.py @@ -90,11 +90,14 @@ class _AvatarAssets(_AssetsService): base_path.mkdir(exist_ok=True, parents=True) gacha_path = base_path / "gacha.png" icon_path = base_path / "icon.png" + square_path = base_path / "square.png" normal_path = base_path / "normal.png" if not gacha_path.exists(): tasks.append(self._download(icon.gacha, gacha_path)) if not icon_path.exists(): tasks.append(self._download(icon.icon_, icon_path)) + if not square_path.exists(): + tasks.append(self._download(icon.square, square_path)) if not normal_path.exists(): tasks.append(self._download(icon.normal, normal_path)) @@ -136,6 +139,10 @@ class _AvatarAssets(_AssetsService): icon = self.get_target(target, second_target) return self.get_path(icon, "icon") + def square(self, target: StrOrInt, second_target: StrOrInt = None) -> Path: + icon = self.get_target(target, second_target) + return self.get_path(icon, "square") + def normal(self, target: StrOrInt, second_target: StrOrInt = None) -> Path: icon = self.get_target(target, second_target) return self.get_path(icon, "normal") @@ -218,10 +225,13 @@ class _BuddyAssets(_AssetsService): for icon in self.data: webp_path = self.path / f"{icon.id}.webp" png_path = self.path / f"{icon.id}.png" + square_path = self.path / f"{icon.id}_square.png" if not webp_path.exists() and icon.webp: tasks.append(self._download(icon.webp, webp_path)) if not png_path.exists() and icon.png: tasks.append(self._download(icon.png, png_path)) + if not square_path.exists() and icon.square: + tasks.append(self._download(icon.square, square_path)) if len(tasks) >= 100: await asyncio.gather(*tasks) tasks = [] @@ -229,8 +239,9 @@ class _BuddyAssets(_AssetsService): await asyncio.gather(*tasks) logger.info("邦布素材图标初始化完成") - def get_path(self, icon: Buddy, ext: str) -> Path: - path = self.path / f"{icon.id}.{ext}" + def get_path(self, icon: Buddy, ext: str, square: bool = False) -> Path: + square_str = "_square" if square else "" + path = self.path / f"{icon.id}{square_str}.{ext}" return path def get_by_id(self, id_: int) -> Optional[Buddy]: @@ -266,6 +277,10 @@ class _BuddyAssets(_AssetsService): return png_path raise AssetsCouldNotFound("邦布素材图标不存在", target) + def square(self, target: StrOrInt, second_target: StrOrInt = None) -> Path: + icon = self.get_target(target, second_target) + return self.get_path(icon, "png", square=True) + class _EquipmentSuitAssets(_AssetsService): path: Path diff --git a/modules/wiki/models/avatar.py b/modules/wiki/models/avatar.py index c9a4956..af30558 100644 --- a/modules/wiki/models/avatar.py +++ b/modules/wiki/models/avatar.py @@ -22,7 +22,7 @@ class Avatar(BaseModel, frozen=False): """ 元素 """ speciality: ZZZSpeciality """ 特性 """ - icon: List[str] = ["", "", ""] + icon: List[str] = ["", "", "", ""] """ 图标 """ @property @@ -30,9 +30,13 @@ class Avatar(BaseModel, frozen=False): return self.icon[0] @property - def normal(self) -> str: + def square(self) -> str: return self.icon[1] @property - def gacha(self) -> str: + def normal(self) -> str: return self.icon[2] + + @property + def gacha(self) -> str: + return self.icon[3] diff --git a/modules/wiki/models/buddy.py b/modules/wiki/models/buddy.py index 52f11c6..54b7c49 100644 --- a/modules/wiki/models/buddy.py +++ b/modules/wiki/models/buddy.py @@ -12,6 +12,8 @@ class Buddy(BaseModel): """英文名称""" icon: str = "" """图标""" + square: str = "" + """方形图标""" rank: ZZZRank = ZZZRank.NULL """ 星级 """ diff --git a/modules/wiki/models/enums.py b/modules/wiki/models/enums.py index fdfc43b..7c425a0 100644 --- a/modules/wiki/models/enums.py +++ b/modules/wiki/models/enums.py @@ -47,3 +47,8 @@ class ZZZRank(str, Enum): def int(self): value_map = {"S": 5, "A": 4, "B": 3, "C": 2, "D": 1, "NULL": 0} return value_map[self.value] + + @staticmethod + def get_rank(value: int): + value_map = {5: "S", 4: "A", 3: "B", 2: "C", 1: "D", 0: "NULL"} + return ZZZRank(value_map[value]) diff --git a/plugins/zzz/challenge.py b/plugins/zzz/challenge.py index 96ce028..b539828 100644 --- a/plugins/zzz/challenge.py +++ b/plugins/zzz/challenge.py @@ -194,19 +194,31 @@ class ChallengePlugin(Plugin): self.log_user(update, logger.info, "[bold]防卫战挑战数据[/bold]: 成功发送图片", extra={"markup": True}) - @staticmethod - def get_floor_data(abyss_data: "ZZZChallenge", floor: int): + def get_floor_data(self, abyss_data: "ZZZChallenge", floor: int): try: floor_data = abyss_data.floors[-floor] except IndexError: floor_data = None if not floor_data: raise AbyssUnlocked() + + character_icons = { + ch.id: self.assets_service.avatar.square(ch.id).as_uri() + for ch in floor_data.node_1.avatars + floor_data.node_2.avatars + } + buddy_icons = { + bu.id: self.assets_service.buddy.square(bu.id).as_uri() + for bu in [floor_data.node_1.buddy, floor_data.node_2.buddy] + if bu + } + render_data = { "floor": floor_data, "floor_time": floor_data.floor_challenge_time.datetime.astimezone(TZ).strftime("%Y-%m-%d %H:%M:%S"), "floor_nodes": [floor_data.node_1, floor_data.node_2], "floor_num": floor, + "character_icons": character_icons, + "buddy_icons": buddy_icons, } return render_data diff --git a/resources/zzz/abyss/floor.html b/resources/zzz/abyss/floor.html index a9cedcf..a62bf9c 100644 --- a/resources/zzz/abyss/floor.html +++ b/resources/zzz/abyss/floor.html @@ -53,7 +53,7 @@
- +
Lv.{{ character.level }}
@@ -63,7 +63,7 @@
- +
Lv.{{ character.level }}