ArturoNereu commited on
Commit
e239b50
·
1 Parent(s): 8c0cd83

Updated tools, and removed unused tools

Browse files
Files changed (3) hide show
  1. app.py +37 -3
  2. chat_client.py +30 -3
  3. frontend/game_viewer.html +40 -0
app.py CHANGED
@@ -245,7 +245,13 @@ APP_CSS = """
245
  .toast.error { border-left-color: #f44336; }
246
 
247
  /* Hide the action data textbox but keep it in DOM for events to fire */
248
- .hidden-action {
 
 
 
 
 
 
249
  position: absolute !important;
250
  width: 1px !important;
251
  height: 1px !important;
@@ -255,6 +261,8 @@ APP_CSS = """
255
  clip: rect(0, 0, 0, 0) !important;
256
  white-space: nowrap !important;
257
  border: 0 !important;
 
 
258
  }
259
  """
260
 
@@ -525,7 +533,12 @@ with gr.Blocks(title="GCP - Game Context Protocol") as demo:
525
  # Full reload: update iframe src
526
  viewer_html = f'<div id="viewer-container" style="width:100%; min-height:500px; height:70vh;"><iframe src="{action_result["url"]}" style="width:100%; height:100%; border:none;"></iframe></div>'
527
 
528
- elif action_type in ["addObject", "removeObject", "setLighting", "setControlMode", "updateMaterial", "addLight", "removeLight", "updateLight", "setBackground", "setFog"]:
 
 
 
 
 
529
  # Build action JSON for the JavaScript watcher
530
  import json
531
  import time
@@ -555,13 +568,34 @@ with gr.Blocks(title="GCP - Game Context Protocol") as demo:
555
  toast_message = "Background updated"
556
  elif action_type == "setFog":
557
  toast_message = "Fog updated"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
558
 
559
  # Create JSON payload for the .then() JavaScript handler
 
560
  action_json = json.dumps({
561
  "action": action_result["action"],
562
  "data": action_result["data"],
563
  "toast": toast_message,
564
- "toastType": "success"
 
565
  })
566
 
567
  return history, viewer_html, action_json
 
245
  .toast.error { border-left-color: #f44336; }
246
 
247
  /* Hide the action data textbox but keep it in DOM for events to fire */
248
+ .hidden-action,
249
+ .hidden-action textarea,
250
+ .hidden-action input,
251
+ .hidden-action label,
252
+ .hidden-action .wrap,
253
+ #action-data,
254
+ #crosshair-pos {
255
  position: absolute !important;
256
  width: 1px !important;
257
  height: 1px !important;
 
261
  clip: rect(0, 0, 0, 0) !important;
262
  white-space: nowrap !important;
263
  border: 0 !important;
264
+ opacity: 0 !important;
265
+ pointer-events: none !important;
266
  }
267
  """
268
 
 
533
  # Full reload: update iframe src
534
  viewer_html = f'<div id="viewer-container" style="width:100%; min-height:500px; height:70vh;"><iframe src="{action_result["url"]}" style="width:100%; height:100%; border:none;"></iframe></div>'
535
 
536
+ elif action_type in ["addObject", "removeObject", "setLighting", "setControlMode",
537
+ "updateMaterial", "addLight", "removeLight", "updateLight",
538
+ "setBackground", "setFog",
539
+ # Player tools
540
+ "setPlayerSpeed", "setJumpForce", "setGravity",
541
+ "setCameraFov", "setMouseSensitivity", "setPlayerDimensions"]:
542
  # Build action JSON for the JavaScript watcher
543
  import json
544
  import time
 
568
  toast_message = "Background updated"
569
  elif action_type == "setFog":
570
  toast_message = "Fog updated"
571
+ # Player tool toast messages
572
+ elif action_type == "setPlayerSpeed":
573
+ speed = action_result["data"].get("walk_speed", 5)
574
+ toast_message = f"Player speed: {speed} m/s"
575
+ elif action_type == "setJumpForce":
576
+ force = action_result["data"].get("jump_force", 5)
577
+ toast_message = f"Jump force: {force} m/s"
578
+ elif action_type == "setGravity":
579
+ gravity = action_result["data"].get("gravity", -9.82)
580
+ toast_message = f"Gravity: {gravity} m/s²"
581
+ elif action_type == "setCameraFov":
582
+ fov = action_result["data"].get("fov", 75)
583
+ toast_message = f"Camera FOV: {fov}°"
584
+ elif action_type == "setMouseSensitivity":
585
+ sens = action_result["data"].get("sensitivity", 0.002)
586
+ toast_message = f"Mouse sensitivity: {sens}"
587
+ elif action_type == "setPlayerDimensions":
588
+ height = action_result["data"].get("height", 1.7)
589
+ toast_message = f"Player height: {height}m"
590
 
591
  # Create JSON payload for the .then() JavaScript handler
592
+ # Include timestamp to ensure Gradio detects change even for repeated actions
593
  action_json = json.dumps({
594
  "action": action_result["action"],
595
  "data": action_result["data"],
596
  "toast": toast_message,
597
+ "toastType": "success",
598
+ "timestamp": time.time()
599
  })
600
 
601
  return history, viewer_html, action_json
