Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -54,6 +54,72 @@ class GameTimer:
|
|
54 |
if self._loop:
|
55 |
self._loop.stop()
|
56 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
57 |
# Initialize timer in session state
|
58 |
if 'game_timer' not in st.session_state:
|
59 |
st.session_state.game_timer = GameTimer()
|
|
|
54 |
if self._loop:
|
55 |
self._loop.stop()
|
56 |
|
57 |
+
|
58 |
+
|
59 |
+
# First define the load_game_state function
|
60 |
+
def load_game_state():
|
61 |
+
if 'player_name' in st.query_params:
|
62 |
+
st.session_state.player_name = st.query_params.player_name
|
63 |
+
st.session_state.position = {
|
64 |
+
'x': int(st.query_params.get('x', random.randint(0, GRID_WIDTH - 1))),
|
65 |
+
'y': int(st.query_params.get('y', random.randint(0, GRID_HEIGHT - 1)))
|
66 |
+
}
|
67 |
+
st.session_state.character_stats = {
|
68 |
+
'STR': int(st.query_params.get('STR', 10)),
|
69 |
+
'DEX': int(st.query_params.get('DEX', 10)),
|
70 |
+
'CON': int(st.query_params.get('CON', 10)),
|
71 |
+
'INT': int(st.query_params.get('INT', 10)),
|
72 |
+
'WIS': int(st.query_params.get('WIS', 10)),
|
73 |
+
'CHA': int(st.query_params.get('CHA', 10)),
|
74 |
+
'HP': int(st.query_params.get('HP', 20)),
|
75 |
+
'MAX_HP': int(st.query_params.get('MAX_HP', 40)),
|
76 |
+
'score': int(st.query_params.get('score', 0)),
|
77 |
+
'created_at': float(st.query_params.get('created_at', time.time()))
|
78 |
+
}
|
79 |
+
|
80 |
+
# Then initialize session state
|
81 |
+
if 'initialized' not in st.session_state:
|
82 |
+
st.session_state.initialized = False
|
83 |
+
st.session_state.game_state = {
|
84 |
+
'players': {},
|
85 |
+
'chat_messages': [],
|
86 |
+
'last_sync': time.time()
|
87 |
+
}
|
88 |
+
st.session_state.player_name = None
|
89 |
+
st.session_state.character_stats = {
|
90 |
+
'STR': 10,
|
91 |
+
'DEX': 10,
|
92 |
+
'CON': 10,
|
93 |
+
'INT': 10,
|
94 |
+
'WIS': 10,
|
95 |
+
'CHA': 10,
|
96 |
+
'HP': 20,
|
97 |
+
'MAX_HP': 40,
|
98 |
+
'score': 0,
|
99 |
+
'created_at': time.time()
|
100 |
+
}
|
101 |
+
st.session_state.position = {
|
102 |
+
'x': random.randint(0, GRID_WIDTH - 1),
|
103 |
+
'y': random.randint(0, GRID_HEIGHT - 1)
|
104 |
+
}
|
105 |
+
st.session_state.last_move = time.time()
|
106 |
+
st.session_state.nearby_players = []
|
107 |
+
|
108 |
+
# Now call load_game_state after it's been defined
|
109 |
+
load_game_state()
|
110 |
+
|
111 |
+
# Make sure all other functions that use load_game_state are defined after this point
|
112 |
+
|
113 |
+
|
114 |
+
|
115 |
+
|
116 |
+
|
117 |
+
|
118 |
+
|
119 |
+
|
120 |
+
|
121 |
+
|
122 |
+
|
123 |
# Initialize timer in session state
|
124 |
if 'game_timer' not in st.session_state:
|
125 |
st.session_state.game_timer = GameTimer()
|