awacke1 commited on
Commit
7dd9bb4
·
verified ·
1 Parent(s): 1d3b6f2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +48 -47
app.py CHANGED
@@ -750,13 +750,6 @@ async def websocket_handler(websocket, path):
750
  st.session_state.current_world_file = new_filename
751
  log_action(sender_username, "delete", {"obj_id": obj_id})
752
 
753
- elif msg_type == "player_position":
754
- pos_data = payload.get("position")
755
- rot_data = payload.get("rotation")
756
- if pos_data:
757
- broadcast_payload = json.dumps({"type": "player_moved", "payload": {"username": sender_username, "id": client_id, "position": pos_data, "rotation": rot_data}})
758
- await broadcast_message(broadcast_payload, exclude_id=client_id)
759
-
760
  elif msg_type == "tool_selected":
761
  tool_type = payload.get("tool_type")
762
  if tool_type in PRIMITIVE_MAP.values() or tool_type == "None":
@@ -921,47 +914,55 @@ def render_sidebar():
921
  st.markdown("---")
922
  st.header("🏗️ Build Tools")
923
  st.caption("Select an object to place.")
924
- # Hidden selectbox to sync tool state
925
- tool_options = ['None'] + list(PRIMITIVE_MAP.values())
926
- selected_tool = st.selectbox("Selected Tool", options=tool_options, index=tool_options.index(st.session_state.get('selected_object', 'None')), key="tool_select", label_visibility="collapsed")
927
- if selected_tool != st.session_state.selected_object:
928
- st.session_state.selected_object = selected_tool
929
- run_async(lambda: streamlit_js_eval(
930
- f"updateSelectedObjectType({json.dumps(selected_tool)});",
931
- key=f"update_tool_js_{selected_tool}"
932
- ))
933
-
934
- cols = st.columns(5)
935
- col_idx = 0
936
- current_tool = st.session_state.get('selected_object', 'None')
 
 
 
 
 
 
 
 
 
 
 
 
937
  for emoji, name in PRIMITIVE_MAP.items():
938
- button_key = f"primitive_{name}"
939
- button_type = "primary" if current_tool == name else "secondary"
940
- if cols[col_idx % 5].button(emoji, key=button_key, help=name, type=button_type, use_container_width=True):
941
- # Update tool via JavaScript without rerun
942
- run_async(lambda name_arg=name: streamlit_js_eval(
943
- f"""
944
- updateSelectedObjectType('{name_arg}');
945
- websocket.send(JSON.stringify({{
946
- type: 'tool_selected',
947
- payload: {{ tool_type: '{name_arg}', username: window.USERNAME }}
948
- }}));
949
- """,
950
- key=f"update_tool_js_{name_arg}"
951
- ))
952
- col_idx += 1
953
- st.markdown("---")
954
- if st.button("🚫 Clear Tool", key="clear_tool", use_container_width=True):
955
- run_async(lambda: streamlit_js_eval(
956
- """
957
- updateSelectedObjectType('None');
958
- websocket.send(JSON.stringify({
959
  type: 'tool_selected',
960
- payload: { tool_type: 'None', username: window.USERNAME }
961
- }));
962
- """,
963
- key="update_tool_js_none"
964
- ))
 
 
 
 
 
 
 
 
 
 
 
965
 
966
  st.markdown("---")
967
  st.header("🗣�� Voice & User")
@@ -990,7 +991,7 @@ def render_main_content():
990
 
991
  with tab_world:
992
  st.header("Shared 3D World")
993
- st.caption("Place objects using the sidebar tools. Changes are shared live!")
994
  current_file_basename = st.session_state.get('current_world_file', None)
995
  if current_file_basename:
996
  parsed = parse_world_filename(os.path.join(SAVED_WORLDS_DIR, current_file_basename))
 
750
  st.session_state.current_world_file = new_filename
751
  log_action(sender_username, "delete", {"obj_id": obj_id})
752
 
 
 
 
 
 
 
 
753
  elif msg_type == "tool_selected":
754
  tool_type = payload.get("tool_type")
755
  if tool_type in PRIMITIVE_MAP.values() or tool_type == "None":
 
914
  st.markdown("---")
915
  st.header("🏗️ Build Tools")
916
  st.caption("Select an object to place.")
917
+
918
+ # Inject JavaScript buttons for tools
919
+ tool_buttons_html = """
920
+ <style>
921
+ .tool-button {
922
+ width: 40px;
923
+ height: 40px;
924
+ margin: 2px;
925
+ font-size: 20px;
926
+ cursor: pointer;
927
+ border: 2px solid #ccc;
928
+ background-color: #f9f9f9;
929
+ }
930
+ .tool-button.selected {
931
+ border-color: #007bff;
932
+ background-color: #e7f3ff;
933
+ }
934
+ .tool-grid {
935
+ display: grid;
936
+ grid-template-columns: repeat(5, 1fr);
937
+ gap: 2px;
938
+ }
939
+ </style>
940
+ <div class="tool-grid">
941
+ """
942
  for emoji, name in PRIMITIVE_MAP.items():
943
+ tool_buttons_html += f"""
944
+ <button class="tool-button" id="tool_{name}" onclick="
945
+ document.querySelectorAll('.tool-button').forEach(btn => btn.classList.remove('selected'));
946
+ this.classList.add('selected');
947
+ updateSelectedObjectType('{name}');
948
+ websocket.send(JSON.stringify({{
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
949
  type: 'tool_selected',
950
+ payload: {{ tool_type: '{name}', username: window.USERNAME }}
951
+ }}));
952
+ " title="{name}">{emoji}</button>
953
+ """
954
+ tool_buttons_html += """
955
+ </div>
956
+ <button style="width: 100%; margin-top: 10px; padding: 5px;" onclick="
957
+ document.querySelectorAll('.tool-button').forEach(btn => btn.classList.remove('selected'));
958
+ updateSelectedObjectType('None');
959
+ websocket.send(JSON.stringify({
960
+ type: 'tool_selected',
961
+ payload: { tool_type: 'None', username: window.USERNAME }
962
+ }));
963
+ ">🚫 Clear Tool</button>
964
+ """
965
+ st.markdown(tool_buttons_html, unsafe_allow_html=True)
966
 
967
  st.markdown("---")
968
  st.header("🗣�� Voice & User")
 
991
 
992
  with tab_world:
993
  st.header("Shared 3D World")
994
+ st.caption("Click to place objects with the selected tool. Right-click to delete. Changes are shared live!")
995
  current_file_basename = st.session_state.get('current_world_file', None)
996
  if current_file_basename:
997
  parsed = parse_world_filename(os.path.join(SAVED_WORLDS_DIR, current_file_basename))