# app.py
import streamlit as st
import streamlit.components.v1 as components
import os
import json # To safely embed the python variable into JS
# --- 1. Set Page Configuration (Set first!) ---
st.set_page_config(
page_title="Three.js Editor",
layout="wide" # Use the full screen width
)
# --- Initialize Session State ---
if 'selected_object' not in st.session_state:
st.session_state.selected_object = 'None' # Default selection
# --- Sidebar Controls ---
with st.sidebar:
st.title("🛠️ Controls & State")
st.caption("Select an object type and click on the ground in the main view to place it.")
# Define available object types (keys should ideally match JS functions/identifiers)
object_types = ["None", "Simple House", "Tree", "Rock", "Fence Post"] # Add more as needed
# Selectbox to choose object type - this updates session_state on change
selected = st.selectbox(
"Select Object to Place:",
options=object_types,
key='selected_object' # Link to session state key
)
st.write("---")
st.header("Current State:")
st.write(f"Selected Object Type: **{st.session_state.selected_object}**")
# Add more state tracking here later if needed
st.info("Use WASD/Arrows in the main view if player movement is enabled in JS.")
# --- Main Area for the 3D View ---
st.header("🏗️ Three.js Primitive Builder")
# --- Load and Prepare HTML ---
html_file_path = 'index.html'
try:
with open(html_file_path, 'r', encoding='utf-8') as f:
html_template = f.read()
# --- Inject Python state into JavaScript ---
# We'll add a script tag to set a global JS variable before the main script runs
js_injection_script = f"""
"""
# Insert the injection script just before the closing or starting