Rev1

#1
by awacke1 - opened
Owner

The program below should generate the aframe html5 and save it if the file doesnt exist yet. Also there is a error on color line for player_html. Fix those and show full code listing. import streamlit as st
import streamlit.components.v1 as components
import random
import string
import time

Load the initial HTML5 app

with open("aframe_app.html", "r") as f:
initial_html = f.read()

Initialize session state

if "html_content" not in st.session_state:
st.session_state.html_content = initial_html
if "player_names" not in st.session_state:
st.session_state.player_names = []

Function to generate a random name for a new player

def generate_player_name():
adjectives = ["Adventurous", "Brave", "Curious", "Daring", "Fearless", "Intrepid", "Valiant"]
nouns = ["Explorer", "Wanderer", "Pathfinder", "Trailblazer", "Voyager", "Wayfarer", "Traveler"]
return random.choice(adjectives) + " " + random.choice(nouns)

Function to add a new player to the scene

def add_player():
player_name = generate_player_name()
while player_name in st.session_state.player_names:
player_name = generate_player_name()
st.session_state.player_names.append(player_name)
player_html = f''
st.session_state.html_content = st.session_state.html_content.replace("", player_html + "\n")

Streamlit app

def main():
st.set_page_config(page_title="3D House Exploration", layout="wide")
st.title("3D House Exploration")

# Add a new player button
if st.button("Join Game"):
    add_player()

# Display the HTML5 app
components.html(st.session_state.html_content, height=800)

# Editor for HTML5 content
st.subheader("Edit Content")
new_html = st.text_area("HTML5 Content", st.session_state.html_content, height=300)

# Save button
if st.button("Save"):
    st.session_state.html_content = new_html

# Refresh timer
last_refresh = st.button("Refresh")
if last_refresh:
    st.experimental_rerun()

if not st.button("Refresh", key="refresh_button"):
    refresh_timer = st.empty()
    while True:
        time.sleep(5)
        refresh_timer.text(f"Refreshing in {5 - int(time.time()) % 5} seconds...")
        if st.button("Refresh", key="refresh_button"):
            st.experimental_rerun()
            break

if name == "main":
main()

Sign up or log in to comment