Spaces:
Sleeping
Sleeping
Commit
·
8309961
1
Parent(s):
82eb64f
feat: add get current storu function
Browse files- utils/utils.py +46 -1
utils/utils.py
CHANGED
@@ -1,3 +1,5 @@
|
|
|
|
|
|
1 |
from typing import List
|
2 |
|
3 |
import gradio as gr
|
@@ -86,4 +88,47 @@ def get_player_achievements(player_info: gr.State) -> List[str]:
|
|
86 |
"完成" if achievement_value["is_completed"] else "未完成",
|
87 |
)
|
88 |
for achievement_key, achievement_value in rewards_status.items()
|
89 |
-
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import json
|
2 |
+
from datetime import datetime
|
3 |
from typing import List
|
4 |
|
5 |
import gradio as gr
|
|
|
88 |
"完成" if achievement_value["is_completed"] else "未完成",
|
89 |
)
|
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)
|
96 |
+
|
97 |
+
storyline_date = {
|
98 |
+
(datetime(2023, 12, 4).date(), datetime(2023, 12, 5).date()): 1,
|
99 |
+
(datetime(2023, 12, 6).date(), datetime(2023, 12, 7).date()): 2,
|
100 |
+
(datetime(2023, 12, 8).date(), datetime(2023, 12, 9).date()): 3,
|
101 |
+
(datetime(2023, 12, 10).date(), datetime(2023, 12, 11).date()): 4,
|
102 |
+
(datetime(2023, 12, 12).date(), datetime(2023, 12, 13).date()): 5,
|
103 |
+
(datetime(2023, 12, 14).date(), datetime(2023, 12, 15).date()): 6,
|
104 |
+
(datetime(2023, 12, 16).date(), datetime(2023, 12, 17).date()): 7,
|
105 |
+
(datetime(2023, 12, 18).date(), datetime(2023, 12, 19).date()): 8,
|
106 |
+
(datetime(2023, 12, 20).date(), datetime(2023, 12, 22).date()): 9,
|
107 |
+
(datetime(2023, 12, 23).date(), datetime(2023, 12, 25).date()): 10,
|
108 |
+
(datetime(2023, 12, 26).date(), datetime(2023, 12, 27).date()): 11,
|
109 |
+
(datetime(2023, 12, 28).date(), datetime(2023, 12, 29).date()): 12,
|
110 |
+
}
|
111 |
+
|
112 |
+
def get_stage(storyline_date):
|
113 |
+
current_date = datetime.now().date()
|
114 |
+
for (start_date, end_date), stage in storyline_date.items():
|
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 |
+
value=stage/12*100,
|
124 |
+
show_label=False,
|
125 |
+
interactive=False,
|
126 |
+
info=story[str(stage)],
|
127 |
+
)
|
128 |
+
else:
|
129 |
+
return gr.Slider.update(
|
130 |
+
value=0,
|
131 |
+
show_label=False,
|
132 |
+
interactive=False,
|
133 |
+
info="狐貍貓與光束守護者的旅程將於 2023/12/04 開始!敬請期待!",
|
134 |
+
)
|