from typing import List
import gradio as gr
MEDIA_PATH = "medias/"
MEDIA_FILE_TYPE = ".png"
def get_content(file_name: str) -> str:
with open(file_name, "r", encoding="utf-8") as file:
content = file.read()
return "
" + content
def get_player_partners(player_info: gr.State) -> List[str]:
return [
f"{MEDIA_PATH}{partner}{MEDIA_FILE_TYPE}" for partner in player_info["partners"]
]
def get_player_nickname(player_info: gr.State) -> str:
player_nickname = player_info["player_nickname"]
if player_nickname:
return f'# 光束守護者 - {player_info["player_nickname"]}'
else:
return "# 光束守護者"
def get_player_badges(player_info: gr.State) -> List[str]:
return [f"{MEDIA_PATH}{badge}{MEDIA_FILE_TYPE}" for badge in player_info["badges"]]
def get_player_adventure_logs(player_info: gr.State) -> List[str]:
log_template = """
"""
return [
log_template.format(player_log=player_log)
for player_log in player_info["adventure_logs"]
]
def get_player_adventure_logs_html(player_info: gr.State) -> str:
adventure_logs = "".join(get_player_adventure_logs(player_info))
template_content = get_content("htmls/adventure_template.html")
return template_content.replace("{logs}", adventure_logs)
def get_player_achievements(player_info: gr.State) -> List[str]:
achivement_name_map = {
"participation_star": "參賽之星",
"star_score_settler": "星際積分領航者",
"interstellar_traveler_I": "星際旅行者 I",
"interstellar_traveler_II": "星際旅行者 II",
"interstellar_traveler_III": "星際旅行者 III",
"interstellar_traveler_IV": "星際旅行者 IV",
"consistent_climbers_club_I": "連續爬升俱樂部 I",
"consistent_climbers_club_II": "連續爬升俱樂部 II",
"consistent_climbers_club_III": "連續爬升俱樂部 III",
"star_cluster_detector": "星團探測官",
"starry_vigilante": "群星瞭望者",
"planetary_decoder": "行星解碼",
"galactic_librarian": "星系圖書館員",
"energy_enthusiast_I": "能量狂熱者 I",
"energy_enthusiast_II": "能量狂熱者 II",
"energy_enthusiast_III": "能量狂熱者 III",
"energy_enthusiast_IV": "能量狂熱者 IV",
"knowledge_planet_explorer_I": "知識星球探險家 I",
"knowledge_planet_explorer_II": "知識星球探險家 II",
"scientific_expedition_explorer_I": "科學探險探險家 I",
"scientific_expedition_explorer_II": "科學探險探險家 II",
"cultural_celebration_explorer_I": "文化慶典探險家 I",
"cultural_celebration_explorer_II": "文化慶典探險家 II",
"youth_literature_explorer_I": "青春文學探險家 I",
"youth_literature_explorer_II": "青春文學探險家 II",
"path_to_wealth_explorer_I": "財富之路探險家 I",
"path_to_wealth_explorer_II": "財富之路探險家 II",
"cultivation_universe_explorer_I": "素養宇宙探險家 I",
"cultivation_universe_explorer_II": "素養宇宙探險家 II",
"electronic_and_information_college_explorer_I": "電資學院探險家 I",
"electronic_and_information_college_explorer_II": "電資學院探險家 II",
"star_warrior": "星空學霸",
}
print(player_info["rewards_status"])
rewards_status = json.loads(player_info["rewards_status"])
# rewards_status rountine_achevement sholud be removed
return [
(
achivement_name_map[achievement_key],
"完成" if achievement_value["is_completed"] else "未完成",
)
for achievement_key, achievement_value in rewards_status.items()
]