Spaces:
Running
Running
ChenyuRabbitLove
commited on
Commit
•
00cd8e1
1
Parent(s):
9dae054
chore: formatting
Browse files- app.py +21 -11
- utils/utils.py +14 -11
app.py
CHANGED
@@ -62,7 +62,9 @@ with gr.Blocks(theme=seafoam, css=get_content("css/style.css")) as demo:
|
|
62 |
|
63 |
with gr.Column(scale=1):
|
64 |
with gr.Column(elem_id="adventure_container"):
|
65 |
-
adventure_description = gr.Markdown(
|
|
|
|
|
66 |
adventure = gr.Slider(
|
67 |
value=0,
|
68 |
show_label=False,
|
@@ -88,19 +90,27 @@ with gr.Blocks(theme=seafoam, css=get_content("css/style.css")) as demo:
|
|
88 |
|
89 |
# handling player info
|
90 |
with gr.Row():
|
91 |
-
player_backend_id = gr.Textbox(
|
92 |
-
"", visible=True, elem_id="player_backend_id"
|
93 |
-
)
|
94 |
player_info_query_btn = gr.Button("Query", elem_id="trigger_button")
|
95 |
|
96 |
# actions when player login
|
97 |
player_info_query_btn.click(get_player_info, player_backend_id, player_info).then(
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
105 |
if __name__ == "__main__":
|
106 |
demo.launch()
|
|
|
62 |
|
63 |
with gr.Column(scale=1):
|
64 |
with gr.Column(elem_id="adventure_container"):
|
65 |
+
adventure_description = gr.Markdown(
|
66 |
+
"# 冒險階段", elem_id="adventure_description"
|
67 |
+
)
|
68 |
adventure = gr.Slider(
|
69 |
value=0,
|
70 |
show_label=False,
|
|
|
90 |
|
91 |
# handling player info
|
92 |
with gr.Row():
|
93 |
+
player_backend_id = gr.Textbox("", visible=True, elem_id="player_backend_id")
|
|
|
|
|
94 |
player_info_query_btn = gr.Button("Query", elem_id="trigger_button")
|
95 |
|
96 |
# actions when player login
|
97 |
player_info_query_btn.click(get_player_info, player_backend_id, player_info).then(
|
98 |
+
player_info_query_btn.click(get_player_partners, player_info, pet_gallery)
|
99 |
+
).then(
|
100 |
+
player_info_query_btn.click(get_player_badges, player_info, badge_gallery)
|
101 |
+
).then(
|
102 |
+
player_info_query_btn.click(
|
103 |
+
get_player_adventure_logs_html, player_info, adventure_log
|
104 |
+
)
|
105 |
+
).then(
|
106 |
+
player_info_query_btn.click(get_player_achievements, player_info, achievements)
|
107 |
+
).then(
|
108 |
+
player_info_query_btn.click(
|
109 |
+
get_player_nickname, player_info, avatar_description
|
110 |
+
)
|
111 |
+
).then(
|
112 |
+
player_info_query_btn.click(get_current_story, None, adventure)
|
113 |
+
)
|
114 |
+
|
115 |
if __name__ == "__main__":
|
116 |
demo.launch()
|
utils/utils.py
CHANGED
@@ -19,6 +19,7 @@ def get_player_partners(player_info: gr.State) -> List[str]:
|
|
19 |
f"{MEDIA_PATH}{partner}{MEDIA_FILE_TYPE}" for partner in player_info["partners"]
|
20 |
]
|
21 |
|
|
|
22 |
def get_player_nickname(player_info: gr.State) -> str:
|
23 |
player_nickname = player_info["player_nickname"]
|
24 |
if player_nickname:
|
@@ -44,6 +45,7 @@ def get_player_adventure_logs_html(player_info: gr.State) -> str:
|
|
44 |
template_content = get_content("htmls/adventure_template.html")
|
45 |
return template_content.replace("{logs}", adventure_logs)
|
46 |
|
|
|
47 |
def get_player_achievements(player_info: gr.State) -> List[str]:
|
48 |
achivement_name_map = {
|
49 |
"participation_star": "參賽之星",
|
@@ -90,6 +92,7 @@ def get_player_achievements(player_info: gr.State) -> List[str]:
|
|
90 |
for achievement_key, achievement_value in rewards_status.items()
|
91 |
]
|
92 |
|
|
|
93 |
def get_current_story():
|
94 |
with open("story.json", "r", encoding="utf-8") as file:
|
95 |
story = json.load(file)
|
@@ -115,20 +118,20 @@ def get_current_story():
|
|
115 |
if start_date <= current_date <= end_date:
|
116 |
return stage
|
117 |
return None
|
118 |
-
|
119 |
stage = get_stage(storyline_date)
|
120 |
|
121 |
if stage:
|
122 |
return gr.Slider.update(
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
else:
|
129 |
return gr.Slider.update(
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
|
|
19 |
f"{MEDIA_PATH}{partner}{MEDIA_FILE_TYPE}" for partner in player_info["partners"]
|
20 |
]
|
21 |
|
22 |
+
|
23 |
def get_player_nickname(player_info: gr.State) -> str:
|
24 |
player_nickname = player_info["player_nickname"]
|
25 |
if player_nickname:
|
|
|
45 |
template_content = get_content("htmls/adventure_template.html")
|
46 |
return template_content.replace("{logs}", adventure_logs)
|
47 |
|
48 |
+
|
49 |
def get_player_achievements(player_info: gr.State) -> List[str]:
|
50 |
achivement_name_map = {
|
51 |
"participation_star": "參賽之星",
|
|
|
92 |
for achievement_key, achievement_value in rewards_status.items()
|
93 |
]
|
94 |
|
95 |
+
|
96 |
def get_current_story():
|
97 |
with open("story.json", "r", encoding="utf-8") as file:
|
98 |
story = json.load(file)
|
|
|
118 |
if start_date <= current_date <= end_date:
|
119 |
return stage
|
120 |
return None
|
121 |
+
|
122 |
stage = get_stage(storyline_date)
|
123 |
|
124 |
if stage:
|
125 |
return gr.Slider.update(
|
126 |
+
value=stage / 12 * 100,
|
127 |
+
show_label=False,
|
128 |
+
interactive=False,
|
129 |
+
info=story[str(stage)],
|
130 |
+
)
|
131 |
else:
|
132 |
return gr.Slider.update(
|
133 |
+
value=0,
|
134 |
+
show_label=False,
|
135 |
+
interactive=False,
|
136 |
+
info="狐貍貓與光束守護者的旅程將於 2023/12/04 開始!敬請期待!",
|
137 |
+
)
|