Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
@@ -31,63 +31,63 @@ def create_room():
|
|
31 |
|
32 |
player_name = request.json.get('name')
|
33 |
if not player_name:
|
34 |
-
return
|
35 |
|
36 |
# Add the player to the room.
|
37 |
player_id = len(rooms[room_code]['players']) + 1
|
38 |
rooms[room_code]['players'].append({'id': player_id, 'name': player_name})
|
39 |
|
40 |
-
return
|
41 |
|
42 |
|
43 |
@app.route('/join-room/<room_code>', methods=['POST', 'GET'])
|
44 |
def join_room(room_code):
|
45 |
if request.method == 'POST':
|
46 |
if room_code not in rooms:
|
47 |
-
return
|
48 |
|
49 |
if len(rooms[room_code]['players']) >= 5:
|
50 |
-
return
|
51 |
|
52 |
player_name = request.json.get('name')
|
53 |
if not player_name:
|
54 |
-
return
|
55 |
|
56 |
# Add the player to the room.
|
57 |
player_id = len(rooms[room_code]['players']) + 1
|
58 |
rooms[room_code]['players'].append({'id': player_id, 'name': player_name})
|
59 |
|
60 |
-
return
|
61 |
|
62 |
if request.method == 'GET':
|
63 |
if room_code not in rooms:
|
64 |
-
return
|
65 |
|
66 |
ready = False
|
67 |
|
68 |
if len(rooms[room_code]['players']) == 5: # do it <= 5
|
69 |
ready = True
|
70 |
|
71 |
-
return
|
72 |
-
'meta_data': rooms[room_code]}
|
73 |
|
74 |
|
75 |
@app.route('/start-room/<room_code>', methods=['POST'])
|
76 |
def start_room(room_code):
|
77 |
if room_code not in rooms:
|
78 |
-
return
|
79 |
|
80 |
rooms[room_code]['started'] = True
|
81 |
rooms[room_code]['process'] = 0
|
82 |
|
83 |
-
return
|
84 |
|
85 |
|
86 |
@app.route('/handle-tokens/<room_code>/<int:player_id>', methods=['POST', 'GET'])
|
87 |
def handle_tokens(room_code, player_id):
|
88 |
if request.method == 'POST':
|
89 |
if room_code not in rooms:
|
90 |
-
return
|
91 |
|
92 |
data = request.get_json()
|
93 |
word = data['word']
|
@@ -107,7 +107,7 @@ def handle_tokens(room_code, player_id):
|
|
107 |
print(rooms[room_code]['players'])
|
108 |
print(rooms[room_code]['process'])
|
109 |
|
110 |
-
return
|
111 |
|
112 |
if request.method == 'GET':
|
113 |
if room_code not in rooms:
|
@@ -122,25 +122,25 @@ def handle_tokens(room_code, player_id):
|
|
122 |
if rooms[room_code]['generated']:
|
123 |
generated = True
|
124 |
|
125 |
-
return
|
126 |
|
127 |
|
128 |
@app.route('/leave-room/<room_code>/<int:player_id>', methods=['POST'])
|
129 |
def leave_room(room_code, player_id):
|
130 |
if room_code not in rooms:
|
131 |
-
return
|
132 |
|
133 |
rooms[room_code]['players'] = [player for player in rooms[room_code]['players'] if player['id'] != player_id]
|
134 |
|
135 |
if player_id == 1 or not rooms[room_code]['players']:
|
136 |
del rooms[room_code]
|
137 |
|
138 |
-
return
|
139 |
|
140 |
|
141 |
def process(room_code):
|
142 |
if room_code not in rooms:
|
143 |
-
return
|
144 |
|
145 |
players = rooms[room_code]['players']
|
146 |
|
@@ -250,33 +250,33 @@ def generate_story(room_code):
|
|
250 |
def reaction_true(room_code):
|
251 |
rooms[room_code]['reactions'] += 1
|
252 |
|
253 |
-
return
|
254 |
|
255 |
|
256 |
@app.route('/reaction-false/<room_code>', methods=['GET'])
|
257 |
def reaction_false(room_code):
|
258 |
rooms[room_code]['reactions'] -= 1
|
259 |
|
260 |
-
return
|
261 |
|
262 |
|
263 |
@app.route('/room-chat/<room_code>', methods=['GET'])
|
264 |
def room_chat(room_code):
|
265 |
if room_code not in rooms:
|
266 |
-
return
|
267 |
print(rooms[room_code]['chats'])
|
268 |
-
return
|
269 |
|
270 |
|
271 |
@app.route('/chat-input/<room_code>/<int:player_id>', methods=['POST'])
|
272 |
def chat_input(room_code, player_id):
|
273 |
data = request.get_json()
|
274 |
if room_code not in rooms:
|
275 |
-
return
|
276 |
|
277 |
rooms[room_code]['chats'].append({'id': player_id, 'text': data.get('text')})
|
278 |
|
279 |
-
return
|
280 |
|
281 |
|
282 |
@app.route('/poll-data/<room_code>', methods=['POST'])
|
@@ -286,13 +286,13 @@ def poll_count(room_code):
|
|
286 |
|
287 |
rooms[room_code]['pollCount'] += 1
|
288 |
|
289 |
-
return
|
290 |
|
291 |
|
292 |
@app.route('/complete/<room_code>', methods=['GET'])
|
293 |
def completed(room_code):
|
294 |
if room_code not in rooms:
|
295 |
-
return
|
296 |
|
297 |
return complete[room_code]
|
298 |
|
|
|
31 |
|
32 |
player_name = request.json.get('name')
|
33 |
if not player_name:
|
34 |
+
return {'error': 'Player name is required'}
|
35 |
|
36 |
# Add the player to the room.
|
37 |
player_id = len(rooms[room_code]['players']) + 1
|
38 |
rooms[room_code]['players'].append({'id': player_id, 'name': player_name})
|
39 |
|
40 |
+
return {'room_code': room_code}
|
41 |
|
42 |
|
43 |
@app.route('/join-room/<room_code>', methods=['POST', 'GET'])
|
44 |
def join_room(room_code):
|
45 |
if request.method == 'POST':
|
46 |
if room_code not in rooms:
|
47 |
+
return {'noRoom': True}
|
48 |
|
49 |
if len(rooms[room_code]['players']) >= 5:
|
50 |
+
return {'error': 'Room is full'}
|
51 |
|
52 |
player_name = request.json.get('name')
|
53 |
if not player_name:
|
54 |
+
return {'error': 'Player name is required'}
|
55 |
|
56 |
# Add the player to the room.
|
57 |
player_id = len(rooms[room_code]['players']) + 1
|
58 |
rooms[room_code]['players'].append({'id': player_id, 'name': player_name})
|
59 |
|
60 |
+
return {'player_id': player_id, 'players': rooms[room_code]['players']}
|
61 |
|
62 |
if request.method == 'GET':
|
63 |
if room_code not in rooms:
|
64 |
+
return {'noRoom': True}
|
65 |
|
66 |
ready = False
|
67 |
|
68 |
if len(rooms[room_code]['players']) == 5: # do it <= 5
|
69 |
ready = True
|
70 |
|
71 |
+
return {'players': rooms[room_code]['players'], 'ready': ready, 'started': rooms[room_code]['started'],
|
72 |
+
'meta_data': rooms[room_code]}
|
73 |
|
74 |
|
75 |
@app.route('/start-room/<room_code>', methods=['POST'])
|
76 |
def start_room(room_code):
|
77 |
if room_code not in rooms:
|
78 |
+
return {'error': 'Room not found'}
|
79 |
|
80 |
rooms[room_code]['started'] = True
|
81 |
rooms[room_code]['process'] = 0
|
82 |
|
83 |
+
return {'success': True}
|
84 |
|
85 |
|
86 |
@app.route('/handle-tokens/<room_code>/<int:player_id>', methods=['POST', 'GET'])
|
87 |
def handle_tokens(room_code, player_id):
|
88 |
if request.method == 'POST':
|
89 |
if room_code not in rooms:
|
90 |
+
return {'error': 'Room not found'}
|
91 |
|
92 |
data = request.get_json()
|
93 |
word = data['word']
|
|
|
107 |
print(rooms[room_code]['players'])
|
108 |
print(rooms[room_code]['process'])
|
109 |
|
110 |
+
return {'success': True, 'process': False}
|
111 |
|
112 |
if request.method == 'GET':
|
113 |
if room_code not in rooms:
|
|
|
122 |
if rooms[room_code]['generated']:
|
123 |
generated = True
|
124 |
|
125 |
+
return {'process': processed, 'generated': generated}
|
126 |
|
127 |
|
128 |
@app.route('/leave-room/<room_code>/<int:player_id>', methods=['POST'])
|
129 |
def leave_room(room_code, player_id):
|
130 |
if room_code not in rooms:
|
131 |
+
return {'error': 'Room not found'}
|
132 |
|
133 |
rooms[room_code]['players'] = [player for player in rooms[room_code]['players'] if player['id'] != player_id]
|
134 |
|
135 |
if player_id == 1 or not rooms[room_code]['players']:
|
136 |
del rooms[room_code]
|
137 |
|
138 |
+
return {'message': 'Player has left the room'}
|
139 |
|
140 |
|
141 |
def process(room_code):
|
142 |
if room_code not in rooms:
|
143 |
+
return {'error': 'Room not found'}
|
144 |
|
145 |
players = rooms[room_code]['players']
|
146 |
|
|
|
250 |
def reaction_true(room_code):
|
251 |
rooms[room_code]['reactions'] += 1
|
252 |
|
253 |
+
return {'success': True, 'likeCount': rooms[room_code]['reactions']}
|
254 |
|
255 |
|
256 |
@app.route('/reaction-false/<room_code>', methods=['GET'])
|
257 |
def reaction_false(room_code):
|
258 |
rooms[room_code]['reactions'] -= 1
|
259 |
|
260 |
+
return {'success': True, 'likeCount': rooms[room_code]['reactions']}
|
261 |
|
262 |
|
263 |
@app.route('/room-chat/<room_code>', methods=['GET'])
|
264 |
def room_chat(room_code):
|
265 |
if room_code not in rooms:
|
266 |
+
return {'success': False, 'error': 'Room not found'}
|
267 |
print(rooms[room_code]['chats'])
|
268 |
+
return {'success': True, 'chats': rooms[room_code]['chats'], 'pollCount': rooms[room_code]['pollCount']}
|
269 |
|
270 |
|
271 |
@app.route('/chat-input/<room_code>/<int:player_id>', methods=['POST'])
|
272 |
def chat_input(room_code, player_id):
|
273 |
data = request.get_json()
|
274 |
if room_code not in rooms:
|
275 |
+
return {'success': False, 'error': 'Room not found'}
|
276 |
|
277 |
rooms[room_code]['chats'].append({'id': player_id, 'text': data.get('text')})
|
278 |
|
279 |
+
return {'success': True}
|
280 |
|
281 |
|
282 |
@app.route('/poll-data/<room_code>', methods=['POST'])
|
|
|
286 |
|
287 |
rooms[room_code]['pollCount'] += 1
|
288 |
|
289 |
+
return {'success': True, 'pollCount': rooms[room_code]['pollCount']}
|
290 |
|
291 |
|
292 |
@app.route('/complete/<room_code>', methods=['GET'])
|
293 |
def completed(room_code):
|
294 |
if room_code not in rooms:
|
295 |
+
return {'success': False, 'error': 'Room not found'}
|
296 |
|
297 |
return complete[room_code]
|
298 |
|