Spaces:
Runtime error
Runtime error
da03
commited on
Commit
·
021f723
1
Parent(s):
9e3f8c4
main.py
CHANGED
|
@@ -320,8 +320,13 @@ async def websocket_endpoint(websocket: WebSocket):
|
|
| 320 |
total_elapsed = process_start_time - connection_start_time
|
| 321 |
global_fps = frame_count / total_elapsed if total_elapsed > 0 else 0
|
| 322 |
|
|
|
|
|
|
|
|
|
|
| 323 |
x = data.get("x")
|
| 324 |
y = data.get("y")
|
|
|
|
|
|
|
| 325 |
is_left_click = data.get("is_left_click")
|
| 326 |
is_right_click = data.get("is_right_click")
|
| 327 |
keys_down_list = data.get("keys_down", []) # Get as list
|
|
|
|
| 320 |
total_elapsed = process_start_time - connection_start_time
|
| 321 |
global_fps = frame_count / total_elapsed if total_elapsed > 0 else 0
|
| 322 |
|
| 323 |
+
# change x and y to be between 0 and width/height-1 in data
|
| 324 |
+
data['x'] = max(0, min(data['x'], SCREEN_WIDTH - 1))
|
| 325 |
+
data['y'] = max(0, min(data['y'], SCREEN_HEIGHT - 1))
|
| 326 |
x = data.get("x")
|
| 327 |
y = data.get("y")
|
| 328 |
+
assert 0 <= x < SCREEN_WIDTH, f"x: {x} is out of range"
|
| 329 |
+
assert 0 <= y < SCREEN_HEIGHT, f"y: {y} is out of range"
|
| 330 |
is_left_click = data.get("is_left_click")
|
| 331 |
is_right_click = data.get("is_right_click")
|
| 332 |
keys_down_list = data.get("keys_down", []) # Get as list
|