chat_client.py CHANGED
@@ -900,9 +900,30 @@ If the user DOES specify a position (e.g., "add a cube at 0, 0, 0"), use their s
900
  if scene and scene.get("lighting"):
901
  return {"action": "setLighting", "data": scene["lighting"]}
902
 
903
- elif tool in ["set_player_speed", "set_jump_force", "set_gravity",
904
- "set_camera_fov", "set_player_dimensions"]:
905
- return {"action": "reload", "url": f"{self.base_url}/view/scene/{self.scene_id}"}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
906
 
907
  elif tool == "add_light":
908
  return {"action": "addLight", "data": result.get("light")}
@@ -910,6 +931,12 @@ If the user DOES specify a position (e.g., "add a cube at 0, 0, 0"), use their s
910
  elif tool == "remove_light":
911
  return {"action": "removeLight", "data": {"light_name": action["args"].get("light_name")}}
912
 
 
 
 
 
 
 
913
  elif tool == "update_object_material":
914
  return {"action": "updateMaterial", "data": result}
915
 
 
900
  if scene and scene.get("lighting"):
901
  return {"action": "setLighting", "data": scene["lighting"]}
902
 
903
+ elif tool == "set_player_speed":
904
+ return {"action": "setPlayerSpeed", "data": {"walk_speed": result.get("walk_speed")}}
905
+
906
+ elif tool == "set_jump_force":
907
+ return {"action": "setJumpForce", "data": {"jump_force": result.get("jump_force")}}
908
+
909
+ elif tool == "set_gravity":
910
+ return {"action": "setGravity", "data": {"gravity": result.get("gravity")}}
911
+
912
+ elif tool == "set_camera_fov":
913
+ return {"action": "setCameraFov", "data": {"fov": result.get("fov")}}
914
+
915
+ elif tool == "set_mouse_sensitivity":
916
+ return {"action": "setMouseSensitivity", "data": {
917
+ "sensitivity": result.get("sensitivity"),
918
+ "invert_y": result.get("invert_y")
919
+ }}
920
+
921
+ elif tool == "set_player_dimensions":
922
+ return {"action": "setPlayerDimensions", "data": {
923
+ "height": result.get("height"),
924
+ "radius": result.get("radius"),
925
+ "eye_height": result.get("eye_height")
926
+ }}
927
 
928
  elif tool == "add_light":
929
  return {"action": "addLight", "data": result.get("light")}
 
931
  elif tool == "remove_light":
932
  return {"action": "removeLight", "data": {"light_name": action["args"].get("light_name")}}
933
 
934
+ elif tool == "update_light":
935
+ return {"action": "updateLight", "data": {
936
+ "light_name": action["args"].get("light_name"),
937
+ **result.get("light", {})
938
+ }}
939
+
940
  elif tool == "update_object_material":
941
  return {"action": "updateMaterial", "data": result}
942
 
frontend/game_viewer.html CHANGED
@@ -1282,6 +1282,46 @@
1282
  case 'setFog':
1283
  setSceneFog(data);
1284
  break;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1285
  default:
1286
  console.warn('Unknown postMessage action:', action);
1287
  }
 
1282
  case 'setFog':
1283
  setSceneFog(data);
1284
  break;
1285
+ // Player configuration actions
1286
+ case 'setPlayerSpeed':
1287
+ WALK_SPEED = data.walk_speed || 5.0;
1288
+ console.log('Player speed set to:', WALK_SPEED);
1289
+ break;
1290
+ case 'setJumpForce':
1291
+ JUMP_VELOCITY = data.jump_force || 5.0;
1292
+ console.log('Jump force set to:', JUMP_VELOCITY);
1293
+ break;
1294
+ case 'setGravity':
1295
+ if (world) {
1296
+ world.gravity.set(0, data.gravity || -9.82, 0);
1297
+ console.log('Gravity set to:', data.gravity);
1298
+ }
1299
+ break;
1300
+ case 'setCameraFov':
1301
+ if (camera) {
1302
+ camera.fov = data.fov || 75;
1303
+ camera.updateProjectionMatrix();
1304
+ console.log('Camera FOV set to:', camera.fov);
1305
+ }
1306
+ break;
1307
+ case 'setMouseSensitivity':
1308
+ MOUSE_SENSITIVITY = data.sensitivity || 0.002;
1309
+ if (data.invert_y !== undefined) {
1310
+ // Store invert_y preference (used in mouse movement handler)
1311
+ window.INVERT_Y = data.invert_y;
1312
+ }
1313
+ console.log('Mouse sensitivity set to:', MOUSE_SENSITIVITY);
1314
+ break;
1315
+ case 'setPlayerDimensions':
1316
+ // Update player dimensions
1317
+ if (data.height) PLAYER_HEIGHT = data.height;
1318
+ if (data.radius) PLAYER_RADIUS = data.radius;
1319
+ if (data.eye_height) {
1320
+ // Update camera Y offset relative to player body
1321
+ // This will take effect on next frame
1322
+ }
1323
+ console.log('Player dimensions updated:', { height: PLAYER_HEIGHT, radius: PLAYER_RADIUS });
1324
+ break;
1325
  default:
1326
  console.warn('Unknown postMessage action:', action);
1327
  }