File size: 1,415 Bytes
2475edf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f7eafd6
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# app.py
import streamlit as st
import streamlit.components.v1 as components
import os # Used to construct the file path reliably

# --- 1. Set Page Configuration ---
# This must be the first Streamlit command called
st.set_page_config(
    page_title="Three.js Game Viewer",
    layout="wide"  # Set the layout to wide mode
)

st.header("🎮 Basic Three.js Game Embed")
st.caption("Displays the content of index.html below.")

# --- 2. Define the path to your HTML file ---
# Assumes index.html is in the same directory as app.py
html_file_path = 'index.html'

# --- 3. Read the HTML file ---
try:
    with open(html_file_path, 'r', encoding='utf-8') as f:
        html_content = f.read()

    # --- 4. Embed the HTML into the Streamlit app ---
    # Adjust the height as needed for your specific game view
    components.html(
        html_content,
        height=700, # You might need to adjust this value
        scrolling=False # Set to True if your HTML content needs scrolling
    )

    st.sidebar.info("Use WASD or Arrow Keys inside the frame above to move the cube.")

except FileNotFoundError:
    st.error(f"Error: Could not find the file '{html_file_path}'.")
    st.warning("Please make sure the `index.html` file (containing the Three.js code) is in the same directory as this `app.py` script.")
except Exception as e:
    st.error(f"An error occurred while reading or embedding the HTML file: {e}")