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)
|
base_path.mkdir(exist_ok=True, parents=True)
|
||||||
gacha_path = base_path / "gacha.png"
|
gacha_path = base_path / "gacha.png"
|
||||||
icon_path = base_path / "icon.png"
|
icon_path = base_path / "icon.png"
|
||||||
|
square_path = base_path / "square.png"
|
||||||
normal_path = base_path / "normal.png"
|
normal_path = base_path / "normal.png"
|
||||||
if not gacha_path.exists():
|
if not gacha_path.exists():
|
||||||
tasks.append(self._download(icon.gacha, gacha_path))
|
tasks.append(self._download(icon.gacha, gacha_path))
|
||||||
if not icon_path.exists():
|
if not icon_path.exists():
|
||||||
tasks.append(self._download(icon.icon_, icon_path))
|
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():
|
if not normal_path.exists():
|
||||||
tasks.append(self._download(icon.normal, normal_path))
|
tasks.append(self._download(icon.normal, normal_path))
|
||||||
|
|
||||||
@ -136,6 +139,10 @@ class _AvatarAssets(_AssetsService):
|
|||||||
icon = self.get_target(target, second_target)
|
icon = self.get_target(target, second_target)
|
||||||
return self.get_path(icon, "icon")
|
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:
|
def normal(self, target: StrOrInt, second_target: StrOrInt = None) -> Path:
|
||||||
icon = self.get_target(target, second_target)
|
icon = self.get_target(target, second_target)
|
||||||
return self.get_path(icon, "normal")
|
return self.get_path(icon, "normal")
|
||||||
@ -218,10 +225,13 @@ class _BuddyAssets(_AssetsService):
|
|||||||
for icon in self.data:
|
for icon in self.data:
|
||||||
webp_path = self.path / f"{icon.id}.webp"
|
webp_path = self.path / f"{icon.id}.webp"
|
||||||
png_path = self.path / f"{icon.id}.png"
|
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:
|
if not webp_path.exists() and icon.webp:
|
||||||
tasks.append(self._download(icon.webp, webp_path))
|
tasks.append(self._download(icon.webp, webp_path))
|
||||||
if not png_path.exists() and icon.png:
|
if not png_path.exists() and icon.png:
|
||||||
tasks.append(self._download(icon.png, png_path))
|
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:
|
if len(tasks) >= 100:
|
||||||
await asyncio.gather(*tasks)
|
await asyncio.gather(*tasks)
|
||||||
tasks = []
|
tasks = []
|
||||||
@ -229,8 +239,9 @@ class _BuddyAssets(_AssetsService):
|
|||||||
await asyncio.gather(*tasks)
|
await asyncio.gather(*tasks)
|
||||||
logger.info("邦布素材图标初始化完成")
|
logger.info("邦布素材图标初始化完成")
|
||||||
|
|
||||||
def get_path(self, icon: Buddy, ext: str) -> Path:
|
def get_path(self, icon: Buddy, ext: str, square: bool = False) -> Path:
|
||||||
path = self.path / f"{icon.id}.{ext}"
|
square_str = "_square" if square else ""
|
||||||
|
path = self.path / f"{icon.id}{square_str}.{ext}"
|
||||||
return path
|
return path
|
||||||
|
|
||||||
def get_by_id(self, id_: int) -> Optional[Buddy]:
|
def get_by_id(self, id_: int) -> Optional[Buddy]:
|
||||||
@ -266,6 +277,10 @@ class _BuddyAssets(_AssetsService):
|
|||||||
return png_path
|
return png_path
|
||||||
raise AssetsCouldNotFound("邦布素材图标不存在", target)
|
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):
|
class _EquipmentSuitAssets(_AssetsService):
|
||||||
path: Path
|
path: Path
|
||||||
|
@ -22,7 +22,7 @@ class Avatar(BaseModel, frozen=False):
|
|||||||
""" 元素 """
|
""" 元素 """
|
||||||
speciality: ZZZSpeciality
|
speciality: ZZZSpeciality
|
||||||
""" 特性 """
|
""" 特性 """
|
||||||
icon: List[str] = ["", "", ""]
|
icon: List[str] = ["", "", "", ""]
|
||||||
""" 图标 """
|
""" 图标 """
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@ -30,9 +30,13 @@ class Avatar(BaseModel, frozen=False):
|
|||||||
return self.icon[0]
|
return self.icon[0]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def normal(self) -> str:
|
def square(self) -> str:
|
||||||
return self.icon[1]
|
return self.icon[1]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def gacha(self) -> str:
|
def normal(self) -> str:
|
||||||
return self.icon[2]
|
return self.icon[2]
|
||||||
|
|
||||||
|
@property
|
||||||
|
def gacha(self) -> str:
|
||||||
|
return self.icon[3]
|
||||||
|
@ -12,6 +12,8 @@ class Buddy(BaseModel):
|
|||||||
"""英文名称"""
|
"""英文名称"""
|
||||||
icon: str = ""
|
icon: str = ""
|
||||||
"""图标"""
|
"""图标"""
|
||||||
|
square: str = ""
|
||||||
|
"""方形图标"""
|
||||||
rank: ZZZRank = ZZZRank.NULL
|
rank: ZZZRank = ZZZRank.NULL
|
||||||
""" 星级 """
|
""" 星级 """
|
||||||
|
|
||||||
|
@ -47,3 +47,8 @@ class ZZZRank(str, Enum):
|
|||||||
def int(self):
|
def int(self):
|
||||||
value_map = {"S": 5, "A": 4, "B": 3, "C": 2, "D": 1, "NULL": 0}
|
value_map = {"S": 5, "A": 4, "B": 3, "C": 2, "D": 1, "NULL": 0}
|
||||||
return value_map[self.value]
|
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})
|
self.log_user(update, logger.info, "[bold]防卫战挑战数据[/bold]: 成功发送图片", extra={"markup": True})
|
||||||
|
|
||||||
@staticmethod
|
def get_floor_data(self, abyss_data: "ZZZChallenge", floor: int):
|
||||||
def get_floor_data(abyss_data: "ZZZChallenge", floor: int):
|
|
||||||
try:
|
try:
|
||||||
floor_data = abyss_data.floors[-floor]
|
floor_data = abyss_data.floors[-floor]
|
||||||
except IndexError:
|
except IndexError:
|
||||||
floor_data = None
|
floor_data = None
|
||||||
if not floor_data:
|
if not floor_data:
|
||||||
raise AbyssUnlocked()
|
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 = {
|
render_data = {
|
||||||
"floor": floor_data,
|
"floor": floor_data,
|
||||||
"floor_time": floor_data.floor_challenge_time.datetime.astimezone(TZ).strftime("%Y-%m-%d %H:%M:%S"),
|
"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_nodes": [floor_data.node_1, floor_data.node_2],
|
||||||
"floor_num": floor,
|
"floor_num": floor,
|
||||||
|
"character_icons": character_icons,
|
||||||
|
"buddy_icons": buddy_icons,
|
||||||
}
|
}
|
||||||
return render_data
|
return render_data
|
||||||
|
|
||||||
|
@ -53,7 +53,7 @@
|
|||||||
<div class="element" style="background-image: url('../../img/attribute/{{ character.element_type }}.png')"></div>
|
<div class="element" style="background-image: url('../../img/attribute/{{ character.element_type }}.png')"></div>
|
||||||
<div class="icon"
|
<div class="icon"
|
||||||
style="background-image: url('../../background/rarity/half/{{ character.rarity }}.png')">
|
style="background-image: url('../../background/rarity/half/{{ character.rarity }}.png')">
|
||||||
<img src="{{ character.icon }}" alt=""/>
|
<img src="{{ character_icons[character.id] }}" alt=""/>
|
||||||
</div>
|
</div>
|
||||||
<div class="caption">Lv.{{ character.level }}</div>
|
<div class="caption">Lv.{{ character.level }}</div>
|
||||||
</div>
|
</div>
|
||||||
@ -63,7 +63,7 @@
|
|||||||
<div class="character">
|
<div class="character">
|
||||||
<div class="icon"
|
<div class="icon"
|
||||||
style="background-image: url('../../background/rarity/half/{{ character.rarity }}.png')">
|
style="background-image: url('../../background/rarity/half/{{ character.rarity }}.png')">
|
||||||
<img src="{{ character.icon }}" alt=""/>
|
<img src="{{ buddy_icons[character.id] }}" alt=""/>
|
||||||
</div>
|
</div>
|
||||||
<div class="caption">Lv.{{ character.level }}</div>
|
<div class="caption">Lv.{{ character.level }}</div>
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
Reference in New Issue
Block a user