ChenyuRabbitLove commited on
Commit
bd68530
1 Parent(s): 5e1e107

fix: optmize render player data workflow

Browse files
Files changed (2) hide show
  1. app.py +3 -12
  2. utils/utils.py +19 -2
app.py CHANGED
@@ -7,12 +7,7 @@ from theme import Seafoam
7
  from utils.mes_player_model import Player
8
  from utils.utils import (
9
  get_content,
10
- get_player_partners,
11
- get_player_badges,
12
- get_player_adventure_logs_html,
13
- get_player_achievements,
14
- get_current_story,
15
- get_player_avatar,
16
  save_latest_player_data,
17
  )
18
 
@@ -110,12 +105,8 @@ with gr.Blocks(theme=seafoam, css=get_content("css/style.css")) as demo:
110
 
111
  # actions when player login
112
  player_info_query_btn.click(get_player_info, player_backend_id, player_info).then(
113
- get_player_partners, player_info, pet_gallery).then(
114
- get_player_badges, player_info, badge_gallery).then(
115
- get_player_adventure_logs_html, player_info, adventure_log).then(
116
- get_player_achievements, player_info, achievements).then(
117
- get_current_story, None, adventure).then(
118
- get_player_avatar, player_info, avatar)
119
 
120
  pull_newest_player_data.submit(
121
  save_latest_player_data,
 
7
  from utils.mes_player_model import Player
8
  from utils.utils import (
9
  get_content,
10
+ render_player_data,
 
 
 
 
 
11
  save_latest_player_data,
12
  )
13
 
 
105
 
106
  # actions when player login
107
  player_info_query_btn.click(get_player_info, player_backend_id, player_info).then(
108
+ render_player_data, player_info, [avatar, pet_gallery, badge_gallery, adventure_log, achievements, adventure]
109
+ )
 
 
 
 
110
 
111
  pull_newest_player_data.submit(
112
  save_latest_player_data,
utils/utils.py CHANGED
@@ -136,14 +136,14 @@ def get_current_story():
136
  stage = get_stage(storyline_date)
137
 
138
  if stage:
139
- return gr.Slider.update(
140
  value=stage / 12 * 100,
141
  show_label=False,
142
  interactive=False,
143
  info=story[str(stage)],
144
  )
145
  else:
146
- return gr.Slider.update(
147
  value=0,
148
  show_label=False,
149
  interactive=False,
@@ -189,3 +189,20 @@ def save_latest_player_data():
189
  with open("latest_player_data.json", "w") as fp:
190
  print("Saving latest player data...")
191
  json.dump(latest_player_data_as_dict, fp, default=date_serializer)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
136
  stage = get_stage(storyline_date)
137
 
138
  if stage:
139
+ return gr.Slider(
140
  value=stage / 12 * 100,
141
  show_label=False,
142
  interactive=False,
143
  info=story[str(stage)],
144
  )
145
  else:
146
+ return gr.Slider(
147
  value=0,
148
  show_label=False,
149
  interactive=False,
 
189
  with open("latest_player_data.json", "w") as fp:
190
  print("Saving latest player data...")
191
  json.dump(latest_player_data_as_dict, fp, default=date_serializer)
192
+
193
+ def render_player_data(player_info: gr.State):
194
+ player_avatar = get_player_avatar(player_info)
195
+ player_partners = get_player_partners(player_info)
196
+ player_badges = get_player_badges(player_info)
197
+ player_adventure_logs = get_player_adventure_logs_html(player_info)
198
+ player_achievements = get_player_achievements(player_info)
199
+ current_story = get_current_story()
200
+
201
+ return (
202
+ player_avatar,
203
+ player_partners,
204
+ player_badges,
205
+ player_adventure_logs,
206
+ player_achievements,
207
+ current_story
208
+ )