File size: 4,328 Bytes
550acf8
 
 
 
edee69e
550acf8
 
0438bd7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
edee69e
0438bd7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
550acf8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0438bd7
 
 
 
 
 
 
 
 
 
 
550acf8
 
 
0438bd7
 
550acf8
 
0438bd7
550acf8
 
 
 
 
 
 
 
 
 
81ffa58
550acf8
 
0438bd7
81ffa58
550acf8
 
 
 
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
import streamlit as st
import streamlit.components.v1 as components
import random
import time
import os

# Load the initial HTML5 app
if not os.path.exists("chofko_ecosystem.html"):
    with open("chofko_ecosystem.html", "w") as f:
        f.write('''
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>Chofko's Diverse Ecosystem Simulator</title>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/aframe/1.2.0/aframe.min.js"></script>
    <style>
      .controls {
        position: absolute;
        bottom: 20px;
        left: 50%;
        transform: translateX(-50%);
        display: flex;
        gap: 10px;
      }
      .controls button {
        padding: 10px 20px;
        font-size: 16px;
        cursor: pointer;
      }
      #score {
        position: absolute;
        top: 20px;
        left: 20px;
        font-size: 24px;
        color: white;
        background-color: rgba(0,0,0,0.5);
        padding: 10px;
        border-radius: 5px;
      }
    </style>
  </head>
  <body>
    <a-scene>
      <a-assets>
        <img id="sky" src="/api/placeholder/1024/512" alt="surrealist sky">
      </a-assets>

      <a-sky src="#sky"></a-sky>

      <a-plane position="0 0 -4" rotation="-90 0 0" width="100" height="100" color="#7BC8A4"></a-plane>

      <a-entity id="entities"></a-entity>

      <a-entity id="camera" camera look-controls position="0 40 0" rotation="-90 0 0"></a-entity>
    </a-scene>

    <div id="score">Score: 0</div>

    <div class="controls">
      <button onmousedown="startMove('left')" onmouseup="stopMove('left')" ontouchstart="startMove('left')" ontouchend="stopMove('left')">Left</button>
      <button onmousedown="startMove('right')" onmouseup="stopMove('right')" ontouchstart="startMove('right')" ontouchend="stopMove('right')">Right</button>
      <button onmousedown="startMove('up')" onmouseup="stopMove('up')" ontouchstart="startMove('up')" ontouchend="stopMove('up')">Up</button>
      <button onmousedown="startMove('down')" onmouseup="stopMove('down')" ontouchstart="startMove('down')" ontouchend="stopMove('down')">Down</button>
      <button onclick="toggleSpeed()">Toggle Speed</button>
    </div>

    <script>
      // ... (Include the entire JavaScript code from the original HTML file here)
    </script>
  </body>
</html>
''')

with open("chofko_ecosystem.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'''
    new Entity(
        {random.uniform(-50, 50)},
        {random.uniform(-50, 50)},
        false,
        'a-sphere',
        '{random.choice(['male', 'female'])}',
        1
    );
    '''
    st.session_state.html_content = st.session_state.html_content.replace("createEntities();", f"createEntities();\n    {player_html}")

# Streamlit app
def main():
    st.set_page_config(page_title="Chofko's Diverse Ecosystem Simulator", layout="wide")
    st.title("Chofko's Diverse Ecosystem Simulator")

    # Add a new player button
    if st.button("Add New Player", key="add_player"):
        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", key="save_button"):
        st.session_state.html_content = new_html

    # Refresh button
    if st.button("Refresh", key="refresh_button"):
        st.experimental_rerun()

if __name__ == "__main__":
    main()