mirror of
https://github.com/PaiGramTeam/MibooGram.git
synced 2024-11-23 08:10:56 +00:00
🐛 Fix challenge avatar icon
This commit is contained in:
parent
3869616850
commit
cfead16f87
@ -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
|
||||
|
@ -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]
|
||||
|
@ -12,6 +12,8 @@ class Buddy(BaseModel):
|
||||
"""英文名称"""
|
||||
icon: str = ""
|
||||
"""图标"""
|
||||
square: str = ""
|
||||
"""方形图标"""
|
||||
rank: ZZZRank = ZZZRank.NULL
|
||||
""" 星级 """
|
||||
|
||||
|
@ -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])
|
||||
|
@ -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
|
||||
|
||||
|
@ -53,7 +53,7 @@
|
||||
<div class="element" style="background-image: url('../../img/attribute/{{ character.element_type }}.png')"></div>
|
||||
<div class="icon"
|
||||
style="background-image: url('../../background/rarity/half/{{ character.rarity }}.png')">
|
||||
<img src="{{ character.icon }}" alt=""/>
|
||||
<img src="{{ character_icons[character.id] }}" alt=""/>
|
||||
</div>
|
||||
<div class="caption">Lv.{{ character.level }}</div>
|
||||
</div>
|
||||
@ -63,7 +63,7 @@
|
||||
<div class="character">
|
||||
<div class="icon"
|
||||
style="background-image: url('../../background/rarity/half/{{ character.rarity }}.png')">
|
||||
<img src="{{ character.icon }}" alt=""/>
|
||||
<img src="{{ buddy_icons[character.id] }}" alt=""/>
|
||||
</div>
|
||||
<div class="caption">Lv.{{ character.level }}</div>
|
||||
</div>
|
||||
|
Loading…
Reference in New Issue
Block a user